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 #ifdef CONFIG_MMC_OMAP
18 static const int slot_switch_gpio = 96;
19 static const int slot1_wp_gpio = 23;
20 static const int slot2_wp_gpio = 8;
21 static int slot1_cover_closed;
22 static int slot2_cover_closed;
23 static struct device *mmc_device;
27 * VDCDC3_APE, VMCS2_APE --> slot 2
28 * GPIO96 --> Menelaus GPIO2
31 static int n800_mmc_switch_slot(struct device *dev, int slot)
33 #ifdef CONFIG_MMC_DEBUG
34 dev_dbg(dev, "Choose slot %d\n", slot + 1);
37 omap_set_gpio_dataout(slot_switch_gpio, 0);
39 omap_set_gpio_dataout(slot_switch_gpio, 1);
43 static int n800_mmc_set_power(struct device *dev, int slot, int power_on,
48 #ifdef CONFIG_MMC_DEBUG
49 dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
50 power_on ? "on" : "off", vdd);
54 return menelaus_set_vmmc(0);
73 return menelaus_set_vmmc(mV);
76 return menelaus_set_vdcdc(3, 0);
106 case MMC_VDD_150_155:
107 case MMC_VDD_145_150:
113 return menelaus_set_vdcdc(3, mV);
118 static int n800_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
122 #ifdef CONFIG_MMC_DEBUG
123 dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
124 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
126 BUG_ON(slot != 0 && slot != 1);
129 case MMC_BUSMODE_OPENDRAIN:
130 r = menelaus_set_mmc_opendrain(slot, 1);
132 case MMC_BUSMODE_PUSHPULL:
133 r = menelaus_set_mmc_opendrain(slot, 0);
138 if (r != 0 && printk_ratelimit())
139 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
145 static int n800_mmc_get_ro(struct device *dev, int slot)
151 ro = omap_get_gpio_datain(slot1_wp_gpio);
153 ro = omap_get_gpio_datain(slot2_wp_gpio);
154 #ifdef CONFIG_MMC_DEBUG
155 dev_dbg(dev, "Get RO slot %d: %s\n",
156 slot, ro ? "read-only" : "read-write");
162 static int n800_mmc_get_cover_state(struct device *dev, int slot)
165 BUG_ON(slot != 1 && slot != 2);
167 return slot1_cover_closed;
169 return slot2_cover_closed;
172 static void n800_mmc_callback(void *data, u8 card_mask)
174 if (card_mask & (1 << 1))
175 slot2_cover_closed = 0;
177 slot2_cover_closed = 1;
178 omap_mmc_notify_cover_event(mmc_device, 1, slot2_cover_closed);
181 void n800_mmc_slot1_cover_handler(void *arg, int state)
183 if (mmc_device == NULL)
186 slot1_cover_closed = state;
187 omap_mmc_notify_cover_event(mmc_device, 0, state);
190 static int n800_mmc_late_init(struct device *dev)
196 r = menelaus_set_slot_sel(1);
200 r = menelaus_set_mmc_slot(1, 1, 0, 1);
203 r = menelaus_set_mmc_slot(2, 1, 0, 1);
207 r = menelaus_get_slot_pin_states();
212 slot2_cover_closed = 1;
214 slot2_cover_closed = 0;
216 r = menelaus_register_mmc_callback(n800_mmc_callback, NULL);
221 static void n800_mmc_cleanup(struct device *dev)
223 menelaus_unregister_mmc_callback();
226 static struct omap_mmc_platform_data n800_mmc_data = {
230 .switch_slot = n800_mmc_switch_slot,
231 .init = n800_mmc_late_init,
232 .cleanup = n800_mmc_cleanup,
234 .set_power = n800_mmc_set_power,
235 .set_bus_mode = n800_mmc_set_bus_mode,
237 .get_cover_state= n800_mmc_get_cover_state,
238 .ocr_mask = MMC_VDD_18_19 | MMC_VDD_28_29 | MMC_VDD_30_31 |
239 MMC_VDD_32_33 | MMC_VDD_33_34,
243 .set_power = n800_mmc_set_power,
244 .set_bus_mode = n800_mmc_set_bus_mode,
246 .get_cover_state= n800_mmc_get_cover_state,
247 .ocr_mask = MMC_VDD_150_155 | MMC_VDD_145_150 | MMC_VDD_17_18 |
248 MMC_VDD_18_19 | MMC_VDD_19_20 | MMC_VDD_20_21 |
249 MMC_VDD_21_22 | MMC_VDD_22_23 | MMC_VDD_23_24 |
250 MMC_VDD_24_25 | MMC_VDD_27_28 | MMC_VDD_28_29 |
251 MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_32_33 |
257 void __init n800_mmc_init(void)
259 omap_set_mmc_info(1, &n800_mmc_data);
260 if (omap_request_gpio(slot_switch_gpio) < 0)
262 omap_set_gpio_dataout(slot_switch_gpio, 0);
263 omap_set_gpio_direction(slot_switch_gpio, 0);
264 if (omap_request_gpio(slot1_wp_gpio) < 0)
266 if (omap_request_gpio(slot2_wp_gpio) < 0)
268 omap_set_gpio_direction(slot1_wp_gpio, 1);
269 omap_set_gpio_direction(slot2_wp_gpio, 1);
274 void __init n800_mmc_init(void)
278 void n800_mmc_slot1_cover_handler(void *arg, int state)