2 * linux/arch/arm/mach-omap2/board-h4-mmc.c
4 * Copyright (C) 2007 Instituto Nokia de Tecnologia - INdT
5 * Authors: David Cohen <david.cohen@indt.org.br>
6 * Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
8 * This code is based on linux/arch/arm/mach-omap2/board-n800-mmc.c, which is:
9 * Copyright (C) 2006 Nokia Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <linux/delay.h>
18 #include <linux/platform_device.h>
19 #include <linux/i2c/menelaus.h>
21 #include <asm/mach-types.h>
25 #ifdef CONFIG_MMC_OMAP
27 /* Bit mask for slots detection interrupts */
28 #define SD1_CD_ST (1 << 0)
29 #define SD2_CD_ST (1 << 1)
31 static int slot1_cover_open;
32 static int slot2_cover_open;
33 static struct device *mmc_device;
37 * VDCDC3_APE, VMCS2_APE --> slot 2
40 static int h4_mmc_switch_slot(struct device *dev, int slot)
44 #ifdef CONFIG_MMC_DEBUG
45 dev_dbg(dev, "Choose slot %d\n", slot + 1);
48 r = menelaus_enable_slot(2, 0);
49 r |= menelaus_enable_slot(1, 1);
51 r = menelaus_enable_slot(1, 0);
52 r |= menelaus_enable_slot(2, 1);
55 return r ? -ENODEV : 0;
58 static int h4_mmc_set_power(struct device *dev, int slot, int power_on,
63 #ifdef CONFIG_MMC_DEBUG
64 dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
65 power_on ? "on" : "off", vdd);
69 return menelaus_set_vmmc(3000);
88 return menelaus_set_vmmc(mV);
91 return menelaus_set_vdcdc(3, 3000);
116 case MMC_VDD_165_195:
122 return menelaus_set_vdcdc(3, mV);
127 static int h4_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
131 #ifdef CONFIG_MMC_DEBUG
132 dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
133 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
135 BUG_ON(slot != 0 && slot != 1);
138 case MMC_BUSMODE_OPENDRAIN:
139 r = menelaus_set_mmc_opendrain(slot, 1);
141 case MMC_BUSMODE_PUSHPULL:
142 r = menelaus_set_mmc_opendrain(slot, 0);
147 if (r != 0 && printk_ratelimit()) {
148 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
154 static int h4_mmc_slot1_cover_state(struct device *dev, int slot)
157 return slot1_cover_open;
160 static int h4_mmc_slot2_cover_state(struct device *dev, int slot)
163 return slot2_cover_open;
166 static void h4_mmc_slot_callback(void *data, u8 card_mask)
170 cover_open = (card_mask & SD1_CD_ST) ? 0 : 1;
171 if (cover_open != slot1_cover_open) {
172 slot1_cover_open = cover_open;
173 omap_mmc_notify_cover_event(mmc_device, 0, slot1_cover_open);
176 cover_open = (card_mask & SD2_CD_ST) ? 0 : 1;
177 if (cover_open != slot2_cover_open) {
178 slot2_cover_open = cover_open;
179 omap_mmc_notify_cover_event(mmc_device, 1, slot2_cover_open);
183 static int h4_mmc_late_init(struct device *dev)
189 r = menelaus_set_mmc_slot(1, 0, 0, 1);
192 r = menelaus_set_mmc_slot(2, 0, 0, 1);
196 r = menelaus_get_slot_pin_states();
201 slot1_cover_open = 1;
203 slot1_cover_open = 0;
205 /* Slot pin bits seem to be inversed until first swith change,
206 * but just for slot 2
208 if ((r == 0xf) || (r == (0xf & ~SD2_CD_ST)))
212 slot2_cover_open = 1;
214 slot2_cover_open = 0;
216 r = menelaus_register_mmc_callback(h4_mmc_slot_callback, NULL);
222 static void h4_mmc_cleanup(struct device *dev)
224 menelaus_unregister_mmc_callback();
227 static struct omap_mmc_platform_data mmc1_data = {
229 .switch_slot = h4_mmc_switch_slot,
230 .init = h4_mmc_late_init,
231 .cleanup = h4_mmc_cleanup,
232 .dma_mask = 0xffffffff,
235 .set_power = h4_mmc_set_power,
236 .set_bus_mode = h4_mmc_set_bus_mode,
237 .get_cover_state= h4_mmc_slot1_cover_state,
238 .ocr_mask = MMC_VDD_165_195 |
239 MMC_VDD_28_29 | MMC_VDD_30_31 |
240 MMC_VDD_32_33 | MMC_VDD_33_34,
245 .set_power = h4_mmc_set_power,
246 .set_bus_mode = h4_mmc_set_bus_mode,
247 .get_cover_state= h4_mmc_slot2_cover_state,
248 .ocr_mask = MMC_VDD_165_195 | 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 static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
259 void __init h4_mmc_init(void)
261 mmc_data[0] = &mmc1_data;
262 omap2_init_mmc(mmc_data, OMAP24XX_NR_MMC);
267 void __init h4_mmc_init(void)