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