Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 1 | /* |
Adrian Hunter | d02a900b | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2 | * linux/arch/arm/mach-omap2/hsmmc.c |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007-2008 Texas Instruments |
| 5 | * Copyright (C) 2008 Nokia Corporation |
| 6 | * Author: Texas Instruments |
| 7 | * |
| 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. |
| 11 | */ |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/string.h> |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 15 | #include <linux/delay.h> |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 16 | #include <mach/hardware.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 17 | #include <plat/mmc.h> |
Adrian Hunter | e3df0fb | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 18 | #include <plat/omap-pm.h> |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame^] | 19 | #include <plat/mux.h> |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 20 | |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame^] | 21 | #include "mux.h" |
Adrian Hunter | d02a900b | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 22 | #include "hsmmc.h" |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 23 | #include "control.h" |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 24 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 25 | #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 26 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 27 | static u16 control_pbias_offset; |
| 28 | static u16 control_devconf1_offset; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 29 | static u16 control_mmc1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 30 | |
| 31 | #define HSMMC_NAME_LEN 9 |
| 32 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 33 | static struct hsmmc_controller { |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 34 | char name[HSMMC_NAME_LEN + 1]; |
| 35 | } hsmmc[OMAP34XX_NR_MMC]; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 36 | |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 37 | #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) |
| 38 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 39 | static int hsmmc_get_context_loss(struct device *dev) |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 40 | { |
Adrian Hunter | e3df0fb | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 41 | return omap_pm_get_dev_context_loss_count(dev); |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | #else |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 45 | #define hsmmc_get_context_loss NULL |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 48 | static void omap_hsmmc1_before_set_reg(struct device *dev, int slot, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 49 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 50 | { |
Madhu | 555d503 | 2009-11-22 10:11:08 -0800 | [diff] [blame] | 51 | u32 reg, prog_io; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 52 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 53 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 54 | if (mmc->slots[0].remux) |
| 55 | mmc->slots[0].remux(dev, slot, power_on); |
| 56 | |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 57 | /* |
| 58 | * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 59 | * card with Vcc regulator (from twl4030 or whatever). OMAP has both |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 60 | * 1.8V and 3.0V modes, controlled by the PBIAS register. |
| 61 | * |
| 62 | * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which |
| 63 | * is most naturally TWL VSIM; those pins also use PBIAS. |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 64 | * |
| 65 | * FIXME handle VMMC1A as needed ... |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 66 | */ |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 67 | if (power_on) { |
| 68 | if (cpu_is_omap2430()) { |
| 69 | reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1); |
| 70 | if ((1 << vdd) >= MMC_VDD_30_31) |
| 71 | reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE; |
| 72 | else |
| 73 | reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE; |
| 74 | omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1); |
| 75 | } |
| 76 | |
| 77 | if (mmc->slots[0].internal_clock) { |
| 78 | reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 79 | reg |= OMAP2_MMCSDIO1ADPCLKISEL; |
| 80 | omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0); |
| 81 | } |
| 82 | |
| 83 | reg = omap_ctrl_readl(control_pbias_offset); |
Madhu | 555d503 | 2009-11-22 10:11:08 -0800 | [diff] [blame] | 84 | if (cpu_is_omap3630()) { |
| 85 | /* Set MMC I/O to 52Mhz */ |
| 86 | prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1); |
| 87 | prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL; |
| 88 | omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1); |
| 89 | } else { |
| 90 | reg |= OMAP2_PBIASSPEEDCTRL0; |
| 91 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 92 | reg &= ~OMAP2_PBIASLITEPWRDNZ0; |
| 93 | omap_ctrl_writel(reg, control_pbias_offset); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 94 | } else { |
| 95 | reg = omap_ctrl_readl(control_pbias_offset); |
| 96 | reg &= ~OMAP2_PBIASLITEPWRDNZ0; |
| 97 | omap_ctrl_writel(reg, control_pbias_offset); |
| 98 | } |
| 99 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 100 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 101 | static void omap_hsmmc1_after_set_reg(struct device *dev, int slot, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 102 | int power_on, int vdd) |
| 103 | { |
| 104 | u32 reg; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 105 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 106 | /* 100ms delay required for PBIAS configuration */ |
| 107 | msleep(100); |
| 108 | |
| 109 | if (power_on) { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 110 | reg = omap_ctrl_readl(control_pbias_offset); |
| 111 | reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0); |
| 112 | if ((1 << vdd) <= MMC_VDD_165_195) |
| 113 | reg &= ~OMAP2_PBIASLITEVMODE0; |
| 114 | else |
| 115 | reg |= OMAP2_PBIASLITEVMODE0; |
| 116 | omap_ctrl_writel(reg, control_pbias_offset); |
| 117 | } else { |
| 118 | reg = omap_ctrl_readl(control_pbias_offset); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 119 | reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 | |
| 120 | OMAP2_PBIASLITEVMODE0); |
| 121 | omap_ctrl_writel(reg, control_pbias_offset); |
| 122 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 123 | } |
| 124 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 125 | static void omap4_hsmmc1_before_set_reg(struct device *dev, int slot, |
| 126 | int power_on, int vdd) |
| 127 | { |
| 128 | u32 reg; |
| 129 | |
| 130 | /* |
| 131 | * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the |
| 132 | * card with Vcc regulator (from twl4030 or whatever). OMAP has both |
| 133 | * 1.8V and 3.0V modes, controlled by the PBIAS register. |
| 134 | * |
| 135 | * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which |
| 136 | * is most naturally TWL VSIM; those pins also use PBIAS. |
| 137 | * |
| 138 | * FIXME handle VMMC1A as needed ... |
| 139 | */ |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 140 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 141 | reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK | |
| 142 | OMAP4_MMC1_PWRDNZ_MASK | |
| 143 | OMAP4_USBC1_ICUSB_PWRDNZ_MASK); |
| 144 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot, |
| 148 | int power_on, int vdd) |
| 149 | { |
| 150 | u32 reg; |
| 151 | |
| 152 | if (power_on) { |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 153 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 154 | reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 155 | if ((1 << vdd) <= MMC_VDD_165_195) |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 156 | reg &= ~OMAP4_MMC1_PBIASLITE_VMODE_MASK; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 157 | else |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 158 | reg |= OMAP4_MMC1_PBIASLITE_VMODE_MASK; |
| 159 | reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK | |
| 160 | OMAP4_MMC1_PWRDNZ_MASK | |
| 161 | OMAP4_USBC1_ICUSB_PWRDNZ_MASK); |
| 162 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 163 | /* 4 microsec delay for comparator to generate an error*/ |
| 164 | udelay(4); |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 165 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 166 | if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK) { |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 167 | pr_err("Pbias Voltage is not same as LDO\n"); |
| 168 | /* Caution : On VMODE_ERROR Power Down MMC IO */ |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 169 | reg &= ~(OMAP4_MMC1_PWRDNZ_MASK | |
| 170 | OMAP4_USBC1_ICUSB_PWRDNZ_MASK); |
| 171 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 172 | } |
| 173 | } else { |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 174 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 175 | reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK | |
| 176 | OMAP4_MMC1_PWRDNZ_MASK | |
| 177 | OMAP4_MMC1_PBIASLITE_VMODE_MASK | |
| 178 | OMAP4_USBC1_ICUSB_PWRDNZ_MASK); |
| 179 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 183 | static void hsmmc23_before_set_reg(struct device *dev, int slot, |
| 184 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 185 | { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 186 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
Grazvydas Ignotas | 762ad3a4 | 2009-06-23 13:30:22 +0300 | [diff] [blame] | 187 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 188 | if (mmc->slots[0].remux) |
| 189 | mmc->slots[0].remux(dev, slot, power_on); |
| 190 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 191 | if (power_on) { |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 192 | /* Only MMC2 supports a CLKIN */ |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 193 | if (mmc->slots[0].internal_clock) { |
| 194 | u32 reg; |
| 195 | |
| 196 | reg = omap_ctrl_readl(control_devconf1_offset); |
| 197 | reg |= OMAP2_MMCSDIO2ADPCLKISEL; |
| 198 | omap_ctrl_writel(reg, control_devconf1_offset); |
| 199 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 200 | } |
Adrian Hunter | 9b7c18e | 2009-09-22 16:44:50 -0700 | [diff] [blame] | 201 | } |
| 202 | |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 203 | static int nop_mmc_set_power(struct device *dev, int slot, int power_on, |
| 204 | int vdd) |
| 205 | { |
| 206 | return 0; |
| 207 | } |
| 208 | |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame^] | 209 | static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller, |
| 210 | int controller_nr) |
| 211 | { |
| 212 | if ((mmc_controller->slots[0].switch_pin > 0) && \ |
| 213 | (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES)) |
| 214 | omap_mux_init_gpio(mmc_controller->slots[0].switch_pin, |
| 215 | OMAP_PIN_INPUT_PULLUP); |
| 216 | if ((mmc_controller->slots[0].gpio_wp > 0) && \ |
| 217 | (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES)) |
| 218 | omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp, |
| 219 | OMAP_PIN_INPUT_PULLUP); |
| 220 | if (cpu_is_omap34xx()) { |
| 221 | if (controller_nr == 0) { |
| 222 | omap_mux_init_signal("sdmmc1_clk", |
| 223 | OMAP_PIN_INPUT_PULLUP); |
| 224 | omap_mux_init_signal("sdmmc1_cmd", |
| 225 | OMAP_PIN_INPUT_PULLUP); |
| 226 | omap_mux_init_signal("sdmmc1_dat0", |
| 227 | OMAP_PIN_INPUT_PULLUP); |
| 228 | if (mmc_controller->slots[0].caps & |
| 229 | (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { |
| 230 | omap_mux_init_signal("sdmmc1_dat1", |
| 231 | OMAP_PIN_INPUT_PULLUP); |
| 232 | omap_mux_init_signal("sdmmc1_dat2", |
| 233 | OMAP_PIN_INPUT_PULLUP); |
| 234 | omap_mux_init_signal("sdmmc1_dat3", |
| 235 | OMAP_PIN_INPUT_PULLUP); |
| 236 | } |
| 237 | if (mmc_controller->slots[0].caps & |
| 238 | MMC_CAP_8_BIT_DATA) { |
| 239 | omap_mux_init_signal("sdmmc1_dat4", |
| 240 | OMAP_PIN_INPUT_PULLUP); |
| 241 | omap_mux_init_signal("sdmmc1_dat5", |
| 242 | OMAP_PIN_INPUT_PULLUP); |
| 243 | omap_mux_init_signal("sdmmc1_dat6", |
| 244 | OMAP_PIN_INPUT_PULLUP); |
| 245 | omap_mux_init_signal("sdmmc1_dat7", |
| 246 | OMAP_PIN_INPUT_PULLUP); |
| 247 | } |
| 248 | } |
| 249 | if (controller_nr == 1) { |
| 250 | /* MMC2 */ |
| 251 | omap_mux_init_signal("sdmmc2_clk", |
| 252 | OMAP_PIN_INPUT_PULLUP); |
| 253 | omap_mux_init_signal("sdmmc2_cmd", |
| 254 | OMAP_PIN_INPUT_PULLUP); |
| 255 | omap_mux_init_signal("sdmmc2_dat0", |
| 256 | OMAP_PIN_INPUT_PULLUP); |
| 257 | |
| 258 | /* |
| 259 | * For 8 wire configurations, Lines DAT4, 5, 6 and 7 |
| 260 | * need to be muxed in the board-*.c files |
| 261 | */ |
| 262 | if (mmc_controller->slots[0].caps & |
| 263 | (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { |
| 264 | omap_mux_init_signal("sdmmc2_dat1", |
| 265 | OMAP_PIN_INPUT_PULLUP); |
| 266 | omap_mux_init_signal("sdmmc2_dat2", |
| 267 | OMAP_PIN_INPUT_PULLUP); |
| 268 | omap_mux_init_signal("sdmmc2_dat3", |
| 269 | OMAP_PIN_INPUT_PULLUP); |
| 270 | } |
| 271 | if (mmc_controller->slots[0].caps & |
| 272 | MMC_CAP_8_BIT_DATA) { |
| 273 | omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4", |
| 274 | OMAP_PIN_INPUT_PULLUP); |
| 275 | omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5", |
| 276 | OMAP_PIN_INPUT_PULLUP); |
| 277 | omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6", |
| 278 | OMAP_PIN_INPUT_PULLUP); |
| 279 | omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7", |
| 280 | OMAP_PIN_INPUT_PULLUP); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * For MMC3 the pins need to be muxed in the board-*.c files |
| 286 | */ |
| 287 | } |
| 288 | } |
| 289 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 290 | static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata; |
| 291 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 292 | void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 293 | { |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 294 | struct omap2_hsmmc_info *c; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 295 | int nr_hsmmc = ARRAY_SIZE(hsmmc_data); |
Aaro Koskinen | a6c7fdd | 2010-02-04 13:06:59 +0200 | [diff] [blame] | 296 | int i; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 297 | u32 reg; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 298 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 299 | if (!cpu_is_omap44xx()) { |
| 300 | if (cpu_is_omap2430()) { |
| 301 | control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE; |
| 302 | control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1; |
| 303 | } else { |
| 304 | control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE; |
| 305 | control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1; |
| 306 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 307 | } else { |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 308 | control_pbias_offset = |
| 309 | OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_PBIASLITE; |
| 310 | control_mmc1 = OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_MMC1; |
| 311 | reg = omap4_ctrl_pad_readl(control_mmc1); |
| 312 | reg |= (OMAP4_SDMMC1_PUSTRENGTH_GRP0_MASK | |
| 313 | OMAP4_SDMMC1_PUSTRENGTH_GRP1_MASK); |
| 314 | reg &= ~(OMAP4_SDMMC1_PUSTRENGTH_GRP2_MASK | |
| 315 | OMAP4_SDMMC1_PUSTRENGTH_GRP3_MASK); |
| 316 | reg |= (OMAP4_USBC1_DR0_SPEEDCTRL_MASK| |
| 317 | OMAP4_SDMMC1_DR1_SPEEDCTRL_MASK | |
| 318 | OMAP4_SDMMC1_DR2_SPEEDCTRL_MASK); |
| 319 | omap4_ctrl_pad_writel(reg, control_mmc1); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | for (c = controllers; c->mmc; c++) { |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 323 | struct hsmmc_controller *hc = hsmmc + c->mmc - 1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 324 | struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1]; |
| 325 | |
| 326 | if (!c->mmc || c->mmc > nr_hsmmc) { |
| 327 | pr_debug("MMC%d: no such controller\n", c->mmc); |
| 328 | continue; |
| 329 | } |
| 330 | if (mmc) { |
| 331 | pr_debug("MMC%d: already configured\n", c->mmc); |
| 332 | continue; |
| 333 | } |
| 334 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 335 | mmc = kzalloc(sizeof(struct omap_mmc_platform_data), |
| 336 | GFP_KERNEL); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 337 | if (!mmc) { |
| 338 | pr_err("Cannot allocate memory for mmc device!\n"); |
Aaro Koskinen | a6c7fdd | 2010-02-04 13:06:59 +0200 | [diff] [blame] | 339 | goto done; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Adrian Hunter | e51151a | 2009-03-23 18:23:48 -0700 | [diff] [blame] | 342 | if (c->name) |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 343 | strncpy(hc->name, c->name, HSMMC_NAME_LEN); |
Adrian Hunter | e51151a | 2009-03-23 18:23:48 -0700 | [diff] [blame] | 344 | else |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 345 | snprintf(hc->name, ARRAY_SIZE(hc->name), |
Adrian Hunter | e51151a | 2009-03-23 18:23:48 -0700 | [diff] [blame] | 346 | "mmc%islot%i", c->mmc, 1); |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 347 | mmc->slots[0].name = hc->name; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 348 | mmc->nr_slots = 1; |
Sukumar Ghorai | 3a63833 | 2010-09-15 14:49:23 +0000 | [diff] [blame] | 349 | mmc->slots[0].caps = c->caps; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 350 | mmc->slots[0].internal_clock = !c->ext_clock; |
| 351 | mmc->dma_mask = 0xffffffff; |
kishore kadiyala | 91a0b08 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 352 | if (cpu_is_omap44xx()) |
| 353 | mmc->reg_offset = OMAP4_MMC_REG_OFFSET; |
| 354 | else |
| 355 | mmc->reg_offset = 0; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 356 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 357 | mmc->get_context_loss_count = hsmmc_get_context_loss; |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 358 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 359 | mmc->slots[0].switch_pin = c->gpio_cd; |
| 360 | mmc->slots[0].gpio_wp = c->gpio_wp; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 361 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 362 | mmc->slots[0].remux = c->remux; |
Grazvydas Ignotas | ed199f7 | 2010-08-10 18:01:52 -0700 | [diff] [blame] | 363 | mmc->slots[0].init_card = c->init_card; |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 364 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 365 | if (c->cover_only) |
| 366 | mmc->slots[0].cover = 1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 367 | |
Adrian Hunter | 23d99bb | 2009-09-22 16:44:48 -0700 | [diff] [blame] | 368 | if (c->nonremovable) |
| 369 | mmc->slots[0].nonremovable = 1; |
| 370 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 371 | if (c->power_saving) |
| 372 | mmc->slots[0].power_saving = 1; |
| 373 | |
Adrian Hunter | 1df58db | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 374 | if (c->no_off) |
| 375 | mmc->slots[0].no_off = 1; |
| 376 | |
Adrian Hunter | e0eb242 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 377 | if (c->vcc_aux_disable_is_sleep) |
| 378 | mmc->slots[0].vcc_aux_disable_is_sleep = 1; |
| 379 | |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 380 | /* NOTE: MMC slots should have a Vcc regulator set up. |
| 381 | * This may be from a TWL4030-family chip, another |
| 382 | * controllable regulator, or a fixed supply. |
| 383 | * |
| 384 | * temporary HACK: ocr_mask instead of fixed supply |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 385 | */ |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 386 | mmc->slots[0].ocr_mask = c->ocr_mask; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 387 | |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 388 | if (cpu_is_omap3517() || cpu_is_omap3505()) |
| 389 | mmc->slots[0].set_power = nop_mmc_set_power; |
| 390 | else |
| 391 | mmc->slots[0].features |= HSMMC_HAS_PBIAS; |
| 392 | |
Madhusudhan Chikkature | 07ad64b | 2010-10-01 16:35:25 -0700 | [diff] [blame] | 393 | if (cpu_is_omap44xx() && (omap_rev() > OMAP4430_REV_ES1_0)) |
| 394 | mmc->slots[0].features |= HSMMC_HAS_UPDATED_RESET; |
| 395 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 396 | switch (c->mmc) { |
| 397 | case 1: |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 398 | if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { |
| 399 | /* on-chip level shifting via PBIAS0/PBIAS1 */ |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 400 | if (cpu_is_omap44xx()) { |
| 401 | mmc->slots[0].before_set_reg = |
| 402 | omap4_hsmmc1_before_set_reg; |
| 403 | mmc->slots[0].after_set_reg = |
| 404 | omap4_hsmmc1_after_set_reg; |
| 405 | } else { |
| 406 | mmc->slots[0].before_set_reg = |
| 407 | omap_hsmmc1_before_set_reg; |
| 408 | mmc->slots[0].after_set_reg = |
| 409 | omap_hsmmc1_after_set_reg; |
| 410 | } |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 411 | } |
Madhu | 41fd03d | 2009-11-22 10:11:07 -0800 | [diff] [blame] | 412 | |
| 413 | /* Omap3630 HSMMC1 supports only 4-bit */ |
Sukumar Ghorai | 3a63833 | 2010-09-15 14:49:23 +0000 | [diff] [blame] | 414 | if (cpu_is_omap3630() && |
| 415 | (c->caps & MMC_CAP_8_BIT_DATA)) { |
| 416 | c->caps &= ~MMC_CAP_8_BIT_DATA; |
| 417 | c->caps |= MMC_CAP_4_BIT_DATA; |
| 418 | mmc->slots[0].caps = c->caps; |
Madhu | 41fd03d | 2009-11-22 10:11:07 -0800 | [diff] [blame] | 419 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 420 | break; |
| 421 | case 2: |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 422 | if (c->ext_clock) |
| 423 | c->transceiver = 1; |
Sukumar Ghorai | 3a63833 | 2010-09-15 14:49:23 +0000 | [diff] [blame] | 424 | if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) { |
| 425 | c->caps &= ~MMC_CAP_8_BIT_DATA; |
| 426 | c->caps |= MMC_CAP_4_BIT_DATA; |
| 427 | } |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 428 | /* FALLTHROUGH */ |
Grazvydas Ignotas | 07d83cc | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 429 | case 3: |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 430 | if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { |
| 431 | /* off-chip level shifting, or none */ |
| 432 | mmc->slots[0].before_set_reg = hsmmc23_before_set_reg; |
| 433 | mmc->slots[0].after_set_reg = NULL; |
| 434 | } |
Grazvydas Ignotas | 07d83cc | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 435 | break; |
Kishore Kadiyala | 7715db5 | 2011-02-15 03:40:36 -0500 | [diff] [blame] | 436 | case 4: |
| 437 | case 5: |
| 438 | mmc->slots[0].before_set_reg = NULL; |
| 439 | mmc->slots[0].after_set_reg = NULL; |
| 440 | break; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 441 | default: |
| 442 | pr_err("MMC%d configuration not supported!\n", c->mmc); |
Grazvydas Ignotas | 07d83cc | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 443 | kfree(mmc); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 444 | continue; |
| 445 | } |
| 446 | hsmmc_data[c->mmc - 1] = mmc; |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame^] | 447 | omap_hsmmc_mux(hsmmc_data[c->mmc - 1], (c->mmc - 1)); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC); |
David Brownell | 01971f6 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 451 | |
| 452 | /* pass the device nodes back to board setup code */ |
| 453 | for (c = controllers; c->mmc; c++) { |
| 454 | struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1]; |
| 455 | |
| 456 | if (!c->mmc || c->mmc > nr_hsmmc) |
| 457 | continue; |
| 458 | c->dev = mmc->dev; |
| 459 | } |
Aaro Koskinen | a6c7fdd | 2010-02-04 13:06:59 +0200 | [diff] [blame] | 460 | |
| 461 | done: |
| 462 | for (i = 0; i < nr_hsmmc; i++) |
| 463 | kfree(hsmmc_data[i]); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | #endif |