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