blob: 88a519d339bd2adc713d92a27a087934b9a664eb [file] [log] [blame]
Taniya Dasc868a2e2012-01-03 10:18:47 +05301/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Chintan Pandyacf467fc2011-12-01 17:11:11 +05302 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <asm/mach-types.h>
15#include <asm/mach/mmc.h>
16#include <linux/regulator/consumer.h>
17#include <mach/gpio.h>
18#include <mach/gpiomux.h>
19#include <mach/board.h>
20
21#include "devices.h"
22#include "board-msm7627a.h"
23
24#if (defined(CONFIG_MMC_MSM_SDC1_SUPPORT)\
25 || defined(CONFIG_MMC_MSM_SDC2_SUPPORT)\
26 || defined(CONFIG_MMC_MSM_SDC3_SUPPORT)\
27 || defined(CONFIG_MMC_MSM_SDC4_SUPPORT))
28
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +053029#define MAX_SDCC_CONTROLLER 4
Chintan Pandyacf467fc2011-12-01 17:11:11 +053030static unsigned long vreg_sts, gpio_sts;
31
32struct sdcc_gpio {
33 struct msm_gpio *cfg_data;
34 uint32_t size;
35 struct msm_gpio *sleep_cfg_data;
36};
37
38/**
39 * Due to insufficient drive strengths for SDC GPIO lines some old versioned
40 * SD/MMC cards may cause data CRC errors. Hence, set optimal values
41 * for SDC slots based on timing closure and marginality. SDC1 slot
42 * require higher value since it should handle bad signal quality due
43 * to size of T-flash adapters.
44 */
45static struct msm_gpio sdc1_cfg_data[] = {
46 {GPIO_CFG(51, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_14MA),
47 "sdc1_dat_3"},
48 {GPIO_CFG(52, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_14MA),
49 "sdc1_dat_2"},
50 {GPIO_CFG(53, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_14MA),
51 "sdc1_dat_1"},
52 {GPIO_CFG(54, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_14MA),
53 "sdc1_dat_0"},
54 {GPIO_CFG(55, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_14MA),
55 "sdc1_cmd"},
56 {GPIO_CFG(56, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_14MA),
57 "sdc1_clk"},
58};
59
60static struct msm_gpio sdc2_cfg_data[] = {
61 {GPIO_CFG(62, 2, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA),
62 "sdc2_clk"},
63 {GPIO_CFG(63, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
64 "sdc2_cmd"},
65 {GPIO_CFG(64, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
66 "sdc2_dat_3"},
67 {GPIO_CFG(65, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
68 "sdc2_dat_2"},
69 {GPIO_CFG(66, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
70 "sdc2_dat_1"},
71 {GPIO_CFG(67, 2, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
72 "sdc2_dat_0"},
73};
74
75static struct msm_gpio sdc2_sleep_cfg_data[] = {
Sujit Reddy Thumma4a6d84b2012-02-15 19:40:45 +053076 {GPIO_CFG(62, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
Chintan Pandyacf467fc2011-12-01 17:11:11 +053077 "sdc2_clk"},
Sujit Reddy Thumma4a6d84b2012-02-15 19:40:45 +053078 {GPIO_CFG(63, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA),
Chintan Pandyacf467fc2011-12-01 17:11:11 +053079 "sdc2_cmd"},
Sujit Reddy Thumma4a6d84b2012-02-15 19:40:45 +053080 {GPIO_CFG(64, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA),
Chintan Pandyacf467fc2011-12-01 17:11:11 +053081 "sdc2_dat_3"},
Sujit Reddy Thumma4a6d84b2012-02-15 19:40:45 +053082 {GPIO_CFG(65, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA),
Chintan Pandyacf467fc2011-12-01 17:11:11 +053083 "sdc2_dat_2"},
Sujit Reddy Thumma4a6d84b2012-02-15 19:40:45 +053084 {GPIO_CFG(66, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA),
Chintan Pandyacf467fc2011-12-01 17:11:11 +053085 "sdc2_dat_1"},
Sujit Reddy Thumma4a6d84b2012-02-15 19:40:45 +053086 {GPIO_CFG(67, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA),
Chintan Pandyacf467fc2011-12-01 17:11:11 +053087 "sdc2_dat_0"},
88};
89static struct msm_gpio sdc3_cfg_data[] = {
90 {GPIO_CFG(88, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA),
91 "sdc3_clk"},
92 {GPIO_CFG(89, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
93 "sdc3_cmd"},
94 {GPIO_CFG(90, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
95 "sdc3_dat_3"},
96 {GPIO_CFG(91, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
97 "sdc3_dat_2"},
98 {GPIO_CFG(92, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
99 "sdc3_dat_1"},
100 {GPIO_CFG(93, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
101 "sdc3_dat_0"},
102#ifdef CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT
103 {GPIO_CFG(19, 3, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
104 "sdc3_dat_7"},
105 {GPIO_CFG(20, 3, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
106 "sdc3_dat_6"},
107 {GPIO_CFG(21, 3, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
108 "sdc3_dat_5"},
109 {GPIO_CFG(108, 3, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
110 "sdc3_dat_4"},
111#endif
112};
113
114static struct msm_gpio sdc4_cfg_data[] = {
115 {GPIO_CFG(19, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
116 "sdc4_dat_3"},
117 {GPIO_CFG(20, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
118 "sdc4_dat_2"},
119 {GPIO_CFG(21, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
120 "sdc4_dat_1"},
121 {GPIO_CFG(107, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
122 "sdc4_cmd"},
123 {GPIO_CFG(108, 1, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_10MA),
124 "sdc4_dat_0"},
125 {GPIO_CFG(109, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_8MA),
126 "sdc4_clk"},
127};
128
129static struct sdcc_gpio sdcc_cfg_data[] = {
130 {
131 .cfg_data = sdc1_cfg_data,
132 .size = ARRAY_SIZE(sdc1_cfg_data),
133 },
134 {
135 .cfg_data = sdc2_cfg_data,
136 .size = ARRAY_SIZE(sdc2_cfg_data),
137 .sleep_cfg_data = sdc2_sleep_cfg_data,
138 },
139 {
140 .cfg_data = sdc3_cfg_data,
141 .size = ARRAY_SIZE(sdc3_cfg_data),
142 },
143 {
144 .cfg_data = sdc4_cfg_data,
145 .size = ARRAY_SIZE(sdc4_cfg_data),
146 },
147};
148
149static int gpio_sdc1_hw_det = 85;
150static void gpio_sdc1_config(void)
151{
Taniya Dasc868a2e2012-01-03 10:18:47 +0530152 if (machine_is_msm7627a_qrd1() || machine_is_msm7627a_evb())
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530153 gpio_sdc1_hw_det = 42;
154}
155
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +0530156static struct regulator *sdcc_vreg_data[MAX_SDCC_CONTROLLER];
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530157static int msm_sdcc_setup_gpio(int dev_id, unsigned int enable)
158{
159 int rc = 0;
160 struct sdcc_gpio *curr;
161
162 curr = &sdcc_cfg_data[dev_id - 1];
163 if (!(test_bit(dev_id, &gpio_sts)^enable))
164 return rc;
165
166 if (enable) {
167 set_bit(dev_id, &gpio_sts);
168 rc = msm_gpios_request_enable(curr->cfg_data, curr->size);
169 if (rc)
170 pr_err("%s: Failed to turn on GPIOs for slot %d\n",
171 __func__, dev_id);
172 } else {
173 clear_bit(dev_id, &gpio_sts);
174 if (curr->sleep_cfg_data) {
175 rc = msm_gpios_enable(curr->sleep_cfg_data, curr->size);
176 msm_gpios_free(curr->sleep_cfg_data, curr->size);
177 return rc;
178 }
179 msm_gpios_disable_free(curr->cfg_data, curr->size);
180 }
181 return rc;
182}
183
184static int msm_sdcc_setup_vreg(int dev_id, unsigned int enable)
185{
186 int rc = 0;
187 struct regulator *curr = sdcc_vreg_data[dev_id - 1];
188
189 if (test_bit(dev_id, &vreg_sts) == enable)
190 return 0;
191
192 if (!curr)
193 return -ENODEV;
194
195 if (IS_ERR(curr))
196 return PTR_ERR(curr);
197
198 if (enable) {
199 set_bit(dev_id, &vreg_sts);
200
201 rc = regulator_enable(curr);
202 if (rc)
203 pr_err("%s: could not enable regulator: %d\n",
204 __func__, rc);
205 } else {
206 clear_bit(dev_id, &vreg_sts);
207
208 rc = regulator_disable(curr);
209 if (rc)
210 pr_err("%s: could not disable regulator: %d\n",
211 __func__, rc);
212 }
213 return rc;
214}
215
216static uint32_t msm_sdcc_setup_power(struct device *dv, unsigned int vdd)
217{
218 int rc = 0;
219 struct platform_device *pdev;
220
221 pdev = container_of(dv, struct platform_device, dev);
222
223 rc = msm_sdcc_setup_gpio(pdev->id, !!vdd);
224 if (rc)
225 goto out;
226
227 rc = msm_sdcc_setup_vreg(pdev->id, !!vdd);
228out:
229 return rc;
230}
231
232#if defined(CONFIG_MMC_MSM_SDC1_SUPPORT) \
233 && defined(CONFIG_MMC_MSM_CARD_HW_DETECTION)
234static unsigned int msm7627a_sdcc_slot_status(struct device *dev)
235{
236 int status;
237
238 status = gpio_tlmm_config(GPIO_CFG(gpio_sdc1_hw_det, 2, GPIO_CFG_INPUT,
239 GPIO_CFG_PULL_UP, GPIO_CFG_8MA),
240 GPIO_CFG_ENABLE);
241 if (status)
242 pr_err("%s:Failed to configure tlmm for GPIO %d\n", __func__,
243 gpio_sdc1_hw_det);
244
245 status = gpio_request(gpio_sdc1_hw_det, "SD_HW_Detect");
246 if (status) {
247 pr_err("%s:Failed to request GPIO %d\n", __func__,
248 gpio_sdc1_hw_det);
249 } else {
250 status = gpio_direction_input(gpio_sdc1_hw_det);
251 if (!status) {
Taniya Dasc868a2e2012-01-03 10:18:47 +0530252 if (machine_is_msm7627a_qrd1() ||
253 machine_is_msm7627a_evb())
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530254 status = !gpio_get_value(gpio_sdc1_hw_det);
255 else
256 status = gpio_get_value(gpio_sdc1_hw_det);
257 }
258 gpio_free(gpio_sdc1_hw_det);
259 }
260 return status;
261}
262#endif
263
264#ifdef CONFIG_MMC_MSM_SDC1_SUPPORT
265static struct mmc_platform_data sdc1_plat_data = {
266 .ocr_mask = MMC_VDD_28_29,
267 .translate_vdd = msm_sdcc_setup_power,
268 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
269 .msmsdcc_fmin = 144000,
270 .msmsdcc_fmid = 24576000,
271 .msmsdcc_fmax = 49152000,
272#ifdef CONFIG_MMC_MSM_CARD_HW_DETECTION
273 .status = msm7627a_sdcc_slot_status,
274 .irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
275#endif
276};
277#endif
278
279#ifdef CONFIG_MMC_MSM_SDC2_SUPPORT
280static struct mmc_platform_data sdc2_plat_data = {
281 /*
282 * SDC2 supports only 1.8V, claim for 2.85V range is just
283 * for allowing buggy cards who advertise 2.8V even though
284 * they can operate at 1.8V supply.
285 */
286 .ocr_mask = MMC_VDD_28_29 | MMC_VDD_165_195,
287 .translate_vdd = msm_sdcc_setup_power,
288 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
289#ifdef CONFIG_MMC_MSM_SDIO_SUPPORT
290 .sdiowakeup_irq = MSM_GPIO_TO_INT(66),
291#endif
292 .msmsdcc_fmin = 144000,
293 .msmsdcc_fmid = 24576000,
294 .msmsdcc_fmax = 49152000,
295#ifdef CONFIG_MMC_MSM_SDC2_DUMMY52_REQUIRED
296 .dummy52_required = 1,
297#endif
298};
299#endif
300
301#ifdef CONFIG_MMC_MSM_SDC3_SUPPORT
302static struct mmc_platform_data sdc3_plat_data = {
303 .ocr_mask = MMC_VDD_28_29,
304 .translate_vdd = msm_sdcc_setup_power,
305#ifdef CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT
306 .mmc_bus_width = MMC_CAP_8_BIT_DATA,
307#else
308 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
309#endif
310 .msmsdcc_fmin = 144000,
311 .msmsdcc_fmid = 24576000,
312 .msmsdcc_fmax = 49152000,
313 .nonremovable = 1,
314};
315#endif
316
317#if (defined(CONFIG_MMC_MSM_SDC4_SUPPORT)\
318 && !defined(CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT))
319static struct mmc_platform_data sdc4_plat_data = {
320 .ocr_mask = MMC_VDD_28_29,
321 .translate_vdd = msm_sdcc_setup_power,
322 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
323 .msmsdcc_fmin = 144000,
324 .msmsdcc_fmid = 24576000,
325 .msmsdcc_fmax = 49152000,
326};
327#endif
328
329static int __init mmc_regulator_init(int sdcc_no, const char *supply, int uV)
330{
331 int rc;
332
333 BUG_ON(sdcc_no < 1 || sdcc_no > 4);
334
335 sdcc_no--;
336
337 sdcc_vreg_data[sdcc_no] = regulator_get(NULL, supply);
338
339 if (IS_ERR(sdcc_vreg_data[sdcc_no])) {
340 rc = PTR_ERR(sdcc_vreg_data[sdcc_no]);
341 pr_err("%s: could not get regulator \"%s\": %d\n",
342 __func__, supply, rc);
343 goto out;
344 }
345
346 rc = regulator_set_voltage(sdcc_vreg_data[sdcc_no], uV, uV);
347
348 if (rc) {
349 pr_err("%s: could not set voltage for \"%s\" to %d uV: %d\n",
350 __func__, supply, uV, rc);
351 goto reg_free;
352 }
353
354 return rc;
355
356reg_free:
357 regulator_put(sdcc_vreg_data[sdcc_no]);
358out:
359 sdcc_vreg_data[sdcc_no] = NULL;
360 return rc;
361}
362
363void __init msm7627a_init_mmc(void)
364{
365 /* eMMC slot */
366#ifdef CONFIG_MMC_MSM_SDC3_SUPPORT
367 if (mmc_regulator_init(3, "emmc", 3000000))
368 return;
369 msm_add_sdcc(3, &sdc3_plat_data);
370#endif
371 /* Micro-SD slot */
372#ifdef CONFIG_MMC_MSM_SDC1_SUPPORT
373 gpio_sdc1_config();
374 if (mmc_regulator_init(1, "mmc", 2850000))
375 return;
376 sdc1_plat_data.status_irq = MSM_GPIO_TO_INT(gpio_sdc1_hw_det);
377 msm_add_sdcc(1, &sdc1_plat_data);
378#endif
379 /* SDIO WLAN slot */
380#ifdef CONFIG_MMC_MSM_SDC2_SUPPORT
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +0530381 if (mmc_regulator_init(2, "smps3", 1800000))
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530382 return;
383 msm_add_sdcc(2, &sdc2_plat_data);
384#endif
385 /* Not Used */
386#if (defined(CONFIG_MMC_MSM_SDC4_SUPPORT)\
387 && !defined(CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT))
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +0530388 if (mmc_regulator_init(4, "smps3", 1800000))
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530389 return;
390 msm_add_sdcc(4, &sdc4_plat_data);
391#endif
392}
393#endif