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/control.h> |
| 18 | #include <plat/mmc.h> |
Adrian Hunter | e3df0fb | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 19 | #include <plat/omap-pm.h> |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 20 | |
Adrian Hunter | d02a900b | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 21 | #include "hsmmc.h" |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 22 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 23 | #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 24 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 25 | static u16 control_pbias_offset; |
| 26 | static u16 control_devconf1_offset; |
| 27 | |
| 28 | #define HSMMC_NAME_LEN 9 |
| 29 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 30 | static struct hsmmc_controller { |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 31 | char name[HSMMC_NAME_LEN + 1]; |
| 32 | } hsmmc[OMAP34XX_NR_MMC]; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 33 | |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 34 | #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) |
| 35 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 36 | static int hsmmc_get_context_loss(struct device *dev) |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 37 | { |
Adrian Hunter | e3df0fb | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 38 | return omap_pm_get_dev_context_loss_count(dev); |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | #else |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 42 | #define hsmmc_get_context_loss NULL |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 43 | #endif |
| 44 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 45 | static void hsmmc1_before_set_reg(struct device *dev, int slot, |
| 46 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 47 | { |
Madhu | 555d503 | 2009-11-22 10:11:08 -0800 | [diff] [blame] | 48 | u32 reg, prog_io; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 49 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
| 50 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 51 | if (mmc->slots[0].remux) |
| 52 | mmc->slots[0].remux(dev, slot, power_on); |
| 53 | |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 54 | /* |
| 55 | * 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] | 56 | * card with Vcc regulator (from twl4030 or whatever). OMAP has both |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 57 | * 1.8V and 3.0V modes, controlled by the PBIAS register. |
| 58 | * |
| 59 | * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which |
| 60 | * is most naturally TWL VSIM; those pins also use PBIAS. |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 61 | * |
| 62 | * FIXME handle VMMC1A as needed ... |
David Brownell | 0329c37 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 63 | */ |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 64 | if (power_on) { |
| 65 | if (cpu_is_omap2430()) { |
| 66 | reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1); |
| 67 | if ((1 << vdd) >= MMC_VDD_30_31) |
| 68 | reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE; |
| 69 | else |
| 70 | reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE; |
| 71 | omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1); |
| 72 | } |
| 73 | |
| 74 | if (mmc->slots[0].internal_clock) { |
| 75 | reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 76 | reg |= OMAP2_MMCSDIO1ADPCLKISEL; |
| 77 | omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0); |
| 78 | } |
| 79 | |
| 80 | reg = omap_ctrl_readl(control_pbias_offset); |
Madhu | 555d503 | 2009-11-22 10:11:08 -0800 | [diff] [blame] | 81 | if (cpu_is_omap3630()) { |
| 82 | /* Set MMC I/O to 52Mhz */ |
| 83 | prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1); |
| 84 | prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL; |
| 85 | omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1); |
| 86 | } else { |
| 87 | reg |= OMAP2_PBIASSPEEDCTRL0; |
| 88 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 89 | reg &= ~OMAP2_PBIASLITEPWRDNZ0; |
| 90 | omap_ctrl_writel(reg, control_pbias_offset); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 91 | } else { |
| 92 | reg = omap_ctrl_readl(control_pbias_offset); |
| 93 | reg &= ~OMAP2_PBIASLITEPWRDNZ0; |
| 94 | omap_ctrl_writel(reg, control_pbias_offset); |
| 95 | } |
| 96 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 97 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 98 | static void hsmmc1_after_set_reg(struct device *dev, int slot, |
| 99 | int power_on, int vdd) |
| 100 | { |
| 101 | u32 reg; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 102 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 103 | /* 100ms delay required for PBIAS configuration */ |
| 104 | msleep(100); |
| 105 | |
| 106 | if (power_on) { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 107 | reg = omap_ctrl_readl(control_pbias_offset); |
| 108 | reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0); |
| 109 | if ((1 << vdd) <= MMC_VDD_165_195) |
| 110 | reg &= ~OMAP2_PBIASLITEVMODE0; |
| 111 | else |
| 112 | reg |= OMAP2_PBIASLITEVMODE0; |
| 113 | omap_ctrl_writel(reg, control_pbias_offset); |
| 114 | } else { |
| 115 | reg = omap_ctrl_readl(control_pbias_offset); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 116 | reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 | |
| 117 | OMAP2_PBIASLITEVMODE0); |
| 118 | omap_ctrl_writel(reg, control_pbias_offset); |
| 119 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 122 | static void hsmmc23_before_set_reg(struct device *dev, int slot, |
| 123 | int power_on, int vdd) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 124 | { |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 125 | struct omap_mmc_platform_data *mmc = dev->platform_data; |
Grazvydas Ignotas | 762ad3a4 | 2009-06-23 13:30:22 +0300 | [diff] [blame] | 126 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 127 | if (mmc->slots[0].remux) |
| 128 | mmc->slots[0].remux(dev, slot, power_on); |
| 129 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 130 | if (power_on) { |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 131 | /* Only MMC2 supports a CLKIN */ |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 132 | if (mmc->slots[0].internal_clock) { |
| 133 | u32 reg; |
| 134 | |
| 135 | reg = omap_ctrl_readl(control_devconf1_offset); |
| 136 | reg |= OMAP2_MMCSDIO2ADPCLKISEL; |
| 137 | omap_ctrl_writel(reg, control_devconf1_offset); |
| 138 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 139 | } |
Adrian Hunter | 9b7c18e | 2009-09-22 16:44:50 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 142 | static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata; |
| 143 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 144 | void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers) |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 145 | { |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 146 | struct omap2_hsmmc_info *c; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 147 | int nr_hsmmc = ARRAY_SIZE(hsmmc_data); |
Aaro Koskinen | a6c7fdd | 2010-02-04 13:06:59 +0200 | [diff] [blame] | 148 | int i; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 149 | |
| 150 | if (cpu_is_omap2430()) { |
| 151 | control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE; |
| 152 | control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 153 | } else { |
| 154 | control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE; |
| 155 | control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1; |
| 156 | } |
| 157 | |
| 158 | for (c = controllers; c->mmc; c++) { |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 159 | struct hsmmc_controller *hc = hsmmc + c->mmc - 1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 160 | struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1]; |
| 161 | |
| 162 | if (!c->mmc || c->mmc > nr_hsmmc) { |
| 163 | pr_debug("MMC%d: no such controller\n", c->mmc); |
| 164 | continue; |
| 165 | } |
| 166 | if (mmc) { |
| 167 | pr_debug("MMC%d: already configured\n", c->mmc); |
| 168 | continue; |
| 169 | } |
| 170 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 171 | mmc = kzalloc(sizeof(struct omap_mmc_platform_data), |
| 172 | GFP_KERNEL); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 173 | if (!mmc) { |
| 174 | pr_err("Cannot allocate memory for mmc device!\n"); |
Aaro Koskinen | a6c7fdd | 2010-02-04 13:06:59 +0200 | [diff] [blame] | 175 | goto done; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Adrian Hunter | e51151a | 2009-03-23 18:23:48 -0700 | [diff] [blame] | 178 | if (c->name) |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 179 | strncpy(hc->name, c->name, HSMMC_NAME_LEN); |
Adrian Hunter | e51151a | 2009-03-23 18:23:48 -0700 | [diff] [blame] | 180 | else |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 181 | snprintf(hc->name, ARRAY_SIZE(hc->name), |
Adrian Hunter | e51151a | 2009-03-23 18:23:48 -0700 | [diff] [blame] | 182 | "mmc%islot%i", c->mmc, 1); |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 183 | mmc->slots[0].name = hc->name; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 184 | mmc->nr_slots = 1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 185 | mmc->slots[0].wires = c->wires; |
| 186 | mmc->slots[0].internal_clock = !c->ext_clock; |
| 187 | mmc->dma_mask = 0xffffffff; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 188 | |
Adrian Hunter | 68ff042 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 189 | mmc->get_context_loss_count = hsmmc_get_context_loss; |
Denis Karpov | 1887bde | 2009-09-22 16:44:40 -0700 | [diff] [blame] | 190 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 191 | mmc->slots[0].switch_pin = c->gpio_cd; |
| 192 | mmc->slots[0].gpio_wp = c->gpio_wp; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 193 | |
Adrian Hunter | ce6f001 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 194 | mmc->slots[0].remux = c->remux; |
| 195 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 196 | if (c->cover_only) |
| 197 | mmc->slots[0].cover = 1; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 198 | |
Adrian Hunter | 23d99bb | 2009-09-22 16:44:48 -0700 | [diff] [blame] | 199 | if (c->nonremovable) |
| 200 | mmc->slots[0].nonremovable = 1; |
| 201 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 202 | if (c->power_saving) |
| 203 | mmc->slots[0].power_saving = 1; |
| 204 | |
Adrian Hunter | 1df58db | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 205 | if (c->no_off) |
| 206 | mmc->slots[0].no_off = 1; |
| 207 | |
Adrian Hunter | e0eb242 | 2010-02-15 10:03:34 -0800 | [diff] [blame^] | 208 | if (c->vcc_aux_disable_is_sleep) |
| 209 | mmc->slots[0].vcc_aux_disable_is_sleep = 1; |
| 210 | |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 211 | /* NOTE: MMC slots should have a Vcc regulator set up. |
| 212 | * This may be from a TWL4030-family chip, another |
| 213 | * controllable regulator, or a fixed supply. |
| 214 | * |
| 215 | * temporary HACK: ocr_mask instead of fixed supply |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 216 | */ |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 217 | mmc->slots[0].ocr_mask = c->ocr_mask; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 218 | |
| 219 | switch (c->mmc) { |
| 220 | case 1: |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 221 | /* on-chip level shifting via PBIAS0/PBIAS1 */ |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 222 | mmc->slots[0].before_set_reg = hsmmc1_before_set_reg; |
| 223 | mmc->slots[0].after_set_reg = hsmmc1_after_set_reg; |
Madhu | 41fd03d | 2009-11-22 10:11:07 -0800 | [diff] [blame] | 224 | |
| 225 | /* Omap3630 HSMMC1 supports only 4-bit */ |
| 226 | if (cpu_is_omap3630() && c->wires > 4) { |
| 227 | c->wires = 4; |
| 228 | mmc->slots[0].wires = c->wires; |
| 229 | } |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 230 | break; |
| 231 | case 2: |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 232 | if (c->ext_clock) |
| 233 | c->transceiver = 1; |
| 234 | if (c->transceiver && c->wires > 4) |
| 235 | c->wires = 4; |
| 236 | /* FALLTHROUGH */ |
Grazvydas Ignotas | 07d83cc | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 237 | case 3: |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 238 | /* off-chip level shifting, or none */ |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 239 | mmc->slots[0].before_set_reg = hsmmc23_before_set_reg; |
| 240 | mmc->slots[0].after_set_reg = NULL; |
Grazvydas Ignotas | 07d83cc | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 241 | break; |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 242 | default: |
| 243 | pr_err("MMC%d configuration not supported!\n", c->mmc); |
Grazvydas Ignotas | 07d83cc | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 244 | kfree(mmc); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 245 | continue; |
| 246 | } |
| 247 | hsmmc_data[c->mmc - 1] = mmc; |
| 248 | } |
| 249 | |
| 250 | omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC); |
David Brownell | 01971f6 | 2009-03-23 18:23:47 -0700 | [diff] [blame] | 251 | |
| 252 | /* pass the device nodes back to board setup code */ |
| 253 | for (c = controllers; c->mmc; c++) { |
| 254 | struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1]; |
| 255 | |
| 256 | if (!c->mmc || c->mmc > nr_hsmmc) |
| 257 | continue; |
| 258 | c->dev = mmc->dev; |
| 259 | } |
Aaro Koskinen | a6c7fdd | 2010-02-04 13:06:59 +0200 | [diff] [blame] | 260 | |
| 261 | done: |
| 262 | for (i = 0; i < nr_hsmmc; i++) |
| 263 | kfree(hsmmc_data[i]); |
Tony Lindgren | 90c62bf | 2008-12-10 17:37:17 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | #endif |