Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Freescale eSDHC controller driver. |
| 3 | * |
Jerry Huang | f060bc9 | 2012-02-14 14:05:37 +0800 | [diff] [blame] | 4 | * Copyright (c) 2007, 2010, 2012 Freescale Semiconductor, Inc. |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009 MontaVista Software, Inc. |
| 6 | * |
| 7 | * Authors: Xiaobo Xie <X.Xie@freescale.com> |
| 8 | * Anton Vorontsov <avorontsov@ru.mvista.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or (at |
| 13 | * your option) any later version. |
| 14 | */ |
| 15 | |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 16 | #include <linux/err.h> |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 17 | #include <linux/io.h> |
Jerry Huang | f060bc9 | 2012-02-14 14:05:37 +0800 | [diff] [blame] | 18 | #include <linux/of.h> |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 19 | #include <linux/delay.h> |
Paul Gortmaker | 88b4767 | 2011-07-03 15:15:51 -0400 | [diff] [blame] | 20 | #include <linux/module.h> |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 21 | #include <linux/mmc/host.h> |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 22 | #include "sdhci-pltfm.h" |
Wolfram Sang | 80872e2 | 2010-10-15 12:21:03 +0200 | [diff] [blame] | 23 | #include "sdhci-esdhc.h" |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 24 | |
Jerry Huang | 137ccd4 | 2012-03-08 11:25:02 +0800 | [diff] [blame] | 25 | #define VENDOR_V_22 0x12 |
Haijun Zhang | a4071fb | 2012-12-04 10:41:28 +0800 | [diff] [blame] | 26 | #define VENDOR_V_23 0x13 |
Jerry Huang | 137ccd4 | 2012-03-08 11:25:02 +0800 | [diff] [blame] | 27 | static u32 esdhc_readl(struct sdhci_host *host, int reg) |
| 28 | { |
| 29 | u32 ret; |
| 30 | |
| 31 | ret = in_be32(host->ioaddr + reg); |
| 32 | /* |
| 33 | * The bit of ADMA flag in eSDHC is not compatible with standard |
| 34 | * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is |
| 35 | * supported by eSDHC. |
| 36 | * And for many FSL eSDHC controller, the reset value of field |
| 37 | * SDHCI_CAN_DO_ADMA1 is one, but some of them can't support ADMA, |
| 38 | * only these vendor version is greater than 2.2/0x12 support ADMA. |
| 39 | * For FSL eSDHC, must aligned 4-byte, so use 0xFC to read the |
| 40 | * the verdor version number, oxFE is SDHCI_HOST_VERSION. |
| 41 | */ |
| 42 | if ((reg == SDHCI_CAPABILITIES) && (ret & SDHCI_CAN_DO_ADMA1)) { |
| 43 | u32 tmp = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); |
| 44 | tmp = (tmp & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; |
| 45 | if (tmp > VENDOR_V_22) |
| 46 | ret |= SDHCI_CAN_DO_ADMA2; |
| 47 | } |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 52 | static u16 esdhc_readw(struct sdhci_host *host, int reg) |
| 53 | { |
| 54 | u16 ret; |
Xu lei | e51cbc9 | 2011-09-09 20:05:46 +0800 | [diff] [blame] | 55 | int base = reg & ~0x3; |
| 56 | int shift = (reg & 0x2) * 8; |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 57 | |
| 58 | if (unlikely(reg == SDHCI_HOST_VERSION)) |
Xu lei | e51cbc9 | 2011-09-09 20:05:46 +0800 | [diff] [blame] | 59 | ret = in_be32(host->ioaddr + base) & 0xffff; |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 60 | else |
Xu lei | e51cbc9 | 2011-09-09 20:05:46 +0800 | [diff] [blame] | 61 | ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff; |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | static u8 esdhc_readb(struct sdhci_host *host, int reg) |
| 66 | { |
| 67 | int base = reg & ~0x3; |
| 68 | int shift = (reg & 0x3) * 8; |
| 69 | u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff; |
Roy Zang | ba8c4dc | 2012-01-13 15:02:01 +0800 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * "DMA select" locates at offset 0x28 in SD specification, but on |
| 73 | * P5020 or P3041, it locates at 0x29. |
| 74 | */ |
| 75 | if (reg == SDHCI_HOST_CONTROL) { |
| 76 | u32 dma_bits; |
| 77 | |
| 78 | dma_bits = in_be32(host->ioaddr + reg); |
| 79 | /* DMA select is 22,23 bits in Protocol Control Register */ |
| 80 | dma_bits = (dma_bits >> 5) & SDHCI_CTRL_DMA_MASK; |
| 81 | |
| 82 | /* fixup the result */ |
| 83 | ret &= ~SDHCI_CTRL_DMA_MASK; |
| 84 | ret |= dma_bits; |
| 85 | } |
| 86 | |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 87 | return ret; |
| 88 | } |
| 89 | |
Haijun Zhang | a4071fb | 2012-12-04 10:41:28 +0800 | [diff] [blame] | 90 | static void esdhc_writel(struct sdhci_host *host, u32 val, int reg) |
| 91 | { |
| 92 | /* |
| 93 | * Enable IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE] |
| 94 | * when SYSCTL[RSTD]) is set for some special operations. |
| 95 | * No any impact other operation. |
| 96 | */ |
| 97 | if (reg == SDHCI_INT_ENABLE) |
| 98 | val |= SDHCI_INT_BLK_GAP; |
| 99 | sdhci_be32bs_writel(host, val, reg); |
| 100 | } |
| 101 | |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 102 | static void esdhc_writew(struct sdhci_host *host, u16 val, int reg) |
| 103 | { |
| 104 | if (reg == SDHCI_BLOCK_SIZE) { |
| 105 | /* |
| 106 | * Two last DMA bits are reserved, and first one is used for |
| 107 | * non-standard blksz of 4096 bytes that we don't support |
| 108 | * yet. So clear the DMA boundary bits. |
| 109 | */ |
| 110 | val &= ~SDHCI_MAKE_BLKSZ(0x7, 0); |
| 111 | } |
| 112 | sdhci_be32bs_writew(host, val, reg); |
| 113 | } |
| 114 | |
| 115 | static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg) |
| 116 | { |
Roy Zang | ba8c4dc | 2012-01-13 15:02:01 +0800 | [diff] [blame] | 117 | /* |
| 118 | * "DMA select" location is offset 0x28 in SD specification, but on |
| 119 | * P5020 or P3041, it's located at 0x29. |
| 120 | */ |
| 121 | if (reg == SDHCI_HOST_CONTROL) { |
| 122 | u32 dma_bits; |
| 123 | |
Oded Gabbay | dcaff04 | 2013-07-05 12:48:35 -0400 | [diff] [blame] | 124 | /* |
| 125 | * If host control register is not standard, exit |
| 126 | * this function |
| 127 | */ |
| 128 | if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL) |
| 129 | return; |
| 130 | |
Roy Zang | ba8c4dc | 2012-01-13 15:02:01 +0800 | [diff] [blame] | 131 | /* DMA select is 22,23 bits in Protocol Control Register */ |
| 132 | dma_bits = (val & SDHCI_CTRL_DMA_MASK) << 5; |
| 133 | clrsetbits_be32(host->ioaddr + reg , SDHCI_CTRL_DMA_MASK << 5, |
| 134 | dma_bits); |
| 135 | val &= ~SDHCI_CTRL_DMA_MASK; |
| 136 | val |= in_be32(host->ioaddr + reg) & SDHCI_CTRL_DMA_MASK; |
| 137 | } |
| 138 | |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 139 | /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */ |
| 140 | if (reg == SDHCI_HOST_CONTROL) |
| 141 | val &= ~ESDHC_HOST_CONTROL_RES; |
| 142 | sdhci_be32bs_writeb(host, val, reg); |
| 143 | } |
| 144 | |
Haijun Zhang | a4071fb | 2012-12-04 10:41:28 +0800 | [diff] [blame] | 145 | /* |
| 146 | * For Abort or Suspend after Stop at Block Gap, ignore the ADMA |
| 147 | * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC]) |
| 148 | * and Block Gap Event(IRQSTAT[BGE]) are also set. |
| 149 | * For Continue, apply soft reset for data(SYSCTL[RSTD]); |
| 150 | * and re-issue the entire read transaction from beginning. |
| 151 | */ |
| 152 | static void esdhci_of_adma_workaround(struct sdhci_host *host, u32 intmask) |
| 153 | { |
| 154 | u32 tmp; |
| 155 | bool applicable; |
| 156 | dma_addr_t dmastart; |
| 157 | dma_addr_t dmanow; |
| 158 | |
| 159 | tmp = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); |
| 160 | tmp = (tmp & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; |
| 161 | |
| 162 | applicable = (intmask & SDHCI_INT_DATA_END) && |
| 163 | (intmask & SDHCI_INT_BLK_GAP) && |
| 164 | (tmp == VENDOR_V_23); |
| 165 | if (!applicable) |
| 166 | return; |
| 167 | |
| 168 | host->data->error = 0; |
| 169 | dmastart = sg_dma_address(host->data->sg); |
| 170 | dmanow = dmastart + host->data->bytes_xfered; |
| 171 | /* |
| 172 | * Force update to the next DMA block boundary. |
| 173 | */ |
| 174 | dmanow = (dmanow & ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) + |
| 175 | SDHCI_DEFAULT_BOUNDARY_SIZE; |
| 176 | host->data->bytes_xfered = dmanow - dmastart; |
| 177 | sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS); |
| 178 | } |
| 179 | |
Wolfram Sang | 80872e2 | 2010-10-15 12:21:03 +0200 | [diff] [blame] | 180 | static int esdhc_of_enable_dma(struct sdhci_host *host) |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 181 | { |
| 182 | setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP); |
| 183 | return 0; |
| 184 | } |
| 185 | |
Wolfram Sang | 80872e2 | 2010-10-15 12:21:03 +0200 | [diff] [blame] | 186 | static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host) |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 187 | { |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 188 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 189 | |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 190 | return pltfm_host->clock; |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Wolfram Sang | 80872e2 | 2010-10-15 12:21:03 +0200 | [diff] [blame] | 193 | static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 194 | { |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 195 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 196 | |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 197 | return pltfm_host->clock / 256 / 16; |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Jerry Huang | f060bc9 | 2012-02-14 14:05:37 +0800 | [diff] [blame] | 200 | static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) |
| 201 | { |
Joakim Tjernlund | bd45502 | 2015-04-20 23:12:13 +0200 | [diff] [blame] | 202 | int pre_div = 1; |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame] | 203 | int div = 1; |
| 204 | u32 temp; |
| 205 | |
Russell King | 1650d0c | 2014-04-25 12:58:50 +0100 | [diff] [blame] | 206 | host->mmc->actual_clock = 0; |
| 207 | |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame] | 208 | if (clock == 0) |
Russell King | 373073e | 2014-04-25 12:58:45 +0100 | [diff] [blame] | 209 | return; |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame] | 210 | |
Yangbo Lu | 77bd2f6 | 2015-08-11 10:53:34 +0800 | [diff] [blame] | 211 | /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */ |
| 212 | temp = esdhc_readw(host, SDHCI_HOST_VERSION); |
| 213 | temp = (temp & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; |
| 214 | if (temp < VENDOR_V_23) |
| 215 | pre_div = 2; |
| 216 | |
Jerry Huang | f060bc9 | 2012-02-14 14:05:37 +0800 | [diff] [blame] | 217 | /* Workaround to reduce the clock frequency for p1010 esdhc */ |
| 218 | if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) { |
| 219 | if (clock > 20000000) |
| 220 | clock -= 5000000; |
| 221 | if (clock > 40000000) |
| 222 | clock -= 5000000; |
| 223 | } |
| 224 | |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame] | 225 | temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); |
| 226 | temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
| 227 | | ESDHC_CLOCK_MASK); |
| 228 | sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); |
| 229 | |
| 230 | while (host->max_clk / pre_div / 16 > clock && pre_div < 256) |
| 231 | pre_div *= 2; |
| 232 | |
| 233 | while (host->max_clk / pre_div / div > clock && div < 16) |
| 234 | div++; |
| 235 | |
| 236 | dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", |
Dong Aisheng | e76b855 | 2013-09-13 19:11:37 +0800 | [diff] [blame] | 237 | clock, host->max_clk / pre_div / div); |
Joakim Tjernlund | bd45502 | 2015-04-20 23:12:13 +0200 | [diff] [blame] | 238 | host->mmc->actual_clock = host->max_clk / pre_div / div; |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame] | 239 | pre_div >>= 1; |
| 240 | div--; |
| 241 | |
| 242 | temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); |
| 243 | temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
| 244 | | (div << ESDHC_DIVIDER_SHIFT) |
| 245 | | (pre_div << ESDHC_PREDIV_SHIFT)); |
| 246 | sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); |
| 247 | mdelay(1); |
Jerry Huang | f060bc9 | 2012-02-14 14:05:37 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Jerry Huang | 63ef5d8 | 2012-10-25 13:47:19 +0800 | [diff] [blame] | 250 | static void esdhc_of_platform_init(struct sdhci_host *host) |
| 251 | { |
| 252 | u32 vvn; |
| 253 | |
| 254 | vvn = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); |
| 255 | vvn = (vvn & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; |
| 256 | if (vvn == VENDOR_V_22) |
| 257 | host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23; |
Jerry Huang | 3cf3883 | 2012-11-23 17:25:03 +0800 | [diff] [blame] | 258 | |
| 259 | if (vvn > VENDOR_V_22) |
| 260 | host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; |
Jerry Huang | 63ef5d8 | 2012-10-25 13:47:19 +0800 | [diff] [blame] | 261 | } |
| 262 | |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 263 | static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width) |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 264 | { |
| 265 | u32 ctrl; |
| 266 | |
| 267 | switch (width) { |
| 268 | case MMC_BUS_WIDTH_8: |
| 269 | ctrl = ESDHC_CTRL_8BITBUS; |
| 270 | break; |
| 271 | |
| 272 | case MMC_BUS_WIDTH_4: |
| 273 | ctrl = ESDHC_CTRL_4BITBUS; |
| 274 | break; |
| 275 | |
| 276 | default: |
| 277 | ctrl = 0; |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | clrsetbits_be32(host->ioaddr + SDHCI_HOST_CONTROL, |
| 282 | ESDHC_CTRL_BUSWIDTH_MASK, ctrl); |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Alessio Igor Bogani | 304f0a9 | 2014-12-09 09:40:38 +0100 | [diff] [blame] | 285 | static void esdhc_reset(struct sdhci_host *host, u8 mask) |
| 286 | { |
| 287 | sdhci_reset(host, mask); |
| 288 | |
| 289 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 290 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
| 291 | } |
| 292 | |
Lars-Peter Clausen | c915568 | 2013-03-13 19:26:05 +0100 | [diff] [blame] | 293 | static const struct sdhci_ops sdhci_esdhc_ops = { |
Jerry Huang | 137ccd4 | 2012-03-08 11:25:02 +0800 | [diff] [blame] | 294 | .read_l = esdhc_readl, |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 295 | .read_w = esdhc_readw, |
Xu lei | e51cbc9 | 2011-09-09 20:05:46 +0800 | [diff] [blame] | 296 | .read_b = esdhc_readb, |
Haijun Zhang | a4071fb | 2012-12-04 10:41:28 +0800 | [diff] [blame] | 297 | .write_l = esdhc_writel, |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 298 | .write_w = esdhc_writew, |
| 299 | .write_b = esdhc_writeb, |
Jerry Huang | f060bc9 | 2012-02-14 14:05:37 +0800 | [diff] [blame] | 300 | .set_clock = esdhc_of_set_clock, |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 301 | .enable_dma = esdhc_of_enable_dma, |
| 302 | .get_max_clock = esdhc_of_get_max_clock, |
| 303 | .get_min_clock = esdhc_of_get_min_clock, |
Jerry Huang | 63ef5d8 | 2012-10-25 13:47:19 +0800 | [diff] [blame] | 304 | .platform_init = esdhc_of_platform_init, |
Haijun Zhang | a4071fb | 2012-12-04 10:41:28 +0800 | [diff] [blame] | 305 | .adma_workaround = esdhci_of_adma_workaround, |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 306 | .set_bus_width = esdhc_pltfm_set_bus_width, |
Alessio Igor Bogani | 304f0a9 | 2014-12-09 09:40:38 +0100 | [diff] [blame] | 307 | .reset = esdhc_reset, |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 308 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 309 | }; |
| 310 | |
Russell King | 723f792 | 2014-04-25 12:59:46 +0100 | [diff] [blame] | 311 | #ifdef CONFIG_PM |
| 312 | |
| 313 | static u32 esdhc_proctl; |
| 314 | static int esdhc_of_suspend(struct device *dev) |
| 315 | { |
| 316 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 317 | |
| 318 | esdhc_proctl = sdhci_be32bs_readl(host, SDHCI_HOST_CONTROL); |
| 319 | |
| 320 | return sdhci_suspend_host(host); |
| 321 | } |
| 322 | |
Ulf Hansson | 06732b8 | 2014-05-23 10:36:44 +0200 | [diff] [blame] | 323 | static int esdhc_of_resume(struct device *dev) |
Russell King | 723f792 | 2014-04-25 12:59:46 +0100 | [diff] [blame] | 324 | { |
| 325 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 326 | int ret = sdhci_resume_host(host); |
| 327 | |
| 328 | if (ret == 0) { |
| 329 | /* Isn't this already done by sdhci_resume_host() ? --rmk */ |
| 330 | esdhc_of_enable_dma(host); |
| 331 | sdhci_be32bs_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL); |
| 332 | } |
| 333 | |
| 334 | return ret; |
| 335 | } |
| 336 | |
| 337 | static const struct dev_pm_ops esdhc_pmops = { |
Ulf Hansson | 06732b8 | 2014-05-23 10:36:44 +0200 | [diff] [blame] | 338 | .suspend = esdhc_of_suspend, |
| 339 | .resume = esdhc_of_resume, |
Russell King | 723f792 | 2014-04-25 12:59:46 +0100 | [diff] [blame] | 340 | }; |
| 341 | #define ESDHC_PMOPS (&esdhc_pmops) |
| 342 | #else |
| 343 | #define ESDHC_PMOPS NULL |
| 344 | #endif |
| 345 | |
Lars-Peter Clausen | 1db5eeb | 2013-03-13 19:26:03 +0100 | [diff] [blame] | 346 | static const struct sdhci_pltfm_data sdhci_esdhc_pdata = { |
Jerry Huang | 137ccd4 | 2012-03-08 11:25:02 +0800 | [diff] [blame] | 347 | /* |
| 348 | * card detection could be handled via GPIO |
| 349 | * eSDHC cannot support End Attribute in NOP ADMA descriptor |
| 350 | */ |
Richard Zhu | e481e45 | 2011-03-21 13:22:13 +0800 | [diff] [blame] | 351 | .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION |
Jerry Huang | 137ccd4 | 2012-03-08 11:25:02 +0800 | [diff] [blame] | 352 | | SDHCI_QUIRK_NO_CARD_NO_RESET |
| 353 | | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, |
Shawn Guo | e307148 | 2011-07-20 17:13:36 -0400 | [diff] [blame] | 354 | .ops = &sdhci_esdhc_ops, |
Albert Herranz | 7657c3a | 2009-12-17 15:27:20 -0800 | [diff] [blame] | 355 | }; |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 356 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 357 | static int sdhci_esdhc_probe(struct platform_device *pdev) |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 358 | { |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 359 | struct sdhci_host *host; |
Oded Gabbay | dcaff04 | 2013-07-05 12:48:35 -0400 | [diff] [blame] | 360 | struct device_node *np; |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 361 | int ret; |
| 362 | |
| 363 | host = sdhci_pltfm_init(pdev, &sdhci_esdhc_pdata, 0); |
| 364 | if (IS_ERR(host)) |
| 365 | return PTR_ERR(host); |
| 366 | |
| 367 | sdhci_get_of_property(pdev); |
| 368 | |
Oded Gabbay | dcaff04 | 2013-07-05 12:48:35 -0400 | [diff] [blame] | 369 | np = pdev->dev.of_node; |
Yangbo Lu | 74fd5e3 | 2015-06-01 13:47:12 +0800 | [diff] [blame] | 370 | if (of_device_is_compatible(np, "fsl,p5040-esdhc") || |
| 371 | of_device_is_compatible(np, "fsl,p5020-esdhc") || |
| 372 | of_device_is_compatible(np, "fsl,p4080-esdhc") || |
| 373 | of_device_is_compatible(np, "fsl,p1020-esdhc") || |
| 374 | of_device_is_compatible(np, "fsl,t1040-esdhc")) |
| 375 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
| 376 | |
Oded Gabbay | dcaff04 | 2013-07-05 12:48:35 -0400 | [diff] [blame] | 377 | if (of_device_is_compatible(np, "fsl,p2020-esdhc")) { |
| 378 | /* |
| 379 | * Freescale messed up with P2020 as it has a non-standard |
| 380 | * host control register |
| 381 | */ |
| 382 | host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL; |
| 383 | } |
| 384 | |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 385 | /* call to generic mmc_of_parse to support additional capabilities */ |
Ulf Hansson | f099140 | 2014-12-18 10:41:41 +0100 | [diff] [blame] | 386 | ret = mmc_of_parse(host->mmc); |
| 387 | if (ret) |
| 388 | goto err; |
| 389 | |
Haijun Zhang | 490104a | 2013-08-26 09:19:24 +0800 | [diff] [blame] | 390 | mmc_of_parse_voltage(np, &host->ocr_mask); |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 391 | |
| 392 | ret = sdhci_add_host(host); |
| 393 | if (ret) |
Ulf Hansson | f099140 | 2014-12-18 10:41:41 +0100 | [diff] [blame] | 394 | goto err; |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 395 | |
Ulf Hansson | f099140 | 2014-12-18 10:41:41 +0100 | [diff] [blame] | 396 | return 0; |
| 397 | err: |
| 398 | sdhci_pltfm_free(pdev); |
Oded Gabbay | 66b50a0 | 2013-06-27 12:00:05 -0400 | [diff] [blame] | 399 | return ret; |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 400 | } |
| 401 | |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 402 | static const struct of_device_id sdhci_esdhc_of_match[] = { |
| 403 | { .compatible = "fsl,mpc8379-esdhc" }, |
| 404 | { .compatible = "fsl,mpc8536-esdhc" }, |
| 405 | { .compatible = "fsl,esdhc" }, |
| 406 | { } |
| 407 | }; |
| 408 | MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match); |
| 409 | |
| 410 | static struct platform_driver sdhci_esdhc_driver = { |
| 411 | .driver = { |
| 412 | .name = "sdhci-esdhc", |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 413 | .of_match_table = sdhci_esdhc_of_match, |
Russell King | 723f792 | 2014-04-25 12:59:46 +0100 | [diff] [blame] | 414 | .pm = ESDHC_PMOPS, |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 415 | }, |
| 416 | .probe = sdhci_esdhc_probe, |
Kevin Hao | caebcae | 2015-02-27 15:47:31 +0800 | [diff] [blame] | 417 | .remove = sdhci_pltfm_unregister, |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 418 | }; |
| 419 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 420 | module_platform_driver(sdhci_esdhc_driver); |
Shawn Guo | 38576af | 2011-05-27 23:48:14 +0800 | [diff] [blame] | 421 | |
| 422 | MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC"); |
| 423 | MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, " |
| 424 | "Anton Vorontsov <avorontsov@ru.mvista.com>"); |
| 425 | MODULE_LICENSE("GPL v2"); |