2 * linux/arch/arm/mach-omap2/hsmmc.c
4 * Copyright (C) 2007-2008 Texas Instruments
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: Texas Instruments
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/string.h>
15 #include <linux/delay.h>
16 #include <linux/gpio.h>
17 #include <linux/platform_data/gpio-omap.h>
20 #include "omap_device.h"
28 #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
30 static u16 control_pbias_offset
;
31 static u16 control_devconf1_offset
;
33 #define HSMMC_NAME_LEN 9
35 #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
37 static int hsmmc_get_context_loss(struct device
*dev
)
39 return omap_pm_get_dev_context_loss_count(dev
);
43 #define hsmmc_get_context_loss NULL
46 static void omap_hsmmc1_before_set_reg(struct device
*dev
, int slot
,
47 int power_on
, int vdd
)
50 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
52 if (mmc
->slots
[0].remux
)
53 mmc
->slots
[0].remux(dev
, slot
, power_on
);
56 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
57 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
58 * 1.8V and 3.0V modes, controlled by the PBIAS register.
60 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
61 * is most naturally TWL VSIM; those pins also use PBIAS.
63 * FIXME handle VMMC1A as needed ...
66 if (cpu_is_omap2430()) {
67 reg
= omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1
);
68 if ((1 << vdd
) >= MMC_VDD_30_31
)
69 reg
|= OMAP243X_MMC1_ACTIVE_OVERWRITE
;
71 reg
&= ~OMAP243X_MMC1_ACTIVE_OVERWRITE
;
72 omap_ctrl_writel(reg
, OMAP243X_CONTROL_DEVCONF1
);
75 if (mmc
->slots
[0].internal_clock
) {
76 reg
= omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0
);
77 reg
|= OMAP2_MMCSDIO1ADPCLKISEL
;
78 omap_ctrl_writel(reg
, OMAP2_CONTROL_DEVCONF0
);
81 reg
= omap_ctrl_readl(control_pbias_offset
);
82 if (cpu_is_omap3630()) {
83 /* Set MMC I/O to 52Mhz */
84 prog_io
= omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1
);
85 prog_io
|= OMAP3630_PRG_SDMMC1_SPEEDCTRL
;
86 omap_ctrl_writel(prog_io
, OMAP343X_CONTROL_PROG_IO1
);
88 reg
|= OMAP2_PBIASSPEEDCTRL0
;
90 reg
&= ~OMAP2_PBIASLITEPWRDNZ0
;
91 omap_ctrl_writel(reg
, control_pbias_offset
);
93 reg
= omap_ctrl_readl(control_pbias_offset
);
94 reg
&= ~OMAP2_PBIASLITEPWRDNZ0
;
95 omap_ctrl_writel(reg
, control_pbias_offset
);
99 static void omap_hsmmc1_after_set_reg(struct device
*dev
, int slot
,
100 int power_on
, int vdd
)
104 /* 100ms delay required for PBIAS configuration */
108 reg
= omap_ctrl_readl(control_pbias_offset
);
109 reg
|= (OMAP2_PBIASLITEPWRDNZ0
| OMAP2_PBIASSPEEDCTRL0
);
110 if ((1 << vdd
) <= MMC_VDD_165_195
)
111 reg
&= ~OMAP2_PBIASLITEVMODE0
;
113 reg
|= OMAP2_PBIASLITEVMODE0
;
114 omap_ctrl_writel(reg
, control_pbias_offset
);
116 reg
= omap_ctrl_readl(control_pbias_offset
);
117 reg
|= (OMAP2_PBIASSPEEDCTRL0
| OMAP2_PBIASLITEPWRDNZ0
|
118 OMAP2_PBIASLITEVMODE0
);
119 omap_ctrl_writel(reg
, control_pbias_offset
);
123 static void hsmmc2_select_input_clk_src(struct omap_mmc_platform_data
*mmc
)
127 reg
= omap_ctrl_readl(control_devconf1_offset
);
128 if (mmc
->slots
[0].internal_clock
)
129 reg
|= OMAP2_MMCSDIO2ADPCLKISEL
;
131 reg
&= ~OMAP2_MMCSDIO2ADPCLKISEL
;
132 omap_ctrl_writel(reg
, control_devconf1_offset
);
135 static void hsmmc2_before_set_reg(struct device
*dev
, int slot
,
136 int power_on
, int vdd
)
138 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
140 if (mmc
->slots
[0].remux
)
141 mmc
->slots
[0].remux(dev
, slot
, power_on
);
144 hsmmc2_select_input_clk_src(mmc
);
147 static int am35x_hsmmc2_set_power(struct device
*dev
, int slot
,
148 int power_on
, int vdd
)
150 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
153 hsmmc2_select_input_clk_src(mmc
);
158 static int nop_mmc_set_power(struct device
*dev
, int slot
, int power_on
,
164 static inline void omap_hsmmc_mux(struct omap_mmc_platform_data
*mmc_controller
,
167 if (gpio_is_valid(mmc_controller
->slots
[0].switch_pin
) &&
168 (mmc_controller
->slots
[0].switch_pin
< OMAP_MAX_GPIO_LINES
))
169 omap_mux_init_gpio(mmc_controller
->slots
[0].switch_pin
,
170 OMAP_PIN_INPUT_PULLUP
);
171 if (gpio_is_valid(mmc_controller
->slots
[0].gpio_wp
) &&
172 (mmc_controller
->slots
[0].gpio_wp
< OMAP_MAX_GPIO_LINES
))
173 omap_mux_init_gpio(mmc_controller
->slots
[0].gpio_wp
,
174 OMAP_PIN_INPUT_PULLUP
);
175 if (cpu_is_omap34xx()) {
176 if (controller_nr
== 0) {
177 omap_mux_init_signal("sdmmc1_clk",
178 OMAP_PIN_INPUT_PULLUP
);
179 omap_mux_init_signal("sdmmc1_cmd",
180 OMAP_PIN_INPUT_PULLUP
);
181 omap_mux_init_signal("sdmmc1_dat0",
182 OMAP_PIN_INPUT_PULLUP
);
183 if (mmc_controller
->slots
[0].caps
&
184 (MMC_CAP_4_BIT_DATA
| MMC_CAP_8_BIT_DATA
)) {
185 omap_mux_init_signal("sdmmc1_dat1",
186 OMAP_PIN_INPUT_PULLUP
);
187 omap_mux_init_signal("sdmmc1_dat2",
188 OMAP_PIN_INPUT_PULLUP
);
189 omap_mux_init_signal("sdmmc1_dat3",
190 OMAP_PIN_INPUT_PULLUP
);
192 if (mmc_controller
->slots
[0].caps
&
193 MMC_CAP_8_BIT_DATA
) {
194 omap_mux_init_signal("sdmmc1_dat4",
195 OMAP_PIN_INPUT_PULLUP
);
196 omap_mux_init_signal("sdmmc1_dat5",
197 OMAP_PIN_INPUT_PULLUP
);
198 omap_mux_init_signal("sdmmc1_dat6",
199 OMAP_PIN_INPUT_PULLUP
);
200 omap_mux_init_signal("sdmmc1_dat7",
201 OMAP_PIN_INPUT_PULLUP
);
204 if (controller_nr
== 1) {
206 omap_mux_init_signal("sdmmc2_clk",
207 OMAP_PIN_INPUT_PULLUP
);
208 omap_mux_init_signal("sdmmc2_cmd",
209 OMAP_PIN_INPUT_PULLUP
);
210 omap_mux_init_signal("sdmmc2_dat0",
211 OMAP_PIN_INPUT_PULLUP
);
214 * For 8 wire configurations, Lines DAT4, 5, 6 and 7
215 * need to be muxed in the board-*.c files
217 if (mmc_controller
->slots
[0].caps
&
218 (MMC_CAP_4_BIT_DATA
| MMC_CAP_8_BIT_DATA
)) {
219 omap_mux_init_signal("sdmmc2_dat1",
220 OMAP_PIN_INPUT_PULLUP
);
221 omap_mux_init_signal("sdmmc2_dat2",
222 OMAP_PIN_INPUT_PULLUP
);
223 omap_mux_init_signal("sdmmc2_dat3",
224 OMAP_PIN_INPUT_PULLUP
);
226 if (mmc_controller
->slots
[0].caps
&
227 MMC_CAP_8_BIT_DATA
) {
228 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
229 OMAP_PIN_INPUT_PULLUP
);
230 omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5",
231 OMAP_PIN_INPUT_PULLUP
);
232 omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6",
233 OMAP_PIN_INPUT_PULLUP
);
234 omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7",
235 OMAP_PIN_INPUT_PULLUP
);
240 * For MMC3 the pins need to be muxed in the board-*.c files
245 static int __init
omap_hsmmc_pdata_init(struct omap2_hsmmc_info
*c
,
246 struct omap_mmc_platform_data
*mmc
)
250 hc_name
= kzalloc(sizeof(char) * (HSMMC_NAME_LEN
+ 1), GFP_KERNEL
);
252 pr_err("Cannot allocate memory for controller slot name\n");
258 strncpy(hc_name
, c
->name
, HSMMC_NAME_LEN
);
260 snprintf(hc_name
, (HSMMC_NAME_LEN
+ 1), "mmc%islot%i",
262 mmc
->slots
[0].name
= hc_name
;
264 mmc
->slots
[0].caps
= c
->caps
;
265 mmc
->slots
[0].pm_caps
= c
->pm_caps
;
266 mmc
->slots
[0].internal_clock
= !c
->ext_clock
;
267 mmc
->max_freq
= c
->max_freq
;
269 mmc
->get_context_loss_count
= hsmmc_get_context_loss
;
271 mmc
->slots
[0].switch_pin
= c
->gpio_cd
;
272 mmc
->slots
[0].gpio_wp
= c
->gpio_wp
;
274 mmc
->slots
[0].remux
= c
->remux
;
275 mmc
->slots
[0].init_card
= c
->init_card
;
278 mmc
->slots
[0].cover
= 1;
281 mmc
->slots
[0].nonremovable
= 1;
284 mmc
->slots
[0].power_saving
= 1;
287 mmc
->slots
[0].no_off
= 1;
290 mmc
->slots
[0].no_regulator_off_init
= c
->no_off_init
;
292 if (c
->vcc_aux_disable_is_sleep
)
293 mmc
->slots
[0].vcc_aux_disable_is_sleep
= 1;
296 * NOTE: MMC slots should have a Vcc regulator set up.
297 * This may be from a TWL4030-family chip, another
298 * controllable regulator, or a fixed supply.
300 * temporary HACK: ocr_mask instead of fixed supply
303 mmc
->slots
[0].ocr_mask
= MMC_VDD_165_195
|
310 mmc
->slots
[0].ocr_mask
= c
->ocr_mask
;
312 if (!soc_is_am35xx())
313 mmc
->slots
[0].features
|= HSMMC_HAS_PBIAS
;
317 if (mmc
->slots
[0].features
& HSMMC_HAS_PBIAS
) {
318 /* on-chip level shifting via PBIAS0/PBIAS1 */
319 mmc
->slots
[0].before_set_reg
=
320 omap_hsmmc1_before_set_reg
;
321 mmc
->slots
[0].after_set_reg
=
322 omap_hsmmc1_after_set_reg
;
326 mmc
->slots
[0].set_power
= nop_mmc_set_power
;
328 /* OMAP3630 HSMMC1 supports only 4-bit */
329 if (cpu_is_omap3630() &&
330 (c
->caps
& MMC_CAP_8_BIT_DATA
)) {
331 c
->caps
&= ~MMC_CAP_8_BIT_DATA
;
332 c
->caps
|= MMC_CAP_4_BIT_DATA
;
333 mmc
->slots
[0].caps
= c
->caps
;
338 mmc
->slots
[0].set_power
= am35x_hsmmc2_set_power
;
342 if (c
->transceiver
&& (c
->caps
& MMC_CAP_8_BIT_DATA
)) {
343 c
->caps
&= ~MMC_CAP_8_BIT_DATA
;
344 c
->caps
|= MMC_CAP_4_BIT_DATA
;
346 if (mmc
->slots
[0].features
& HSMMC_HAS_PBIAS
) {
347 /* off-chip level shifting, or none */
348 mmc
->slots
[0].before_set_reg
= hsmmc2_before_set_reg
;
349 mmc
->slots
[0].after_set_reg
= NULL
;
355 mmc
->slots
[0].before_set_reg
= NULL
;
356 mmc
->slots
[0].after_set_reg
= NULL
;
359 pr_err("MMC%d configuration not supported!\n", c
->mmc
);
366 static int omap_hsmmc_done
;
368 void omap_hsmmc_late_init(struct omap2_hsmmc_info
*c
)
370 struct platform_device
*pdev
;
371 struct omap_mmc_platform_data
*mmc_pdata
;
374 if (omap_hsmmc_done
!= 1)
379 for (; c
->mmc
; c
++) {
387 mmc_pdata
= pdev
->dev
.platform_data
;
391 mmc_pdata
->slots
[0].switch_pin
= c
->gpio_cd
;
392 mmc_pdata
->slots
[0].gpio_wp
= c
->gpio_wp
;
394 res
= omap_device_register(pdev
);
396 pr_err("Could not late init MMC %s\n",
401 #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
403 static void __init
omap_hsmmc_init_one(struct omap2_hsmmc_info
*hsmmcinfo
,
406 struct omap_hwmod
*oh
;
407 struct omap_hwmod
*ohs
[1];
408 struct omap_device
*od
;
409 struct platform_device
*pdev
;
410 char oh_name
[MAX_OMAP_MMC_HWMOD_NAME_LEN
];
411 struct omap_mmc_platform_data
*mmc_data
;
412 struct omap_mmc_dev_attr
*mmc_dev_attr
;
416 mmc_data
= kzalloc(sizeof(struct omap_mmc_platform_data
), GFP_KERNEL
);
418 pr_err("Cannot allocate memory for mmc device!\n");
422 res
= omap_hsmmc_pdata_init(hsmmcinfo
, mmc_data
);
426 omap_hsmmc_mux(mmc_data
, (ctrl_nr
- 1));
429 res
= snprintf(oh_name
, MAX_OMAP_MMC_HWMOD_NAME_LEN
,
431 WARN(res
>= MAX_OMAP_MMC_HWMOD_NAME_LEN
,
432 "String buffer overflow in MMC%d device setup\n", ctrl_nr
);
434 oh
= omap_hwmod_lookup(oh_name
);
436 pr_err("Could not look up %s\n", oh_name
);
440 if (oh
->dev_attr
!= NULL
) {
441 mmc_dev_attr
= oh
->dev_attr
;
442 mmc_data
->controller_flags
= mmc_dev_attr
->flags
;
444 * erratum 2.1.1.128 doesn't apply if board has
445 * a transceiver is attached
447 if (hsmmcinfo
->transceiver
)
448 mmc_data
->controller_flags
&=
449 ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ
;
452 pdev
= platform_device_alloc(name
, ctrl_nr
- 1);
454 pr_err("Could not allocate pdev for %s\n", name
);
457 dev_set_name(&pdev
->dev
, "%s.%d", pdev
->name
, pdev
->id
);
459 od
= omap_device_alloc(pdev
, ohs
, 1);
461 pr_err("Could not allocate od for %s\n", name
);
465 res
= platform_device_add_data(pdev
, mmc_data
,
466 sizeof(struct omap_mmc_platform_data
));
468 pr_err("Could not add pdata for %s\n", name
);
472 hsmmcinfo
->pdev
= pdev
;
474 if (hsmmcinfo
->deferred
)
477 res
= omap_device_register(pdev
);
479 pr_err("Could not register od for %s\n", name
);
486 omap_device_delete(od
);
489 platform_device_put(pdev
);
492 kfree(mmc_data
->slots
[0].name
);
498 void __init
omap_hsmmc_init(struct omap2_hsmmc_info
*controllers
)
505 if (cpu_is_omap2430()) {
506 control_pbias_offset
= OMAP243X_CONTROL_PBIAS_LITE
;
507 control_devconf1_offset
= OMAP243X_CONTROL_DEVCONF1
;
509 control_pbias_offset
= OMAP343X_CONTROL_PBIAS_LITE
;
510 control_devconf1_offset
= OMAP343X_CONTROL_DEVCONF1
;
513 for (; controllers
->mmc
; controllers
++)
514 omap_hsmmc_init_one(controllers
, controllers
->mmc
);