2 * linux/arch/arm/mach-omap2/board-sdp-hsmmc.c
4 * Copyright (C) 2007 Texas Instruments
5 * Author: Texas Instruments
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.
11 #include <linux/err.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/interrupt.h>
15 #include <linux/delay.h>
16 #include <asm/hardware.h>
17 #include <asm/arch/twl4030.h>
18 #include <asm/arch/mmc.h>
19 #include <asm/arch/board.h>
22 #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
24 #define VMMC1_DEV_GRP 0x27
25 #define P1_DEV_GRP 0x20
26 #define VMMC1_DEDICATED 0x2A
29 #define TWL_GPIO_PUPDCTR1 0x13
30 #define TWL_GPIO_IMR1A 0x1C
31 #define TWL_GPIO_ISR1A 0x19
33 #define VSEL_S2_CLR 0x40
34 #define GPIO_0_BIT_POS 1 << 0
38 static int sdp_mmc_card_detect(int irq)
40 return twl4030_get_gpio_datain(irq - IH_TWL4030_GPIO_BASE);
44 * MMC Slot Initialization.
46 static int sdp_mmc_late_init(struct device *dev)
51 * Configure TWL4030 GPIO parameters for MMC hotplug irq
53 ret = twl4030_request_gpio(MMC1_CD_IRQ);
57 ret = twl4030_set_gpio_edge_ctrl(MMC1_CD_IRQ,
58 TWL4030_GPIO_EDGE_RISING | TWL4030_GPIO_EDGE_FALLING);
62 ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0x02,
67 ret = twl4030_set_gpio_debounce(MMC1_CD_IRQ, TWL4030_GPIO_IS_ENABLE);
73 dev_err(dev, "Failed to configure TWL4030 GPIO IRQ\n");
78 static void sdp_mmc_cleanup(struct device *dev)
82 ret = twl4030_free_gpio(MMC1_CD_IRQ);
84 dev_err(dev, "Failed to configure TWL4030 GPIO IRQ\n");
90 * To mask and unmask MMC Card Detect Interrupt
94 static int mask_cd_interrupt(int mask)
98 ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, ®, TWL_GPIO_IMR1A);
102 reg = (mask == 1) ? (reg | GPIO_0_BIT_POS) : (reg & ~GPIO_0_BIT_POS);
104 ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, reg, TWL_GPIO_IMR1A);
108 ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, ®, TWL_GPIO_ISR1A);
112 reg = (mask == 1) ? (reg | GPIO_0_BIT_POS) : (reg & ~GPIO_0_BIT_POS);
114 ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, reg, TWL_GPIO_ISR1A);
121 static int sdp_mmc_suspend(struct device *dev, int slot)
125 disable_irq(TWL4030_GPIO_IRQ_NO(MMC1_CD_IRQ));
126 ret = mask_cd_interrupt(1);
131 static int sdp_mmc_resume(struct device *dev, int slot)
135 enable_irq(TWL4030_GPIO_IRQ_NO(MMC1_CD_IRQ));
136 ret = mask_cd_interrupt(0);
143 static int sdp_mmc_set_power(struct device *dev, int slot, int power_on,
146 u32 vdd_sel = 0, devconf = 0, reg = 0;
149 /* REVISIT: Using address directly till the control.h defines
152 #if defined(CONFIG_ARCH_OMAP2430)
153 #define OMAP2_CONTROL_PBIAS 0x490024A0
155 #define OMAP2_CONTROL_PBIAS 0x48002520
159 if (cpu_is_omap24xx())
160 devconf = omap_readl(0x490022E8);
162 devconf = omap_readl(0x48002274);
168 if (cpu_is_omap24xx())
169 devconf = (devconf | (1 << 31));
171 case MMC_VDD_165_195:
173 if (cpu_is_omap24xx())
174 devconf = (devconf & ~(1 << 31));
177 if (cpu_is_omap24xx())
178 omap_writel(devconf, 0x490022E8);
180 omap_writel(devconf | 1 << 24, 0x48002274);
182 omap_writel(omap_readl(OMAP2_CONTROL_PBIAS) | 1 << 2,
183 OMAP2_CONTROL_PBIAS);
184 omap_writel(omap_readl(OMAP2_CONTROL_PBIAS) & ~(1 << 1),
185 OMAP2_CONTROL_PBIAS);
187 ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
188 P1_DEV_GRP, VMMC1_DEV_GRP);
192 ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
193 vdd_sel, VMMC1_DEDICATED);
198 reg = omap_readl(OMAP2_CONTROL_PBIAS);
199 reg = (vdd_sel == VSEL_18V) ? ((reg | 0x6) & ~0x1)
201 omap_writel(reg, OMAP2_CONTROL_PBIAS);
205 } else if (power_on == 0) {
208 /* For MMC1, Toggle PBIAS before every power up sequence */
209 omap_writel(omap_readl(OMAP2_CONTROL_PBIAS) & ~(1 << 1),
210 OMAP2_CONTROL_PBIAS);
211 ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
212 LDO_CLR, VMMC1_DEV_GRP);
216 ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
217 VSEL_S2_CLR, VMMC1_DEDICATED);
221 /* 100ms delay required for PBIAS configuration */
223 omap_writel(omap_readl(OMAP2_CONTROL_PBIAS) | 0x7,
224 OMAP2_CONTROL_PBIAS);
235 static struct omap_mmc_platform_data sdp_mmc_data = {
238 .init = sdp_mmc_late_init,
239 .cleanup = sdp_mmc_cleanup,
241 .suspend = sdp_mmc_suspend,
242 .resume = sdp_mmc_resume,
245 .set_power = sdp_mmc_set_power,
246 .set_bus_mode = NULL,
248 .get_cover_state = NULL,
249 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34 |
251 .name = "first slot",
253 .card_detect_irq = TWL4030_GPIO_IRQ_NO(MMC1_CD_IRQ),
254 .card_detect = sdp_mmc_card_detect,
258 void __init sdp_mmc_init(void)
260 omap_set_mmc_info(1, &sdp_mmc_data);
265 void __init sdp_mmc_init(void)