2 * linux/arch/arm/mach-omap2/mmc-twl4030.c
4 * Copyright (C) 2007-2008 Texas Instruments
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: Texas Instruments
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/err.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/gpio.h>
19 #include <linux/i2c/twl4030.h>
21 #include <mach/hardware.h>
22 #include <mach/control.h>
24 #include <mach/board.h>
26 #include "mmc-twl4030.h"
28 #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
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)
36 #define VMMC1_DEV_GRP 0x27
37 #define VMMC1_CLR 0x00
38 #define VMMC1_315V 0x03
39 #define VMMC1_300V 0x02
40 #define VMMC1_285V 0x01
41 #define VMMC1_185V 0x00
42 #define VMMC1_DEDICATED 0x2A
44 #define VMMC2_DEV_GRP 0x2B
45 #define VMMC2_CLR 0x40
46 #define VMMC2_315V 0x0c
47 #define VMMC2_300V 0x0b
48 #define VMMC2_285V 0x0a
49 #define VMMC2_260V 0x08
50 #define VMMC2_185V 0x06
51 #define VMMC2_DEDICATED 0x2E
53 #define VMMC_DEV_GRP_P1 0x20
55 static u16 control_pbias_offset;
57 static struct twl_mmc_controller {
58 u16 control_devconf_offset;
59 u32 devconf_loopback_clock;
65 .control_devconf_offset = OMAP2_CONTROL_DEVCONF0,
66 .devconf_loopback_clock = OMAP2_MMCSDIO1ADPCLKISEL,
67 .card_detect_gpio = OMAP_MAX_GPIO_LINES,
68 .twl_vmmc_dev_grp = VMMC1_DEV_GRP,
69 .twl_mmc_dedicated = VMMC1_DEDICATED,
72 /* control_devconf_offset set dynamically */
73 .devconf_loopback_clock = OMAP2_MMCSDIO2ADPCLKISEL,
74 .twl_vmmc_dev_grp = VMMC2_DEV_GRP,
75 .twl_mmc_dedicated = VMMC2_DEDICATED,
79 static int twl_mmc1_card_detect(int irq)
81 return gpio_get_value_cansleep(hsmmc[0].card_detect_gpio);
85 * MMC Slot Initialization.
87 static int twl_mmc1_late_init(struct device *dev)
92 * Configure TWL4030 GPIO parameters for MMC hotplug irq
94 ret = gpio_request(hsmmc[0].card_detect_gpio, "mmc0_cd");
98 ret = twl4030_set_gpio_debounce(0, true);
105 dev_err(dev, "Failed to configure TWL4030 GPIO IRQ\n");
110 static void twl_mmc1_cleanup(struct device *dev)
112 gpio_free(hsmmc[0].card_detect_gpio);
118 * Mask and unmask MMC Card Detect Interrupt
122 static int twl_mmc_mask_cd_interrupt(int mask)
126 ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, ®, TWL_GPIO_IMR1A);
130 reg = (mask == 1) ? (reg | GPIO_0_BIT_POS) : (reg & ~GPIO_0_BIT_POS);
132 ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, reg, TWL_GPIO_IMR1A);
136 ret = twl4030_i2c_read_u8(TWL4030_MODULE_GPIO, ®, TWL_GPIO_ISR1A);
140 reg = (mask == 1) ? (reg | GPIO_0_BIT_POS) : (reg & ~GPIO_0_BIT_POS);
142 ret = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, reg, TWL_GPIO_ISR1A);
150 static int twl_mmc1_suspend(struct device *dev, int slot)
154 disable_irq(hsmmc[0].card_detect_gpio);
155 ret = twl_mmc_mask_cd_interrupt(1);
160 static int twl_mmc1_resume(struct device *dev, int slot)
164 enable_irq(hsmmc[0].card_detect_gpio);
165 ret = twl_mmc_mask_cd_interrupt(0);
171 #define twl_mmc1_suspend NULL
172 #define twl_mmc1_resume NULL
176 * Sets the MMC voltage in twl4030
178 static int twl_mmc_set_voltage(struct twl_mmc_controller *c, int vdd)
181 u8 vmmc, dev_grp_val;
190 if (c->twl_vmmc_dev_grp == VMMC1_DEV_GRP)
196 if (c->twl_vmmc_dev_grp == VMMC1_DEV_GRP)
203 if (c->twl_vmmc_dev_grp == VMMC1_DEV_GRP)
214 if (c->twl_vmmc_dev_grp == VMMC1_DEV_GRP)
219 case MMC_VDD_165_195:
220 if (c->twl_vmmc_dev_grp == VMMC1_DEV_GRP)
231 dev_grp_val = VMMC_DEV_GRP_P1; /* Power up */
233 dev_grp_val = LDO_CLR; /* Power down */
235 ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
236 dev_grp_val, c->twl_vmmc_dev_grp);
240 ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
241 vmmc, c->twl_mmc_dedicated);
246 static int twl_mmc1_set_power(struct device *dev, int slot, int power_on,
251 struct twl_mmc_controller *c = &hsmmc[0];
254 if (cpu_is_omap2430()) {
255 reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
256 if ((1 << vdd) >= MMC_VDD_30_31)
257 reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
259 reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
260 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
263 /* REVISIT: Loop back clock not needed for 2430? */
264 if (!cpu_is_omap2430()) {
265 reg = omap_ctrl_readl(c->control_devconf_offset);
266 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
267 omap_ctrl_writel(reg, c->control_devconf_offset);
270 reg = omap_ctrl_readl(control_pbias_offset);
271 reg |= OMAP2_PBIASSPEEDCTRL0;
272 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
273 omap_ctrl_writel(reg, control_pbias_offset);
275 ret = twl_mmc_set_voltage(c, vdd);
277 /* 100ms delay required for PBIAS configuration */
279 reg = omap_ctrl_readl(control_pbias_offset);
280 reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
281 if ((1 << vdd) <= MMC_VDD_165_195)
282 reg &= ~OMAP2_PBIASLITEVMODE0;
284 reg |= OMAP2_PBIASLITEVMODE0;
285 omap_ctrl_writel(reg, control_pbias_offset);
287 reg = omap_ctrl_readl(control_pbias_offset);
288 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
289 omap_ctrl_writel(reg, control_pbias_offset);
291 ret = twl_mmc_set_voltage(c, 0);
293 /* 100ms delay required for PBIAS configuration */
295 reg = omap_ctrl_readl(control_pbias_offset);
296 reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
297 OMAP2_PBIASLITEVMODE0);
298 omap_ctrl_writel(reg, control_pbias_offset);
304 static int twl_mmc2_set_power(struct device *dev, int slot, int power_on, int vdd)
308 struct twl_mmc_controller *c = &hsmmc[1];
313 reg = omap_ctrl_readl(c->control_devconf_offset);
314 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
315 omap_ctrl_writel(reg, c->control_devconf_offset);
316 ret = twl_mmc_set_voltage(c, vdd);
318 ret = twl_mmc_set_voltage(c, 0);
324 static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC];
326 #define HSMMC_NAME_LEN 9
328 void __init hsmmc_init(struct twl4030_hsmmc_info *controllers)
330 struct twl4030_hsmmc_info *c;
332 if (cpu_is_omap2430()) {
333 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
334 hsmmc[1].control_devconf_offset = OMAP243X_CONTROL_DEVCONF1;
336 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
337 hsmmc[1].control_devconf_offset = OMAP343X_CONTROL_DEVCONF1;
340 for (c = controllers; c->mmc; c++) {
341 struct omap_mmc_platform_data *mmc;
344 mmc = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
346 pr_err("Cannot allocate memory for mmc device!\n");
350 name = kzalloc(HSMMC_NAME_LEN, GFP_KERNEL);
353 pr_err("Cannot allocate memory for mmc name!\n");
357 sprintf(name, "mmc%islot%i", c->mmc, 1);
358 mmc->slots[0].name = name;
360 mmc->slots[0].ocr_mask = MMC_VDD_165_195 |
361 MMC_VDD_26_27 | MMC_VDD_27_28 |
363 MMC_VDD_30_31 | MMC_VDD_31_32;
364 mmc->slots[0].wires = c->wires;
365 if (c->gpio_cd != -EINVAL)
366 mmc->slots[0].card_detect_irq = c->gpio_cd;
367 mmc->dma_mask = 0xffffffff;
371 mmc->init = twl_mmc1_late_init;
372 mmc->cleanup = twl_mmc1_cleanup;
373 mmc->suspend = twl_mmc1_suspend;
374 mmc->resume = twl_mmc1_resume;
375 mmc->slots[0].set_power = twl_mmc1_set_power;
376 mmc->slots[0].card_detect = twl_mmc1_card_detect;
380 mmc->slots[0].set_power = twl_mmc2_set_power;
384 pr_err("Unknown MMC configuration!\n");
389 omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);