2 * linux/arch/arm/mach-omap2/mmc-am3517evm.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/err.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/gpio.h>
20 #include <mach/hardware.h>
21 #include <plat/control.h>
23 #include <plat/board.h>
24 #include "mmc-am3517evm.h"
27 #define VSEL_S2_CLR 0x40
29 #define VMMC1_DEV_GRP 0x27
30 #define VMMC1_CLR 0x00
31 #define VMMC1_315V 0x03
32 #define VMMC1_300V 0x02
33 #define VMMC1_285V 0x01
34 #define VMMC1_185V 0x00
35 #define VMMC1_DEDICATED 0x2A
37 #define VMMC2_DEV_GRP 0x2B
38 #define VMMC2_CLR 0x40
39 #define VMMC2_315V 0x0c
40 #define VMMC2_300V 0x0b
41 #define VMMC2_285V 0x0a
42 #define VMMC2_260V 0x08
43 #define VMMC2_185V 0x06
44 #define VMMC2_DEDICATED 0x2E
46 #define VMMC_DEV_GRP_P1 0x20
48 #define HSMMC_NAME_LEN 9
50 #if defined(CONFIG_REGULATOR) || \
51 (defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
52 defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE))
58 static struct mmc_controller
{
59 struct omap_mmc_platform_data
*mmc
;
62 char name
[HSMMC_NAME_LEN
];
65 .vmmc_dev_grp
= VMMC1_DEV_GRP
,
66 .vmmc_dedicated
= VMMC1_DEDICATED
,
69 .vmmc_dev_grp
= VMMC2_DEV_GRP
,
70 .vmmc_dedicated
= VMMC2_DEDICATED
,
74 static int mmc_card_detect(int irq
)
78 for (i
= 0; i
< ARRAY_SIZE(hsmmc
); i
++) {
79 struct omap_mmc_platform_data
*mmc
;
84 if (irq
!= mmc
->slots
[0].card_detect_irq
)
87 /* NOTE: assumes card detect signal is active-low */
88 return !gpio_get_value_cansleep(mmc
->slots
[0].switch_pin
);
93 static int mmc_get_ro(struct device
*dev
, int slot
)
95 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
97 /* NOTE: assumes write protect signal is active-high */
98 return gpio_get_value_cansleep(mmc
->slots
[0].gpio_wp
);
102 * MMC Slot Initialization.
104 static int mmc_late_init(struct device
*dev
)
106 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
110 ret
= gpio_request(mmc
->slots
[0].switch_pin
, "mmc_cd");
113 ret
= gpio_direction_input(mmc
->slots
[0].switch_pin
);
117 for (i
= 0; i
< ARRAY_SIZE(hsmmc
); i
++) {
118 if (hsmmc
[i
].name
== mmc
->slots
[0].name
) {
127 gpio_free(mmc
->slots
[0].switch_pin
);
129 mmc
->slots
[0].card_detect_irq
= 0;
130 mmc
->slots
[0].card_detect
= NULL
;
132 dev_err(dev
, "err %d configuring card detect\n", ret
);
136 static void mmc_cleanup(struct device
*dev
)
138 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
140 gpio_free(mmc
->slots
[0].switch_pin
);
145 static int mmc_suspend(struct device
*dev
, int slot
)
147 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
149 disable_irq(mmc
->slots
[0].card_detect_irq
);
153 static int mmc_resume(struct device
*dev
, int slot
)
155 struct omap_mmc_platform_data
*mmc
= dev
->platform_data
;
157 enable_irq(mmc
->slots
[0].card_detect_irq
);
162 #define mmc_suspend NULL
163 #define mmc_resume NULL
167 * the MMC power setting function
170 static int mmc1_set_power(struct device
*dev
, int slot
, int power_on
,
176 static int mmc2_set_power(struct device
*dev
, int slot
, int power_on
, int vdd
)
181 static struct omap_mmc_platform_data
*hsmmc_data
[OMAP34XX_NR_MMC
] __initdata
;
183 void __init
am3517_mmc_init(struct am3517_hsmmc_info
*controllers
)
185 struct am3517_hsmmc_info
*c
;
186 int nr_hsmmc
= ARRAY_SIZE(hsmmc_data
);
188 for (c
= controllers
; c
->mmc
; c
++) {
189 struct mmc_controller
*mmc_control
= hsmmc
+ c
->mmc
- 1;
190 struct omap_mmc_platform_data
*mmc
= hsmmc_data
[c
->mmc
- 1];
192 if (!c
->mmc
|| c
->mmc
> nr_hsmmc
) {
193 pr_debug("MMC%d: no such controller\n", c
->mmc
);
197 pr_debug("MMC%d: already configured\n", c
->mmc
);
201 mmc
= kzalloc(sizeof(struct omap_mmc_platform_data
), GFP_KERNEL
);
203 pr_err("Cannot allocate memory for mmc device!\n");
207 sprintf(mmc_control
->name
, "mmc%islot%i", c
->mmc
, 1);
208 mmc
->slots
[0].name
= mmc_control
->name
;
210 mmc
->slots
[0].ocr_mask
= MMC_VDD_165_195
|
211 MMC_VDD_26_27
| MMC_VDD_27_28
|
213 MMC_VDD_30_31
| MMC_VDD_31_32
;
214 mmc
->slots
[0].wires
= c
->wires
;
215 mmc
->slots
[0].internal_clock
= !c
->ext_clock
;
216 mmc
->dma_mask
= 0xffffffff;
219 mmc
->init
= mmc_late_init
;
220 mmc
->cleanup
= mmc_cleanup
;
221 mmc
->suspend
= mmc_suspend
;
222 mmc
->resume
= mmc_resume
;
224 mmc
->slots
[0].switch_pin
= c
->gpio_cd
;
225 mmc
->slots
[0].card_detect_irq
= gpio_to_irq(c
->gpio_cd
);
226 mmc
->slots
[0].card_detect
= mmc_card_detect
;
228 mmc
->slots
[0].switch_pin
= -EINVAL
;
230 /* write protect normally uses an OMAP gpio */
231 if (gpio_is_valid(c
->gpio_wp
)) {
232 gpio_request(c
->gpio_wp
, "mmc_wp");
233 gpio_direction_input(c
->gpio_wp
);
235 mmc
->slots
[0].gpio_wp
= c
->gpio_wp
;
236 mmc
->slots
[0].get_ro
= mmc_get_ro
;
238 mmc
->slots
[0].gpio_wp
= -EINVAL
;
240 /* NOTE: we assume OMAP's MMC1 and MMC2 use
241 * the TWL4030's VMMC1 and VMMC2, respectively;
242 * and that OMAP's MMC3 isn't used.
247 mmc
->slots
[0].set_power
= mmc1_set_power
;
250 mmc
->slots
[0].set_power
= mmc2_set_power
;
253 pr_err("MMC%d configuration not supported!\n", c
->mmc
);
256 hsmmc_data
[c
->mmc
- 1] = mmc
;
259 omap2_init_mmc(hsmmc_data
, OMAP34XX_NR_MMC
);
262 inline void am3517_mmc_init(struct am3517_hsmmc_info
*info
)