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;
22 static int slot1_cover_open;
23 static int slot2_cover_open;
24 static struct device *mmc_device;
28 * VDCDC3_APE, VMCS2_APE --> slot 2
29 * GPIO96 --> Menelaus GPIO2
32 static int n800_mmc_switch_slot(struct device *dev, int slot)
34 #ifdef CONFIG_MMC_DEBUG
35 dev_dbg(dev, "Choose slot %d\n", slot + 1);
38 omap_set_gpio_dataout(slot_switch_gpio, 0);
40 omap_set_gpio_dataout(slot_switch_gpio, 1);
44 static int n800_mmc_set_power(struct device *dev, int slot, int power_on,
49 #ifdef CONFIG_MMC_DEBUG
50 dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
51 power_on ? "on" : "off", vdd);
55 return menelaus_set_vmmc(0);
74 return menelaus_set_vmmc(mV);
77 return menelaus_set_vdcdc(3, 0);
102 case MMC_VDD_165_195:
108 return menelaus_set_vdcdc(3, mV);
113 static int n800_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
117 #ifdef CONFIG_MMC_DEBUG
118 dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
119 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
121 BUG_ON(slot != 0 && slot != 1);
124 case MMC_BUSMODE_OPENDRAIN:
125 r = menelaus_set_mmc_opendrain(slot, 1);
127 case MMC_BUSMODE_PUSHPULL:
128 r = menelaus_set_mmc_opendrain(slot, 0);
133 if (r != 0 && printk_ratelimit())
134 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
140 static int n800_mmc_get_ro(struct device *dev, int slot)
146 ro = omap_get_gpio_datain(slot1_wp_gpio);
148 ro = omap_get_gpio_datain(slot2_wp_gpio);
149 #ifdef CONFIG_MMC_DEBUG
150 dev_dbg(dev, "Get RO slot %d: %s\n",
151 slot, ro ? "read-only" : "read-write");
157 static int n800_mmc_get_cover_state(struct device *dev, int slot)
160 BUG_ON(slot != 1 && slot != 2);
162 return slot1_cover_open;
164 return slot2_cover_open;
167 static void n800_mmc_callback(void *data, u8 card_mask)
169 int bit, *openp, index;
171 if (machine_is_nokia_n800()) {
173 openp = &slot2_cover_open;
182 omap_mmc_notify_cover_event(mmc_device, index, *openp);
185 void n800_mmc_slot1_cover_handler(void *arg, int state)
187 if (mmc_device == NULL)
190 slot1_cover_open = !state;
191 omap_mmc_notify_cover_event(mmc_device, 0, state);
194 static int n800_mmc_late_init(struct device *dev)
200 r = menelaus_set_slot_sel(1);
204 r = menelaus_set_mmc_slot(1, 1, 0, 1);
207 r = menelaus_set_mmc_slot(2, 1, 0, 1);
211 r = menelaus_get_slot_pin_states();
215 if (machine_is_nokia_n800()) {
217 openp = &slot2_cover_open;
220 /* All slot pin bits seem to be inversed until first swith change */
221 if (r == 0xf || r == (0xf & ~bit))
229 r = menelaus_register_mmc_callback(n800_mmc_callback, NULL);
234 static void n800_mmc_cleanup(struct device *dev)
236 menelaus_unregister_mmc_callback();
239 static struct omap_mmc_platform_data n800_mmc_data = {
241 .switch_slot = n800_mmc_switch_slot,
242 .init = n800_mmc_late_init,
243 .cleanup = n800_mmc_cleanup,
245 .set_power = n800_mmc_set_power,
246 .set_bus_mode = n800_mmc_set_bus_mode,
248 .get_cover_state= n800_mmc_get_cover_state,
249 .ocr_mask = MMC_VDD_165_195 |
250 MMC_VDD_28_29 | MMC_VDD_30_31 |
251 MMC_VDD_32_33 | MMC_VDD_33_34,
255 .set_power = n800_mmc_set_power,
256 .set_bus_mode = n800_mmc_set_bus_mode,
258 .get_cover_state= n800_mmc_get_cover_state,
259 .ocr_mask = MMC_VDD_165_195 | MMC_VDD_20_21 |
260 MMC_VDD_21_22 | MMC_VDD_22_23 | MMC_VDD_23_24 |
261 MMC_VDD_24_25 | MMC_VDD_27_28 | MMC_VDD_28_29 |
262 MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_32_33 |
268 void __init n800_mmc_init(void)
270 omap_set_mmc_info(1, &n800_mmc_data);
271 if (omap_request_gpio(slot_switch_gpio) < 0)
273 omap_set_gpio_dataout(slot_switch_gpio, 0);
274 omap_set_gpio_direction(slot_switch_gpio, 0);
279 void __init n800_mmc_init(void)
283 void n800_mmc_slot1_cover_handler(void *arg, int state)