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 <linux/delay.h>
13 #include <linux/platform_device.h>
14 #include <linux/i2c/menelaus.h>
16 #include <asm/mach-types.h>
19 #include <mach/gpio.h>
22 #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
24 static const int slot_switch_gpio = 96;
26 static const int n810_slot2_pw_vddf = 23;
27 static const int n810_slot2_pw_vdd = 9;
29 static int slot1_cover_open;
30 static int slot2_cover_open;
31 static struct device *mmc_device;
34 * VMMC --> slot 1 (N800 & N810)
35 * VDCDC3_APE, VMCS2_APE --> slot 2 on N800
36 * GPIO96 --> Menelaus GPIO2
37 * GPIO23 --> controls slot2 VSD (N810 only)
38 * GPIO9 --> controls slot2 VIO_SD (N810 only)
41 static int n800_mmc_switch_slot(struct device *dev, int slot)
43 #ifdef CONFIG_MMC_DEBUG
44 dev_dbg(dev, "Choose slot %d\n", slot + 1);
47 omap_set_gpio_dataout(slot_switch_gpio, 0);
49 omap_set_gpio_dataout(slot_switch_gpio, 1);
53 static int n800_mmc_set_power_menelaus(struct device *dev, int slot,
54 int power_on, int vdd)
58 #ifdef CONFIG_MMC_DEBUG
59 dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
60 power_on ? "on" : "off", vdd);
64 return menelaus_set_vmmc(0);
83 return menelaus_set_vmmc(mV);
86 return menelaus_set_vdcdc(3, 0);
111 case MMC_VDD_165_195:
117 return menelaus_set_vdcdc(3, mV);
122 static void nokia_mmc_set_power_internal(struct device *dev,
125 dev_dbg(dev, "Set internal slot power %s\n",
126 power_on ? "on" : "off");
129 omap_set_gpio_dataout(n810_slot2_pw_vddf, 1);
131 omap_set_gpio_dataout(n810_slot2_pw_vdd, 1);
134 omap_set_gpio_dataout(n810_slot2_pw_vdd, 0);
136 omap_set_gpio_dataout(n810_slot2_pw_vddf, 0);
141 static int n800_mmc_set_power(struct device *dev, int slot, int power_on,
144 if (machine_is_nokia_n800() || slot == 0)
145 return n800_mmc_set_power_menelaus(dev, slot, power_on, vdd);
147 nokia_mmc_set_power_internal(dev, power_on);
152 static int n800_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
156 dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
157 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
158 BUG_ON(slot != 0 && slot != 1);
161 case MMC_BUSMODE_OPENDRAIN:
162 r = menelaus_set_mmc_opendrain(slot, 1);
164 case MMC_BUSMODE_PUSHPULL:
165 r = menelaus_set_mmc_opendrain(slot, 0);
170 if (r != 0 && printk_ratelimit())
171 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
176 static int n800_mmc_get_cover_state(struct device *dev, int slot)
179 BUG_ON(slot != 1 && slot != 2);
181 return slot1_cover_open;
183 return slot2_cover_open;
186 static void n800_mmc_callback(void *data, u8 card_mask)
188 int bit, *openp, index;
190 if (machine_is_nokia_n800()) {
192 openp = &slot2_cover_open;
196 openp = &slot1_cover_open;
205 omap_mmc_notify_cover_event(mmc_device, index, *openp);
208 void n800_mmc_slot1_cover_handler(void *arg, int closed_state)
210 if (mmc_device == NULL)
213 slot1_cover_open = !closed_state;
214 omap_mmc_notify_cover_event(mmc_device, 0, closed_state);
217 static int n800_mmc_late_init(struct device *dev)
224 r = menelaus_set_slot_sel(1);
228 if (machine_is_nokia_n800())
233 r = menelaus_set_mmc_slot(2, 0, vs2sel, 1);
237 n800_mmc_set_power(dev, 0, MMC_POWER_ON, 16); /* MMC_VDD_28_29 */
238 n800_mmc_set_power(dev, 1, MMC_POWER_ON, 16);
240 r = menelaus_set_mmc_slot(1, 1, 0, 1);
243 r = menelaus_set_mmc_slot(2, 1, vs2sel, 1);
247 r = menelaus_get_slot_pin_states();
251 if (machine_is_nokia_n800()) {
253 openp = &slot2_cover_open;
256 openp = &slot1_cover_open;
257 slot2_cover_open = 0;
260 /* All slot pin bits seem to be inversed until first swith change */
261 if (r == 0xf || r == (0xf & ~bit))
269 r = menelaus_register_mmc_callback(n800_mmc_callback, NULL);
274 static void n800_mmc_shutdown(struct device *dev)
278 if (machine_is_nokia_n800())
283 menelaus_set_mmc_slot(1, 0, 0, 0);
284 menelaus_set_mmc_slot(2, 0, vs2sel, 0);
287 static void n800_mmc_cleanup(struct device *dev)
289 menelaus_unregister_mmc_callback();
291 omap_free_gpio(slot_switch_gpio);
293 if (machine_is_nokia_n810()) {
294 omap_free_gpio(n810_slot2_pw_vddf);
295 omap_free_gpio(n810_slot2_pw_vdd);
300 * MMC controller1 has two slots that are multiplexed via I2C.
301 * MMC controller2 is not in use.
303 static struct omap_mmc_platform_data mmc1_data = {
305 .switch_slot = n800_mmc_switch_slot,
306 .init = n800_mmc_late_init,
307 .cleanup = n800_mmc_cleanup,
308 .shutdown = n800_mmc_shutdown,
309 .max_freq = 24000000,
310 .dma_mask = 0xffffffff,
313 .set_power = n800_mmc_set_power,
314 .set_bus_mode = n800_mmc_set_bus_mode,
315 .get_cover_state= n800_mmc_get_cover_state,
316 .ocr_mask = MMC_VDD_165_195 | MMC_VDD_30_31 |
317 MMC_VDD_32_33 | MMC_VDD_33_34,
321 .set_power = n800_mmc_set_power,
322 .set_bus_mode = n800_mmc_set_bus_mode,
323 .get_cover_state= n800_mmc_get_cover_state,
324 .ocr_mask = MMC_VDD_165_195 | MMC_VDD_20_21 |
325 MMC_VDD_21_22 | MMC_VDD_22_23 | MMC_VDD_23_24 |
326 MMC_VDD_24_25 | MMC_VDD_27_28 | MMC_VDD_28_29 |
327 MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_32_33 |
333 static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
335 void __init n800_mmc_init(void)
338 if (machine_is_nokia_n810()) {
339 n800_mmc1_data.slots[0].name = "external";
342 * Some Samsung Movinand chips do not like open-ended
343 * multi-block reads and fall to braind-dead state
344 * while doing so. Reducing the number of blocks in
345 * the transfer or delays in clock disable do not help
347 n800_mmc1_data.slots[1].name = "internal";
348 n800_mmc1_data.slots[1].ban_openended = 1;
351 if (omap_request_gpio(slot_switch_gpio) < 0)
353 omap_set_gpio_dataout(slot_switch_gpio, 0);
354 omap_set_gpio_direction(slot_switch_gpio, 0);
356 if (machine_is_nokia_n810()) {
357 if (omap_request_gpio(n810_slot2_pw_vddf) < 0)
359 omap_set_gpio_dataout(n810_slot2_pw_vddf, 0);
360 omap_set_gpio_direction(n810_slot2_pw_vddf, 0);
362 if (omap_request_gpio(n810_slot2_pw_vdd) < 0)
364 omap_set_gpio_dataout(n810_slot2_pw_vdd, 0);
365 omap_set_gpio_direction(n810_slot2_pw_vdd, 0);
368 mmc_data[0] = &mmc1_data;
369 omap2_init_mmc(mmc_data, OMAP24XX_NR_MMC);
373 void __init n800_mmc_init(void)
377 void n800_mmc_slot1_cover_handler(void *arg, int state)