2 * linux/arch/arm/mach-omap2/board-h4-mmc.c
4 * Copyright (C) 2007 Instituto Nokia de Tecnologia - INdT
5 * Authors: David Cohen <david.cohen@indt.org.br>
6 * Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
8 * This code is based on linux/arch/arm/mach-omap2/board-n800-mmc.c, which is:
9 * Copyright (C) 2006 Nokia Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <asm/arch/mmc.h>
18 #include <asm/arch/menelaus.h>
20 #include <asm/mach-types.h>
21 #include <linux/delay.h>
23 #ifdef CONFIG_MMC_OMAP
25 /* Bit mask for slots detection interrupts */
26 #define SD1_CD_ST (1 << 0)
27 #define SD2_CD_ST (1 << 1)
29 static int slot1_cover_open
;
30 static int slot2_cover_open
;
31 static struct device
*mmc_device
;
35 * VDCDC3_APE, VMCS2_APE --> slot 2
38 static int h4_mmc_switch_slot(struct device
*dev
, int slot
)
42 #ifdef CONFIG_MMC_DEBUG
43 dev_dbg(dev
, "Choose slot %d\n", slot
+ 1);
46 r
= menelaus_enable_slot(2, 0);
47 r
|= menelaus_enable_slot(1, 1);
49 r
= menelaus_enable_slot(1, 0);
50 r
|= menelaus_enable_slot(2, 1);
53 return r
? -ENODEV
: 0;
56 static int h4_mmc_set_power(struct device
*dev
, int slot
, int power_on
,
61 #ifdef CONFIG_MMC_DEBUG
62 dev_dbg(dev
, "Set slot %d power: %s (vdd %d)\n", slot
+ 1,
63 power_on
? "on" : "off", vdd
);
67 return menelaus_set_vmmc(3000);
86 return menelaus_set_vmmc(mV
);
89 return menelaus_set_vdcdc(3, 3000);
114 case MMC_VDD_165_195
:
120 return menelaus_set_vdcdc(3, mV
);
125 static int h4_mmc_set_bus_mode(struct device
*dev
, int slot
, int bus_mode
)
129 #ifdef CONFIG_MMC_DEBUG
130 dev_dbg(dev
, "Set slot %d bus mode %s\n", slot
+ 1,
131 bus_mode
== MMC_BUSMODE_OPENDRAIN
? "open-drain" : "push-pull");
133 BUG_ON(slot
!= 0 && slot
!= 1);
136 case MMC_BUSMODE_OPENDRAIN
:
137 r
= menelaus_set_mmc_opendrain(slot
, 1);
139 case MMC_BUSMODE_PUSHPULL
:
140 r
= menelaus_set_mmc_opendrain(slot
, 0);
145 if (r
!= 0 && printk_ratelimit()) {
146 dev_err(dev
, "MMC: unable to set bus mode for slot %d\n",
152 static int h4_mmc_slot1_cover_state(struct device
*dev
, int slot
)
155 return slot1_cover_open
;
158 static int h4_mmc_slot2_cover_state(struct device
*dev
, int slot
)
161 return slot2_cover_open
;
164 static void h4_mmc_slot_callback(void *data
, u8 card_mask
)
168 cover_open
= (card_mask
& SD1_CD_ST
) ? 0 : 1;
169 if (cover_open
!= slot1_cover_open
) {
170 slot1_cover_open
= cover_open
;
171 omap_mmc_notify_cover_event(mmc_device
, 0, slot1_cover_open
);
174 cover_open
= (card_mask
& SD2_CD_ST
) ? 0 : 1;
175 if (cover_open
!= slot2_cover_open
) {
176 slot2_cover_open
= cover_open
;
177 omap_mmc_notify_cover_event(mmc_device
, 1, slot2_cover_open
);
181 static int h4_mmc_late_init(struct device
*dev
)
187 r
= menelaus_set_mmc_slot(1, 0, 0, 1);
190 r
= menelaus_set_mmc_slot(2, 0, 0, 1);
194 r
= menelaus_get_slot_pin_states();
199 slot1_cover_open
= 1;
201 slot1_cover_open
= 0;
203 /* Slot pin bits seem to be inversed until first swith change,
204 * but just for slot 2
206 if ((r
== 0xf) || (r
== (0xf & ~SD2_CD_ST
)))
210 slot2_cover_open
= 1;
212 slot2_cover_open
= 0;
214 r
= menelaus_register_mmc_callback(h4_mmc_slot_callback
, NULL
);
220 static void h4_mmc_cleanup(struct device
*dev
)
222 menelaus_unregister_mmc_callback();
225 static struct omap_mmc_platform_data h4_mmc_data
= {
227 .switch_slot
= h4_mmc_switch_slot
,
228 .init
= h4_mmc_late_init
,
229 .cleanup
= h4_mmc_cleanup
,
231 .set_power
= h4_mmc_set_power
,
232 .set_bus_mode
= h4_mmc_set_bus_mode
,
234 .get_cover_state
= h4_mmc_slot1_cover_state
,
235 .ocr_mask
= MMC_VDD_165_195
|
236 MMC_VDD_28_29
| MMC_VDD_30_31
|
237 MMC_VDD_32_33
| MMC_VDD_33_34
,
241 .set_power
= h4_mmc_set_power
,
242 .set_bus_mode
= h4_mmc_set_bus_mode
,
244 .get_cover_state
= h4_mmc_slot2_cover_state
,
245 .ocr_mask
= MMC_VDD_165_195
| MMC_VDD_20_21
|
246 MMC_VDD_21_22
| MMC_VDD_22_23
| MMC_VDD_23_24
|
247 MMC_VDD_24_25
| MMC_VDD_27_28
| MMC_VDD_28_29
|
248 MMC_VDD_29_30
| MMC_VDD_30_31
| MMC_VDD_32_33
|
254 void __init
h4_mmc_init(void)
256 omap_set_mmc_info(1, &h4_mmc_data
);
261 void __init
h4_mmc_init(void)