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 printk("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, int vdd)
47 #ifdef CONFIG_MMC_DEBUG
48 printk("Set slot %d power: %s (vdd %d)\n", slot + 1,
49 power_on ? "on" : "off", vdd);
53 return menelaus_set_vmmc(0);
72 return menelaus_set_vmmc(mV);
75 return menelaus_set_vdcdc(3, 0);
105 case MMC_VDD_150_155:
106 case MMC_VDD_145_150:
112 return menelaus_set_vdcdc(3, mV);
117 static int n800_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
121 #ifdef CONFIG_MMC_DEBUG
122 printk("Set slot %d bus mode %s\n", slot + 1,
123 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
125 BUG_ON(slot != 0 && slot != 1);
128 case MMC_BUSMODE_OPENDRAIN:
129 r = menelaus_set_mmc_opendrain(slot, 1);
131 case MMC_BUSMODE_PUSHPULL:
132 r = menelaus_set_mmc_opendrain(slot, 0);
137 if (r != 0 && printk_ratelimit())
138 printk(KERN_ERR "MMC: unable to set bus mode for slot %d\n", slot);
143 static int n800_mmc_get_ro(struct device *dev, int slot)
149 ro = omap_get_gpio_datain(slot1_wp_gpio);
151 ro = omap_get_gpio_datain(slot2_wp_gpio);
152 #ifdef CONFIG_MMC_DEBUG
153 printk("Get RO slot %d: %s\n", slot, ro ? "read-only" : "read-write");
159 static int n800_mmc_get_cover_state(struct device *dev, int slot)
162 BUG_ON(slot != 1 && slot != 2);
164 return slot1_cover_closed;
166 return slot2_cover_closed;
169 static void n800_mmc_callback(void *data, u8 card_mask)
171 if (card_mask & (1 << 1))
172 slot2_cover_closed = 0;
174 slot2_cover_closed = 1;
175 omap_mmc_notify_cover_event(mmc_device, 1, slot2_cover_closed);
178 void n800_mmc_slot1_cover_handler(void *arg, int state)
180 if (mmc_device == NULL)
183 slot1_cover_closed = state;
184 omap_mmc_notify_cover_event(mmc_device, 0, state);
187 static int n800_mmc_late_init(struct device *dev)
193 r = menelaus_set_slot_sel(1);
197 r = menelaus_set_mmc_slot(1, 1, 0, 1);
200 r = menelaus_set_mmc_slot(2, 1, 0, 1);
204 r = menelaus_get_slot_pin_states();
209 slot2_cover_closed = 1;
211 slot2_cover_closed = 0;
213 r = menelaus_register_mmc_callback(n800_mmc_callback, NULL);
218 static void n800_mmc_cleanup(struct device *dev)
220 menelaus_unregister_mmc_callback();
223 static struct omap_mmc_platform_data n800_mmc_data = {
227 .switch_slot = n800_mmc_switch_slot,
228 .init = n800_mmc_late_init,
229 .cleanup = n800_mmc_cleanup,
231 .set_power = n800_mmc_set_power,
232 .set_bus_mode = n800_mmc_set_bus_mode,
234 .get_cover_state= n800_mmc_get_cover_state,
235 .ocr_mask = MMC_VDD_18_19 | MMC_VDD_28_29 | MMC_VDD_30_31 |
236 MMC_VDD_32_33 | MMC_VDD_33_34,
240 .set_power = n800_mmc_set_power,
241 .set_bus_mode = n800_mmc_set_bus_mode,
243 .get_cover_state= n800_mmc_get_cover_state,
244 .ocr_mask = MMC_VDD_150_155 | MMC_VDD_145_150 | MMC_VDD_17_18 |
245 MMC_VDD_18_19 | MMC_VDD_19_20 | 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 n800_mmc_init(void)
256 omap_set_mmc_info(1, &n800_mmc_data);
257 if (omap_request_gpio(slot_switch_gpio) < 0)
259 omap_set_gpio_dataout(slot_switch_gpio, 0);
260 omap_set_gpio_direction(slot_switch_gpio, 0);
261 if (omap_request_gpio(slot1_wp_gpio) < 0)
263 if (omap_request_gpio(slot2_wp_gpio) < 0)
265 omap_set_gpio_direction(slot1_wp_gpio, 1);
266 omap_set_gpio_direction(slot2_wp_gpio, 1);
271 void __init n800_mmc_init(void)
275 void n800_mmc_slot1_cover_handler(void *arg, int state)