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 | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 17 | #include <mach/hardware.h> |
Tony Lindgren | 4b25408 | 2012-08-30 15:37:24 -0700 | [diff] [blame] | 18 | #include <linux/platform_data/gpio-omap.h> |
| 19 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame^] | 20 | #include "soc.h" |
Tony Lindgren | 25c7d49 | 2012-10-02 17:25:48 -0700 | [diff] [blame] | 21 | #include "omap_device.h" |
Tony Lindgren | 1d5aef4 | 2012-10-03 16:36:40 -0700 | [diff] [blame] | 22 | #include "omap-pm.h" |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 23 | |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 24 | #include "mux.h" |
Tony Lindgren | 68f39e7 | 2012-10-15 12:09:43 -0700 | [diff] [blame] | 25 | #include "mmc.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; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 33 | static u16 control_mmc1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 34 | |
| 35 | #define HSMMC_NAME_LEN 9 |
| 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. |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 134 | */ |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 135 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 136 | reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK | |
Balaji T K | ff2beb1 | 2011-10-03 17:52:50 +0530 | [diff] [blame] | 137 | OMAP4_MMC1_PWRDNZ_MASK | |
| 138 | OMAP4_MMC1_PBIASLITE_VMODE_MASK); |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 139 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot, |
| 143 | int power_on, int vdd) |
| 144 | { |
| 145 | u32 reg; |
Balaji T K | 1fcecf2 | 2011-06-01 16:45:22 +0530 | [diff] [blame] | 146 | unsigned long timeout; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 147 | |
| 148 | if (power_on) { |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 149 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 150 | reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 151 | if ((1 << vdd) <= MMC_VDD_165_195) |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 152 | reg &= ~OMAP4_MMC1_PBIASLITE_VMODE_MASK; |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 153 | else |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 154 | reg |= OMAP4_MMC1_PBIASLITE_VMODE_MASK; |
| 155 | reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK | |
Bryan Buckley | 3696d30 | 2011-09-30 11:05:55 -0700 | [diff] [blame] | 156 | OMAP4_MMC1_PWRDNZ_MASK); |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 157 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
Balaji T K | 1fcecf2 | 2011-06-01 16:45:22 +0530 | [diff] [blame] | 158 | |
| 159 | timeout = jiffies + msecs_to_jiffies(5); |
| 160 | do { |
| 161 | reg = omap4_ctrl_pad_readl(control_pbias_offset); |
| 162 | if (!(reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK)) |
| 163 | break; |
| 164 | usleep_range(100, 200); |
| 165 | } while (!time_after(jiffies, timeout)); |
| 166 | |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 167 | if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK) { |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 168 | pr_err("Pbias Voltage is not same as LDO\n"); |
| 169 | /* Caution : On VMODE_ERROR Power Down MMC IO */ |
Bryan Buckley | 3696d30 | 2011-09-30 11:05:55 -0700 | [diff] [blame] | 170 | reg &= ~(OMAP4_MMC1_PWRDNZ_MASK); |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 171 | omap4_ctrl_pad_writel(reg, control_pbias_offset); |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 172 | } |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 176 | static void hsmmc2_select_input_clk_src(struct omap_mmc_platform_data *mmc) |
| 177 | { |
| 178 | u32 reg; |
| 179 | |
Grazvydas Ignotas | d82e519 | 2012-01-12 16:26:45 +0200 | [diff] [blame] | 180 | reg = omap_ctrl_readl(control_devconf1_offset); |
| 181 | if (mmc->slots[0].internal_clock) |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 182 | reg |= OMAP2_MMCSDIO2ADPCLKISEL; |
Grazvydas Ignotas | d82e519 | 2012-01-12 16:26:45 +0200 | [diff] [blame] | 183 | else |
| 184 | reg &= ~OMAP2_MMCSDIO2ADPCLKISEL; |
| 185 | omap_ctrl_writel(reg, control_devconf1_offset); |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Grazvydas Ignotas | ffa1e4e | 2011-12-18 02:35:47 +0200 | [diff] [blame] | 188 | static void hsmmc2_before_set_reg(struct device *dev, int slot, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 189 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 190 | { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 191 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
Grazvydas Ignotas | 762ad3a4 | 2009-06-23 13:30:22 +0300 | [diff] [blame] | 192 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 193 | if (mmc->slots[0].remux) |
| 194 | mmc->slots[0].remux(dev, slot, power_on); |
| 195 | |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 196 | if (power_on) |
| 197 | hsmmc2_select_input_clk_src(mmc); |
| 198 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 199 | |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 200 | static int am35x_hsmmc2_set_power(struct device *dev, int slot, |
| 201 | int power_on, int vdd) |
| 202 | { |
| 203 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 204 | |
| 205 | if (power_on) |
| 206 | hsmmc2_select_input_clk_src(mmc); |
| 207 | |
| 208 | return 0; |
Adrian Hunter | 9b7c18e | 2009-09-22 16:44:50 -0700 | [diff] [blame] | 209 | } |
| 210 | |
stanley.miao | 03e7e17 | 2010-05-13 12:39:31 +0000 | [diff] [blame] | 211 | static int nop_mmc_set_power(struct device *dev, int slot, int power_on, |
| 212 | int vdd) |
| 213 | { |
| 214 | return 0; |
| 215 | } |
| 216 | |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 217 | static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller, |
| 218 | int controller_nr) |
| 219 | { |
Thomas Weber | a15164f | 2011-11-17 22:39:40 +0100 | [diff] [blame] | 220 | if (gpio_is_valid(mmc_controller->slots[0].switch_pin) && |
| 221 | (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES)) |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 222 | omap_mux_init_gpio(mmc_controller->slots[0].switch_pin, |
| 223 | OMAP_PIN_INPUT_PULLUP); |
Thomas Weber | a15164f | 2011-11-17 22:39:40 +0100 | [diff] [blame] | 224 | if (gpio_is_valid(mmc_controller->slots[0].gpio_wp) && |
| 225 | (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES)) |
Kishore Kadiyala | d8d0a61 | 2011-02-28 20:48:03 +0530 | [diff] [blame] | 226 | omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp, |
| 227 | OMAP_PIN_INPUT_PULLUP); |
| 228 | if (cpu_is_omap34xx()) { |
| 229 | if (controller_nr == 0) { |
| 230 | omap_mux_init_signal("sdmmc1_clk", |
| 231 | OMAP_PIN_INPUT_PULLUP); |
| 232 | omap_mux_init_signal("sdmmc1_cmd", |
| 233 | OMAP_PIN_INPUT_PULLUP); |
| 234 | omap_mux_init_signal("sdmmc1_dat0", |
| 235 | OMAP_PIN_INPUT_PULLUP); |
| 236 | if (mmc_controller->slots[0].caps & |
| 237 | (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { |
| 238 | omap_mux_init_signal("sdmmc1_dat1", |
| 239 | OMAP_PIN_INPUT_PULLUP); |
| 240 | omap_mux_init_signal("sdmmc1_dat2", |
| 241 | OMAP_PIN_INPUT_PULLUP); |
| 242 | omap_mux_init_signal("sdmmc1_dat3", |
| 243 | OMAP_PIN_INPUT_PULLUP); |
| 244 | } |
| 245 | if (mmc_controller->slots[0].caps & |
| 246 | MMC_CAP_8_BIT_DATA) { |
| 247 | omap_mux_init_signal("sdmmc1_dat4", |
| 248 | OMAP_PIN_INPUT_PULLUP); |
| 249 | omap_mux_init_signal("sdmmc1_dat5", |
| 250 | OMAP_PIN_INPUT_PULLUP); |
| 251 | omap_mux_init_signal("sdmmc1_dat6", |
| 252 | OMAP_PIN_INPUT_PULLUP); |
| 253 | omap_mux_init_signal("sdmmc1_dat7", |
| 254 | OMAP_PIN_INPUT_PULLUP); |
| 255 | } |
| 256 | } |
| 257 | if (controller_nr == 1) { |
| 258 | /* MMC2 */ |
| 259 | omap_mux_init_signal("sdmmc2_clk", |
| 260 | OMAP_PIN_INPUT_PULLUP); |
| 261 | omap_mux_init_signal("sdmmc2_cmd", |
| 262 | OMAP_PIN_INPUT_PULLUP); |
| 263 | omap_mux_init_signal("sdmmc2_dat0", |
| 264 | OMAP_PIN_INPUT_PULLUP); |
| 265 | |
| 266 | /* |
| 267 | * For 8 wire configurations, Lines DAT4, 5, 6 and 7 |
| 268 | * need to be muxed in the board-*.c files |
| 269 | */ |
| 270 | if (mmc_controller->slots[0].caps & |
| 271 | (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { |
| 272 | omap_mux_init_signal("sdmmc2_dat1", |
| 273 | OMAP_PIN_INPUT_PULLUP); |
| 274 | omap_mux_init_signal("sdmmc2_dat2", |
| 275 | OMAP_PIN_INPUT_PULLUP); |
| 276 | omap_mux_init_signal("sdmmc2_dat3", |
| 277 | OMAP_PIN_INPUT_PULLUP); |
| 278 | } |
| 279 | if (mmc_controller->slots[0].caps & |
| 280 | MMC_CAP_8_BIT_DATA) { |
| 281 | omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4", |
| 282 | OMAP_PIN_INPUT_PULLUP); |
| 283 | omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5", |
| 284 | OMAP_PIN_INPUT_PULLUP); |
| 285 | omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6", |
| 286 | OMAP_PIN_INPUT_PULLUP); |
| 287 | omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7", |
| 288 | OMAP_PIN_INPUT_PULLUP); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * For MMC3 the pins need to be muxed in the board-*.c files |
| 294 | */ |
| 295 | } |
| 296 | } |
| 297 | |
Tony Lindgren | d1589f0 | 2012-02-20 09:43:30 -0800 | [diff] [blame] | 298 | static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c, |
| 299 | struct omap_mmc_platform_data *mmc) |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 300 | { |
| 301 | char *hc_name; |
| 302 | |
| 303 | hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL); |
| 304 | if (!hc_name) { |
| 305 | pr_err("Cannot allocate memory for controller slot name\n"); |
| 306 | kfree(hc_name); |
| 307 | return -ENOMEM; |
| 308 | } |
| 309 | |
| 310 | if (c->name) |
| 311 | strncpy(hc_name, c->name, HSMMC_NAME_LEN); |
| 312 | else |
| 313 | snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", |
| 314 | c->mmc, 1); |
| 315 | mmc->slots[0].name = hc_name; |
| 316 | mmc->nr_slots = 1; |
| 317 | mmc->slots[0].caps = c->caps; |
Eliad Peller | 6fdc75d | 2011-11-22 16:02:18 +0200 | [diff] [blame] | 318 | mmc->slots[0].pm_caps = c->pm_caps; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 319 | mmc->slots[0].internal_clock = !c->ext_clock; |
Daniel Mack | d418ed8 | 2012-02-19 13:20:33 +0100 | [diff] [blame] | 320 | mmc->max_freq = c->max_freq; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 321 | if (cpu_is_omap44xx()) |
| 322 | mmc->reg_offset = OMAP4_MMC_REG_OFFSET; |
| 323 | else |
| 324 | mmc->reg_offset = 0; |
| 325 | |
| 326 | mmc->get_context_loss_count = hsmmc_get_context_loss; |
| 327 | |
| 328 | mmc->slots[0].switch_pin = c->gpio_cd; |
| 329 | mmc->slots[0].gpio_wp = c->gpio_wp; |
| 330 | |
| 331 | mmc->slots[0].remux = c->remux; |
| 332 | mmc->slots[0].init_card = c->init_card; |
| 333 | |
| 334 | if (c->cover_only) |
| 335 | mmc->slots[0].cover = 1; |
| 336 | |
| 337 | if (c->nonremovable) |
| 338 | mmc->slots[0].nonremovable = 1; |
| 339 | |
| 340 | if (c->power_saving) |
| 341 | mmc->slots[0].power_saving = 1; |
| 342 | |
| 343 | if (c->no_off) |
| 344 | mmc->slots[0].no_off = 1; |
| 345 | |
Balaji T K | b1c1df7 | 2011-05-30 19:55:34 +0530 | [diff] [blame] | 346 | if (c->no_off_init) |
| 347 | mmc->slots[0].no_regulator_off_init = c->no_off_init; |
| 348 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 349 | if (c->vcc_aux_disable_is_sleep) |
| 350 | mmc->slots[0].vcc_aux_disable_is_sleep = 1; |
| 351 | |
| 352 | /* |
| 353 | * NOTE: MMC slots should have a Vcc regulator set up. |
| 354 | * This may be from a TWL4030-family chip, another |
| 355 | * controllable regulator, or a fixed supply. |
| 356 | * |
| 357 | * temporary HACK: ocr_mask instead of fixed supply |
| 358 | */ |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 359 | if (soc_is_am35xx()) |
Abhilash K V | e89715a | 2011-12-09 12:27:36 -0800 | [diff] [blame] | 360 | mmc->slots[0].ocr_mask = MMC_VDD_165_195 | |
| 361 | MMC_VDD_26_27 | |
| 362 | MMC_VDD_27_28 | |
| 363 | MMC_VDD_29_30 | |
| 364 | MMC_VDD_30_31 | |
| 365 | MMC_VDD_31_32; |
| 366 | else |
| 367 | mmc->slots[0].ocr_mask = c->ocr_mask; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 368 | |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 369 | if (!soc_is_am35xx()) |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 370 | mmc->slots[0].features |= HSMMC_HAS_PBIAS; |
| 371 | |
| 372 | if (cpu_is_omap44xx() && (omap_rev() > OMAP4430_REV_ES1_0)) |
| 373 | mmc->slots[0].features |= HSMMC_HAS_UPDATED_RESET; |
| 374 | |
| 375 | switch (c->mmc) { |
| 376 | case 1: |
| 377 | if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { |
| 378 | /* on-chip level shifting via PBIAS0/PBIAS1 */ |
| 379 | if (cpu_is_omap44xx()) { |
| 380 | mmc->slots[0].before_set_reg = |
| 381 | omap4_hsmmc1_before_set_reg; |
| 382 | mmc->slots[0].after_set_reg = |
| 383 | omap4_hsmmc1_after_set_reg; |
| 384 | } else { |
| 385 | mmc->slots[0].before_set_reg = |
| 386 | omap_hsmmc1_before_set_reg; |
| 387 | mmc->slots[0].after_set_reg = |
| 388 | omap_hsmmc1_after_set_reg; |
| 389 | } |
| 390 | } |
| 391 | |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 392 | if (soc_is_am35xx()) |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 393 | mmc->slots[0].set_power = nop_mmc_set_power; |
| 394 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 395 | /* OMAP3630 HSMMC1 supports only 4-bit */ |
| 396 | if (cpu_is_omap3630() && |
| 397 | (c->caps & MMC_CAP_8_BIT_DATA)) { |
| 398 | c->caps &= ~MMC_CAP_8_BIT_DATA; |
| 399 | c->caps |= MMC_CAP_4_BIT_DATA; |
| 400 | mmc->slots[0].caps = c->caps; |
| 401 | } |
| 402 | break; |
| 403 | case 2: |
Kevin Hilman | 68a88b9 | 2012-04-30 16:37:10 -0700 | [diff] [blame] | 404 | if (soc_is_am35xx()) |
Igor Grinberg | e62245b | 2011-11-29 11:37:48 +0200 | [diff] [blame] | 405 | mmc->slots[0].set_power = am35x_hsmmc2_set_power; |
| 406 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 407 | if (c->ext_clock) |
| 408 | c->transceiver = 1; |
| 409 | if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) { |
| 410 | c->caps &= ~MMC_CAP_8_BIT_DATA; |
| 411 | c->caps |= MMC_CAP_4_BIT_DATA; |
| 412 | } |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 413 | if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { |
| 414 | /* off-chip level shifting, or none */ |
Grazvydas Ignotas | ffa1e4e | 2011-12-18 02:35:47 +0200 | [diff] [blame] | 415 | mmc->slots[0].before_set_reg = hsmmc2_before_set_reg; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 416 | mmc->slots[0].after_set_reg = NULL; |
| 417 | } |
| 418 | break; |
Grazvydas Ignotas | ffa1e4e | 2011-12-18 02:35:47 +0200 | [diff] [blame] | 419 | case 3: |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 420 | case 4: |
| 421 | case 5: |
| 422 | mmc->slots[0].before_set_reg = NULL; |
| 423 | mmc->slots[0].after_set_reg = NULL; |
| 424 | break; |
| 425 | default: |
| 426 | pr_err("MMC%d configuration not supported!\n", c->mmc); |
| 427 | kfree(hc_name); |
| 428 | return -ENODEV; |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
Tony Lindgren | 97899e5 | 2012-02-20 09:43:28 -0800 | [diff] [blame] | 433 | static int omap_hsmmc_done; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 434 | |
| 435 | void omap_hsmmc_late_init(struct omap2_hsmmc_info *c) |
| 436 | { |
| 437 | struct platform_device *pdev; |
| 438 | struct omap_mmc_platform_data *mmc_pdata; |
| 439 | int res; |
| 440 | |
| 441 | if (omap_hsmmc_done != 1) |
| 442 | return; |
| 443 | |
| 444 | omap_hsmmc_done++; |
| 445 | |
| 446 | for (; c->mmc; c++) { |
| 447 | if (!c->deferred) |
| 448 | continue; |
| 449 | |
| 450 | pdev = c->pdev; |
| 451 | if (!pdev) |
| 452 | continue; |
| 453 | |
| 454 | mmc_pdata = pdev->dev.platform_data; |
| 455 | if (!mmc_pdata) |
| 456 | continue; |
| 457 | |
| 458 | mmc_pdata->slots[0].switch_pin = c->gpio_cd; |
| 459 | mmc_pdata->slots[0].gpio_wp = c->gpio_wp; |
| 460 | |
| 461 | res = omap_device_register(pdev); |
| 462 | if (res) |
| 463 | pr_err("Could not late init MMC %s\n", |
| 464 | c->name); |
| 465 | } |
| 466 | } |
| 467 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 468 | #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16 |
| 469 | |
Tony Lindgren | 6028505 | 2012-03-07 18:54:24 -0800 | [diff] [blame] | 470 | static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo, |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 471 | int ctrl_nr) |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 472 | { |
| 473 | struct omap_hwmod *oh; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 474 | struct omap_hwmod *ohs[1]; |
| 475 | struct omap_device *od; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 476 | struct platform_device *pdev; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 477 | char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN]; |
| 478 | struct omap_mmc_platform_data *mmc_data; |
| 479 | struct omap_mmc_dev_attr *mmc_dev_attr; |
| 480 | char *name; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 481 | int res; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 482 | |
| 483 | mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL); |
| 484 | if (!mmc_data) { |
| 485 | pr_err("Cannot allocate memory for mmc device!\n"); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 486 | return; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 487 | } |
| 488 | |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 489 | res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data); |
| 490 | if (res < 0) |
| 491 | goto free_mmc; |
| 492 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 493 | omap_hsmmc_mux(mmc_data, (ctrl_nr - 1)); |
| 494 | |
Kishore Kadiyala | 0005ae7 | 2011-02-28 20:48:05 +0530 | [diff] [blame] | 495 | name = "omap_hsmmc"; |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 496 | res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN, |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 497 | "mmc%d", ctrl_nr); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 498 | WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN, |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 499 | "String buffer overflow in MMC%d device setup\n", ctrl_nr); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 500 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 501 | oh = omap_hwmod_lookup(oh_name); |
| 502 | if (!oh) { |
| 503 | pr_err("Could not look up %s\n", oh_name); |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 504 | goto free_name; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 505 | } |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 506 | ohs[0] = oh; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 507 | if (oh->dev_attr != NULL) { |
| 508 | mmc_dev_attr = oh->dev_attr; |
| 509 | mmc_data->controller_flags = mmc_dev_attr->flags; |
Grazvydas Ignotas | 26c547f | 2012-03-16 14:49:54 +0200 | [diff] [blame] | 510 | /* |
| 511 | * erratum 2.1.1.128 doesn't apply if board has |
| 512 | * a transceiver is attached |
| 513 | */ |
| 514 | if (hsmmcinfo->transceiver) |
| 515 | mmc_data->controller_flags &= |
| 516 | ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 517 | } |
| 518 | |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 519 | pdev = platform_device_alloc(name, ctrl_nr - 1); |
| 520 | if (!pdev) { |
| 521 | pr_err("Could not allocate pdev for %s\n", name); |
| 522 | goto free_name; |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 523 | } |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 524 | dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 525 | |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 526 | od = omap_device_alloc(pdev, ohs, 1, NULL, 0); |
Wei Yongjun | 64de3a0 | 2012-09-21 14:30:50 +0800 | [diff] [blame] | 527 | if (IS_ERR(od)) { |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 528 | pr_err("Could not allocate od for %s\n", name); |
| 529 | goto put_pdev; |
| 530 | } |
| 531 | |
| 532 | res = platform_device_add_data(pdev, mmc_data, |
| 533 | sizeof(struct omap_mmc_platform_data)); |
| 534 | if (res) { |
| 535 | pr_err("Could not add pdata for %s\n", name); |
| 536 | goto put_pdev; |
| 537 | } |
| 538 | |
| 539 | hsmmcinfo->pdev = pdev; |
| 540 | |
| 541 | if (hsmmcinfo->deferred) |
| 542 | goto free_mmc; |
| 543 | |
| 544 | res = omap_device_register(pdev); |
| 545 | if (res) { |
| 546 | pr_err("Could not register od for %s\n", name); |
| 547 | goto free_od; |
| 548 | } |
| 549 | |
| 550 | goto free_mmc; |
| 551 | |
| 552 | free_od: |
| 553 | omap_device_delete(od); |
| 554 | |
| 555 | put_pdev: |
| 556 | platform_device_put(pdev); |
| 557 | |
| 558 | free_name: |
| 559 | kfree(mmc_data->slots[0].name); |
| 560 | |
| 561 | free_mmc: |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 562 | kfree(mmc_data); |
| 563 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 564 | |
Tony Lindgren | d1589f0 | 2012-02-20 09:43:30 -0800 | [diff] [blame] | 565 | void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 566 | { |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 567 | u32 reg; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 568 | |
Tony Lindgren | 97899e5 | 2012-02-20 09:43:28 -0800 | [diff] [blame] | 569 | if (omap_hsmmc_done) |
| 570 | return; |
| 571 | |
| 572 | omap_hsmmc_done = 1; |
| 573 | |
kishore kadiyala | c83c8e6 | 2010-05-15 18:21:25 +0000 | [diff] [blame] | 574 | if (!cpu_is_omap44xx()) { |
| 575 | if (cpu_is_omap2430()) { |
| 576 | control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE; |
| 577 | control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1; |
| 578 | } else { |
| 579 | control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE; |
| 580 | control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1; |
| 581 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 582 | } else { |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 583 | control_pbias_offset = |
| 584 | OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_PBIASLITE; |
| 585 | control_mmc1 = OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_MMC1; |
| 586 | reg = omap4_ctrl_pad_readl(control_mmc1); |
| 587 | reg |= (OMAP4_SDMMC1_PUSTRENGTH_GRP0_MASK | |
| 588 | OMAP4_SDMMC1_PUSTRENGTH_GRP1_MASK); |
| 589 | reg &= ~(OMAP4_SDMMC1_PUSTRENGTH_GRP2_MASK | |
| 590 | OMAP4_SDMMC1_PUSTRENGTH_GRP3_MASK); |
Balaji T K | c862dd7 | 2011-10-03 17:52:51 +0530 | [diff] [blame] | 591 | reg |= (OMAP4_SDMMC1_DR0_SPEEDCTRL_MASK | |
Santosh Shilimkar | dcf5ef3 | 2010-09-27 14:02:58 -0600 | [diff] [blame] | 592 | OMAP4_SDMMC1_DR1_SPEEDCTRL_MASK | |
| 593 | OMAP4_SDMMC1_DR2_SPEEDCTRL_MASK); |
| 594 | omap4_ctrl_pad_writel(reg, control_mmc1); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 597 | for (; controllers->mmc; controllers++) |
Tony Lindgren | 3b972bf | 2012-02-20 09:43:29 -0800 | [diff] [blame] | 598 | omap_hsmmc_init_one(controllers, controllers->mmc); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 599 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | #endif |