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; 8248e304ccSYangbo Lu bool quirk_unreliable_pulse_detection; 83b1f378abSYinbo Zhu bool quirk_fixup_tuning; 8419c3a0efSyangbo lu unsigned int peripheral_clock; 8567fdfbdfSyinbo.zhu const struct esdhc_clk_fixup *clk_fixup; 86b1f378abSYinbo Zhu u32 div_ratio; 87f4932cfdSyangbo lu }; 88f4932cfdSyangbo lu 89f4932cfdSyangbo lu /** 90f4932cfdSyangbo lu * esdhc_read*_fixup - Fixup the value read from incompatible eSDHC register 91f4932cfdSyangbo lu * to make it compatible with SD spec. 92f4932cfdSyangbo lu * 93f4932cfdSyangbo lu * @host: pointer to sdhci_host 94f4932cfdSyangbo lu * @spec_reg: SD spec register address 95f4932cfdSyangbo lu * @value: 32bit eSDHC register value on spec_reg address 96f4932cfdSyangbo lu * 97f4932cfdSyangbo lu * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC 98f4932cfdSyangbo lu * registers are 32 bits. There are differences in register size, register 99f4932cfdSyangbo lu * address, register function, bit position and function between eSDHC spec 100f4932cfdSyangbo lu * and SD spec. 101f4932cfdSyangbo lu * 102f4932cfdSyangbo lu * Return a fixed up register value 103f4932cfdSyangbo lu */ 104f4932cfdSyangbo lu static u32 esdhc_readl_fixup(struct sdhci_host *host, 105f4932cfdSyangbo lu int spec_reg, u32 value) 106137ccd46SJerry Huang { 107f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 1088605e7aeSJisheng Zhang struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 109137ccd46SJerry Huang u32 ret; 110137ccd46SJerry Huang 111137ccd46SJerry Huang /* 112137ccd46SJerry Huang * The bit of ADMA flag in eSDHC is not compatible with standard 113137ccd46SJerry Huang * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is 114137ccd46SJerry Huang * supported by eSDHC. 115137ccd46SJerry Huang * And for many FSL eSDHC controller, the reset value of field 116f4932cfdSyangbo lu * SDHCI_CAN_DO_ADMA1 is 1, but some of them can't support ADMA, 117137ccd46SJerry Huang * only these vendor version is greater than 2.2/0x12 support ADMA. 118137ccd46SJerry Huang */ 119f4932cfdSyangbo lu if ((spec_reg == SDHCI_CAPABILITIES) && (value & SDHCI_CAN_DO_ADMA1)) { 120f4932cfdSyangbo lu if (esdhc->vendor_ver > VENDOR_V_22) { 121f4932cfdSyangbo lu ret = value | SDHCI_CAN_DO_ADMA2; 122f4932cfdSyangbo lu return ret; 123137ccd46SJerry Huang } 124f4932cfdSyangbo lu } 125b0921d5cSMichael Walle /* 126b0921d5cSMichael Walle * The DAT[3:0] line signal levels and the CMD line signal level are 127b0921d5cSMichael Walle * not compatible with standard SDHC register. The line signal levels 128b0921d5cSMichael Walle * DAT[7:0] are at bits 31:24 and the command line signal level is at 129b0921d5cSMichael Walle * bit 23. All other bits are the same as in the standard SDHC 130b0921d5cSMichael Walle * register. 131b0921d5cSMichael Walle */ 132b0921d5cSMichael Walle if (spec_reg == SDHCI_PRESENT_STATE) { 133b0921d5cSMichael Walle ret = value & 0x000fffff; 134b0921d5cSMichael Walle ret |= (value >> 4) & SDHCI_DATA_LVL_MASK; 135b0921d5cSMichael Walle ret |= (value << 1) & SDHCI_CMD_LVL; 136b0921d5cSMichael Walle return ret; 137b0921d5cSMichael Walle } 138b0921d5cSMichael Walle 1392f3110ccSyangbo lu /* 1402f3110ccSyangbo lu * DTS properties of mmc host are used to enable each speed mode 1412f3110ccSyangbo lu * according to soc and board capability. So clean up 1422f3110ccSyangbo lu * SDR50/SDR104/DDR50 support bits here. 1432f3110ccSyangbo lu */ 1442f3110ccSyangbo lu if (spec_reg == SDHCI_CAPABILITIES_1) { 1452f3110ccSyangbo lu ret = value & ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 | 1462f3110ccSyangbo lu SDHCI_SUPPORT_DDR50); 1472f3110ccSyangbo lu return ret; 1482f3110ccSyangbo lu } 1492f3110ccSyangbo lu 150f4932cfdSyangbo lu ret = value; 151137ccd46SJerry Huang return ret; 152137ccd46SJerry Huang } 153137ccd46SJerry Huang 154f4932cfdSyangbo lu static u16 esdhc_readw_fixup(struct sdhci_host *host, 155f4932cfdSyangbo lu int spec_reg, u32 value) 1567657c3a7SAlbert Herranz { 157151ede40Syangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 158151ede40Syangbo lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 1597657c3a7SAlbert Herranz u16 ret; 160f4932cfdSyangbo lu int shift = (spec_reg & 0x2) * 8; 1617657c3a7SAlbert Herranz 162f4932cfdSyangbo lu if (spec_reg == SDHCI_HOST_VERSION) 163f4932cfdSyangbo lu ret = value & 0xffff; 1647657c3a7SAlbert Herranz else 165f4932cfdSyangbo lu ret = (value >> shift) & 0xffff; 166151ede40Syangbo lu /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect 167151ede40Syangbo lu * vendor version and spec version information. 168151ede40Syangbo lu */ 169151ede40Syangbo lu if ((spec_reg == SDHCI_HOST_VERSION) && 170151ede40Syangbo lu (esdhc->quirk_incorrect_hostver)) 171151ede40Syangbo lu ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200; 172e51cbc9eSXu lei return ret; 173e51cbc9eSXu lei } 174e51cbc9eSXu lei 175f4932cfdSyangbo lu static u8 esdhc_readb_fixup(struct sdhci_host *host, 176f4932cfdSyangbo lu int spec_reg, u32 value) 177e51cbc9eSXu lei { 178f4932cfdSyangbo lu u8 ret; 179f4932cfdSyangbo lu u8 dma_bits; 180f4932cfdSyangbo lu int shift = (spec_reg & 0x3) * 8; 181f4932cfdSyangbo lu 182f4932cfdSyangbo lu ret = (value >> shift) & 0xff; 183ba8c4dc9SRoy Zang 184ba8c4dc9SRoy Zang /* 185ba8c4dc9SRoy Zang * "DMA select" locates at offset 0x28 in SD specification, but on 186ba8c4dc9SRoy Zang * P5020 or P3041, it locates at 0x29. 187ba8c4dc9SRoy Zang */ 188f4932cfdSyangbo lu if (spec_reg == SDHCI_HOST_CONTROL) { 189ba8c4dc9SRoy Zang /* DMA select is 22,23 bits in Protocol Control Register */ 190f4932cfdSyangbo lu dma_bits = (value >> 5) & SDHCI_CTRL_DMA_MASK; 191ba8c4dc9SRoy Zang /* fixup the result */ 192ba8c4dc9SRoy Zang ret &= ~SDHCI_CTRL_DMA_MASK; 193ba8c4dc9SRoy Zang ret |= dma_bits; 194ba8c4dc9SRoy Zang } 195f4932cfdSyangbo lu return ret; 196f4932cfdSyangbo lu } 197f4932cfdSyangbo lu 198f4932cfdSyangbo lu /** 199f4932cfdSyangbo lu * esdhc_write*_fixup - Fixup the SD spec register value so that it could be 200f4932cfdSyangbo lu * written into eSDHC register. 201f4932cfdSyangbo lu * 202f4932cfdSyangbo lu * @host: pointer to sdhci_host 203f4932cfdSyangbo lu * @spec_reg: SD spec register address 204f4932cfdSyangbo lu * @value: 8/16/32bit SD spec register value that would be written 205f4932cfdSyangbo lu * @old_value: 32bit eSDHC register value on spec_reg address 206f4932cfdSyangbo lu * 207f4932cfdSyangbo lu * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC 208f4932cfdSyangbo lu * registers are 32 bits. There are differences in register size, register 209f4932cfdSyangbo lu * address, register function, bit position and function between eSDHC spec 210f4932cfdSyangbo lu * and SD spec. 211f4932cfdSyangbo lu * 212f4932cfdSyangbo lu * Return a fixed up register value 213f4932cfdSyangbo lu */ 214f4932cfdSyangbo lu static u32 esdhc_writel_fixup(struct sdhci_host *host, 215f4932cfdSyangbo lu int spec_reg, u32 value, u32 old_value) 216f4932cfdSyangbo lu { 217f4932cfdSyangbo lu u32 ret; 218f4932cfdSyangbo lu 219f4932cfdSyangbo lu /* 220f4932cfdSyangbo lu * Enabling IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE] 221f4932cfdSyangbo lu * when SYSCTL[RSTD] is set for some special operations. 222f4932cfdSyangbo lu * No any impact on other operation. 223f4932cfdSyangbo lu */ 224f4932cfdSyangbo lu if (spec_reg == SDHCI_INT_ENABLE) 225f4932cfdSyangbo lu ret = value | SDHCI_INT_BLK_GAP; 226f4932cfdSyangbo lu else 227f4932cfdSyangbo lu ret = value; 228ba8c4dc9SRoy Zang 2297657c3a7SAlbert Herranz return ret; 2307657c3a7SAlbert Herranz } 2317657c3a7SAlbert Herranz 232f4932cfdSyangbo lu static u32 esdhc_writew_fixup(struct sdhci_host *host, 233f4932cfdSyangbo lu int spec_reg, u16 value, u32 old_value) 234a4071fbbSHaijun Zhang { 235f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 236f4932cfdSyangbo lu int shift = (spec_reg & 0x2) * 8; 237f4932cfdSyangbo lu u32 ret; 238f4932cfdSyangbo lu 239f4932cfdSyangbo lu switch (spec_reg) { 240f4932cfdSyangbo lu case SDHCI_TRANSFER_MODE: 241a4071fbbSHaijun Zhang /* 242f4932cfdSyangbo lu * Postpone this write, we must do it together with a 243f4932cfdSyangbo lu * command write that is down below. Return old value. 244a4071fbbSHaijun Zhang */ 245f4932cfdSyangbo lu pltfm_host->xfer_mode_shadow = value; 246f4932cfdSyangbo lu return old_value; 247f4932cfdSyangbo lu case SDHCI_COMMAND: 248f4932cfdSyangbo lu ret = (value << 16) | pltfm_host->xfer_mode_shadow; 249f4932cfdSyangbo lu return ret; 250a4071fbbSHaijun Zhang } 251a4071fbbSHaijun Zhang 252f4932cfdSyangbo lu ret = old_value & (~(0xffff << shift)); 253f4932cfdSyangbo lu ret |= (value << shift); 254f4932cfdSyangbo lu 255f4932cfdSyangbo lu if (spec_reg == SDHCI_BLOCK_SIZE) { 2567657c3a7SAlbert Herranz /* 2577657c3a7SAlbert Herranz * Two last DMA bits are reserved, and first one is used for 2587657c3a7SAlbert Herranz * non-standard blksz of 4096 bytes that we don't support 2597657c3a7SAlbert Herranz * yet. So clear the DMA boundary bits. 2607657c3a7SAlbert Herranz */ 261f4932cfdSyangbo lu ret &= (~SDHCI_MAKE_BLKSZ(0x7, 0)); 2627657c3a7SAlbert Herranz } 263f4932cfdSyangbo lu return ret; 2647657c3a7SAlbert Herranz } 2657657c3a7SAlbert Herranz 266f4932cfdSyangbo lu static u32 esdhc_writeb_fixup(struct sdhci_host *host, 267f4932cfdSyangbo lu int spec_reg, u8 value, u32 old_value) 2687657c3a7SAlbert Herranz { 269f4932cfdSyangbo lu u32 ret; 270f4932cfdSyangbo lu u32 dma_bits; 271f4932cfdSyangbo lu u8 tmp; 272f4932cfdSyangbo lu int shift = (spec_reg & 0x3) * 8; 273f4932cfdSyangbo lu 274ba8c4dc9SRoy Zang /* 2759e4703dfSyangbo lu * eSDHC doesn't have a standard power control register, so we do 2769e4703dfSyangbo lu * nothing here to avoid incorrect operation. 2779e4703dfSyangbo lu */ 2789e4703dfSyangbo lu if (spec_reg == SDHCI_POWER_CONTROL) 2799e4703dfSyangbo lu return old_value; 2809e4703dfSyangbo lu /* 281ba8c4dc9SRoy Zang * "DMA select" location is offset 0x28 in SD specification, but on 282ba8c4dc9SRoy Zang * P5020 or P3041, it's located at 0x29. 283ba8c4dc9SRoy Zang */ 284f4932cfdSyangbo lu if (spec_reg == SDHCI_HOST_CONTROL) { 285dcaff04dSOded Gabbay /* 286dcaff04dSOded Gabbay * If host control register is not standard, exit 287dcaff04dSOded Gabbay * this function 288dcaff04dSOded Gabbay */ 289dcaff04dSOded Gabbay if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL) 290f4932cfdSyangbo lu return old_value; 291dcaff04dSOded Gabbay 292ba8c4dc9SRoy Zang /* DMA select is 22,23 bits in Protocol Control Register */ 293f4932cfdSyangbo lu dma_bits = (value & SDHCI_CTRL_DMA_MASK) << 5; 294f4932cfdSyangbo lu ret = (old_value & (~(SDHCI_CTRL_DMA_MASK << 5))) | dma_bits; 295f4932cfdSyangbo lu tmp = (value & (~SDHCI_CTRL_DMA_MASK)) | 296f4932cfdSyangbo lu (old_value & SDHCI_CTRL_DMA_MASK); 297f4932cfdSyangbo lu ret = (ret & (~0xff)) | tmp; 298f4932cfdSyangbo lu 299f4932cfdSyangbo lu /* Prevent SDHCI core from writing reserved bits (e.g. HISPD) */ 300f4932cfdSyangbo lu ret &= ~ESDHC_HOST_CONTROL_RES; 301f4932cfdSyangbo lu return ret; 302ba8c4dc9SRoy Zang } 303ba8c4dc9SRoy Zang 304f4932cfdSyangbo lu ret = (old_value & (~(0xff << shift))) | (value << shift); 305f4932cfdSyangbo lu return ret; 306f4932cfdSyangbo lu } 307f4932cfdSyangbo lu 308f4932cfdSyangbo lu static u32 esdhc_be_readl(struct sdhci_host *host, int reg) 309f4932cfdSyangbo lu { 310f4932cfdSyangbo lu u32 ret; 311f4932cfdSyangbo lu u32 value; 312f4932cfdSyangbo lu 3132f3110ccSyangbo lu if (reg == SDHCI_CAPABILITIES_1) 3142f3110ccSyangbo lu value = ioread32be(host->ioaddr + ESDHC_CAPABILITIES_1); 3152f3110ccSyangbo lu else 316f4932cfdSyangbo lu value = ioread32be(host->ioaddr + reg); 3172f3110ccSyangbo lu 318f4932cfdSyangbo lu ret = esdhc_readl_fixup(host, reg, value); 319f4932cfdSyangbo lu 320f4932cfdSyangbo lu return ret; 321f4932cfdSyangbo lu } 322f4932cfdSyangbo lu 323f4932cfdSyangbo lu static u32 esdhc_le_readl(struct sdhci_host *host, int reg) 324f4932cfdSyangbo lu { 325f4932cfdSyangbo lu u32 ret; 326f4932cfdSyangbo lu u32 value; 327f4932cfdSyangbo lu 3282f3110ccSyangbo lu if (reg == SDHCI_CAPABILITIES_1) 3292f3110ccSyangbo lu value = ioread32(host->ioaddr + ESDHC_CAPABILITIES_1); 3302f3110ccSyangbo lu else 331f4932cfdSyangbo lu value = ioread32(host->ioaddr + reg); 3322f3110ccSyangbo lu 333f4932cfdSyangbo lu ret = esdhc_readl_fixup(host, reg, value); 334f4932cfdSyangbo lu 335f4932cfdSyangbo lu return ret; 336f4932cfdSyangbo lu } 337f4932cfdSyangbo lu 338f4932cfdSyangbo lu static u16 esdhc_be_readw(struct sdhci_host *host, int reg) 339f4932cfdSyangbo lu { 340f4932cfdSyangbo lu u16 ret; 341f4932cfdSyangbo lu u32 value; 342f4932cfdSyangbo lu int base = reg & ~0x3; 343f4932cfdSyangbo lu 344f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 345f4932cfdSyangbo lu ret = esdhc_readw_fixup(host, reg, value); 346f4932cfdSyangbo lu return ret; 347f4932cfdSyangbo lu } 348f4932cfdSyangbo lu 349f4932cfdSyangbo lu static u16 esdhc_le_readw(struct sdhci_host *host, int reg) 350f4932cfdSyangbo lu { 351f4932cfdSyangbo lu u16 ret; 352f4932cfdSyangbo lu u32 value; 353f4932cfdSyangbo lu int base = reg & ~0x3; 354f4932cfdSyangbo lu 355f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 356f4932cfdSyangbo lu ret = esdhc_readw_fixup(host, reg, value); 357f4932cfdSyangbo lu return ret; 358f4932cfdSyangbo lu } 359f4932cfdSyangbo lu 360f4932cfdSyangbo lu static u8 esdhc_be_readb(struct sdhci_host *host, int reg) 361f4932cfdSyangbo lu { 362f4932cfdSyangbo lu u8 ret; 363f4932cfdSyangbo lu u32 value; 364f4932cfdSyangbo lu int base = reg & ~0x3; 365f4932cfdSyangbo lu 366f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 367f4932cfdSyangbo lu ret = esdhc_readb_fixup(host, reg, value); 368f4932cfdSyangbo lu return ret; 369f4932cfdSyangbo lu } 370f4932cfdSyangbo lu 371f4932cfdSyangbo lu static u8 esdhc_le_readb(struct sdhci_host *host, int reg) 372f4932cfdSyangbo lu { 373f4932cfdSyangbo lu u8 ret; 374f4932cfdSyangbo lu u32 value; 375f4932cfdSyangbo lu int base = reg & ~0x3; 376f4932cfdSyangbo lu 377f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 378f4932cfdSyangbo lu ret = esdhc_readb_fixup(host, reg, value); 379f4932cfdSyangbo lu return ret; 380f4932cfdSyangbo lu } 381f4932cfdSyangbo lu 382f4932cfdSyangbo lu static void esdhc_be_writel(struct sdhci_host *host, u32 val, int reg) 383f4932cfdSyangbo lu { 384f4932cfdSyangbo lu u32 value; 385f4932cfdSyangbo lu 386f4932cfdSyangbo lu value = esdhc_writel_fixup(host, reg, val, 0); 387f4932cfdSyangbo lu iowrite32be(value, host->ioaddr + reg); 388f4932cfdSyangbo lu } 389f4932cfdSyangbo lu 390f4932cfdSyangbo lu static void esdhc_le_writel(struct sdhci_host *host, u32 val, int reg) 391f4932cfdSyangbo lu { 392f4932cfdSyangbo lu u32 value; 393f4932cfdSyangbo lu 394f4932cfdSyangbo lu value = esdhc_writel_fixup(host, reg, val, 0); 395f4932cfdSyangbo lu iowrite32(value, host->ioaddr + reg); 396f4932cfdSyangbo lu } 397f4932cfdSyangbo lu 398f4932cfdSyangbo lu static void esdhc_be_writew(struct sdhci_host *host, u16 val, int reg) 399f4932cfdSyangbo lu { 400f4932cfdSyangbo lu int base = reg & ~0x3; 401f4932cfdSyangbo lu u32 value; 402f4932cfdSyangbo lu u32 ret; 403f4932cfdSyangbo lu 404f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 405f4932cfdSyangbo lu ret = esdhc_writew_fixup(host, reg, val, value); 406f4932cfdSyangbo lu if (reg != SDHCI_TRANSFER_MODE) 407f4932cfdSyangbo lu iowrite32be(ret, host->ioaddr + base); 408f4932cfdSyangbo lu } 409f4932cfdSyangbo lu 410f4932cfdSyangbo lu static void esdhc_le_writew(struct sdhci_host *host, u16 val, int reg) 411f4932cfdSyangbo lu { 412f4932cfdSyangbo lu int base = reg & ~0x3; 413f4932cfdSyangbo lu u32 value; 414f4932cfdSyangbo lu u32 ret; 415f4932cfdSyangbo lu 416f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 417f4932cfdSyangbo lu ret = esdhc_writew_fixup(host, reg, val, value); 418f4932cfdSyangbo lu if (reg != SDHCI_TRANSFER_MODE) 419f4932cfdSyangbo lu iowrite32(ret, host->ioaddr + base); 420f4932cfdSyangbo lu } 421f4932cfdSyangbo lu 422f4932cfdSyangbo lu static void esdhc_be_writeb(struct sdhci_host *host, u8 val, int reg) 423f4932cfdSyangbo lu { 424f4932cfdSyangbo lu int base = reg & ~0x3; 425f4932cfdSyangbo lu u32 value; 426f4932cfdSyangbo lu u32 ret; 427f4932cfdSyangbo lu 428f4932cfdSyangbo lu value = ioread32be(host->ioaddr + base); 429f4932cfdSyangbo lu ret = esdhc_writeb_fixup(host, reg, val, value); 430f4932cfdSyangbo lu iowrite32be(ret, host->ioaddr + base); 431f4932cfdSyangbo lu } 432f4932cfdSyangbo lu 433f4932cfdSyangbo lu static void esdhc_le_writeb(struct sdhci_host *host, u8 val, int reg) 434f4932cfdSyangbo lu { 435f4932cfdSyangbo lu int base = reg & ~0x3; 436f4932cfdSyangbo lu u32 value; 437f4932cfdSyangbo lu u32 ret; 438f4932cfdSyangbo lu 439f4932cfdSyangbo lu value = ioread32(host->ioaddr + base); 440f4932cfdSyangbo lu ret = esdhc_writeb_fixup(host, reg, val, value); 441f4932cfdSyangbo lu iowrite32(ret, host->ioaddr + base); 4427657c3a7SAlbert Herranz } 4437657c3a7SAlbert Herranz 444a4071fbbSHaijun Zhang /* 445a4071fbbSHaijun Zhang * For Abort or Suspend after Stop at Block Gap, ignore the ADMA 446a4071fbbSHaijun Zhang * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC]) 447a4071fbbSHaijun Zhang * and Block Gap Event(IRQSTAT[BGE]) are also set. 448a4071fbbSHaijun Zhang * For Continue, apply soft reset for data(SYSCTL[RSTD]); 449a4071fbbSHaijun Zhang * and re-issue the entire read transaction from beginning. 450a4071fbbSHaijun Zhang */ 451f4932cfdSyangbo lu static void esdhc_of_adma_workaround(struct sdhci_host *host, u32 intmask) 452a4071fbbSHaijun Zhang { 453f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 4548605e7aeSJisheng Zhang struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 455a4071fbbSHaijun Zhang bool applicable; 456a4071fbbSHaijun Zhang dma_addr_t dmastart; 457a4071fbbSHaijun Zhang dma_addr_t dmanow; 458a4071fbbSHaijun Zhang 459a4071fbbSHaijun Zhang applicable = (intmask & SDHCI_INT_DATA_END) && 460a4071fbbSHaijun Zhang (intmask & SDHCI_INT_BLK_GAP) && 461f4932cfdSyangbo lu (esdhc->vendor_ver == VENDOR_V_23); 462a4071fbbSHaijun Zhang if (!applicable) 463a4071fbbSHaijun Zhang return; 464a4071fbbSHaijun Zhang 465a4071fbbSHaijun Zhang host->data->error = 0; 466a4071fbbSHaijun Zhang dmastart = sg_dma_address(host->data->sg); 467a4071fbbSHaijun Zhang dmanow = dmastart + host->data->bytes_xfered; 468a4071fbbSHaijun Zhang /* 469a4071fbbSHaijun Zhang * Force update to the next DMA block boundary. 470a4071fbbSHaijun Zhang */ 471a4071fbbSHaijun Zhang dmanow = (dmanow & ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) + 472a4071fbbSHaijun Zhang SDHCI_DEFAULT_BOUNDARY_SIZE; 473a4071fbbSHaijun Zhang host->data->bytes_xfered = dmanow - dmastart; 474a4071fbbSHaijun Zhang sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS); 475a4071fbbSHaijun Zhang } 476a4071fbbSHaijun Zhang 47780872e21SWolfram Sang static int esdhc_of_enable_dma(struct sdhci_host *host) 4787657c3a7SAlbert Herranz { 479f4932cfdSyangbo lu u32 value; 4805552d7adSLaurentiu Tudor struct device *dev = mmc_dev(host->mmc); 4815552d7adSLaurentiu Tudor 4825552d7adSLaurentiu Tudor if (of_device_is_compatible(dev->of_node, "fsl,ls1043a-esdhc") || 4835552d7adSLaurentiu Tudor of_device_is_compatible(dev->of_node, "fsl,ls1046a-esdhc")) 4845552d7adSLaurentiu Tudor dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40)); 485f4932cfdSyangbo lu 486f4932cfdSyangbo lu value = sdhci_readl(host, ESDHC_DMA_SYSCTL); 487f4932cfdSyangbo lu value |= ESDHC_DMA_SNOOP; 488f4932cfdSyangbo lu sdhci_writel(host, value, ESDHC_DMA_SYSCTL); 4897657c3a7SAlbert Herranz return 0; 4907657c3a7SAlbert Herranz } 4917657c3a7SAlbert Herranz 49280872e21SWolfram Sang static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host) 4937657c3a7SAlbert Herranz { 494e307148fSShawn Guo struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 49519c3a0efSyangbo lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 4967657c3a7SAlbert Herranz 49719c3a0efSyangbo lu if (esdhc->peripheral_clock) 49819c3a0efSyangbo lu return esdhc->peripheral_clock; 49919c3a0efSyangbo lu else 500e307148fSShawn Guo return pltfm_host->clock; 5017657c3a7SAlbert Herranz } 5027657c3a7SAlbert Herranz 50380872e21SWolfram Sang static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) 5047657c3a7SAlbert Herranz { 505e307148fSShawn Guo struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 50619c3a0efSyangbo lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 50719c3a0efSyangbo lu unsigned int clock; 5087657c3a7SAlbert Herranz 50919c3a0efSyangbo lu if (esdhc->peripheral_clock) 51019c3a0efSyangbo lu clock = esdhc->peripheral_clock; 51119c3a0efSyangbo lu else 51219c3a0efSyangbo lu clock = pltfm_host->clock; 51319c3a0efSyangbo lu return clock / 256 / 16; 5147657c3a7SAlbert Herranz } 5157657c3a7SAlbert Herranz 516dd3f6983Syangbo lu static void esdhc_clock_enable(struct sdhci_host *host, bool enable) 517dd3f6983Syangbo lu { 518dd3f6983Syangbo lu u32 val; 519dd3f6983Syangbo lu ktime_t timeout; 520dd3f6983Syangbo lu 521dd3f6983Syangbo lu val = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 522dd3f6983Syangbo lu 523dd3f6983Syangbo lu if (enable) 524dd3f6983Syangbo lu val |= ESDHC_CLOCK_SDCLKEN; 525dd3f6983Syangbo lu else 526dd3f6983Syangbo lu val &= ~ESDHC_CLOCK_SDCLKEN; 527dd3f6983Syangbo lu 528dd3f6983Syangbo lu sdhci_writel(host, val, ESDHC_SYSTEM_CONTROL); 529dd3f6983Syangbo lu 530dd3f6983Syangbo lu /* Wait max 20 ms */ 531dd3f6983Syangbo lu timeout = ktime_add_ms(ktime_get(), 20); 532dd3f6983Syangbo lu val = ESDHC_CLOCK_STABLE; 533*ea6d0273SAdrian Hunter while (1) { 534*ea6d0273SAdrian Hunter bool timedout = ktime_after(ktime_get(), timeout); 535*ea6d0273SAdrian Hunter 536*ea6d0273SAdrian Hunter if (sdhci_readl(host, ESDHC_PRSSTAT) & val) 537*ea6d0273SAdrian Hunter break; 538*ea6d0273SAdrian Hunter if (timedout) { 539dd3f6983Syangbo lu pr_err("%s: Internal clock never stabilised.\n", 540dd3f6983Syangbo lu mmc_hostname(host->mmc)); 541dd3f6983Syangbo lu break; 542dd3f6983Syangbo lu } 543dd3f6983Syangbo lu udelay(10); 544dd3f6983Syangbo lu } 545dd3f6983Syangbo lu } 546dd3f6983Syangbo lu 547f060bc9cSJerry Huang static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) 548f060bc9cSJerry Huang { 549f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 5508605e7aeSJisheng Zhang struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 551bd455029SJoakim Tjernlund int pre_div = 1; 552d31fc00aSDong Aisheng int div = 1; 5536079e63cSYangbo Lu int division; 554e145ac45Syangbo lu ktime_t timeout; 55567fdfbdfSyinbo.zhu long fixup = 0; 556d31fc00aSDong Aisheng u32 temp; 557d31fc00aSDong Aisheng 5581650d0c7SRussell King host->mmc->actual_clock = 0; 5591650d0c7SRussell King 560dd3f6983Syangbo lu if (clock == 0) { 561dd3f6983Syangbo lu esdhc_clock_enable(host, false); 562373073efSRussell King return; 563dd3f6983Syangbo lu } 564d31fc00aSDong Aisheng 56577bd2f6fSYangbo Lu /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */ 566f4932cfdSyangbo lu if (esdhc->vendor_ver < VENDOR_V_23) 56777bd2f6fSYangbo Lu pre_div = 2; 56877bd2f6fSYangbo Lu 56967fdfbdfSyinbo.zhu if (host->mmc->card && mmc_card_sd(host->mmc->card) && 57067fdfbdfSyinbo.zhu esdhc->clk_fixup && host->mmc->ios.timing == MMC_TIMING_LEGACY) 57167fdfbdfSyinbo.zhu fixup = esdhc->clk_fixup->sd_dflt_max_clk; 57267fdfbdfSyinbo.zhu else if (esdhc->clk_fixup) 57367fdfbdfSyinbo.zhu fixup = esdhc->clk_fixup->max_clk[host->mmc->ios.timing]; 574a627f025Syangbo lu 57567fdfbdfSyinbo.zhu if (fixup && clock > fixup) 57667fdfbdfSyinbo.zhu clock = fixup; 577f060bc9cSJerry Huang 578d31fc00aSDong Aisheng temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 579e87d2db2Syangbo lu temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | 580e87d2db2Syangbo lu ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK); 581d31fc00aSDong Aisheng sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 582d31fc00aSDong Aisheng 583d31fc00aSDong Aisheng while (host->max_clk / pre_div / 16 > clock && pre_div < 256) 584d31fc00aSDong Aisheng pre_div *= 2; 585d31fc00aSDong Aisheng 586d31fc00aSDong Aisheng while (host->max_clk / pre_div / div > clock && div < 16) 587d31fc00aSDong Aisheng div++; 588d31fc00aSDong Aisheng 5896079e63cSYangbo Lu if (esdhc->quirk_limited_clk_division && 5906079e63cSYangbo Lu clock == MMC_HS200_MAX_DTR && 5916079e63cSYangbo Lu (host->mmc->ios.timing == MMC_TIMING_MMC_HS400 || 5926079e63cSYangbo Lu host->flags & SDHCI_HS400_TUNING)) { 5936079e63cSYangbo Lu division = pre_div * div; 5946079e63cSYangbo Lu if (division <= 4) { 5956079e63cSYangbo Lu pre_div = 4; 5966079e63cSYangbo Lu div = 1; 5976079e63cSYangbo Lu } else if (division <= 8) { 5986079e63cSYangbo Lu pre_div = 4; 5996079e63cSYangbo Lu div = 2; 6006079e63cSYangbo Lu } else if (division <= 12) { 6016079e63cSYangbo Lu pre_div = 4; 6026079e63cSYangbo Lu div = 3; 6036079e63cSYangbo Lu } else { 604b11c36d5SColin Ian King pr_warn("%s: using unsupported clock division.\n", 6056079e63cSYangbo Lu mmc_hostname(host->mmc)); 6066079e63cSYangbo Lu } 6076079e63cSYangbo Lu } 6086079e63cSYangbo Lu 609d31fc00aSDong Aisheng dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", 610e76b8559SDong Aisheng clock, host->max_clk / pre_div / div); 611bd455029SJoakim Tjernlund host->mmc->actual_clock = host->max_clk / pre_div / div; 612b1f378abSYinbo Zhu esdhc->div_ratio = pre_div * div; 613d31fc00aSDong Aisheng pre_div >>= 1; 614d31fc00aSDong Aisheng div--; 615d31fc00aSDong Aisheng 616d31fc00aSDong Aisheng temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 617d31fc00aSDong Aisheng temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN 618d31fc00aSDong Aisheng | (div << ESDHC_DIVIDER_SHIFT) 619d31fc00aSDong Aisheng | (pre_div << ESDHC_PREDIV_SHIFT)); 620d31fc00aSDong Aisheng sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 621e87d2db2Syangbo lu 62254e08d9aSYangbo Lu if (host->mmc->ios.timing == MMC_TIMING_MMC_HS400 && 62354e08d9aSYangbo Lu clock == MMC_HS200_MAX_DTR) { 62454e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_TBCTL); 62554e08d9aSYangbo Lu sdhci_writel(host, temp | ESDHC_HS400_MODE, ESDHC_TBCTL); 62654e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_SDCLKCTL); 62754e08d9aSYangbo Lu sdhci_writel(host, temp | ESDHC_CMD_CLK_CTL, ESDHC_SDCLKCTL); 62854e08d9aSYangbo Lu esdhc_clock_enable(host, true); 62954e08d9aSYangbo Lu 63054e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_DLLCFG0); 63158d0bf84SYangbo Lu temp |= ESDHC_DLL_ENABLE; 63258d0bf84SYangbo Lu if (host->mmc->actual_clock == MMC_HS200_MAX_DTR) 63358d0bf84SYangbo Lu temp |= ESDHC_DLL_FREQ_SEL; 63454e08d9aSYangbo Lu sdhci_writel(host, temp, ESDHC_DLLCFG0); 63554e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_TBCTL); 63654e08d9aSYangbo Lu sdhci_writel(host, temp | ESDHC_HS400_WNDW_ADJUST, ESDHC_TBCTL); 63754e08d9aSYangbo Lu 63854e08d9aSYangbo Lu esdhc_clock_enable(host, false); 63954e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_DMA_SYSCTL); 64054e08d9aSYangbo Lu temp |= ESDHC_FLUSH_ASYNC_FIFO; 64154e08d9aSYangbo Lu sdhci_writel(host, temp, ESDHC_DMA_SYSCTL); 64254e08d9aSYangbo Lu } 64354e08d9aSYangbo Lu 644e87d2db2Syangbo lu /* Wait max 20 ms */ 645e145ac45Syangbo lu timeout = ktime_add_ms(ktime_get(), 20); 646*ea6d0273SAdrian Hunter while (1) { 647*ea6d0273SAdrian Hunter bool timedout = ktime_after(ktime_get(), timeout); 648*ea6d0273SAdrian Hunter 649*ea6d0273SAdrian Hunter if (sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE) 650*ea6d0273SAdrian Hunter break; 651*ea6d0273SAdrian Hunter if (timedout) { 652e87d2db2Syangbo lu pr_err("%s: Internal clock never stabilised.\n", 653e87d2db2Syangbo lu mmc_hostname(host->mmc)); 654e87d2db2Syangbo lu return; 655e87d2db2Syangbo lu } 656e145ac45Syangbo lu udelay(10); 657f060bc9cSJerry Huang } 658f060bc9cSJerry Huang 65954e08d9aSYangbo Lu temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 660e87d2db2Syangbo lu temp |= ESDHC_CLOCK_SDCLKEN; 661e87d2db2Syangbo lu sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 662e87d2db2Syangbo lu } 663e87d2db2Syangbo lu 6642317f56cSRussell King static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width) 66566b50a00SOded Gabbay { 66666b50a00SOded Gabbay u32 ctrl; 66766b50a00SOded Gabbay 668f4932cfdSyangbo lu ctrl = sdhci_readl(host, ESDHC_PROCTL); 669f4932cfdSyangbo lu ctrl &= (~ESDHC_CTRL_BUSWIDTH_MASK); 67066b50a00SOded Gabbay switch (width) { 67166b50a00SOded Gabbay case MMC_BUS_WIDTH_8: 672f4932cfdSyangbo lu ctrl |= ESDHC_CTRL_8BITBUS; 67366b50a00SOded Gabbay break; 67466b50a00SOded Gabbay 67566b50a00SOded Gabbay case MMC_BUS_WIDTH_4: 676f4932cfdSyangbo lu ctrl |= ESDHC_CTRL_4BITBUS; 67766b50a00SOded Gabbay break; 67866b50a00SOded Gabbay 67966b50a00SOded Gabbay default: 68066b50a00SOded Gabbay break; 68166b50a00SOded Gabbay } 68266b50a00SOded Gabbay 683f4932cfdSyangbo lu sdhci_writel(host, ctrl, ESDHC_PROCTL); 68466b50a00SOded Gabbay } 68566b50a00SOded Gabbay 686304f0a98SAlessio Igor Bogani static void esdhc_reset(struct sdhci_host *host, u8 mask) 687304f0a98SAlessio Igor Bogani { 68848e304ccSYangbo Lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 68948e304ccSYangbo Lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 690f2bc6000Syinbo.zhu u32 val; 691f2bc6000Syinbo.zhu 692304f0a98SAlessio Igor Bogani sdhci_reset(host, mask); 693304f0a98SAlessio Igor Bogani 694304f0a98SAlessio Igor Bogani sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); 695304f0a98SAlessio Igor Bogani sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); 696f2bc6000Syinbo.zhu 697f2bc6000Syinbo.zhu if (mask & SDHCI_RESET_ALL) { 698f2bc6000Syinbo.zhu val = sdhci_readl(host, ESDHC_TBCTL); 699f2bc6000Syinbo.zhu val &= ~ESDHC_TB_EN; 700f2bc6000Syinbo.zhu sdhci_writel(host, val, ESDHC_TBCTL); 70148e304ccSYangbo Lu 70248e304ccSYangbo Lu if (esdhc->quirk_unreliable_pulse_detection) { 70348e304ccSYangbo Lu val = sdhci_readl(host, ESDHC_DLLCFG1); 70448e304ccSYangbo Lu val &= ~ESDHC_DLL_PD_PULSE_STRETCH_SEL; 70548e304ccSYangbo Lu sdhci_writel(host, val, ESDHC_DLLCFG1); 70648e304ccSYangbo Lu } 707f2bc6000Syinbo.zhu } 708304f0a98SAlessio Igor Bogani } 709304f0a98SAlessio Igor Bogani 710ea35645aSyangbo lu /* The SCFG, Supplemental Configuration Unit, provides SoC specific 711ea35645aSyangbo lu * configuration and status registers for the device. There is a 712ea35645aSyangbo lu * SDHC IO VSEL control register on SCFG for some platforms. It's 713ea35645aSyangbo lu * used to support SDHC IO voltage switching. 714ea35645aSyangbo lu */ 715ea35645aSyangbo lu static const struct of_device_id scfg_device_ids[] = { 716ea35645aSyangbo lu { .compatible = "fsl,t1040-scfg", }, 717ea35645aSyangbo lu { .compatible = "fsl,ls1012a-scfg", }, 718ea35645aSyangbo lu { .compatible = "fsl,ls1046a-scfg", }, 719ea35645aSyangbo lu {} 720ea35645aSyangbo lu }; 721ea35645aSyangbo lu 722ea35645aSyangbo lu /* SDHC IO VSEL control register definition */ 723ea35645aSyangbo lu #define SCFG_SDHCIOVSELCR 0x408 724ea35645aSyangbo lu #define SDHCIOVSELCR_TGLEN 0x80000000 725ea35645aSyangbo lu #define SDHCIOVSELCR_VSELVAL 0x60000000 726ea35645aSyangbo lu #define SDHCIOVSELCR_SDHC_VS 0x00000001 727ea35645aSyangbo lu 728ea35645aSyangbo lu static int esdhc_signal_voltage_switch(struct mmc_host *mmc, 729ea35645aSyangbo lu struct mmc_ios *ios) 730ea35645aSyangbo lu { 731ea35645aSyangbo lu struct sdhci_host *host = mmc_priv(mmc); 732ea35645aSyangbo lu struct device_node *scfg_node; 733ea35645aSyangbo lu void __iomem *scfg_base = NULL; 734ea35645aSyangbo lu u32 sdhciovselcr; 735ea35645aSyangbo lu u32 val; 736ea35645aSyangbo lu 737ea35645aSyangbo lu /* 738ea35645aSyangbo lu * Signal Voltage Switching is only applicable for Host Controllers 739ea35645aSyangbo lu * v3.00 and above. 740ea35645aSyangbo lu */ 741ea35645aSyangbo lu if (host->version < SDHCI_SPEC_300) 742ea35645aSyangbo lu return 0; 743ea35645aSyangbo lu 744ea35645aSyangbo lu val = sdhci_readl(host, ESDHC_PROCTL); 745ea35645aSyangbo lu 746ea35645aSyangbo lu switch (ios->signal_voltage) { 747ea35645aSyangbo lu case MMC_SIGNAL_VOLTAGE_330: 748ea35645aSyangbo lu val &= ~ESDHC_VOLT_SEL; 749ea35645aSyangbo lu sdhci_writel(host, val, ESDHC_PROCTL); 750ea35645aSyangbo lu return 0; 751ea35645aSyangbo lu case MMC_SIGNAL_VOLTAGE_180: 752ea35645aSyangbo lu scfg_node = of_find_matching_node(NULL, scfg_device_ids); 753ea35645aSyangbo lu if (scfg_node) 754ea35645aSyangbo lu scfg_base = of_iomap(scfg_node, 0); 755ea35645aSyangbo lu if (scfg_base) { 756ea35645aSyangbo lu sdhciovselcr = SDHCIOVSELCR_TGLEN | 757ea35645aSyangbo lu SDHCIOVSELCR_VSELVAL; 758ea35645aSyangbo lu iowrite32be(sdhciovselcr, 759ea35645aSyangbo lu scfg_base + SCFG_SDHCIOVSELCR); 760ea35645aSyangbo lu 761ea35645aSyangbo lu val |= ESDHC_VOLT_SEL; 762ea35645aSyangbo lu sdhci_writel(host, val, ESDHC_PROCTL); 763ea35645aSyangbo lu mdelay(5); 764ea35645aSyangbo lu 765ea35645aSyangbo lu sdhciovselcr = SDHCIOVSELCR_TGLEN | 766ea35645aSyangbo lu SDHCIOVSELCR_SDHC_VS; 767ea35645aSyangbo lu iowrite32be(sdhciovselcr, 768ea35645aSyangbo lu scfg_base + SCFG_SDHCIOVSELCR); 769ea35645aSyangbo lu iounmap(scfg_base); 770ea35645aSyangbo lu } else { 771ea35645aSyangbo lu val |= ESDHC_VOLT_SEL; 772ea35645aSyangbo lu sdhci_writel(host, val, ESDHC_PROCTL); 773ea35645aSyangbo lu } 774ea35645aSyangbo lu return 0; 775ea35645aSyangbo lu default: 776ea35645aSyangbo lu return 0; 777ea35645aSyangbo lu } 778ea35645aSyangbo lu } 779ea35645aSyangbo lu 780b1f378abSYinbo Zhu static struct soc_device_attribute soc_fixup_tuning[] = { 781b1f378abSYinbo Zhu { .family = "QorIQ T1040", .revision = "1.0", }, 782b1f378abSYinbo Zhu { .family = "QorIQ T2080", .revision = "1.0", }, 783b1f378abSYinbo Zhu { .family = "QorIQ T1023", .revision = "1.0", }, 784b1f378abSYinbo Zhu { .family = "QorIQ LS1021A", .revision = "1.0", }, 785b1f378abSYinbo Zhu { .family = "QorIQ LS1080A", .revision = "1.0", }, 786b1f378abSYinbo Zhu { .family = "QorIQ LS2080A", .revision = "1.0", }, 787b1f378abSYinbo Zhu { .family = "QorIQ LS1012A", .revision = "1.0", }, 788b1f378abSYinbo Zhu { .family = "QorIQ LS1043A", .revision = "1.*", }, 789b1f378abSYinbo Zhu { .family = "QorIQ LS1046A", .revision = "1.0", }, 790b1f378abSYinbo Zhu { }, 791b1f378abSYinbo Zhu }; 792b1f378abSYinbo Zhu 79354e08d9aSYangbo Lu static void esdhc_tuning_block_enable(struct sdhci_host *host, bool enable) 794ba49cbd0Syangbo lu { 795ba49cbd0Syangbo lu u32 val; 796ba49cbd0Syangbo lu 797ba49cbd0Syangbo lu esdhc_clock_enable(host, false); 79854e08d9aSYangbo Lu 799ba49cbd0Syangbo lu val = sdhci_readl(host, ESDHC_DMA_SYSCTL); 800ba49cbd0Syangbo lu val |= ESDHC_FLUSH_ASYNC_FIFO; 801ba49cbd0Syangbo lu sdhci_writel(host, val, ESDHC_DMA_SYSCTL); 802ba49cbd0Syangbo lu 803ba49cbd0Syangbo lu val = sdhci_readl(host, ESDHC_TBCTL); 80454e08d9aSYangbo Lu if (enable) 805ba49cbd0Syangbo lu val |= ESDHC_TB_EN; 80654e08d9aSYangbo Lu else 80754e08d9aSYangbo Lu val &= ~ESDHC_TB_EN; 808ba49cbd0Syangbo lu sdhci_writel(host, val, ESDHC_TBCTL); 809ba49cbd0Syangbo lu 81054e08d9aSYangbo Lu esdhc_clock_enable(host, true); 81154e08d9aSYangbo Lu } 81254e08d9aSYangbo Lu 81354e08d9aSYangbo Lu static int esdhc_execute_tuning(struct mmc_host *mmc, u32 opcode) 81454e08d9aSYangbo Lu { 81554e08d9aSYangbo Lu struct sdhci_host *host = mmc_priv(mmc); 81654e08d9aSYangbo Lu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 81754e08d9aSYangbo Lu struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); 81854e08d9aSYangbo Lu bool hs400_tuning; 81954e08d9aSYangbo Lu u32 val; 82054e08d9aSYangbo Lu int ret; 82154e08d9aSYangbo Lu 8226079e63cSYangbo Lu if (esdhc->quirk_limited_clk_division && 8236079e63cSYangbo Lu host->flags & SDHCI_HS400_TUNING) 8246079e63cSYangbo Lu esdhc_of_set_clock(host, host->clock); 8256079e63cSYangbo Lu 82654e08d9aSYangbo Lu esdhc_tuning_block_enable(host, true); 82754e08d9aSYangbo Lu 82854e08d9aSYangbo Lu hs400_tuning = host->flags & SDHCI_HS400_TUNING; 82954e08d9aSYangbo Lu ret = sdhci_execute_tuning(mmc, opcode); 83054e08d9aSYangbo Lu 83154e08d9aSYangbo Lu if (hs400_tuning) { 83254e08d9aSYangbo Lu val = sdhci_readl(host, ESDHC_SDTIMNGCTL); 83354e08d9aSYangbo Lu val |= ESDHC_FLW_CTL_BG; 83454e08d9aSYangbo Lu sdhci_writel(host, val, ESDHC_SDTIMNGCTL); 83554e08d9aSYangbo Lu } 83654e08d9aSYangbo Lu 837b1f378abSYinbo Zhu if (host->tuning_err == -EAGAIN && esdhc->quirk_fixup_tuning) { 838b1f378abSYinbo Zhu 839b1f378abSYinbo Zhu /* program TBPTR[TB_WNDW_END_PTR] = 3*DIV_RATIO and 840b1f378abSYinbo Zhu * program TBPTR[TB_WNDW_START_PTR] = 5*DIV_RATIO 841b1f378abSYinbo Zhu */ 842b1f378abSYinbo Zhu val = sdhci_readl(host, ESDHC_TBPTR); 843b1f378abSYinbo Zhu val = (val & ~((0x7f << 8) | 0x7f)) | 844b1f378abSYinbo Zhu (3 * esdhc->div_ratio) | ((5 * esdhc->div_ratio) << 8); 845b1f378abSYinbo Zhu sdhci_writel(host, val, ESDHC_TBPTR); 846b1f378abSYinbo Zhu 847b1f378abSYinbo Zhu /* program the software tuning mode by setting 848b1f378abSYinbo Zhu * TBCTL[TB_MODE]=2'h3 849b1f378abSYinbo Zhu */ 850b1f378abSYinbo Zhu val = sdhci_readl(host, ESDHC_TBCTL); 851b1f378abSYinbo Zhu val |= 0x3; 852b1f378abSYinbo Zhu sdhci_writel(host, val, ESDHC_TBCTL); 853b1f378abSYinbo Zhu sdhci_execute_tuning(mmc, opcode); 854b1f378abSYinbo Zhu } 85554e08d9aSYangbo Lu return ret; 85654e08d9aSYangbo Lu } 85754e08d9aSYangbo Lu 85854e08d9aSYangbo Lu static void esdhc_set_uhs_signaling(struct sdhci_host *host, 85954e08d9aSYangbo Lu unsigned int timing) 86054e08d9aSYangbo Lu { 86154e08d9aSYangbo Lu if (timing == MMC_TIMING_MMC_HS400) 86254e08d9aSYangbo Lu esdhc_tuning_block_enable(host, true); 86354e08d9aSYangbo Lu else 86454e08d9aSYangbo Lu sdhci_set_uhs_signaling(host, timing); 865ba49cbd0Syangbo lu } 866ba49cbd0Syangbo lu 8679e48b336SUlf Hansson #ifdef CONFIG_PM_SLEEP 868723f7924SRussell King static u32 esdhc_proctl; 869723f7924SRussell King static int esdhc_of_suspend(struct device *dev) 870723f7924SRussell King { 871723f7924SRussell King struct sdhci_host *host = dev_get_drvdata(dev); 872723f7924SRussell King 873f4932cfdSyangbo lu esdhc_proctl = sdhci_readl(host, SDHCI_HOST_CONTROL); 874723f7924SRussell King 875d38dcad4SAdrian Hunter if (host->tuning_mode != SDHCI_TUNING_MODE_3) 876d38dcad4SAdrian Hunter mmc_retune_needed(host->mmc); 877d38dcad4SAdrian Hunter 878723f7924SRussell King return sdhci_suspend_host(host); 879723f7924SRussell King } 880723f7924SRussell King 88106732b84SUlf Hansson static int esdhc_of_resume(struct device *dev) 882723f7924SRussell King { 883723f7924SRussell King struct sdhci_host *host = dev_get_drvdata(dev); 884723f7924SRussell King int ret = sdhci_resume_host(host); 885723f7924SRussell King 886723f7924SRussell King if (ret == 0) { 887723f7924SRussell King /* Isn't this already done by sdhci_resume_host() ? --rmk */ 888723f7924SRussell King esdhc_of_enable_dma(host); 889f4932cfdSyangbo lu sdhci_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL); 890723f7924SRussell King } 891723f7924SRussell King return ret; 892723f7924SRussell King } 893723f7924SRussell King #endif 894723f7924SRussell King 8959e48b336SUlf Hansson static SIMPLE_DEV_PM_OPS(esdhc_of_dev_pm_ops, 8969e48b336SUlf Hansson esdhc_of_suspend, 8979e48b336SUlf Hansson esdhc_of_resume); 8989e48b336SUlf Hansson 899f4932cfdSyangbo lu static const struct sdhci_ops sdhci_esdhc_be_ops = { 900f4932cfdSyangbo lu .read_l = esdhc_be_readl, 901f4932cfdSyangbo lu .read_w = esdhc_be_readw, 902f4932cfdSyangbo lu .read_b = esdhc_be_readb, 903f4932cfdSyangbo lu .write_l = esdhc_be_writel, 904f4932cfdSyangbo lu .write_w = esdhc_be_writew, 905f4932cfdSyangbo lu .write_b = esdhc_be_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_ops sdhci_esdhc_le_ops = { 917f4932cfdSyangbo lu .read_l = esdhc_le_readl, 918f4932cfdSyangbo lu .read_w = esdhc_le_readw, 919f4932cfdSyangbo lu .read_b = esdhc_le_readb, 920f4932cfdSyangbo lu .write_l = esdhc_le_writel, 921f4932cfdSyangbo lu .write_w = esdhc_le_writew, 922f4932cfdSyangbo lu .write_b = esdhc_le_writeb, 923f4932cfdSyangbo lu .set_clock = esdhc_of_set_clock, 924f4932cfdSyangbo lu .enable_dma = esdhc_of_enable_dma, 925f4932cfdSyangbo lu .get_max_clock = esdhc_of_get_max_clock, 926f4932cfdSyangbo lu .get_min_clock = esdhc_of_get_min_clock, 927f4932cfdSyangbo lu .adma_workaround = esdhc_of_adma_workaround, 928f4932cfdSyangbo lu .set_bus_width = esdhc_pltfm_set_bus_width, 929f4932cfdSyangbo lu .reset = esdhc_reset, 93054e08d9aSYangbo Lu .set_uhs_signaling = esdhc_set_uhs_signaling, 931f4932cfdSyangbo lu }; 932f4932cfdSyangbo lu 933f4932cfdSyangbo lu static const struct sdhci_pltfm_data sdhci_esdhc_be_pdata = { 934e9acc77dSyangbo lu .quirks = ESDHC_DEFAULT_QUIRKS | 935e9acc77dSyangbo lu #ifdef CONFIG_PPC 936e9acc77dSyangbo lu SDHCI_QUIRK_BROKEN_CARD_DETECTION | 937e9acc77dSyangbo lu #endif 938e9acc77dSyangbo lu SDHCI_QUIRK_NO_CARD_NO_RESET | 939e9acc77dSyangbo lu SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 940f4932cfdSyangbo lu .ops = &sdhci_esdhc_be_ops, 9417657c3a7SAlbert Herranz }; 94238576af1SShawn Guo 943f4932cfdSyangbo lu static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = { 944e9acc77dSyangbo lu .quirks = ESDHC_DEFAULT_QUIRKS | 945e9acc77dSyangbo lu SDHCI_QUIRK_NO_CARD_NO_RESET | 946e9acc77dSyangbo lu SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 947f4932cfdSyangbo lu .ops = &sdhci_esdhc_le_ops, 948f4932cfdSyangbo lu }; 949f4932cfdSyangbo lu 950151ede40Syangbo lu static struct soc_device_attribute soc_incorrect_hostver[] = { 951151ede40Syangbo lu { .family = "QorIQ T4240", .revision = "1.0", }, 952151ede40Syangbo lu { .family = "QorIQ T4240", .revision = "2.0", }, 953151ede40Syangbo lu { }, 954151ede40Syangbo lu }; 955151ede40Syangbo lu 9566079e63cSYangbo Lu static struct soc_device_attribute soc_fixup_sdhc_clkdivs[] = { 9576079e63cSYangbo Lu { .family = "QorIQ LX2160A", .revision = "1.0", }, 9586079e63cSYangbo Lu { }, 9596079e63cSYangbo Lu }; 9606079e63cSYangbo Lu 96148e304ccSYangbo Lu static struct soc_device_attribute soc_unreliable_pulse_detection[] = { 96248e304ccSYangbo Lu { .family = "QorIQ LX2160A", .revision = "1.0", }, 96348e304ccSYangbo Lu { }, 96448e304ccSYangbo Lu }; 96548e304ccSYangbo Lu 966f4932cfdSyangbo lu static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host) 967f4932cfdSyangbo lu { 96867fdfbdfSyinbo.zhu const struct of_device_id *match; 969f4932cfdSyangbo lu struct sdhci_pltfm_host *pltfm_host; 970f4932cfdSyangbo lu struct sdhci_esdhc *esdhc; 97119c3a0efSyangbo lu struct device_node *np; 97219c3a0efSyangbo lu struct clk *clk; 97319c3a0efSyangbo lu u32 val; 974f4932cfdSyangbo lu u16 host_ver; 975f4932cfdSyangbo lu 976f4932cfdSyangbo lu pltfm_host = sdhci_priv(host); 9778605e7aeSJisheng Zhang esdhc = sdhci_pltfm_priv(pltfm_host); 978f4932cfdSyangbo lu 979f4932cfdSyangbo lu host_ver = sdhci_readw(host, SDHCI_HOST_VERSION); 980f4932cfdSyangbo lu esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >> 981f4932cfdSyangbo lu SDHCI_VENDOR_VER_SHIFT; 982f4932cfdSyangbo lu esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK; 983151ede40Syangbo lu if (soc_device_match(soc_incorrect_hostver)) 984151ede40Syangbo lu esdhc->quirk_incorrect_hostver = true; 985151ede40Syangbo lu else 986151ede40Syangbo lu esdhc->quirk_incorrect_hostver = false; 98719c3a0efSyangbo lu 9886079e63cSYangbo Lu if (soc_device_match(soc_fixup_sdhc_clkdivs)) 9896079e63cSYangbo Lu esdhc->quirk_limited_clk_division = true; 9906079e63cSYangbo Lu else 9916079e63cSYangbo Lu esdhc->quirk_limited_clk_division = false; 9926079e63cSYangbo Lu 99348e304ccSYangbo Lu if (soc_device_match(soc_unreliable_pulse_detection)) 99448e304ccSYangbo Lu esdhc->quirk_unreliable_pulse_detection = true; 99548e304ccSYangbo Lu else 99648e304ccSYangbo Lu esdhc->quirk_unreliable_pulse_detection = false; 99748e304ccSYangbo Lu 99867fdfbdfSyinbo.zhu match = of_match_node(sdhci_esdhc_of_match, pdev->dev.of_node); 99967fdfbdfSyinbo.zhu if (match) 100067fdfbdfSyinbo.zhu esdhc->clk_fixup = match->data; 100119c3a0efSyangbo lu np = pdev->dev.of_node; 100219c3a0efSyangbo lu clk = of_clk_get(np, 0); 100319c3a0efSyangbo lu if (!IS_ERR(clk)) { 100419c3a0efSyangbo lu /* 100519c3a0efSyangbo lu * esdhc->peripheral_clock would be assigned with a value 100619c3a0efSyangbo lu * which is eSDHC base clock when use periperal clock. 100719c3a0efSyangbo lu * For ls1046a, the clock value got by common clk API is 100819c3a0efSyangbo lu * peripheral clock while the eSDHC base clock is 1/2 100919c3a0efSyangbo lu * peripheral clock. 101019c3a0efSyangbo lu */ 101119c3a0efSyangbo lu if (of_device_is_compatible(np, "fsl,ls1046a-esdhc")) 101219c3a0efSyangbo lu esdhc->peripheral_clock = clk_get_rate(clk) / 2; 101319c3a0efSyangbo lu else 101419c3a0efSyangbo lu esdhc->peripheral_clock = clk_get_rate(clk); 101519c3a0efSyangbo lu 101619c3a0efSyangbo lu clk_put(clk); 101719c3a0efSyangbo lu } 101819c3a0efSyangbo lu 101919c3a0efSyangbo lu if (esdhc->peripheral_clock) { 102019c3a0efSyangbo lu esdhc_clock_enable(host, false); 102119c3a0efSyangbo lu val = sdhci_readl(host, ESDHC_DMA_SYSCTL); 102219c3a0efSyangbo lu val |= ESDHC_PERIPHERAL_CLK_SEL; 102319c3a0efSyangbo lu sdhci_writel(host, val, ESDHC_DMA_SYSCTL); 102419c3a0efSyangbo lu esdhc_clock_enable(host, true); 102519c3a0efSyangbo lu } 1026f4932cfdSyangbo lu } 1027f4932cfdSyangbo lu 102854e08d9aSYangbo Lu static int esdhc_hs400_prepare_ddr(struct mmc_host *mmc) 102954e08d9aSYangbo Lu { 103054e08d9aSYangbo Lu esdhc_tuning_block_enable(mmc_priv(mmc), false); 103154e08d9aSYangbo Lu return 0; 103254e08d9aSYangbo Lu } 103354e08d9aSYangbo Lu 1034c3be1efdSBill Pemberton static int sdhci_esdhc_probe(struct platform_device *pdev) 103538576af1SShawn Guo { 103666b50a00SOded Gabbay struct sdhci_host *host; 1037dcaff04dSOded Gabbay struct device_node *np; 10381ef5e49eSyangbo lu struct sdhci_pltfm_host *pltfm_host; 10391ef5e49eSyangbo lu struct sdhci_esdhc *esdhc; 104066b50a00SOded Gabbay int ret; 104166b50a00SOded Gabbay 1042f4932cfdSyangbo lu np = pdev->dev.of_node; 1043f4932cfdSyangbo lu 1044150d4240SJulia Lawall if (of_property_read_bool(np, "little-endian")) 10458605e7aeSJisheng Zhang host = sdhci_pltfm_init(pdev, &sdhci_esdhc_le_pdata, 10468605e7aeSJisheng Zhang sizeof(struct sdhci_esdhc)); 1047f4932cfdSyangbo lu else 10488605e7aeSJisheng Zhang host = sdhci_pltfm_init(pdev, &sdhci_esdhc_be_pdata, 10498605e7aeSJisheng Zhang sizeof(struct sdhci_esdhc)); 1050f4932cfdSyangbo lu 105166b50a00SOded Gabbay if (IS_ERR(host)) 105266b50a00SOded Gabbay return PTR_ERR(host); 105366b50a00SOded Gabbay 1054ea35645aSyangbo lu host->mmc_host_ops.start_signal_voltage_switch = 1055ea35645aSyangbo lu esdhc_signal_voltage_switch; 1056ba49cbd0Syangbo lu host->mmc_host_ops.execute_tuning = esdhc_execute_tuning; 105754e08d9aSYangbo Lu host->mmc_host_ops.hs400_prepare_ddr = esdhc_hs400_prepare_ddr; 10586b236f37Syangbo lu host->tuning_delay = 1; 1059ea35645aSyangbo lu 1060f4932cfdSyangbo lu esdhc_init(pdev, host); 1061f4932cfdSyangbo lu 106266b50a00SOded Gabbay sdhci_get_of_property(pdev); 106366b50a00SOded Gabbay 10641ef5e49eSyangbo lu pltfm_host = sdhci_priv(host); 10658605e7aeSJisheng Zhang esdhc = sdhci_pltfm_priv(pltfm_host); 1066b1f378abSYinbo Zhu if (soc_device_match(soc_fixup_tuning)) 1067b1f378abSYinbo Zhu esdhc->quirk_fixup_tuning = true; 1068b1f378abSYinbo Zhu else 1069b1f378abSYinbo Zhu esdhc->quirk_fixup_tuning = false; 1070b1f378abSYinbo Zhu 10711ef5e49eSyangbo lu if (esdhc->vendor_ver == VENDOR_V_22) 10721ef5e49eSyangbo lu host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23; 10731ef5e49eSyangbo lu 10741ef5e49eSyangbo lu if (esdhc->vendor_ver > VENDOR_V_22) 10751ef5e49eSyangbo lu host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; 10761ef5e49eSyangbo lu 107774fd5e30SYangbo Lu if (of_device_is_compatible(np, "fsl,p5040-esdhc") || 107874fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p5020-esdhc") || 107974fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p4080-esdhc") || 108074fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p1020-esdhc") || 1081e9acc77dSyangbo lu of_device_is_compatible(np, "fsl,t1040-esdhc")) 108274fd5e30SYangbo Lu host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; 108374fd5e30SYangbo Lu 1084a22950c8Syangbo lu if (of_device_is_compatible(np, "fsl,ls1021a-esdhc")) 1085a22950c8Syangbo lu host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 1086a22950c8Syangbo lu 1087dcaff04dSOded Gabbay if (of_device_is_compatible(np, "fsl,p2020-esdhc")) { 1088dcaff04dSOded Gabbay /* 1089dcaff04dSOded Gabbay * Freescale messed up with P2020 as it has a non-standard 1090dcaff04dSOded Gabbay * host control register 1091dcaff04dSOded Gabbay */ 1092dcaff04dSOded Gabbay host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL; 1093dcaff04dSOded Gabbay } 1094dcaff04dSOded Gabbay 109566b50a00SOded Gabbay /* call to generic mmc_of_parse to support additional capabilities */ 1096f0991408SUlf Hansson ret = mmc_of_parse(host->mmc); 1097f0991408SUlf Hansson if (ret) 1098f0991408SUlf Hansson goto err; 1099f0991408SUlf Hansson 1100490104acSHaijun Zhang mmc_of_parse_voltage(np, &host->ocr_mask); 110166b50a00SOded Gabbay 110266b50a00SOded Gabbay ret = sdhci_add_host(host); 110366b50a00SOded Gabbay if (ret) 1104f0991408SUlf Hansson goto err; 110566b50a00SOded Gabbay 1106f0991408SUlf Hansson return 0; 1107f0991408SUlf Hansson err: 1108f0991408SUlf Hansson sdhci_pltfm_free(pdev); 110966b50a00SOded Gabbay return ret; 111038576af1SShawn Guo } 111138576af1SShawn Guo 111238576af1SShawn Guo static struct platform_driver sdhci_esdhc_driver = { 111338576af1SShawn Guo .driver = { 111438576af1SShawn Guo .name = "sdhci-esdhc", 111538576af1SShawn Guo .of_match_table = sdhci_esdhc_of_match, 11169e48b336SUlf Hansson .pm = &esdhc_of_dev_pm_ops, 111738576af1SShawn Guo }, 111838576af1SShawn Guo .probe = sdhci_esdhc_probe, 1119caebcae9SKevin Hao .remove = sdhci_pltfm_unregister, 112038576af1SShawn Guo }; 112138576af1SShawn Guo 1122d1f81a64SAxel Lin module_platform_driver(sdhci_esdhc_driver); 112338576af1SShawn Guo 112438576af1SShawn Guo MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC"); 112538576af1SShawn Guo MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, " 112638576af1SShawn Guo "Anton Vorontsov <avorontsov@ru.mvista.com>"); 112738576af1SShawn Guo MODULE_LICENSE("GPL v2"); 1128