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