2 * linux/arch/arm/mach-omap2/board-n800-mmc.c
4 * Copyright (C) 2006 Nokia Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <asm/arch/mmc.h>
13 #include <asm/arch/menelaus.h>
14 #include <asm/arch/gpio.h>
16 #include <asm/mach-types.h>
17 #include <linux/delay.h>
19 #ifdef CONFIG_MMC_OMAP
21 static const int slot_switch_gpio
= 96;
23 static const int n810_slot2_pw_vddf
= 23;
24 static const int n810_slot2_pw_vdd
= 9;
26 static int slot1_cover_open
;
27 static int slot2_cover_open
;
28 static struct device
*mmc_device
;
31 * VMMC --> slot 1 (N800 & N810)
32 * VDCDC3_APE, VMCS2_APE --> slot 2 on N800
33 * GPIO96 --> Menelaus GPIO2
34 * GPIO23 --> controls slot2 VSD (N810 only)
35 * GPIO9 --> controls slot2 VIO_SD (N810 only)
38 static int n800_mmc_switch_slot(struct device
*dev
, int slot
)
40 #ifdef CONFIG_MMC_DEBUG
41 dev_dbg(dev
, "Choose slot %d\n", slot
+ 1);
44 omap_set_gpio_dataout(slot_switch_gpio
, 0);
46 omap_set_gpio_dataout(slot_switch_gpio
, 1);
50 static int n800_mmc_set_power_menelaus(struct device
*dev
, int slot
,
51 int power_on
, int vdd
)
55 #ifdef CONFIG_MMC_DEBUG
56 dev_dbg(dev
, "Set slot %d power: %s (vdd %d)\n", slot
+ 1,
57 power_on
? "on" : "off", vdd
);
61 return menelaus_set_vmmc(0);
80 return menelaus_set_vmmc(mV
);
83 return menelaus_set_vdcdc(3, 0);
108 case MMC_VDD_165_195
:
114 return menelaus_set_vdcdc(3, mV
);
119 static void nokia_mmc_set_power_internal(struct device
*dev
,
122 dev_dbg(dev
, "Set internal slot power %s\n",
123 power_on
? "on" : "off");
126 omap_set_gpio_dataout(n810_slot2_pw_vddf
, 1);
128 omap_set_gpio_dataout(n810_slot2_pw_vdd
, 1);
131 omap_set_gpio_dataout(n810_slot2_pw_vdd
, 0);
133 omap_set_gpio_dataout(n810_slot2_pw_vddf
, 0);
138 static int n800_mmc_set_power(struct device
*dev
, int slot
, int power_on
,
141 if (machine_is_nokia_n800() || slot
== 0)
142 return n800_mmc_set_power_menelaus(dev
, slot
, power_on
, vdd
);
144 nokia_mmc_set_power_internal(dev
, power_on
);
149 static int n800_mmc_set_bus_mode(struct device
*dev
, int slot
, int bus_mode
)
153 dev_dbg(dev
, "Set slot %d bus mode %s\n", slot
+ 1,
154 bus_mode
== MMC_BUSMODE_OPENDRAIN
? "open-drain" : "push-pull");
155 BUG_ON(slot
!= 0 && slot
!= 1);
158 case MMC_BUSMODE_OPENDRAIN
:
159 r
= menelaus_set_mmc_opendrain(slot
, 1);
161 case MMC_BUSMODE_PUSHPULL
:
162 r
= menelaus_set_mmc_opendrain(slot
, 0);
167 if (r
!= 0 && printk_ratelimit())
168 dev_err(dev
, "MMC: unable to set bus mode for slot %d\n",
173 static int n800_mmc_get_cover_state(struct device
*dev
, int slot
)
176 BUG_ON(slot
!= 1 && slot
!= 2);
178 return slot1_cover_open
;
180 return slot2_cover_open
;
183 static void n800_mmc_callback(void *data
, u8 card_mask
)
185 int bit
, *openp
, index
;
187 if (machine_is_nokia_n800()) {
189 openp
= &slot2_cover_open
;
193 openp
= &slot1_cover_open
;
202 omap_mmc_notify_cover_event(mmc_device
, index
, *openp
);
205 void n800_mmc_slot1_cover_handler(void *arg
, int closed_state
)
207 if (mmc_device
== NULL
)
210 slot1_cover_open
= !closed_state
;
211 omap_mmc_notify_cover_event(mmc_device
, 0, closed_state
);
214 static int n800_mmc_late_init(struct device
*dev
)
221 r
= menelaus_set_slot_sel(1);
225 if (machine_is_nokia_n800())
230 r
= menelaus_set_mmc_slot(2, 0, vs2sel
, 1);
234 n800_mmc_set_power(dev
, 0, MMC_POWER_ON
, 16); /* MMC_VDD_28_29 */
235 n800_mmc_set_power(dev
, 1, MMC_POWER_ON
, 16);
237 r
= menelaus_set_mmc_slot(1, 1, 0, 1);
240 r
= menelaus_set_mmc_slot(2, 1, vs2sel
, 1);
244 r
= menelaus_get_slot_pin_states();
248 if (machine_is_nokia_n800()) {
250 openp
= &slot2_cover_open
;
253 openp
= &slot1_cover_open
;
254 slot2_cover_open
= 0;
257 /* All slot pin bits seem to be inversed until first swith change */
258 if (r
== 0xf || r
== (0xf & ~bit
))
266 r
= menelaus_register_mmc_callback(n800_mmc_callback
, NULL
);
271 static void n800_mmc_shutdown(struct device
*dev
)
275 if (machine_is_nokia_n800())
280 menelaus_set_mmc_slot(1, 0, 0, 0);
281 menelaus_set_mmc_slot(2, 0, vs2sel
, 0);
284 static void n800_mmc_cleanup(struct device
*dev
)
286 menelaus_unregister_mmc_callback();
288 omap_free_gpio(slot_switch_gpio
);
290 if (machine_is_nokia_n810()) {
291 omap_free_gpio(n810_slot2_pw_vddf
);
292 omap_free_gpio(n810_slot2_pw_vdd
);
296 static struct omap_mmc_platform_data n800_mmc_data
= {
298 .switch_slot
= n800_mmc_switch_slot
,
299 .init
= n800_mmc_late_init
,
300 .cleanup
= n800_mmc_cleanup
,
301 .shutdown
= n800_mmc_shutdown
,
302 .max_freq
= 24000000,
304 .set_power
= n800_mmc_set_power
,
305 .set_bus_mode
= n800_mmc_set_bus_mode
,
307 .get_cover_state
= n800_mmc_get_cover_state
,
308 .ocr_mask
= MMC_VDD_165_195
| MMC_VDD_30_31
|
309 MMC_VDD_32_33
| MMC_VDD_33_34
,
313 .set_power
= n800_mmc_set_power
,
314 .set_bus_mode
= n800_mmc_set_bus_mode
,
316 .get_cover_state
= n800_mmc_get_cover_state
,
317 .ocr_mask
= MMC_VDD_165_195
| MMC_VDD_20_21
|
318 MMC_VDD_21_22
| MMC_VDD_22_23
| MMC_VDD_23_24
|
319 MMC_VDD_24_25
| MMC_VDD_27_28
| MMC_VDD_28_29
|
320 MMC_VDD_29_30
| MMC_VDD_30_31
| MMC_VDD_32_33
|
326 void __init
n800_mmc_init(void)
329 if (machine_is_nokia_n810()) {
330 n800_mmc_data
.slots
[0].name
= "external";
333 * Some Samsung Movinand chips do not like open-ended
334 * multi-block reads and fall to braind-dead state
335 * while doing so. Reducing the number of blocks in
336 * the transfer or delays in clock disable do not help
338 n800_mmc_data
.slots
[1].name
= "internal";
339 n800_mmc_data
.slots
[1].ban_openended
= 1;
342 omap_set_mmc_info(1, &n800_mmc_data
);
343 if (omap_request_gpio(slot_switch_gpio
) < 0)
345 omap_set_gpio_dataout(slot_switch_gpio
, 0);
346 omap_set_gpio_direction(slot_switch_gpio
, 0);
348 if (machine_is_nokia_n810()) {
349 if (omap_request_gpio(n810_slot2_pw_vddf
) < 0)
351 omap_set_gpio_dataout(n810_slot2_pw_vddf
, 0);
352 omap_set_gpio_direction(n810_slot2_pw_vddf
, 0);
354 if (omap_request_gpio(n810_slot2_pw_vdd
) < 0)
356 omap_set_gpio_dataout(n810_slot2_pw_vdd
, 0);
357 omap_set_gpio_direction(n810_slot2_pw_vdd
, 0);
362 void __init
n800_mmc_init(void)
366 void n800_mmc_slot1_cover_handler(void *arg
, int state
)