blob: f7109d5f4ab1a08aa39c2453b2e4b8282d6291ce [file] [log] [blame]
Daniel Walker42a2c212010-03-30 16:11:57 -07001/* linux/arch/arm/mach-msm/board-trout-mmc.c
2** Author: Brian Swetland <swetland@google.com>
3*/
Russell King2f8163b2011-07-26 10:53:52 +01004#include <linux/gpio.h>
Daniel Walker42a2c212010-03-30 16:11:57 -07005#include <linux/kernel.h>
6#include <linux/init.h>
7#include <linux/platform_device.h>
8#include <linux/delay.h>
9#include <linux/mmc/host.h>
10#include <linux/mmc/sdio_ids.h>
11#include <linux/err.h>
12#include <linux/debugfs.h>
13
Daniel Walker42a2c212010-03-30 16:11:57 -070014#include <asm/io.h>
15
16#include <mach/vreg.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070017#include <mach/proc_comm.h>
Daniel Walker42a2c212010-03-30 16:11:57 -070018#include <mach/mmc.h>
19
20#include "devices.h"
21
22#include "board-trout.h"
23
Daniel Walker42a2c212010-03-30 16:11:57 -070024#define DEBUG_SDSLOT_VDD 1
25
Daniel Walker42a2c212010-03-30 16:11:57 -070026/* ---- COMMON ---- */
27static void config_gpio_table(uint32_t *table, int len)
28{
29 int n;
30 unsigned id;
31 for(n = 0; n < len; n++) {
32 id = table[n];
33 msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &id, 0);
34 }
35}
36
37/* ---- SDCARD ---- */
38
39static uint32_t sdcard_on_gpio_table[] = {
40 PCOM_GPIO_CFG(62, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA), /* CLK */
41 PCOM_GPIO_CFG(63, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* CMD */
42 PCOM_GPIO_CFG(64, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT3 */
43 PCOM_GPIO_CFG(65, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT2 */
44 PCOM_GPIO_CFG(66, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT1 */
45 PCOM_GPIO_CFG(67, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT0 */
46};
47
48static uint32_t sdcard_off_gpio_table[] = {
49 PCOM_GPIO_CFG(62, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CLK */
50 PCOM_GPIO_CFG(63, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CMD */
51 PCOM_GPIO_CFG(64, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT3 */
52 PCOM_GPIO_CFG(65, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT2 */
53 PCOM_GPIO_CFG(66, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT1 */
54 PCOM_GPIO_CFG(67, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT0 */
55};
56
57static uint opt_disable_sdcard;
58
59static int __init trout_disablesdcard_setup(char *str)
60{
61 int cal = simple_strtol(str, NULL, 0);
62
63 opt_disable_sdcard = cal;
64 return 1;
65}
66
67__setup("board_trout.disable_sdcard=", trout_disablesdcard_setup);
68
69static struct vreg *vreg_sdslot; /* SD slot power */
70
71struct mmc_vdd_xlat {
72 int mask;
73 int level;
74};
75
76static struct mmc_vdd_xlat mmc_vdd_table[] = {
77 { MMC_VDD_165_195, 1800 },
78 { MMC_VDD_20_21, 2050 },
79 { MMC_VDD_21_22, 2150 },
80 { MMC_VDD_22_23, 2250 },
81 { MMC_VDD_23_24, 2350 },
82 { MMC_VDD_24_25, 2450 },
83 { MMC_VDD_25_26, 2550 },
84 { MMC_VDD_26_27, 2650 },
85 { MMC_VDD_27_28, 2750 },
86 { MMC_VDD_28_29, 2850 },
87 { MMC_VDD_29_30, 2950 },
88};
89
90static unsigned int sdslot_vdd = 0xffffffff;
91static unsigned int sdslot_vreg_enabled;
92
93static uint32_t trout_sdslot_switchvdd(struct device *dev, unsigned int vdd)
94{
95 int i, rc;
96
97 BUG_ON(!vreg_sdslot);
98
99 if (vdd == sdslot_vdd)
100 return 0;
101
102 sdslot_vdd = vdd;
103
104 if (vdd == 0) {
105#if DEBUG_SDSLOT_VDD
106 printk("%s: Disabling SD slot power\n", __func__);
107#endif
108 config_gpio_table(sdcard_off_gpio_table,
109 ARRAY_SIZE(sdcard_off_gpio_table));
110 vreg_disable(vreg_sdslot);
111 sdslot_vreg_enabled = 0;
112 return 0;
113 }
114
115 if (!sdslot_vreg_enabled) {
116 rc = vreg_enable(vreg_sdslot);
117 if (rc) {
118 printk(KERN_ERR "%s: Error enabling vreg (%d)\n",
119 __func__, rc);
120 }
121 config_gpio_table(sdcard_on_gpio_table,
122 ARRAY_SIZE(sdcard_on_gpio_table));
123 sdslot_vreg_enabled = 1;
124 }
125
126 for (i = 0; i < ARRAY_SIZE(mmc_vdd_table); i++) {
127 if (mmc_vdd_table[i].mask == (1 << vdd)) {
128#if DEBUG_SDSLOT_VDD
129 printk("%s: Setting level to %u\n",
130 __func__, mmc_vdd_table[i].level);
131#endif
132 rc = vreg_set_level(vreg_sdslot,
133 mmc_vdd_table[i].level);
134 if (rc) {
135 printk(KERN_ERR
136 "%s: Error setting vreg level (%d)\n",
137 __func__, rc);
138 }
139 return 0;
140 }
141 }
142
143 printk(KERN_ERR "%s: Invalid VDD %d specified\n", __func__, vdd);
144 return 0;
145}
146
147static unsigned int trout_sdslot_status(struct device *dev)
148{
149 unsigned int status;
150
151 status = (unsigned int) gpio_get_value(TROUT_GPIO_SDMC_CD_N);
152 return (!status);
153}
154
155#define TROUT_MMC_VDD MMC_VDD_165_195 | MMC_VDD_20_21 | MMC_VDD_21_22 \
156 | MMC_VDD_22_23 | MMC_VDD_23_24 | MMC_VDD_24_25 \
157 | MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 \
158 | MMC_VDD_28_29 | MMC_VDD_29_30
159
Sahitya Tummalab5d643d2010-07-29 16:55:34 +0530160static struct msm_mmc_platform_data trout_sdslot_data = {
Daniel Walker42a2c212010-03-30 16:11:57 -0700161 .ocr_mask = TROUT_MMC_VDD,
162 .status = trout_sdslot_status,
163 .translate_vdd = trout_sdslot_switchvdd,
164};
165
166int __init trout_init_mmc(unsigned int sys_rev)
167{
168 sdslot_vreg_enabled = 0;
169
170 vreg_sdslot = vreg_get(0, "gp6");
171 if (IS_ERR(vreg_sdslot))
172 return PTR_ERR(vreg_sdslot);
173
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100174 irq_set_irq_wake(TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 1);
Daniel Walker42a2c212010-03-30 16:11:57 -0700175
176 if (!opt_disable_sdcard)
177 msm_add_sdcc(2, &trout_sdslot_data,
178 TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 0);
179 else
180 printk(KERN_INFO "trout: SD-Card interface disabled\n");
181 return 0;
182}
183