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> |
Silesh C V | 5e4698f | 2011-07-04 04:10:00 -0700 | [diff] [blame] | 16 | #include <linux/gpio.h> |
Tony Lindgren | 4b25408 | 2012-08-30 15:37:24 -0700 | [diff] [blame] | 17 | #include <linux/platform_data/gpio-omap.h> |
| 18 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame] | 19 | #include "soc.h" |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 20 | #include "omap_device.h" |
Tony Lindgren | 1d5aef4 | 2012-10-03 16:36:40 -0700 | [diff] [blame] | 21 | #include "omap-pm.h" |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 22 | |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 23 | #include "mux.h" |
Tony Lindgren | 68f39e7 | 2012-10-15 12:09:43 -0700 | [diff] [blame] | 24 | #include "mmc.h" |
Adrian Hunter | d02a900b | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 25 | #include "hsmmc.h" |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 26 | #include "control.h" |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 27 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 28 | #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 29 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 30 | static u16 control_pbias_offset; |
| 31 | static u16 control_devconf1_offset; |
| 32 | |
| 33 | #define HSMMC_NAME_LEN 9 |
| 34 | |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 35 | #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) |
| 36 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 37 | static int hsmmc_get_context_loss(struct device *dev) |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 38 | { |
Adrian Hunter | e3df0fb | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 39 | return omap_pm_get_dev_context_loss_count(dev); |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | #else |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 43 | #define hsmmc_get_context_loss NULL |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 44 | #endif |
| 45 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 46 | static void omap_hsmmc1_before_set_reg(struct device *dev, int slot, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 47 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 48 | { |
Madhu | 555d503 | 2009-11-22 10:11:08 -0800 | [diff] [blame] | 49 | u32 reg, prog_io; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 50 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 51 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 52 | if (mmc->slots[0].remux) |
| 53 | mmc->slots[0].remux(dev, slot, power_on); |
| 54 | |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 55 | /* |
| 56 | * 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] | 57 | * card with Vcc regulator (from twl4030 or whatever). OMAP has both |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 58 | * 1.8V and 3.0V modes, controlled by the PBIAS register. |
| 59 | * |
| 60 | * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which |
| 61 | * is most naturally TWL VSIM; those pins also use PBIAS. |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 62 | * |
| 63 | * FIXME handle VMMC1A as needed ... |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 64 | */ |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 65 | if (power_on) { |
| 66 | if (cpu_is_omap2430()) { |
| 67 | reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1); |
| 68 | if ((1 << vdd) >= MMC_VDD_30_31) |
| 69 | reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE; |
| 70 | else |
| 71 | reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE; |
| 72 | omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1); |
| 73 | } |
| 74 | |
| 75 | if (mmc->slots[0].internal_clock) { |
| 76 | reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 77 | reg |= OMAP2_MMCSDIO1ADPCLKISEL; |
| 78 | omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0); |
| 79 | } |
| 80 | |
| 81 | reg = omap_ctrl_readl(control_pbias_offset); |
Madhu | 555d503 | 2009-11-22 10:11:08 -0800 | [diff] [blame] | 82 | if (cpu_is_omap3630()) { |
| 83 | /* Set MMC I/O to 52Mhz */ |
| 84 | prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1); |
| 85 | prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL; |
| 86 | omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1); |
| 87 | } else { |
| 88 | reg |= OMAP2_PBIASSPEEDCTRL0; |
| 89 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 90 | reg &= ~OMAP2_PBIASLITEPWRDNZ0; |
| 91 | omap_ctrl_writel(reg, control_pbias_offset); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 92 | } else { |
| 93 | reg = omap_ctrl_readl(control_pbias_offset); |
| 94 | reg &= ~OMAP2_PBIASLITEPWRDNZ0; |
| 95 | omap_ctrl_writel(reg, control_pbias_offset); |
| 96 | } |
| 97 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 98 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 99 | static void omap_hsmmc1_after_set_reg(struct device *dev, int slot, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 100 | int power_on, int vdd) |
| 101 | { |
| 102 | u32 reg; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 103 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 104 | /* 100ms delay required for PBIAS configuration */ |
| 105 | msleep(100); |
| 106 | |
| 107 | if (power_on) { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 108 | reg = omap_ctrl_readl(control_pbias_offset); |
| 109 | reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0); |
| 110 | if ((1 << vdd) <= MMC_VDD_165_195) |
| 111 | reg &= ~OMAP2_PBIASLITEVMODE0; |
| 112 | else |
| 113 | reg |= OMAP2_PBIASLITEVMODE0; |
| 114 | omap_ctrl_writel(reg, control_pbias_offset); |
| 115 | } else { |
| 116 | reg = omap_ctrl_readl(control_pbias_offset); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 117 | reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 | |
| 118 | OMAP2_PBIASLITEVMODE0); |
| 119 | omap_ctrl_writel(reg, control_pbias_offset); |
| 120 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 123 | static void hsmmc2_select_input_clk_src(struct omap_mmc_platform_data *mmc) |
| 124 | { |
| 125 | u32 reg; |
| 126 | |
Grazvydas Ignotas | d82e519 | 2012-01-12 16:26:45 +0200 | [diff] [blame] | 127 | reg = omap_ctrl_readl(control_devconf1_offset); |
| 128 | if (mmc->slots[0].internal_clock) |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 129 | reg |= OMAP2_MMCSDIO2ADPCLKISEL; |
Grazvydas Ignotas | d82e519 | 2012-01-12 16:26:45 +0200 | [diff] [blame] | 130 | else |
| 131 | reg &= ~OMAP2_MMCSDIO2ADPCLKISEL; |
| 132 | omap_ctrl_writel(reg, control_devconf1_offset); |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Grazvydas Ignotas | ffa1e4e | 2011-12-18 02:35:47 +0200 | [diff] [blame] | 135 | static void hsmmc2_before_set_reg(struct device *dev, int slot, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 136 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 137 | { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 138 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
Grazvydas Ignotas | 762ad3a4 | 2009-06-23 13:30:22 +0300 | [diff] [blame] | 139 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 140 | if (mmc->slots[0].remux) |
| 141 | mmc->slots[0].remux(dev, slot, power_on); |
| 142 | |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 143 | if (power_on) |
| 144 | hsmmc2_select_input_clk_src(mmc); |
| 145 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 146 | |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 147 | static int am35x_hsmmc2_set_power(struct device *dev, int slot, |
| 148 | int power_on, int vdd) |
| 149 | { |
| 150 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 151 | |
| 152 | if (power_on) |
| 153 | hsmmc2_select_input_clk_src(mmc); |
| 154 | |
| 155 | return 0; |
Adrian Hunter | 9b7c18e | 2009-09-22 16:44:50 -0700 | [diff] [blame] | 156 | } |
| 157 | |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 158 | static int nop_mmc_set_power(struct device *dev, int slot, int power_on, |
| 159 | int vdd) |
| 160 | { |
| 161 | return 0; |
| 162 | } |
| 163 | |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 164 | static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller, |
| 165 | int controller_nr) |
| 166 | { |
Thomas Weber | a15164f | 2011-11-17 22:39:40 +0100 | [diff] [blame] | 167 | if (gpio_is_valid(mmc_controller->slots[0].switch_pin) && |
| 168 | (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES)) |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 169 | omap_mux_init_gpio(mmc_controller->slots[0].switch_pin, |
| 170 | OMAP_PIN_INPUT_PULLUP); |
Thomas Weber | a15164f | 2011-11-17 22:39:40 +0100 | [diff] [blame] | 171 | if (gpio_is_valid(mmc_controller->slots[0].gpio_wp) && |
| 172 | (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES)) |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 173 | omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp, |
| 174 | OMAP_PIN_INPUT_PULLUP); |
| 175 | if (cpu_is_omap34xx()) { |
| 176 | if (controller_nr == 0) { |
| 177 | omap_mux_init_signal("sdmmc1_clk", |
| 178 | OMAP_PIN_INPUT_PULLUP); |
| 179 | omap_mux_init_signal("sdmmc1_cmd", |
| 180 | OMAP_PIN_INPUT_PULLUP); |
| 181 | omap_mux_init_signal("sdmmc1_dat0", |
| 182 | OMAP_PIN_INPUT_PULLUP); |
| 183 | if (mmc_controller->slots[0].caps & |
| 184 | (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { |
| 185 | omap_mux_init_signal("sdmmc1_dat1", |
| 186 | OMAP_PIN_INPUT_PULLUP); |
| 187 | omap_mux_init_signal("sdmmc1_dat2", |
| 188 | OMAP_PIN_INPUT_PULLUP); |
| 189 | omap_mux_init_signal("sdmmc1_dat3", |
| 190 | OMAP_PIN_INPUT_PULLUP); |
| 191 | } |
| 192 | if (mmc_controller->slots[0].caps & |
| 193 | MMC_CAP_8_BIT_DATA) { |
| 194 | omap_mux_init_signal("sdmmc1_dat4", |
| 195 | OMAP_PIN_INPUT_PULLUP); |
| 196 | omap_mux_init_signal("sdmmc1_dat5", |
| 197 | OMAP_PIN_INPUT_PULLUP); |
| 198 | omap_mux_init_signal("sdmmc1_dat6", |
| 199 | OMAP_PIN_INPUT_PULLUP); |
| 200 | omap_mux_init_signal("sdmmc1_dat7", |
| 201 | OMAP_PIN_INPUT_PULLUP); |
| 202 | } |
| 203 | } |
| 204 | if (controller_nr == 1) { |
| 205 | /* MMC2 */ |
| 206 | omap_mux_init_signal("sdmmc2_clk", |
| 207 | OMAP_PIN_INPUT_PULLUP); |
| 208 | omap_mux_init_signal("sdmmc2_cmd", |
| 209 | OMAP_PIN_INPUT_PULLUP); |
| 210 | omap_mux_init_signal("sdmmc2_dat0", |
| 211 | OMAP_PIN_INPUT_PULLUP); |
| 212 | |
| 213 | /* |
| 214 | * For 8 wire configurations, Lines DAT4, 5, 6 and 7 |
| 215 | * need to be muxed in the board-*.c files |
| 216 | */ |
| 217 | if (mmc_controller->slots[0].caps & |
| 218 | (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { |
| 219 | omap_mux_init_signal("sdmmc2_dat1", |
| 220 | OMAP_PIN_INPUT_PULLUP); |
| 221 | omap_mux_init_signal("sdmmc2_dat2", |
| 222 | OMAP_PIN_INPUT_PULLUP); |
| 223 | omap_mux_init_signal("sdmmc2_dat3", |
| 224 | OMAP_PIN_INPUT_PULLUP); |
| 225 | } |
| 226 | if (mmc_controller->slots[0].caps & |
| 227 | MMC_CAP_8_BIT_DATA) { |
| 228 | omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4", |
| 229 | OMAP_PIN_INPUT_PULLUP); |
| 230 | omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5", |
| 231 | OMAP_PIN_INPUT_PULLUP); |
| 232 | omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6", |
| 233 | OMAP_PIN_INPUT_PULLUP); |
| 234 | omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7", |
| 235 | OMAP_PIN_INPUT_PULLUP); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * For MMC3 the pins need to be muxed in the board-*.c files |
| 241 | */ |
| 242 | } |
| 243 | } |
| 244 | |
Tony Lindgren | d1589f0 | 2012-02-20 09:43:30 -0800 | [diff] [blame] | 245 | static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c, |
| 246 | struct omap_mmc_platform_data *mmc) |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 247 | { |
| 248 | char *hc_name; |
| 249 | |
| 250 | hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL); |
| 251 | if (!hc_name) { |
| 252 | pr_err("Cannot allocate memory for controller slot name\n"); |
| 253 | kfree(hc_name); |
| 254 | return -ENOMEM; |
| 255 | } |
| 256 | |
| 257 | if (c->name) |
| 258 | strncpy(hc_name, c->name, HSMMC_NAME_LEN); |
| 259 | else |
| 260 | snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", |
| 261 | c->mmc, 1); |
| 262 | mmc->slots[0].name = hc_name; |
| 263 | mmc->nr_slots = 1; |
| 264 | mmc->slots[0].caps = c->caps; |
Eliad Peller | 6fdc75d | 2011-11-22 16:02:18 +0200 | [diff] [blame] | 265 | mmc->slots[0].pm_caps = c->pm_caps; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 266 | mmc->slots[0].internal_clock = !c->ext_clock; |
Daniel Mack | d418ed8 | 2012-02-19 13:20:33 +0100 | [diff] [blame] | 267 | mmc->max_freq = c->max_freq; |
Tony Lindgren | b30e321 | 2013-05-30 12:53:06 -0700 | [diff] [blame] | 268 | mmc->reg_offset = 0; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 269 | mmc->get_context_loss_count = hsmmc_get_context_loss; |
| 270 | |
| 271 | mmc->slots[0].switch_pin = c->gpio_cd; |
| 272 | mmc->slots[0].gpio_wp = c->gpio_wp; |
| 273 | |
| 274 | mmc->slots[0].remux = c->remux; |
| 275 | mmc->slots[0].init_card = c->init_card; |
| 276 | |
| 277 | if (c->cover_only) |
| 278 | mmc->slots[0].cover = 1; |
| 279 | |
| 280 | if (c->nonremovable) |
| 281 | mmc->slots[0].nonremovable = 1; |
| 282 | |
| 283 | if (c->power_saving) |
| 284 | mmc->slots[0].power_saving = 1; |
| 285 | |
| 286 | if (c->no_off) |
| 287 | mmc->slots[0].no_off = 1; |
| 288 | |
Balaji T K | b1c1df7 | 2011-05-30 19:55:34 +0530 | [diff] [blame] | 289 | if (c->no_off_init) |
| 290 | mmc->slots[0].no_regulator_off_init = c->no_off_init; |
| 291 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 292 | if (c->vcc_aux_disable_is_sleep) |
| 293 | mmc->slots[0].vcc_aux_disable_is_sleep = 1; |
| 294 | |
| 295 | /* |
| 296 | * NOTE: MMC slots should have a Vcc regulator set up. |
| 297 | * This may be from a TWL4030-family chip, another |
| 298 | * controllable regulator, or a fixed supply. |
| 299 | * |
| 300 | * temporary HACK: ocr_mask instead of fixed supply |
| 301 | */ |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 302 | if (soc_is_am35xx()) |
Abhilash K V | e89715a | 2011-12-09 12:27:36 -0800 | [diff] [blame] | 303 | mmc->slots[0].ocr_mask = MMC_VDD_165_195 | |
| 304 | MMC_VDD_26_27 | |
| 305 | MMC_VDD_27_28 | |
| 306 | MMC_VDD_29_30 | |
| 307 | MMC_VDD_30_31 | |
| 308 | MMC_VDD_31_32; |
| 309 | else |
| 310 | mmc->slots[0].ocr_mask = c->ocr_mask; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 311 | |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 312 | if (!soc_is_am35xx()) |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 313 | mmc->slots[0].features |= HSMMC_HAS_PBIAS; |
| 314 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 315 | switch (c->mmc) { |
| 316 | case 1: |
| 317 | if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { |
| 318 | /* on-chip level shifting via PBIAS0/PBIAS1 */ |
Tony Lindgren | b30e321 | 2013-05-30 12:53:06 -0700 | [diff] [blame] | 319 | mmc->slots[0].before_set_reg = |
| 320 | omap_hsmmc1_before_set_reg; |
| 321 | mmc->slots[0].after_set_reg = |
| 322 | omap_hsmmc1_after_set_reg; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 323 | } |
| 324 | |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 325 | if (soc_is_am35xx()) |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 326 | mmc->slots[0].set_power = nop_mmc_set_power; |
| 327 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 328 | /* OMAP3630 HSMMC1 supports only 4-bit */ |
| 329 | if (cpu_is_omap3630() && |
| 330 | (c->caps & MMC_CAP_8_BIT_DATA)) { |
| 331 | c->caps &= ~MMC_CAP_8_BIT_DATA; |
| 332 | c->caps |= MMC_CAP_4_BIT_DATA; |
| 333 | mmc->slots[0].caps = c->caps; |
| 334 | } |
| 335 | break; |
| 336 | case 2: |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 337 | if (soc_is_am35xx()) |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 338 | mmc->slots[0].set_power = am35x_hsmmc2_set_power; |
| 339 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 340 | if (c->ext_clock) |
| 341 | c->transceiver = 1; |
| 342 | if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) { |
| 343 | c->caps &= ~MMC_CAP_8_BIT_DATA; |
| 344 | c->caps |= MMC_CAP_4_BIT_DATA; |
| 345 | } |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 346 | if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { |
| 347 | /* off-chip level shifting, or none */ |
Grazvydas Ignotas | ffa1e4e | 2011-12-18 02:35:47 +0200 | [diff] [blame] | 348 | mmc->slots[0].before_set_reg = hsmmc2_before_set_reg; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 349 | mmc->slots[0].after_set_reg = NULL; |
| 350 | } |
| 351 | break; |
Grazvydas Ignotas | ffa1e4e | 2011-12-18 02:35:47 +0200 | [diff] [blame] | 352 | case 3: |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 353 | case 4: |
| 354 | case 5: |
| 355 | mmc->slots[0].before_set_reg = NULL; |
| 356 | mmc->slots[0].after_set_reg = NULL; |
| 357 | break; |
| 358 | default: |
| 359 | pr_err("MMC%d configuration not supported!\n", c->mmc); |
| 360 | kfree(hc_name); |
| 361 | return -ENODEV; |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
Tony Lindgren | 97899e5 | 2012-02-20 09:43:28 -0800 | [diff] [blame] | 366 | static int omap_hsmmc_done; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 367 | |
| 368 | void omap_hsmmc_late_init(struct omap2_hsmmc_info *c) |
| 369 | { |
| 370 | struct platform_device *pdev; |
| 371 | struct omap_mmc_platform_data *mmc_pdata; |
| 372 | int res; |
| 373 | |
| 374 | if (omap_hsmmc_done != 1) |
| 375 | return; |
| 376 | |
| 377 | omap_hsmmc_done++; |
| 378 | |
| 379 | for (; c->mmc; c++) { |
| 380 | if (!c->deferred) |
| 381 | continue; |
| 382 | |
| 383 | pdev = c->pdev; |
| 384 | if (!pdev) |
| 385 | continue; |
| 386 | |
| 387 | mmc_pdata = pdev->dev.platform_data; |
| 388 | if (!mmc_pdata) |
| 389 | continue; |
| 390 | |
| 391 | mmc_pdata->slots[0].switch_pin = c->gpio_cd; |
| 392 | mmc_pdata->slots[0].gpio_wp = c->gpio_wp; |
| 393 | |
| 394 | res = omap_device_register(pdev); |
| 395 | if (res) |
| 396 | pr_err("Could not late init MMC %s\n", |
| 397 | c->name); |
| 398 | } |
| 399 | } |
| 400 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 401 | #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16 |
| 402 | |
Tony Lindgren | 6028505 | 2012-03-07 18:54:24 -0800 | [diff] [blame] | 403 | static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo, |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 404 | int ctrl_nr) |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 405 | { |
| 406 | struct omap_hwmod *oh; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 407 | struct omap_hwmod *ohs[1]; |
| 408 | struct omap_device *od; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 409 | struct platform_device *pdev; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 410 | char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN]; |
| 411 | struct omap_mmc_platform_data *mmc_data; |
| 412 | struct omap_mmc_dev_attr *mmc_dev_attr; |
| 413 | char *name; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 414 | int res; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 415 | |
| 416 | mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL); |
| 417 | if (!mmc_data) { |
| 418 | pr_err("Cannot allocate memory for mmc device!\n"); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 419 | return; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 420 | } |
| 421 | |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 422 | res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data); |
| 423 | if (res < 0) |
| 424 | goto free_mmc; |
| 425 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 426 | omap_hsmmc_mux(mmc_data, (ctrl_nr - 1)); |
| 427 | |
Kishore Kadiyala | 0005ae7 | 2011-02-28 20:48:05 +0530 | [diff] [blame] | 428 | name = "omap_hsmmc"; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 429 | res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN, |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 430 | "mmc%d", ctrl_nr); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 431 | WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN, |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 432 | "String buffer overflow in MMC%d device setup\n", ctrl_nr); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 433 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 434 | oh = omap_hwmod_lookup(oh_name); |
| 435 | if (!oh) { |
| 436 | pr_err("Could not look up %s\n", oh_name); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 437 | goto free_name; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 438 | } |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 439 | ohs[0] = oh; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 440 | if (oh->dev_attr != NULL) { |
| 441 | mmc_dev_attr = oh->dev_attr; |
| 442 | mmc_data->controller_flags = mmc_dev_attr->flags; |
Grazvydas Ignotas | 26c547f | 2012-03-16 14:49:54 +0200 | [diff] [blame] | 443 | /* |
| 444 | * erratum 2.1.1.128 doesn't apply if board has |
| 445 | * a transceiver is attached |
| 446 | */ |
| 447 | if (hsmmcinfo->transceiver) |
| 448 | mmc_data->controller_flags &= |
| 449 | ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 450 | } |
| 451 | |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 452 | pdev = platform_device_alloc(name, ctrl_nr - 1); |
| 453 | if (!pdev) { |
| 454 | pr_err("Could not allocate pdev for %s\n", name); |
| 455 | goto free_name; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 456 | } |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 457 | dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 458 | |
Paul Walmsley | c1d1cd5 | 2013-01-26 00:48:53 -0700 | [diff] [blame] | 459 | od = omap_device_alloc(pdev, ohs, 1); |
Wei Yongjun | 64de3a0 | 2012-09-21 14:30:50 +0800 | [diff] [blame] | 460 | if (IS_ERR(od)) { |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 461 | pr_err("Could not allocate od for %s\n", name); |
| 462 | goto put_pdev; |
| 463 | } |
| 464 | |
| 465 | res = platform_device_add_data(pdev, mmc_data, |
| 466 | sizeof(struct omap_mmc_platform_data)); |
| 467 | if (res) { |
| 468 | pr_err("Could not add pdata for %s\n", name); |
| 469 | goto put_pdev; |
| 470 | } |
| 471 | |
| 472 | hsmmcinfo->pdev = pdev; |
| 473 | |
| 474 | if (hsmmcinfo->deferred) |
| 475 | goto free_mmc; |
| 476 | |
| 477 | res = omap_device_register(pdev); |
| 478 | if (res) { |
| 479 | pr_err("Could not register od for %s\n", name); |
| 480 | goto free_od; |
| 481 | } |
| 482 | |
| 483 | goto free_mmc; |
| 484 | |
| 485 | free_od: |
| 486 | omap_device_delete(od); |
| 487 | |
| 488 | put_pdev: |
| 489 | platform_device_put(pdev); |
| 490 | |
| 491 | free_name: |
| 492 | kfree(mmc_data->slots[0].name); |
| 493 | |
| 494 | free_mmc: |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 495 | kfree(mmc_data); |
| 496 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 497 | |
Tony Lindgren | d1589f0 | 2012-02-20 09:43:30 -0800 | [diff] [blame] | 498 | void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 499 | { |
Tony Lindgren | 97899e5 | 2012-02-20 09:43:28 -0800 | [diff] [blame] | 500 | if (omap_hsmmc_done) |
| 501 | return; |
| 502 | |
| 503 | omap_hsmmc_done = 1; |
| 504 | |
Tony Lindgren | b30e321 | 2013-05-30 12:53:06 -0700 | [diff] [blame] | 505 | if (cpu_is_omap2430()) { |
| 506 | control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE; |
| 507 | control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 508 | } else { |
Tony Lindgren | b30e321 | 2013-05-30 12:53:06 -0700 | [diff] [blame] | 509 | control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE; |
| 510 | control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 513 | for (; controllers->mmc; controllers++) |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 514 | omap_hsmmc_init_one(controllers, controllers->mmc); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 515 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | #endif |