blob: e4ee52e6d7946ad5400365ba2c0d64dd9510302f [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{
Chintan Pandyaf4ad4002012-02-28 19:49:03 +0530153 if (machine_is_msm7627a_qrd1() || machine_is_msm7627a_evb()
154 || machine_is_msm8625_evb())
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530155 gpio_sdc1_hw_det = 42;
156}
157
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +0530158static struct regulator *sdcc_vreg_data[MAX_SDCC_CONTROLLER];
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530159static int msm_sdcc_setup_gpio(int dev_id, unsigned int enable)
160{
161 int rc = 0;
162 struct sdcc_gpio *curr;
163
164 curr = &sdcc_cfg_data[dev_id - 1];
165 if (!(test_bit(dev_id, &gpio_sts)^enable))
166 return rc;
167
168 if (enable) {
169 set_bit(dev_id, &gpio_sts);
170 rc = msm_gpios_request_enable(curr->cfg_data, curr->size);
171 if (rc)
172 pr_err("%s: Failed to turn on GPIOs for slot %d\n",
173 __func__, dev_id);
174 } else {
175 clear_bit(dev_id, &gpio_sts);
176 if (curr->sleep_cfg_data) {
177 rc = msm_gpios_enable(curr->sleep_cfg_data, curr->size);
178 msm_gpios_free(curr->sleep_cfg_data, curr->size);
179 return rc;
180 }
181 msm_gpios_disable_free(curr->cfg_data, curr->size);
182 }
183 return rc;
184}
185
186static int msm_sdcc_setup_vreg(int dev_id, unsigned int enable)
187{
188 int rc = 0;
189 struct regulator *curr = sdcc_vreg_data[dev_id - 1];
190
191 if (test_bit(dev_id, &vreg_sts) == enable)
192 return 0;
193
194 if (!curr)
195 return -ENODEV;
196
197 if (IS_ERR(curr))
198 return PTR_ERR(curr);
199
200 if (enable) {
201 set_bit(dev_id, &vreg_sts);
202
203 rc = regulator_enable(curr);
204 if (rc)
205 pr_err("%s: could not enable regulator: %d\n",
206 __func__, rc);
207 } else {
208 clear_bit(dev_id, &vreg_sts);
209
210 rc = regulator_disable(curr);
211 if (rc)
212 pr_err("%s: could not disable regulator: %d\n",
213 __func__, rc);
214 }
215 return rc;
216}
217
218static uint32_t msm_sdcc_setup_power(struct device *dv, unsigned int vdd)
219{
220 int rc = 0;
221 struct platform_device *pdev;
222
223 pdev = container_of(dv, struct platform_device, dev);
224
225 rc = msm_sdcc_setup_gpio(pdev->id, !!vdd);
226 if (rc)
227 goto out;
228
229 rc = msm_sdcc_setup_vreg(pdev->id, !!vdd);
230out:
231 return rc;
232}
233
234#if defined(CONFIG_MMC_MSM_SDC1_SUPPORT) \
235 && defined(CONFIG_MMC_MSM_CARD_HW_DETECTION)
236static unsigned int msm7627a_sdcc_slot_status(struct device *dev)
237{
238 int status;
239
240 status = gpio_tlmm_config(GPIO_CFG(gpio_sdc1_hw_det, 2, GPIO_CFG_INPUT,
241 GPIO_CFG_PULL_UP, GPIO_CFG_8MA),
242 GPIO_CFG_ENABLE);
243 if (status)
244 pr_err("%s:Failed to configure tlmm for GPIO %d\n", __func__,
245 gpio_sdc1_hw_det);
246
247 status = gpio_request(gpio_sdc1_hw_det, "SD_HW_Detect");
248 if (status) {
249 pr_err("%s:Failed to request GPIO %d\n", __func__,
250 gpio_sdc1_hw_det);
251 } else {
252 status = gpio_direction_input(gpio_sdc1_hw_det);
253 if (!status) {
Taniya Dasc868a2e2012-01-03 10:18:47 +0530254 if (machine_is_msm7627a_qrd1() ||
Chintan Pandyaf4ad4002012-02-28 19:49:03 +0530255 machine_is_msm7627a_evb() ||
256 machine_is_msm8625_evb())
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530257 status = !gpio_get_value(gpio_sdc1_hw_det);
258 else
259 status = gpio_get_value(gpio_sdc1_hw_det);
260 }
261 gpio_free(gpio_sdc1_hw_det);
262 }
263 return status;
264}
265#endif
266
267#ifdef CONFIG_MMC_MSM_SDC1_SUPPORT
268static struct mmc_platform_data sdc1_plat_data = {
269 .ocr_mask = MMC_VDD_28_29,
270 .translate_vdd = msm_sdcc_setup_power,
271 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
272 .msmsdcc_fmin = 144000,
273 .msmsdcc_fmid = 24576000,
274 .msmsdcc_fmax = 49152000,
275#ifdef CONFIG_MMC_MSM_CARD_HW_DETECTION
276 .status = msm7627a_sdcc_slot_status,
277 .irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
278#endif
279};
280#endif
281
282#ifdef CONFIG_MMC_MSM_SDC2_SUPPORT
283static struct mmc_platform_data sdc2_plat_data = {
284 /*
285 * SDC2 supports only 1.8V, claim for 2.85V range is just
286 * for allowing buggy cards who advertise 2.8V even though
287 * they can operate at 1.8V supply.
288 */
289 .ocr_mask = MMC_VDD_28_29 | MMC_VDD_165_195,
290 .translate_vdd = msm_sdcc_setup_power,
291 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
292#ifdef CONFIG_MMC_MSM_SDIO_SUPPORT
293 .sdiowakeup_irq = MSM_GPIO_TO_INT(66),
294#endif
295 .msmsdcc_fmin = 144000,
296 .msmsdcc_fmid = 24576000,
297 .msmsdcc_fmax = 49152000,
298#ifdef CONFIG_MMC_MSM_SDC2_DUMMY52_REQUIRED
299 .dummy52_required = 1,
300#endif
301};
302#endif
303
304#ifdef CONFIG_MMC_MSM_SDC3_SUPPORT
305static struct mmc_platform_data sdc3_plat_data = {
306 .ocr_mask = MMC_VDD_28_29,
307 .translate_vdd = msm_sdcc_setup_power,
308#ifdef CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT
309 .mmc_bus_width = MMC_CAP_8_BIT_DATA,
310#else
311 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
312#endif
313 .msmsdcc_fmin = 144000,
314 .msmsdcc_fmid = 24576000,
315 .msmsdcc_fmax = 49152000,
316 .nonremovable = 1,
317};
318#endif
319
320#if (defined(CONFIG_MMC_MSM_SDC4_SUPPORT)\
321 && !defined(CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT))
322static struct mmc_platform_data sdc4_plat_data = {
323 .ocr_mask = MMC_VDD_28_29,
324 .translate_vdd = msm_sdcc_setup_power,
325 .mmc_bus_width = MMC_CAP_4_BIT_DATA,
326 .msmsdcc_fmin = 144000,
327 .msmsdcc_fmid = 24576000,
328 .msmsdcc_fmax = 49152000,
329};
330#endif
331
332static int __init mmc_regulator_init(int sdcc_no, const char *supply, int uV)
333{
334 int rc;
335
336 BUG_ON(sdcc_no < 1 || sdcc_no > 4);
337
338 sdcc_no--;
339
340 sdcc_vreg_data[sdcc_no] = regulator_get(NULL, supply);
341
342 if (IS_ERR(sdcc_vreg_data[sdcc_no])) {
343 rc = PTR_ERR(sdcc_vreg_data[sdcc_no]);
344 pr_err("%s: could not get regulator \"%s\": %d\n",
345 __func__, supply, rc);
346 goto out;
347 }
348
349 rc = regulator_set_voltage(sdcc_vreg_data[sdcc_no], uV, uV);
350
351 if (rc) {
352 pr_err("%s: could not set voltage for \"%s\" to %d uV: %d\n",
353 __func__, supply, uV, rc);
354 goto reg_free;
355 }
356
357 return rc;
358
359reg_free:
360 regulator_put(sdcc_vreg_data[sdcc_no]);
361out:
362 sdcc_vreg_data[sdcc_no] = NULL;
363 return rc;
364}
365
366void __init msm7627a_init_mmc(void)
367{
368 /* eMMC slot */
369#ifdef CONFIG_MMC_MSM_SDC3_SUPPORT
370 if (mmc_regulator_init(3, "emmc", 3000000))
371 return;
Sujit Reddy Thummaca0c1062012-02-24 14:47:05 +0530372 sdc3_plat_data.swfi_latency = msm7627a_power_collapse_latency(
373 MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT);
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530374 msm_add_sdcc(3, &sdc3_plat_data);
375#endif
376 /* Micro-SD slot */
377#ifdef CONFIG_MMC_MSM_SDC1_SUPPORT
378 gpio_sdc1_config();
379 if (mmc_regulator_init(1, "mmc", 2850000))
380 return;
381 sdc1_plat_data.status_irq = MSM_GPIO_TO_INT(gpio_sdc1_hw_det);
Sujit Reddy Thummaca0c1062012-02-24 14:47:05 +0530382 sdc1_plat_data.swfi_latency = msm7627a_power_collapse_latency(
383 MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT);
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530384 msm_add_sdcc(1, &sdc1_plat_data);
385#endif
386 /* SDIO WLAN slot */
387#ifdef CONFIG_MMC_MSM_SDC2_SUPPORT
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +0530388 if (mmc_regulator_init(2, "smps3", 1800000))
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530389 return;
390 msm_add_sdcc(2, &sdc2_plat_data);
391#endif
392 /* Not Used */
393#if (defined(CONFIG_MMC_MSM_SDC4_SUPPORT)\
394 && !defined(CONFIG_MMC_MSM_SDC3_8_BIT_SUPPORT))
Sujit Reddy Thumma464a1792012-02-17 15:54:13 +0530395 if (mmc_regulator_init(4, "smps3", 1800000))
Chintan Pandyacf467fc2011-12-01 17:11:11 +0530396 return;
397 msm_add_sdcc(4, &sdc4_plat_data);
398#endif
399}
400#endif