17657c3a7SAlbert Herranz /* 27657c3a7SAlbert Herranz * Freescale eSDHC controller driver. 37657c3a7SAlbert Herranz * 4f060bc9cSJerry Huang * Copyright (c) 2007, 2010, 2012 Freescale Semiconductor, Inc. 57657c3a7SAlbert Herranz * Copyright (c) 2009 MontaVista Software, Inc. 67657c3a7SAlbert Herranz * 77657c3a7SAlbert Herranz * Authors: Xiaobo Xie <X.Xie@freescale.com> 87657c3a7SAlbert Herranz * Anton Vorontsov <avorontsov@ru.mvista.com> 97657c3a7SAlbert Herranz * 107657c3a7SAlbert Herranz * This program is free software; you can redistribute it and/or modify 117657c3a7SAlbert Herranz * it under the terms of the GNU General Public License as published by 127657c3a7SAlbert Herranz * the Free Software Foundation; either version 2 of the License, or (at 137657c3a7SAlbert Herranz * your option) any later version. 147657c3a7SAlbert Herranz */ 157657c3a7SAlbert Herranz 1666b50a00SOded Gabbay #include <linux/err.h> 177657c3a7SAlbert Herranz #include <linux/io.h> 18f060bc9cSJerry Huang #include <linux/of.h> 19ea35645aSyangbo lu #include <linux/of_address.h> 207657c3a7SAlbert Herranz #include <linux/delay.h> 2188b47679SPaul Gortmaker #include <linux/module.h> 22151ede40Syangbo lu #include <linux/sys_soc.h> 2319c3a0efSyangbo lu #include <linux/clk.h> 2419c3a0efSyangbo lu #include <linux/ktime.h> 255552d7adSLaurentiu Tudor #include <linux/dma-mapping.h> 267657c3a7SAlbert Herranz #include <linux/mmc/host.h> 2738576af1SShawn Guo #include "sdhci-pltfm.h" 2880872e21SWolfram Sang #include "sdhci-esdhc.h" 297657c3a7SAlbert Herranz 30137ccd46SJerry Huang #define VENDOR_V_22 0x12 31a4071fbbSHaijun Zhang #define VENDOR_V_23 0x13 32f4932cfdSyangbo lu 3367fdfbdfSyinbo.zhu #define MMC_TIMING_NUM (MMC_TIMING_MMC_HS400 + 1) 3467fdfbdfSyinbo.zhu 3567fdfbdfSyinbo.zhu struct esdhc_clk_fixup { 3667fdfbdfSyinbo.zhu const unsigned int sd_dflt_max_clk; 3767fdfbdfSyinbo.zhu const unsigned int max_clk[MMC_TIMING_NUM]; 3867fdfbdfSyinbo.zhu }; 3967fdfbdfSyinbo.zhu 4067fdfbdfSyinbo.zhu static const struct esdhc_clk_fixup ls1021a_esdhc_clk = { 4167fdfbdfSyinbo.zhu .sd_dflt_max_clk = 25000000, 4267fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_MMC_HS] = 46500000, 4367fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_SD_HS] = 46500000, 4467fdfbdfSyinbo.zhu }; 4567fdfbdfSyinbo.zhu 4667fdfbdfSyinbo.zhu static const struct esdhc_clk_fixup ls1046a_esdhc_clk = { 4767fdfbdfSyinbo.zhu .sd_dflt_max_clk = 25000000, 4867fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_UHS_SDR104] = 167000000, 4967fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_MMC_HS200] = 167000000, 5067fdfbdfSyinbo.zhu }; 5167fdfbdfSyinbo.zhu 5267fdfbdfSyinbo.zhu static const struct esdhc_clk_fixup ls1012a_esdhc_clk = { 5367fdfbdfSyinbo.zhu .sd_dflt_max_clk = 25000000, 5467fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_UHS_SDR104] = 125000000, 5567fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_MMC_HS200] = 125000000, 5667fdfbdfSyinbo.zhu }; 5767fdfbdfSyinbo.zhu 5867fdfbdfSyinbo.zhu static const struct esdhc_clk_fixup p1010_esdhc_clk = { 5967fdfbdfSyinbo.zhu .sd_dflt_max_clk = 20000000, 6067fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_LEGACY] = 20000000, 6167fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_MMC_HS] = 42000000, 6267fdfbdfSyinbo.zhu .max_clk[MMC_TIMING_SD_HS] = 40000000, 6367fdfbdfSyinbo.zhu }; 6467fdfbdfSyinbo.zhu 6567fdfbdfSyinbo.zhu static const struct of_device_id sdhci_esdhc_of_match[] = { 6667fdfbdfSyinbo.zhu { .compatible = "fsl,ls1021a-esdhc", .data = &ls1021a_esdhc_clk}, 6767fdfbdfSyinbo.zhu { .compatible = "fsl,ls1046a-esdhc", .data = &ls1046a_esdhc_clk}, 6867fdfbdfSyinbo.zhu { .compatible = "fsl,ls1012a-esdhc", .data = &ls1012a_esdhc_clk}, 6967fdfbdfSyinbo.zhu { .compatible = "fsl,p1010-esdhc", .data = &p1010_esdhc_clk}, 7067fdfbdfSyinbo.zhu { .compatible = "fsl,mpc8379-esdhc" }, 7167fdfbdfSyinbo.zhu { .compatible = "fsl,mpc8536-esdhc" }, 7267fdfbdfSyinbo.zhu { .compatible = "fsl,esdhc" }, 7367fdfbdfSyinbo.zhu { } 7467fdfbdfSyinbo.zhu }; 7567fdfbdfSyinbo.zhu MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match); 7667fdfbdfSyinbo.zhu 77f4932cfdSyangbo lu struct sdhci_esdhc { 78f4932cfdSyangbo lu u8 vendor_ver; 79f4932cfdSyangbo lu u8 spec_ver; 80151ede40Syangbo lu bool quirk_incorrect_hostver; 816079e63cSYangbo Lu bool quirk_limited_clk_division; 82b1f378abSYinbo Zhu bool quirk_fixup_tuning; 8319c3a0efSyangbo lu unsigned int peripheral_clock; 8467fdfbdfSyinbo.zhu const struct esdhc_clk_fixup *clk_fixup; 85b1f378abSYinbo Zhu u32 div_ratio; 86f4932cfdSyangbo lu }; 87f4932cfdSyangbo lu 88f4932cfdSyangbo lu /** 89f4932cfdSyangbo lu * esdhc_read*_fixup - Fixup the value read from incompatible eSDHC register 90f4932cfdSyangbo lu * to make it compatible with SD spec. 91f4932cfdSyangbo lu * 92f4932cfdSyangbo lu * @host: pointer to sdhci_host 93f4932cfdSyangbo lu * @spec_reg: SD spec register address 94f4932cfdSyangbo lu * @value: 32bit eSDHC register value on spec_reg address 95f4932cfdSyangbo lu * 96f4932cfdSyangbo lu * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC 97f4932cfdSyangbo lu * registers are 32 bits. There are differences in register size, register 98f4932cfdSyangbo lu * address, register function, bit position and function between eSDHC spec 99f4932cfdSyangbo lu * and SD spec. 100f4932cfdSyangbo lu * 101f4932cfdSyangbo lu * Return a fixed up register value 102f4932cfdSyangbo lu */ 103f4932cfdSyangbo lu static u32 esdhc_readl_fixup(struct sdhci_host *host, 104f4932cfdSyangbo lu int spec_reg, u32 value) 105137ccd46SJerry Huang { 106f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 1078605e7aeSJisheng Zhang struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 108137ccd46SJerry Huang u32 ret; 109137ccd46SJerry Huang 110137ccd46SJerry Huang /* 111137ccd46SJerry Huang * The bit of ADMA flag in eSDHC is not compatible with standard 112137ccd46SJerry Huang * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is 113137ccd46SJerry Huang * supported by eSDHC. 114137ccd46SJerry Huang * And for many FSL eSDHC controller, the reset value of field 115f4932cfdSyangbo lu * SDHCI_CAN_DO_ADMA1 is 1, but some of them can't support ADMA, 116137ccd46SJerry Huang * only these vendor version is greater than 2.2/0x12 support ADMA. 117137ccd46SJerry Huang */ 118f4932cfdSyangbo lu if ((spec_reg == SDHCI_CAPABILITIES) && (value & SDHCI_CAN_DO_ADMA1)) { 119f4932cfdSyangbo lu if (esdhc->vendor_ver > VENDOR_V_22) { 120f4932cfdSyangbo lu ret = value | SDHCI_CAN_DO_ADMA2; 121f4932cfdSyangbo lu return ret; 122137ccd46SJerry Huang } 123f4932cfdSyangbo lu } 124b0921d5cSMichael Walle /* 125b0921d5cSMichael Walle * The DAT[3:0] line signal levels and the CMD line signal level are 126b0921d5cSMichael Walle * not compatible with standard SDHC register. The line signal levels 127b0921d5cSMichael Walle * DAT[7:0] are at bits 31:24 and the command line signal level is at 128b0921d5cSMichael Walle * bit 23. All other bits are the same as in the standard SDHC 129b0921d5cSMichael Walle * register. 130b0921d5cSMichael Walle */ 131b0921d5cSMichael Walle if (spec_reg == SDHCI_PRESENT_STATE) { 132b0921d5cSMichael Walle ret = value & 0x000fffff; 133b0921d5cSMichael Walle ret |= (value >> 4) & SDHCI_DATA_LVL_MASK; 134b0921d5cSMichael Walle ret |= (value << 1) & SDHCI_CMD_LVL; 135b0921d5cSMichael Walle return ret; 136b0921d5cSMichael Walle } 137b0921d5cSMichael Walle 1382f3110ccSyangbo lu /* 1392f3110ccSyangbo lu * DTS properties of mmc host are used to enable each speed mode 1402f3110ccSyangbo lu * according to soc and board capability. So clean up 1412f3110ccSyangbo lu * SDR50/SDR104/DDR50 support bits here. 1422f3110ccSyangbo lu */ 1432f3110ccSyangbo lu if (spec_reg == SDHCI_CAPABILITIES_1) { 1442f3110ccSyangbo lu ret = value & ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 | 1452f3110ccSyangbo lu SDHCI_SUPPORT_DDR50); 1462f3110ccSyangbo lu return ret; 1472f3110ccSyangbo lu } 1482f3110ccSyangbo lu 149f4932cfdSyangbo lu ret = value; 150137ccd46SJerry Huang return ret; 151137ccd46SJerry Huang } 152137ccd46SJerry Huang 153f4932cfdSyangbo lu static u16 esdhc_readw_fixup(struct sdhci_host *host, 154f4932cfdSyangbo lu int spec_reg, u32 value) 1557657c3a7SAlbert Herranz { 156151ede40Syangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 157151ede40Syangbo lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 1587657c3a7SAlbert Herranz u16 ret; 159f4932cfdSyangbo lu int shift = (spec_reg & 0x2) * 8; 1607657c3a7SAlbert Herranz 161f4932cfdSyangbo lu if (spec_reg == SDHCI_HOST_VERSION) 162f4932cfdSyangbo lu ret = value & 0xffff; 1637657c3a7SAlbert Herranz else 164f4932cfdSyangbo lu ret = (value >> shift) & 0xffff; 165151ede40Syangbo lu /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect 166151ede40Syangbo lu * vendor version and spec version information. 167151ede40Syangbo lu */ 168151ede40Syangbo lu if ((spec_reg == SDHCI_HOST_VERSION) && 169151ede40Syangbo lu (esdhc->quirk_incorrect_hostver)) 170151ede40Syangbo lu ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200; 171e51cbc9eSXu lei return ret; 172e51cbc9eSXu lei } 173e51cbc9eSXu lei 174f4932cfdSyangbo lu static u8 esdhc_readb_fixup(struct sdhci_host *host, 175f4932cfdSyangbo lu int spec_reg, u32 value) 176e51cbc9eSXu lei { 177f4932cfdSyangbo lu u8 ret; 178f4932cfdSyangbo lu u8 dma_bits; 179f4932cfdSyangbo lu int shift = (spec_reg & 0x3) * 8; 180f4932cfdSyangbo lu 181f4932cfdSyangbo lu ret = (value >> shift) & 0xff; 182ba8c4dc9SRoy Zang 183ba8c4dc9SRoy Zang /* 184ba8c4dc9SRoy Zang * "DMA select" locates at offset 0x28 in SD specification, but on 185ba8c4dc9SRoy Zang * P5020 or P3041, it locates at 0x29. 186ba8c4dc9SRoy Zang */ 187f4932cfdSyangbo lu if (spec_reg == SDHCI_HOST_CONTROL) { 188ba8c4dc9SRoy Zang /* DMA select is 22,23 bits in Protocol Control Register */ 189f4932cfdSyangbo lu dma_bits = (value >> 5) & SDHCI_CTRL_DMA_MASK; 190ba8c4dc9SRoy Zang /* fixup the result */ 191ba8c4dc9SRoy Zang ret &= ~SDHCI_CTRL_DMA_MASK; 192ba8c4dc9SRoy Zang ret |= dma_bits; 193ba8c4dc9SRoy Zang } 194f4932cfdSyangbo lu return ret; 195f4932cfdSyangbo lu } 196f4932cfdSyangbo lu 197f4932cfdSyangbo lu /** 198f4932cfdSyangbo lu * esdhc_write*_fixup - Fixup the SD spec register value so that it could be 199f4932cfdSyangbo lu * written into eSDHC register. 200f4932cfdSyangbo lu * 201f4932cfdSyangbo lu * @host: pointer to sdhci_host 202f4932cfdSyangbo lu * @spec_reg: SD spec register address 203f4932cfdSyangbo lu * @value: 8/16/32bit SD spec register value that would be written 204f4932cfdSyangbo lu * @old_value: 32bit eSDHC register value on spec_reg address 205f4932cfdSyangbo lu * 206f4932cfdSyangbo lu * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC 207f4932cfdSyangbo lu * registers are 32 bits. There are differences in register size, register 208f4932cfdSyangbo lu * address, register function, bit position and function between eSDHC spec 209f4932cfdSyangbo lu * and SD spec. 210f4932cfdSyangbo lu * 211f4932cfdSyangbo lu * Return a fixed up register value 212f4932cfdSyangbo lu */ 213f4932cfdSyangbo lu static u32 esdhc_writel_fixup(struct sdhci_host *host, 214f4932cfdSyangbo lu int spec_reg, u32 value, u32 old_value) 215f4932cfdSyangbo lu { 216f4932cfdSyangbo lu u32 ret; 217f4932cfdSyangbo lu 218f4932cfdSyangbo lu /* 219f4932cfdSyangbo lu * Enabling IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE] 220f4932cfdSyangbo lu * when SYSCTL[RSTD] is set for some special operations. 221f4932cfdSyangbo lu * No any impact on other operation. 222f4932cfdSyangbo lu */ 223f4932cfdSyangbo lu if (spec_reg == SDHCI_INT_ENABLE) 224f4932cfdSyangbo lu ret = value | SDHCI_INT_BLK_GAP; 225f4932cfdSyangbo lu else 226f4932cfdSyangbo lu ret = value; 227ba8c4dc9SRoy Zang 2287657c3a7SAlbert Herranz return ret; 2297657c3a7SAlbert Herranz } 2307657c3a7SAlbert Herranz 231f4932cfdSyangbo lu static u32 esdhc_writew_fixup(struct sdhci_host *host, 232f4932cfdSyangbo lu int spec_reg, u16 value, u32 old_value) 233a4071fbbSHaijun Zhang { 234f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 235f4932cfdSyangbo lu int shift = (spec_reg & 0x2) * 8; 236f4932cfdSyangbo lu u32 ret; 237f4932cfdSyangbo lu 238f4932cfdSyangbo lu switch (spec_reg) { 239f4932cfdSyangbo lu case SDHCI_TRANSFER_MODE: 240a4071fbbSHaijun Zhang /* 241f4932cfdSyangbo lu * Postpone this write, we must do it together with a 242f4932cfdSyangbo lu * command write that is down below. Return old value. 243a4071fbbSHaijun Zhang */ 244f4932cfdSyangbo lu pltfm_host->xfer_mode_shadow = value; 245f4932cfdSyangbo lu return old_value; 246f4932cfdSyangbo lu case SDHCI_COMMAND: 247f4932cfdSyangbo lu ret = (value << 16) | pltfm_host->xfer_mode_shadow; 248f4932cfdSyangbo lu return ret; 249a4071fbbSHaijun Zhang } 250a4071fbbSHaijun Zhang 251f4932cfdSyangbo lu ret = old_value & (~(0xffff << shift)); 252f4932cfdSyangbo lu ret |= (value << shift); 253f4932cfdSyangbo lu 254f4932cfdSyangbo lu if (spec_reg == SDHCI_BLOCK_SIZE) { 2557657c3a7SAlbert Herranz /* 2567657c3a7SAlbert Herranz * Two last DMA bits are reserved, and first one is used for 2577657c3a7SAlbert Herranz * non-standard blksz of 4096 bytes that we don't support 2587657c3a7SAlbert Herranz * yet. So clear the DMA boundary bits. 2597657c3a7SAlbert Herranz */ 260f4932cfdSyangbo lu ret &= (~SDHCI_MAKE_BLKSZ(0x7, 0)); 2617657c3a7SAlbert Herranz } 262f4932cfdSyangbo lu return ret; 2637657c3a7SAlbert Herranz } 2647657c3a7SAlbert Herranz 265f4932cfdSyangbo lu static u32 esdhc_writeb_fixup(struct sdhci_host *host, 266f4932cfdSyangbo lu int spec_reg, u8 value, u32 old_value) 2677657c3a7SAlbert Herranz { 268f4932cfdSyangbo lu u32 ret; 269f4932cfdSyangbo lu u32 dma_bits; 270f4932cfdSyangbo lu u8 tmp; 271f4932cfdSyangbo lu int shift = (spec_reg & 0x3) * 8; 272f4932cfdSyangbo lu 273ba8c4dc9SRoy Zang /* 2749e4703dfSyangbo lu * eSDHC doesn't have a standard power control register, so we do 2759e4703dfSyangbo lu * nothing here to avoid incorrect operation. 2769e4703dfSyangbo lu */ 2779e4703dfSyangbo lu if (spec_reg == SDHCI_POWER_CONTROL) 2789e4703dfSyangbo lu return old_value; 2799e4703dfSyangbo lu /* 280ba8c4dc9SRoy Zang * "DMA select" location is offset 0x28 in SD specification, but on 281ba8c4dc9SRoy Zang * P5020 or P3041, it's located at 0x29. 282ba8c4dc9SRoy Zang */ 283f4932cfdSyangbo lu if (spec_reg == SDHCI_HOST_CONTROL) { 284dcaff04dSOded Gabbay /* 285dcaff04dSOded Gabbay * If host control register is not standard, exit 286dcaff04dSOded Gabbay * this function 287dcaff04dSOded Gabbay */ 288dcaff04dSOded Gabbay if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL) 289f4932cfdSyangbo lu return old_value; 290dcaff04dSOded Gabbay 291ba8c4dc9SRoy Zang /* DMA select is 22,23 bits in Protocol Control Register */ 292f4932cfdSyangbo lu dma_bits = (value & SDHCI_CTRL_DMA_MASK) << 5; 293f4932cfdSyangbo lu ret = (old_value & (~(SDHCI_CTRL_DMA_MASK << 5))) | dma_bits; 294f4932cfdSyangbo lu tmp = (value & (~SDHCI_CTRL_DMA_MASK)) | 295f4932cfdSyangbo lu (old_value & SDHCI_CTRL_DMA_MASK); 296f4932cfdSyangbo lu ret = (ret & (~0xff)) | tmp; 297f4932cfdSyangbo lu 298f4932cfdSyangbo lu /* Prevent SDHCI core from writing reserved bits (e.g. HISPD) */ 299f4932cfdSyangbo lu ret &= ~ESDHC_HOST_CONTROL_RES; 300f4932cfdSyangbo lu return ret; 301ba8c4dc9SRoy Zang } 302ba8c4dc9SRoy Zang 303f4932cfdSyangbo lu ret = (old_value & (~(0xff << shift))) | (value << shift); 304f4932cfdSyangbo lu return ret; 305f4932cfdSyangbo lu } 306f4932cfdSyangbo lu 307f4932cfdSyangbo lu static u32 esdhc_be_readl(struct sdhci_host *host, int reg) 308f4932cfdSyangbo lu { 309f4932cfdSyangbo lu u32 ret; 310f4932cfdSyangbo lu u32 value; 311f4932cfdSyangbo lu 3122f3110ccSyangbo lu if (reg == SDHCI_CAPABILITIES_1) 3132f3110ccSyangbo lu value = ioread32be(host->ioaddr + ESDHC_CAPABILITIES_1); 3142f3110ccSyangbo lu else 315f4932cfdSyangbo lu value = ioread32be(host->ioaddr + reg); 3162f3110ccSyangbo lu 317f4932cfdSyangbo lu ret = esdhc_readl_fixup(host, reg, value); 318f4932cfdSyangbo lu 319f4932cfdSyangbo lu return ret; 320f4932cfdSyangbo lu } 321f4932cfdSyangbo lu 322f4932cfdSyangbo lu static u32 esdhc_le_readl(struct sdhci_host *host, int reg) 323f4932cfdSyangbo lu { 324f4932cfdSyangbo lu u32 ret; 325f4932cfdSyangbo lu u32 value; 326f4932cfdSyangbo lu 3272f3110ccSyangbo lu if (reg == SDHCI_CAPABILITIES_1) 3282f3110ccSyangbo lu value = ioread32(host->ioaddr + ESDHC_CAPABILITIES_1); 3292f3110ccSyangbo lu else 330f4932cfdSyangbo lu value = ioread32(host->ioaddr + reg); 3312f3110ccSyangbo lu 332f4932cfdSyangbo lu ret = esdhc_readl_fixup(host, reg, value); 333f4932cfdSyangbo lu 334f4932cfdSyangbo lu return ret; 335f4932cfdSyangbo lu } 336f4932cfdSyangbo lu 337f4932cfdSyangbo lu static u16 esdhc_be_readw(struct sdhci_host *host, int reg) 338f4932cfdSyangbo lu { 339f4932cfdSyangbo lu u16 ret; 340f4932cfdSyangbo lu u32 value; 341f4932cfdSyangbo lu int base = reg & ~0x3; 342f4932cfdSyangbo lu 343f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 344f4932cfdSyangbo lu ret = esdhc_readw_fixup(host, reg, value); 345f4932cfdSyangbo lu return ret; 346f4932cfdSyangbo lu } 347f4932cfdSyangbo lu 348f4932cfdSyangbo lu static u16 esdhc_le_readw(struct sdhci_host *host, int reg) 349f4932cfdSyangbo lu { 350f4932cfdSyangbo lu u16 ret; 351f4932cfdSyangbo lu u32 value; 352f4932cfdSyangbo lu int base = reg & ~0x3; 353f4932cfdSyangbo lu 354f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 355f4932cfdSyangbo lu ret = esdhc_readw_fixup(host, reg, value); 356f4932cfdSyangbo lu return ret; 357f4932cfdSyangbo lu } 358f4932cfdSyangbo lu 359f4932cfdSyangbo lu static u8 esdhc_be_readb(struct sdhci_host *host, int reg) 360f4932cfdSyangbo lu { 361f4932cfdSyangbo lu u8 ret; 362f4932cfdSyangbo lu u32 value; 363f4932cfdSyangbo lu int base = reg & ~0x3; 364f4932cfdSyangbo lu 365f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 366f4932cfdSyangbo lu ret = esdhc_readb_fixup(host, reg, value); 367f4932cfdSyangbo lu return ret; 368f4932cfdSyangbo lu } 369f4932cfdSyangbo lu 370f4932cfdSyangbo lu static u8 esdhc_le_readb(struct sdhci_host *host, int reg) 371f4932cfdSyangbo lu { 372f4932cfdSyangbo lu u8 ret; 373f4932cfdSyangbo lu u32 value; 374f4932cfdSyangbo lu int base = reg & ~0x3; 375f4932cfdSyangbo lu 376f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 377f4932cfdSyangbo lu ret = esdhc_readb_fixup(host, reg, value); 378f4932cfdSyangbo lu return ret; 379f4932cfdSyangbo lu } 380f4932cfdSyangbo lu 381f4932cfdSyangbo lu static void esdhc_be_writel(struct sdhci_host *host, u32 val, int reg) 382f4932cfdSyangbo lu { 383f4932cfdSyangbo lu u32 value; 384f4932cfdSyangbo lu 385f4932cfdSyangbo lu value = esdhc_writel_fixup(host, reg, val, 0); 386f4932cfdSyangbo lu iowrite32be(value, host->ioaddr + reg); 387f4932cfdSyangbo lu } 388f4932cfdSyangbo lu 389f4932cfdSyangbo lu static void esdhc_le_writel(struct sdhci_host *host, u32 val, int reg) 390f4932cfdSyangbo lu { 391f4932cfdSyangbo lu u32 value; 392f4932cfdSyangbo lu 393f4932cfdSyangbo lu value = esdhc_writel_fixup(host, reg, val, 0); 394f4932cfdSyangbo lu iowrite32(value, host->ioaddr + reg); 395f4932cfdSyangbo lu } 396f4932cfdSyangbo lu 397f4932cfdSyangbo lu static void esdhc_be_writew(struct sdhci_host *host, u16 val, int reg) 398f4932cfdSyangbo lu { 399f4932cfdSyangbo lu int base = reg & ~0x3; 400f4932cfdSyangbo lu u32 value; 401f4932cfdSyangbo lu u32 ret; 402f4932cfdSyangbo lu 403f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 404f4932cfdSyangbo lu ret = esdhc_writew_fixup(host, reg, val, value); 405f4932cfdSyangbo lu if (reg != SDHCI_TRANSFER_MODE) 406f4932cfdSyangbo lu iowrite32be(ret, host->ioaddr + base); 407f4932cfdSyangbo lu } 408f4932cfdSyangbo lu 409f4932cfdSyangbo lu static void esdhc_le_writew(struct sdhci_host *host, u16 val, int reg) 410f4932cfdSyangbo lu { 411f4932cfdSyangbo lu int base = reg & ~0x3; 412f4932cfdSyangbo lu u32 value; 413f4932cfdSyangbo lu u32 ret; 414f4932cfdSyangbo lu 415f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 416f4932cfdSyangbo lu ret = esdhc_writew_fixup(host, reg, val, value); 417f4932cfdSyangbo lu if (reg != SDHCI_TRANSFER_MODE) 418f4932cfdSyangbo lu iowrite32(ret, host->ioaddr + base); 419f4932cfdSyangbo lu } 420f4932cfdSyangbo lu 421f4932cfdSyangbo lu static void esdhc_be_writeb(struct sdhci_host *host, u8 val, int reg) 422f4932cfdSyangbo lu { 423f4932cfdSyangbo lu int base = reg & ~0x3; 424f4932cfdSyangbo lu u32 value; 425f4932cfdSyangbo lu u32 ret; 426f4932cfdSyangbo lu 427f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 428f4932cfdSyangbo lu ret = esdhc_writeb_fixup(host, reg, val, value); 429f4932cfdSyangbo lu iowrite32be(ret, host->ioaddr + base); 430f4932cfdSyangbo lu } 431f4932cfdSyangbo lu 432f4932cfdSyangbo lu static void esdhc_le_writeb(struct sdhci_host *host, u8 val, int reg) 433f4932cfdSyangbo lu { 434f4932cfdSyangbo lu int base = reg & ~0x3; 435f4932cfdSyangbo lu u32 value; 436f4932cfdSyangbo lu u32 ret; 437f4932cfdSyangbo lu 438f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 439f4932cfdSyangbo lu ret = esdhc_writeb_fixup(host, reg, val, value); 440f4932cfdSyangbo lu iowrite32(ret, host->ioaddr + base); 4417657c3a7SAlbert Herranz } 4427657c3a7SAlbert Herranz 443a4071fbbSHaijun Zhang /* 444a4071fbbSHaijun Zhang * For Abort or Suspend after Stop at Block Gap, ignore the ADMA 445a4071fbbSHaijun Zhang * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC]) 446a4071fbbSHaijun Zhang * and Block Gap Event(IRQSTAT[BGE]) are also set. 447a4071fbbSHaijun Zhang * For Continue, apply soft reset for data(SYSCTL[RSTD]); 448a4071fbbSHaijun Zhang * and re-issue the entire read transaction from beginning. 449a4071fbbSHaijun Zhang */ 450f4932cfdSyangbo lu static void esdhc_of_adma_workaround(struct sdhci_host *host, u32 intmask) 451a4071fbbSHaijun Zhang { 452f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 4538605e7aeSJisheng Zhang struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 454a4071fbbSHaijun Zhang bool applicable; 455a4071fbbSHaijun Zhang dma_addr_t dmastart; 456a4071fbbSHaijun Zhang dma_addr_t dmanow; 457a4071fbbSHaijun Zhang 458a4071fbbSHaijun Zhang applicable = (intmask & SDHCI_INT_DATA_END) && 459a4071fbbSHaijun Zhang (intmask & SDHCI_INT_BLK_GAP) && 460f4932cfdSyangbo lu (esdhc->vendor_ver == VENDOR_V_23); 461a4071fbbSHaijun Zhang if (!applicable) 462a4071fbbSHaijun Zhang return; 463a4071fbbSHaijun Zhang 464a4071fbbSHaijun Zhang host->data->error = 0; 465a4071fbbSHaijun Zhang dmastart = sg_dma_address(host->data->sg); 466a4071fbbSHaijun Zhang dmanow = dmastart + host->data->bytes_xfered; 467a4071fbbSHaijun Zhang /* 468a4071fbbSHaijun Zhang * Force update to the next DMA block boundary. 469a4071fbbSHaijun Zhang */ 470a4071fbbSHaijun Zhang dmanow = (dmanow & ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) + 471a4071fbbSHaijun Zhang SDHCI_DEFAULT_BOUNDARY_SIZE; 472a4071fbbSHaijun Zhang host->data->bytes_xfered = dmanow - dmastart; 473a4071fbbSHaijun Zhang sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS); 474a4071fbbSHaijun Zhang } 475a4071fbbSHaijun Zhang 47680872e21SWolfram Sang static int esdhc_of_enable_dma(struct sdhci_host *host) 4777657c3a7SAlbert Herranz { 478f4932cfdSyangbo lu u32 value; 4795552d7adSLaurentiu Tudor struct device *dev = mmc_dev(host->mmc); 4805552d7adSLaurentiu Tudor 4815552d7adSLaurentiu Tudor if (of_device_is_compatible(dev->of_node, "fsl,ls1043a-esdhc") || 4825552d7adSLaurentiu Tudor of_device_is_compatible(dev->of_node, "fsl,ls1046a-esdhc")) 4835552d7adSLaurentiu Tudor dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40)); 484f4932cfdSyangbo lu 485f4932cfdSyangbo lu value = sdhci_readl(host, ESDHC_DMA_SYSCTL); 486f4932cfdSyangbo lu value |= ESDHC_DMA_SNOOP; 487f4932cfdSyangbo lu sdhci_writel(host, value, ESDHC_DMA_SYSCTL); 4887657c3a7SAlbert Herranz return 0; 4897657c3a7SAlbert Herranz } 4907657c3a7SAlbert Herranz 49180872e21SWolfram Sang static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host) 4927657c3a7SAlbert Herranz { 493e307148fSShawn Guo struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 49419c3a0efSyangbo lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 4957657c3a7SAlbert Herranz 49619c3a0efSyangbo lu if (esdhc->peripheral_clock) 49719c3a0efSyangbo lu return esdhc->peripheral_clock; 49819c3a0efSyangbo lu else 499e307148fSShawn Guo return pltfm_host->clock; 5007657c3a7SAlbert Herranz } 5017657c3a7SAlbert Herranz 50280872e21SWolfram Sang static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) 5037657c3a7SAlbert Herranz { 504e307148fSShawn Guo struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 50519c3a0efSyangbo lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 50619c3a0efSyangbo lu unsigned int clock; 5077657c3a7SAlbert Herranz 50819c3a0efSyangbo lu if (esdhc->peripheral_clock) 50919c3a0efSyangbo lu clock = esdhc->peripheral_clock; 51019c3a0efSyangbo lu else 51119c3a0efSyangbo lu clock = pltfm_host->clock; 51219c3a0efSyangbo lu return clock / 256 / 16; 5137657c3a7SAlbert Herranz } 5147657c3a7SAlbert Herranz 515dd3f6983Syangbo lu static void esdhc_clock_enable(struct sdhci_host *host, bool enable) 516dd3f6983Syangbo lu { 517dd3f6983Syangbo lu u32 val; 518dd3f6983Syangbo lu ktime_t timeout; 519dd3f6983Syangbo lu 520dd3f6983Syangbo lu val = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 521dd3f6983Syangbo lu 522dd3f6983Syangbo lu if (enable) 523dd3f6983Syangbo lu val |= ESDHC_CLOCK_SDCLKEN; 524dd3f6983Syangbo lu else 525dd3f6983Syangbo lu val &= ~ESDHC_CLOCK_SDCLKEN; 526dd3f6983Syangbo lu 527dd3f6983Syangbo lu sdhci_writel(host, val, ESDHC_SYSTEM_CONTROL); 528dd3f6983Syangbo lu 529dd3f6983Syangbo lu /* Wait max 20 ms */ 530dd3f6983Syangbo lu timeout = ktime_add_ms(ktime_get(), 20); 531dd3f6983Syangbo lu val = ESDHC_CLOCK_STABLE; 532dd3f6983Syangbo lu while (!(sdhci_readl(host, ESDHC_PRSSTAT) & val)) { 533dd3f6983Syangbo lu if (ktime_after(ktime_get(), timeout)) { 534dd3f6983Syangbo lu pr_err("%s: Internal clock never stabilised.\n", 535dd3f6983Syangbo lu mmc_hostname(host->mmc)); 536dd3f6983Syangbo lu break; 537dd3f6983Syangbo lu } 538dd3f6983Syangbo lu udelay(10); 539dd3f6983Syangbo lu } 540dd3f6983Syangbo lu } 541dd3f6983Syangbo lu 542f060bc9cSJerry Huang static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) 543f060bc9cSJerry Huang { 544f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 5458605e7aeSJisheng Zhang struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 546bd455029SJoakim Tjernlund int pre_div = 1; 547d31fc00aSDong Aisheng int div = 1; 5486079e63cSYangbo Lu int division; 549e145ac45Syangbo lu ktime_t timeout; 55067fdfbdfSyinbo.zhu long fixup = 0; 551d31fc00aSDong Aisheng u32 temp; 552d31fc00aSDong Aisheng 5531650d0c7SRussell King host->mmc->actual_clock = 0; 5541650d0c7SRussell King 555dd3f6983Syangbo lu if (clock == 0) { 556dd3f6983Syangbo lu esdhc_clock_enable(host, false); 557373073efSRussell King return; 558dd3f6983Syangbo lu } 559d31fc00aSDong Aisheng 56077bd2f6fSYangbo Lu /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */ 561f4932cfdSyangbo lu if (esdhc->vendor_ver < VENDOR_V_23) 56277bd2f6fSYangbo Lu pre_div = 2; 56377bd2f6fSYangbo Lu 56467fdfbdfSyinbo.zhu if (host->mmc->card && mmc_card_sd(host->mmc->card) && 56567fdfbdfSyinbo.zhu esdhc->clk_fixup && host->mmc->ios.timing == MMC_TIMING_LEGACY) 56667fdfbdfSyinbo.zhu fixup = esdhc->clk_fixup->sd_dflt_max_clk; 56767fdfbdfSyinbo.zhu else if (esdhc->clk_fixup) 56867fdfbdfSyinbo.zhu fixup = esdhc->clk_fixup->max_clk[host->mmc->ios.timing]; 569a627f025Syangbo lu 57067fdfbdfSyinbo.zhu if (fixup && clock > fixup) 57167fdfbdfSyinbo.zhu clock = fixup; 572f060bc9cSJerry Huang 573d31fc00aSDong Aisheng temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 574e87d2db2Syangbo lu temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | 575e87d2db2Syangbo lu ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK); 576d31fc00aSDong Aisheng sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 577d31fc00aSDong Aisheng 578d31fc00aSDong Aisheng while (host->max_clk / pre_div / 16 > clock && pre_div < 256) 579d31fc00aSDong Aisheng pre_div *= 2; 580d31fc00aSDong Aisheng 581d31fc00aSDong Aisheng while (host->max_clk / pre_div / div > clock && div < 16) 582d31fc00aSDong Aisheng div++; 583d31fc00aSDong Aisheng 5846079e63cSYangbo Lu if (esdhc->quirk_limited_clk_division && 5856079e63cSYangbo Lu clock == MMC_HS200_MAX_DTR && 5866079e63cSYangbo Lu (host->mmc->ios.timing == MMC_TIMING_MMC_HS400 || 5876079e63cSYangbo Lu host->flags & SDHCI_HS400_TUNING)) { 5886079e63cSYangbo Lu division = pre_div * div; 5896079e63cSYangbo Lu if (division <= 4) { 5906079e63cSYangbo Lu pre_div = 4; 5916079e63cSYangbo Lu div = 1; 5926079e63cSYangbo Lu } else if (division <= 8) { 5936079e63cSYangbo Lu pre_div = 4; 5946079e63cSYangbo Lu div = 2; 5956079e63cSYangbo Lu } else if (division <= 12) { 5966079e63cSYangbo Lu pre_div = 4; 5976079e63cSYangbo Lu div = 3; 5986079e63cSYangbo Lu } else { 5996079e63cSYangbo Lu pr_warn("%s: using upsupported clock division.\n", 6006079e63cSYangbo Lu mmc_hostname(host->mmc)); 6016079e63cSYangbo Lu } 6026079e63cSYangbo Lu } 6036079e63cSYangbo Lu 604d31fc00aSDong Aisheng dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", 605e76b8559SDong Aisheng clock, host->max_clk / pre_div / div); 606bd455029SJoakim Tjernlund host->mmc->actual_clock = host->max_clk / pre_div / div; 607b1f378abSYinbo Zhu esdhc->div_ratio = pre_div * div; 608d31fc00aSDong Aisheng pre_div >>= 1; 609d31fc00aSDong Aisheng div--; 610d31fc00aSDong Aisheng 611d31fc00aSDong Aisheng temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 612d31fc00aSDong Aisheng temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN 613d31fc00aSDong Aisheng | (div << ESDHC_DIVIDER_SHIFT) 614d31fc00aSDong Aisheng | (pre_div << ESDHC_PREDIV_SHIFT)); 615d31fc00aSDong Aisheng sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 616e87d2db2Syangbo lu 61754e08d9aSYangbo Lu if (host->mmc->ios.timing == MMC_TIMING_MMC_HS400 && 61854e08d9aSYangbo Lu clock == MMC_HS200_MAX_DTR) { 61954e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_TBCTL); 62054e08d9aSYangbo Lu sdhci_writel(host, temp | ESDHC_HS400_MODE, ESDHC_TBCTL); 62154e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_SDCLKCTL); 62254e08d9aSYangbo Lu sdhci_writel(host, temp | ESDHC_CMD_CLK_CTL, ESDHC_SDCLKCTL); 62354e08d9aSYangbo Lu esdhc_clock_enable(host, true); 62454e08d9aSYangbo Lu 62554e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_DLLCFG0); 626*58d0bf84SYangbo Lu temp |= ESDHC_DLL_ENABLE; 627*58d0bf84SYangbo Lu if (host->mmc->actual_clock == MMC_HS200_MAX_DTR) 628*58d0bf84SYangbo Lu temp |= ESDHC_DLL_FREQ_SEL; 62954e08d9aSYangbo Lu sdhci_writel(host, temp, ESDHC_DLLCFG0); 63054e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_TBCTL); 63154e08d9aSYangbo Lu sdhci_writel(host, temp | ESDHC_HS400_WNDW_ADJUST, ESDHC_TBCTL); 63254e08d9aSYangbo Lu 63354e08d9aSYangbo Lu esdhc_clock_enable(host, false); 63454e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_DMA_SYSCTL); 63554e08d9aSYangbo Lu temp |= ESDHC_FLUSH_ASYNC_FIFO; 63654e08d9aSYangbo Lu sdhci_writel(host, temp, ESDHC_DMA_SYSCTL); 63754e08d9aSYangbo Lu } 63854e08d9aSYangbo Lu 639e87d2db2Syangbo lu /* Wait max 20 ms */ 640e145ac45Syangbo lu timeout = ktime_add_ms(ktime_get(), 20); 641e87d2db2Syangbo lu while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) { 642e145ac45Syangbo lu if (ktime_after(ktime_get(), timeout)) { 643e87d2db2Syangbo lu pr_err("%s: Internal clock never stabilised.\n", 644e87d2db2Syangbo lu mmc_hostname(host->mmc)); 645e87d2db2Syangbo lu return; 646e87d2db2Syangbo lu } 647e145ac45Syangbo lu udelay(10); 648f060bc9cSJerry Huang } 649f060bc9cSJerry Huang 65054e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 651e87d2db2Syangbo lu temp |= ESDHC_CLOCK_SDCLKEN; 652e87d2db2Syangbo lu sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 653e87d2db2Syangbo lu } 654e87d2db2Syangbo lu 6552317f56cSRussell King static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width) 65666b50a00SOded Gabbay { 65766b50a00SOded Gabbay u32 ctrl; 65866b50a00SOded Gabbay 659f4932cfdSyangbo lu ctrl = sdhci_readl(host, ESDHC_PROCTL); 660f4932cfdSyangbo lu ctrl &= (~ESDHC_CTRL_BUSWIDTH_MASK); 66166b50a00SOded Gabbay switch (width) { 66266b50a00SOded Gabbay case MMC_BUS_WIDTH_8: 663f4932cfdSyangbo lu ctrl |= ESDHC_CTRL_8BITBUS; 66466b50a00SOded Gabbay break; 66566b50a00SOded Gabbay 66666b50a00SOded Gabbay case MMC_BUS_WIDTH_4: 667f4932cfdSyangbo lu ctrl |= ESDHC_CTRL_4BITBUS; 66866b50a00SOded Gabbay break; 66966b50a00SOded Gabbay 67066b50a00SOded Gabbay default: 67166b50a00SOded Gabbay break; 67266b50a00SOded Gabbay } 67366b50a00SOded Gabbay 674f4932cfdSyangbo lu sdhci_writel(host, ctrl, ESDHC_PROCTL); 67566b50a00SOded Gabbay } 67666b50a00SOded Gabbay 677304f0a98SAlessio Igor Bogani static void esdhc_reset(struct sdhci_host *host, u8 mask) 678304f0a98SAlessio Igor Bogani { 679f2bc6000Syinbo.zhu u32 val; 680f2bc6000Syinbo.zhu 681304f0a98SAlessio Igor Bogani sdhci_reset(host, mask); 682304f0a98SAlessio Igor Bogani 683304f0a98SAlessio Igor Bogani sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); 684304f0a98SAlessio Igor Bogani sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); 685f2bc6000Syinbo.zhu 686f2bc6000Syinbo.zhu if (mask & SDHCI_RESET_ALL) { 687f2bc6000Syinbo.zhu val = sdhci_readl(host, ESDHC_TBCTL); 688f2bc6000Syinbo.zhu val &= ~ESDHC_TB_EN; 689f2bc6000Syinbo.zhu sdhci_writel(host, val, ESDHC_TBCTL); 690f2bc6000Syinbo.zhu } 691304f0a98SAlessio Igor Bogani } 692304f0a98SAlessio Igor Bogani 693ea35645aSyangbo lu /* The SCFG, Supplemental Configuration Unit, provides SoC specific 694ea35645aSyangbo lu * configuration and status registers for the device. There is a 695ea35645aSyangbo lu * SDHC IO VSEL control register on SCFG for some platforms. It's 696ea35645aSyangbo lu * used to support SDHC IO voltage switching. 697ea35645aSyangbo lu */ 698ea35645aSyangbo lu static const struct of_device_id scfg_device_ids[] = { 699ea35645aSyangbo lu { .compatible = "fsl,t1040-scfg", }, 700ea35645aSyangbo lu { .compatible = "fsl,ls1012a-scfg", }, 701ea35645aSyangbo lu { .compatible = "fsl,ls1046a-scfg", }, 702ea35645aSyangbo lu {} 703ea35645aSyangbo lu }; 704ea35645aSyangbo lu 705ea35645aSyangbo lu /* SDHC IO VSEL control register definition */ 706ea35645aSyangbo lu #define SCFG_SDHCIOVSELCR 0x408 707ea35645aSyangbo lu #define SDHCIOVSELCR_TGLEN 0x80000000 708ea35645aSyangbo lu #define SDHCIOVSELCR_VSELVAL 0x60000000 709ea35645aSyangbo lu #define SDHCIOVSELCR_SDHC_VS 0x00000001 710ea35645aSyangbo lu 711ea35645aSyangbo lu static int esdhc_signal_voltage_switch(struct mmc_host *mmc, 712ea35645aSyangbo lu struct mmc_ios *ios) 713ea35645aSyangbo lu { 714ea35645aSyangbo lu struct sdhci_host *host = mmc_priv(mmc); 715ea35645aSyangbo lu struct device_node *scfg_node; 716ea35645aSyangbo lu void __iomem *scfg_base = NULL; 717ea35645aSyangbo lu u32 sdhciovselcr; 718ea35645aSyangbo lu u32 val; 719ea35645aSyangbo lu 720ea35645aSyangbo lu /* 721ea35645aSyangbo lu * Signal Voltage Switching is only applicable for Host Controllers 722ea35645aSyangbo lu * v3.00 and above. 723ea35645aSyangbo lu */ 724ea35645aSyangbo lu if (host->version < SDHCI_SPEC_300) 725ea35645aSyangbo lu return 0; 726ea35645aSyangbo lu 727ea35645aSyangbo lu val = sdhci_readl(host, ESDHC_PROCTL); 728ea35645aSyangbo lu 729ea35645aSyangbo lu switch (ios->signal_voltage) { 730ea35645aSyangbo lu case MMC_SIGNAL_VOLTAGE_330: 731ea35645aSyangbo lu val &= ~ESDHC_VOLT_SEL; 732ea35645aSyangbo lu sdhci_writel(host, val, ESDHC_PROCTL); 733ea35645aSyangbo lu return 0; 734ea35645aSyangbo lu case MMC_SIGNAL_VOLTAGE_180: 735ea35645aSyangbo lu scfg_node = of_find_matching_node(NULL, scfg_device_ids); 736ea35645aSyangbo lu if (scfg_node) 737ea35645aSyangbo lu scfg_base = of_iomap(scfg_node, 0); 738ea35645aSyangbo lu if (scfg_base) { 739ea35645aSyangbo lu sdhciovselcr = SDHCIOVSELCR_TGLEN | 740ea35645aSyangbo lu SDHCIOVSELCR_VSELVAL; 741ea35645aSyangbo lu iowrite32be(sdhciovselcr, 742ea35645aSyangbo lu scfg_base + SCFG_SDHCIOVSELCR); 743ea35645aSyangbo lu 744ea35645aSyangbo lu val |= ESDHC_VOLT_SEL; 745ea35645aSyangbo lu sdhci_writel(host, val, ESDHC_PROCTL); 746ea35645aSyangbo lu mdelay(5); 747ea35645aSyangbo lu 748ea35645aSyangbo lu sdhciovselcr = SDHCIOVSELCR_TGLEN | 749ea35645aSyangbo lu SDHCIOVSELCR_SDHC_VS; 750ea35645aSyangbo lu iowrite32be(sdhciovselcr, 751ea35645aSyangbo lu scfg_base + SCFG_SDHCIOVSELCR); 752ea35645aSyangbo lu iounmap(scfg_base); 753ea35645aSyangbo lu } else { 754ea35645aSyangbo lu val |= ESDHC_VOLT_SEL; 755ea35645aSyangbo lu sdhci_writel(host, val, ESDHC_PROCTL); 756ea35645aSyangbo lu } 757ea35645aSyangbo lu return 0; 758ea35645aSyangbo lu default: 759ea35645aSyangbo lu return 0; 760ea35645aSyangbo lu } 761ea35645aSyangbo lu } 762ea35645aSyangbo lu 763b1f378abSYinbo Zhu static struct soc_device_attribute soc_fixup_tuning[] = { 764b1f378abSYinbo Zhu { .family = "QorIQ T1040", .revision = "1.0", }, 765b1f378abSYinbo Zhu { .family = "QorIQ T2080", .revision = "1.0", }, 766b1f378abSYinbo Zhu { .family = "QorIQ T1023", .revision = "1.0", }, 767b1f378abSYinbo Zhu { .family = "QorIQ LS1021A", .revision = "1.0", }, 768b1f378abSYinbo Zhu { .family = "QorIQ LS1080A", .revision = "1.0", }, 769b1f378abSYinbo Zhu { .family = "QorIQ LS2080A", .revision = "1.0", }, 770b1f378abSYinbo Zhu { .family = "QorIQ LS1012A", .revision = "1.0", }, 771b1f378abSYinbo Zhu { .family = "QorIQ LS1043A", .revision = "1.*", }, 772b1f378abSYinbo Zhu { .family = "QorIQ LS1046A", .revision = "1.0", }, 773b1f378abSYinbo Zhu { }, 774b1f378abSYinbo Zhu }; 775b1f378abSYinbo Zhu 77654e08d9aSYangbo Lu static void esdhc_tuning_block_enable(struct sdhci_host *host, bool enable) 777ba49cbd0Syangbo lu { 778ba49cbd0Syangbo lu u32 val; 779ba49cbd0Syangbo lu 780ba49cbd0Syangbo lu esdhc_clock_enable(host, false); 78154e08d9aSYangbo Lu 782ba49cbd0Syangbo lu val = sdhci_readl(host, ESDHC_DMA_SYSCTL); 783ba49cbd0Syangbo lu val |= ESDHC_FLUSH_ASYNC_FIFO; 784ba49cbd0Syangbo lu sdhci_writel(host, val, ESDHC_DMA_SYSCTL); 785ba49cbd0Syangbo lu 786ba49cbd0Syangbo lu val = sdhci_readl(host, ESDHC_TBCTL); 78754e08d9aSYangbo Lu if (enable) 788ba49cbd0Syangbo lu val |= ESDHC_TB_EN; 78954e08d9aSYangbo Lu else 79054e08d9aSYangbo Lu val &= ~ESDHC_TB_EN; 791ba49cbd0Syangbo lu sdhci_writel(host, val, ESDHC_TBCTL); 792ba49cbd0Syangbo lu 79354e08d9aSYangbo Lu esdhc_clock_enable(host, true); 79454e08d9aSYangbo Lu } 79554e08d9aSYangbo Lu 79654e08d9aSYangbo Lu static int esdhc_execute_tuning(struct mmc_host *mmc, u32 opcode) 79754e08d9aSYangbo Lu { 79854e08d9aSYangbo Lu struct sdhci_host *host = mmc_priv(mmc); 79954e08d9aSYangbo Lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 80054e08d9aSYangbo Lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 80154e08d9aSYangbo Lu bool hs400_tuning; 80254e08d9aSYangbo Lu u32 val; 80354e08d9aSYangbo Lu int ret; 80454e08d9aSYangbo Lu 8056079e63cSYangbo Lu if (esdhc->quirk_limited_clk_division && 8066079e63cSYangbo Lu host->flags & SDHCI_HS400_TUNING) 8076079e63cSYangbo Lu esdhc_of_set_clock(host, host->clock); 8086079e63cSYangbo Lu 80954e08d9aSYangbo Lu esdhc_tuning_block_enable(host, true); 81054e08d9aSYangbo Lu 81154e08d9aSYangbo Lu hs400_tuning = host->flags & SDHCI_HS400_TUNING; 81254e08d9aSYangbo Lu ret = sdhci_execute_tuning(mmc, opcode); 81354e08d9aSYangbo Lu 81454e08d9aSYangbo Lu if (hs400_tuning) { 81554e08d9aSYangbo Lu val = sdhci_readl(host, ESDHC_SDTIMNGCTL); 81654e08d9aSYangbo Lu val |= ESDHC_FLW_CTL_BG; 81754e08d9aSYangbo Lu sdhci_writel(host, val, ESDHC_SDTIMNGCTL); 81854e08d9aSYangbo Lu } 81954e08d9aSYangbo Lu 820b1f378abSYinbo Zhu if (host->tuning_err == -EAGAIN && esdhc->quirk_fixup_tuning) { 821b1f378abSYinbo Zhu 822b1f378abSYinbo Zhu /* program TBPTR[TB_WNDW_END_PTR] = 3*DIV_RATIO and 823b1f378abSYinbo Zhu * program TBPTR[TB_WNDW_START_PTR] = 5*DIV_RATIO 824b1f378abSYinbo Zhu */ 825b1f378abSYinbo Zhu val = sdhci_readl(host, ESDHC_TBPTR); 826b1f378abSYinbo Zhu val = (val & ~((0x7f << 8) | 0x7f)) | 827b1f378abSYinbo Zhu (3 * esdhc->div_ratio) | ((5 * esdhc->div_ratio) << 8); 828b1f378abSYinbo Zhu sdhci_writel(host, val, ESDHC_TBPTR); 829b1f378abSYinbo Zhu 830b1f378abSYinbo Zhu /* program the software tuning mode by setting 831b1f378abSYinbo Zhu * TBCTL[TB_MODE]=2'h3 832b1f378abSYinbo Zhu */ 833b1f378abSYinbo Zhu val = sdhci_readl(host, ESDHC_TBCTL); 834b1f378abSYinbo Zhu val |= 0x3; 835b1f378abSYinbo Zhu sdhci_writel(host, val, ESDHC_TBCTL); 836b1f378abSYinbo Zhu sdhci_execute_tuning(mmc, opcode); 837b1f378abSYinbo Zhu } 83854e08d9aSYangbo Lu return ret; 83954e08d9aSYangbo Lu } 84054e08d9aSYangbo Lu 84154e08d9aSYangbo Lu static void esdhc_set_uhs_signaling(struct sdhci_host *host, 84254e08d9aSYangbo Lu unsigned int timing) 84354e08d9aSYangbo Lu { 84454e08d9aSYangbo Lu if (timing == MMC_TIMING_MMC_HS400) 84554e08d9aSYangbo Lu esdhc_tuning_block_enable(host, true); 84654e08d9aSYangbo Lu else 84754e08d9aSYangbo Lu sdhci_set_uhs_signaling(host, timing); 848ba49cbd0Syangbo lu } 849ba49cbd0Syangbo lu 8509e48b336SUlf Hansson #ifdef CONFIG_PM_SLEEP 851723f7924SRussell King static u32 esdhc_proctl; 852723f7924SRussell King static int esdhc_of_suspend(struct device *dev) 853723f7924SRussell King { 854723f7924SRussell King struct sdhci_host *host = dev_get_drvdata(dev); 855723f7924SRussell King 856f4932cfdSyangbo lu esdhc_proctl = sdhci_readl(host, SDHCI_HOST_CONTROL); 857723f7924SRussell King 858d38dcad4SAdrian Hunter if (host->tuning_mode != SDHCI_TUNING_MODE_3) 859d38dcad4SAdrian Hunter mmc_retune_needed(host->mmc); 860d38dcad4SAdrian Hunter 861723f7924SRussell King return sdhci_suspend_host(host); 862723f7924SRussell King } 863723f7924SRussell King 86406732b84SUlf Hansson static int esdhc_of_resume(struct device *dev) 865723f7924SRussell King { 866723f7924SRussell King struct sdhci_host *host = dev_get_drvdata(dev); 867723f7924SRussell King int ret = sdhci_resume_host(host); 868723f7924SRussell King 869723f7924SRussell King if (ret == 0) { 870723f7924SRussell King /* Isn't this already done by sdhci_resume_host() ? --rmk */ 871723f7924SRussell King esdhc_of_enable_dma(host); 872f4932cfdSyangbo lu sdhci_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL); 873723f7924SRussell King } 874723f7924SRussell King return ret; 875723f7924SRussell King } 876723f7924SRussell King #endif 877723f7924SRussell King 8789e48b336SUlf Hansson static SIMPLE_DEV_PM_OPS(esdhc_of_dev_pm_ops, 8799e48b336SUlf Hansson esdhc_of_suspend, 8809e48b336SUlf Hansson esdhc_of_resume); 8819e48b336SUlf Hansson 882f4932cfdSyangbo lu static const struct sdhci_ops sdhci_esdhc_be_ops = { 883f4932cfdSyangbo lu .read_l = esdhc_be_readl, 884f4932cfdSyangbo lu .read_w = esdhc_be_readw, 885f4932cfdSyangbo lu .read_b = esdhc_be_readb, 886f4932cfdSyangbo lu .write_l = esdhc_be_writel, 887f4932cfdSyangbo lu .write_w = esdhc_be_writew, 888f4932cfdSyangbo lu .write_b = esdhc_be_writeb, 889f4932cfdSyangbo lu .set_clock = esdhc_of_set_clock, 890f4932cfdSyangbo lu .enable_dma = esdhc_of_enable_dma, 891f4932cfdSyangbo lu .get_max_clock = esdhc_of_get_max_clock, 892f4932cfdSyangbo lu .get_min_clock = esdhc_of_get_min_clock, 893f4932cfdSyangbo lu .adma_workaround = esdhc_of_adma_workaround, 894f4932cfdSyangbo lu .set_bus_width = esdhc_pltfm_set_bus_width, 895f4932cfdSyangbo lu .reset = esdhc_reset, 89654e08d9aSYangbo Lu .set_uhs_signaling = esdhc_set_uhs_signaling, 897f4932cfdSyangbo lu }; 898f4932cfdSyangbo lu 899f4932cfdSyangbo lu static const struct sdhci_ops sdhci_esdhc_le_ops = { 900f4932cfdSyangbo lu .read_l = esdhc_le_readl, 901f4932cfdSyangbo lu .read_w = esdhc_le_readw, 902f4932cfdSyangbo lu .read_b = esdhc_le_readb, 903f4932cfdSyangbo lu .write_l = esdhc_le_writel, 904f4932cfdSyangbo lu .write_w = esdhc_le_writew, 905f4932cfdSyangbo lu .write_b = esdhc_le_writeb, 906f4932cfdSyangbo lu .set_clock = esdhc_of_set_clock, 907f4932cfdSyangbo lu .enable_dma = esdhc_of_enable_dma, 908f4932cfdSyangbo lu .get_max_clock = esdhc_of_get_max_clock, 909f4932cfdSyangbo lu .get_min_clock = esdhc_of_get_min_clock, 910f4932cfdSyangbo lu .adma_workaround = esdhc_of_adma_workaround, 911f4932cfdSyangbo lu .set_bus_width = esdhc_pltfm_set_bus_width, 912f4932cfdSyangbo lu .reset = esdhc_reset, 91354e08d9aSYangbo Lu .set_uhs_signaling = esdhc_set_uhs_signaling, 914f4932cfdSyangbo lu }; 915f4932cfdSyangbo lu 916f4932cfdSyangbo lu static const struct sdhci_pltfm_data sdhci_esdhc_be_pdata = { 917e9acc77dSyangbo lu .quirks = ESDHC_DEFAULT_QUIRKS | 918e9acc77dSyangbo lu #ifdef CONFIG_PPC 919e9acc77dSyangbo lu SDHCI_QUIRK_BROKEN_CARD_DETECTION | 920e9acc77dSyangbo lu #endif 921e9acc77dSyangbo lu SDHCI_QUIRK_NO_CARD_NO_RESET | 922e9acc77dSyangbo lu SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 923f4932cfdSyangbo lu .ops = &sdhci_esdhc_be_ops, 9247657c3a7SAlbert Herranz }; 92538576af1SShawn Guo 926f4932cfdSyangbo lu static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = { 927e9acc77dSyangbo lu .quirks = ESDHC_DEFAULT_QUIRKS | 928e9acc77dSyangbo lu SDHCI_QUIRK_NO_CARD_NO_RESET | 929e9acc77dSyangbo lu SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 930f4932cfdSyangbo lu .ops = &sdhci_esdhc_le_ops, 931f4932cfdSyangbo lu }; 932f4932cfdSyangbo lu 933151ede40Syangbo lu static struct soc_device_attribute soc_incorrect_hostver[] = { 934151ede40Syangbo lu { .family = "QorIQ T4240", .revision = "1.0", }, 935151ede40Syangbo lu { .family = "QorIQ T4240", .revision = "2.0", }, 936151ede40Syangbo lu { }, 937151ede40Syangbo lu }; 938151ede40Syangbo lu 9396079e63cSYangbo Lu static struct soc_device_attribute soc_fixup_sdhc_clkdivs[] = { 9406079e63cSYangbo Lu { .family = "QorIQ LX2160A", .revision = "1.0", }, 9416079e63cSYangbo Lu { }, 9426079e63cSYangbo Lu }; 9436079e63cSYangbo Lu 944f4932cfdSyangbo lu static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host) 945f4932cfdSyangbo lu { 94667fdfbdfSyinbo.zhu const struct of_device_id *match; 947f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host; 948f4932cfdSyangbo lu struct sdhci_esdhc *esdhc; 94919c3a0efSyangbo lu struct device_node *np; 95019c3a0efSyangbo lu struct clk *clk; 95119c3a0efSyangbo lu u32 val; 952f4932cfdSyangbo lu u16 host_ver; 953f4932cfdSyangbo lu 954f4932cfdSyangbo lu pltfm_host = sdhci_priv(host); 9558605e7aeSJisheng Zhang esdhc = sdhci_pltfm_priv(pltfm_host); 956f4932cfdSyangbo lu 957f4932cfdSyangbo lu host_ver = sdhci_readw(host, SDHCI_HOST_VERSION); 958f4932cfdSyangbo lu esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >> 959f4932cfdSyangbo lu SDHCI_VENDOR_VER_SHIFT; 960f4932cfdSyangbo lu esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK; 961151ede40Syangbo lu if (soc_device_match(soc_incorrect_hostver)) 962151ede40Syangbo lu esdhc->quirk_incorrect_hostver = true; 963151ede40Syangbo lu else 964151ede40Syangbo lu esdhc->quirk_incorrect_hostver = false; 96519c3a0efSyangbo lu 9666079e63cSYangbo Lu if (soc_device_match(soc_fixup_sdhc_clkdivs)) 9676079e63cSYangbo Lu esdhc->quirk_limited_clk_division = true; 9686079e63cSYangbo Lu else 9696079e63cSYangbo Lu esdhc->quirk_limited_clk_division = false; 9706079e63cSYangbo Lu 97167fdfbdfSyinbo.zhu match = of_match_node(sdhci_esdhc_of_match, pdev->dev.of_node); 97267fdfbdfSyinbo.zhu if (match) 97367fdfbdfSyinbo.zhu esdhc->clk_fixup = match->data; 97419c3a0efSyangbo lu np = pdev->dev.of_node; 97519c3a0efSyangbo lu clk = of_clk_get(np, 0); 97619c3a0efSyangbo lu if (!IS_ERR(clk)) { 97719c3a0efSyangbo lu /* 97819c3a0efSyangbo lu * esdhc->peripheral_clock would be assigned with a value 97919c3a0efSyangbo lu * which is eSDHC base clock when use periperal clock. 98019c3a0efSyangbo lu * For ls1046a, the clock value got by common clk API is 98119c3a0efSyangbo lu * peripheral clock while the eSDHC base clock is 1/2 98219c3a0efSyangbo lu * peripheral clock. 98319c3a0efSyangbo lu */ 98419c3a0efSyangbo lu if (of_device_is_compatible(np, "fsl,ls1046a-esdhc")) 98519c3a0efSyangbo lu esdhc->peripheral_clock = clk_get_rate(clk) / 2; 98619c3a0efSyangbo lu else 98719c3a0efSyangbo lu esdhc->peripheral_clock = clk_get_rate(clk); 98819c3a0efSyangbo lu 98919c3a0efSyangbo lu clk_put(clk); 99019c3a0efSyangbo lu } 99119c3a0efSyangbo lu 99219c3a0efSyangbo lu if (esdhc->peripheral_clock) { 99319c3a0efSyangbo lu esdhc_clock_enable(host, false); 99419c3a0efSyangbo lu val = sdhci_readl(host, ESDHC_DMA_SYSCTL); 99519c3a0efSyangbo lu val |= ESDHC_PERIPHERAL_CLK_SEL; 99619c3a0efSyangbo lu sdhci_writel(host, val, ESDHC_DMA_SYSCTL); 99719c3a0efSyangbo lu esdhc_clock_enable(host, true); 99819c3a0efSyangbo lu } 999f4932cfdSyangbo lu } 1000f4932cfdSyangbo lu 100154e08d9aSYangbo Lu static int esdhc_hs400_prepare_ddr(struct mmc_host *mmc) 100254e08d9aSYangbo Lu { 100354e08d9aSYangbo Lu esdhc_tuning_block_enable(mmc_priv(mmc), false); 100454e08d9aSYangbo Lu return 0; 100554e08d9aSYangbo Lu } 100654e08d9aSYangbo Lu 1007c3be1efdSBill Pemberton static int sdhci_esdhc_probe(struct platform_device *pdev) 100838576af1SShawn Guo { 100966b50a00SOded Gabbay struct sdhci_host *host; 1010dcaff04dSOded Gabbay struct device_node *np; 10111ef5e49eSyangbo lu struct sdhci_pltfm_host *pltfm_host; 10121ef5e49eSyangbo lu struct sdhci_esdhc *esdhc; 101366b50a00SOded Gabbay int ret; 101466b50a00SOded Gabbay 1015f4932cfdSyangbo lu np = pdev->dev.of_node; 1016f4932cfdSyangbo lu 1017150d4240SJulia Lawall if (of_property_read_bool(np, "little-endian")) 10188605e7aeSJisheng Zhang host = sdhci_pltfm_init(pdev, &sdhci_esdhc_le_pdata, 10198605e7aeSJisheng Zhang sizeof(struct sdhci_esdhc)); 1020f4932cfdSyangbo lu else 10218605e7aeSJisheng Zhang host = sdhci_pltfm_init(pdev, &sdhci_esdhc_be_pdata, 10228605e7aeSJisheng Zhang sizeof(struct sdhci_esdhc)); 1023f4932cfdSyangbo lu 102466b50a00SOded Gabbay if (IS_ERR(host)) 102566b50a00SOded Gabbay return PTR_ERR(host); 102666b50a00SOded Gabbay 1027ea35645aSyangbo lu host->mmc_host_ops.start_signal_voltage_switch = 1028ea35645aSyangbo lu esdhc_signal_voltage_switch; 1029ba49cbd0Syangbo lu host->mmc_host_ops.execute_tuning = esdhc_execute_tuning; 103054e08d9aSYangbo Lu host->mmc_host_ops.hs400_prepare_ddr = esdhc_hs400_prepare_ddr; 10316b236f37Syangbo lu host->tuning_delay = 1; 1032ea35645aSyangbo lu 1033f4932cfdSyangbo lu esdhc_init(pdev, host); 1034f4932cfdSyangbo lu 103566b50a00SOded Gabbay sdhci_get_of_property(pdev); 103666b50a00SOded Gabbay 10371ef5e49eSyangbo lu pltfm_host = sdhci_priv(host); 10388605e7aeSJisheng Zhang esdhc = sdhci_pltfm_priv(pltfm_host); 1039b1f378abSYinbo Zhu if (soc_device_match(soc_fixup_tuning)) 1040b1f378abSYinbo Zhu esdhc->quirk_fixup_tuning = true; 1041b1f378abSYinbo Zhu else 1042b1f378abSYinbo Zhu esdhc->quirk_fixup_tuning = false; 1043b1f378abSYinbo Zhu 10441ef5e49eSyangbo lu if (esdhc->vendor_ver == VENDOR_V_22) 10451ef5e49eSyangbo lu host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23; 10461ef5e49eSyangbo lu 10471ef5e49eSyangbo lu if (esdhc->vendor_ver > VENDOR_V_22) 10481ef5e49eSyangbo lu host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; 10491ef5e49eSyangbo lu 105074fd5e30SYangbo Lu if (of_device_is_compatible(np, "fsl,p5040-esdhc") || 105174fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p5020-esdhc") || 105274fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p4080-esdhc") || 105374fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p1020-esdhc") || 1054e9acc77dSyangbo lu of_device_is_compatible(np, "fsl,t1040-esdhc")) 105574fd5e30SYangbo Lu host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; 105674fd5e30SYangbo Lu 1057a22950c8Syangbo lu if (of_device_is_compatible(np, "fsl,ls1021a-esdhc")) 1058a22950c8Syangbo lu host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 1059a22950c8Syangbo lu 1060dcaff04dSOded Gabbay if (of_device_is_compatible(np, "fsl,p2020-esdhc")) { 1061dcaff04dSOded Gabbay /* 1062dcaff04dSOded Gabbay * Freescale messed up with P2020 as it has a non-standard 1063dcaff04dSOded Gabbay * host control register 1064dcaff04dSOded Gabbay */ 1065dcaff04dSOded Gabbay host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL; 1066dcaff04dSOded Gabbay } 1067dcaff04dSOded Gabbay 106866b50a00SOded Gabbay /* call to generic mmc_of_parse to support additional capabilities */ 1069f0991408SUlf Hansson ret = mmc_of_parse(host->mmc); 1070f0991408SUlf Hansson if (ret) 1071f0991408SUlf Hansson goto err; 1072f0991408SUlf Hansson 1073490104acSHaijun Zhang mmc_of_parse_voltage(np, &host->ocr_mask); 107466b50a00SOded Gabbay 107566b50a00SOded Gabbay ret = sdhci_add_host(host); 107666b50a00SOded Gabbay if (ret) 1077f0991408SUlf Hansson goto err; 107866b50a00SOded Gabbay 1079f0991408SUlf Hansson return 0; 1080f0991408SUlf Hansson err: 1081f0991408SUlf Hansson sdhci_pltfm_free(pdev); 108266b50a00SOded Gabbay return ret; 108338576af1SShawn Guo } 108438576af1SShawn Guo 108538576af1SShawn Guo static struct platform_driver sdhci_esdhc_driver = { 108638576af1SShawn Guo .driver = { 108738576af1SShawn Guo .name = "sdhci-esdhc", 108838576af1SShawn Guo .of_match_table = sdhci_esdhc_of_match, 10899e48b336SUlf Hansson .pm = &esdhc_of_dev_pm_ops, 109038576af1SShawn Guo }, 109138576af1SShawn Guo .probe = sdhci_esdhc_probe, 1092caebcae9SKevin Hao .remove = sdhci_pltfm_unregister, 109338576af1SShawn Guo }; 109438576af1SShawn Guo 1095d1f81a64SAxel Lin module_platform_driver(sdhci_esdhc_driver); 109638576af1SShawn Guo 109738576af1SShawn Guo MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC"); 109838576af1SShawn Guo MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, " 109938576af1SShawn Guo "Anton Vorontsov <avorontsov@ru.mvista.com>"); 110038576af1SShawn Guo MODULE_LICENSE("GPL v2"); 1101