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> 197657c3a7SAlbert Herranz #include <linux/delay.h> 2088b47679SPaul Gortmaker #include <linux/module.h> 217657c3a7SAlbert Herranz #include <linux/mmc/host.h> 2238576af1SShawn Guo #include "sdhci-pltfm.h" 2380872e21SWolfram Sang #include "sdhci-esdhc.h" 247657c3a7SAlbert Herranz 25137ccd46SJerry Huang #define VENDOR_V_22 0x12 26a4071fbbSHaijun Zhang #define VENDOR_V_23 0x13 27137ccd46SJerry Huang static u32 esdhc_readl(struct sdhci_host *host, int reg) 28137ccd46SJerry Huang { 29137ccd46SJerry Huang u32 ret; 30137ccd46SJerry Huang 31137ccd46SJerry Huang ret = in_be32(host->ioaddr + reg); 32137ccd46SJerry Huang /* 33137ccd46SJerry Huang * The bit of ADMA flag in eSDHC is not compatible with standard 34137ccd46SJerry Huang * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is 35137ccd46SJerry Huang * supported by eSDHC. 36137ccd46SJerry Huang * And for many FSL eSDHC controller, the reset value of field 37137ccd46SJerry Huang * SDHCI_CAN_DO_ADMA1 is one, but some of them can't support ADMA, 38137ccd46SJerry Huang * only these vendor version is greater than 2.2/0x12 support ADMA. 39137ccd46SJerry Huang * For FSL eSDHC, must aligned 4-byte, so use 0xFC to read the 40137ccd46SJerry Huang * the verdor version number, oxFE is SDHCI_HOST_VERSION. 41137ccd46SJerry Huang */ 42137ccd46SJerry Huang if ((reg == SDHCI_CAPABILITIES) && (ret & SDHCI_CAN_DO_ADMA1)) { 43137ccd46SJerry Huang u32 tmp = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); 44137ccd46SJerry Huang tmp = (tmp & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; 45137ccd46SJerry Huang if (tmp > VENDOR_V_22) 46137ccd46SJerry Huang ret |= SDHCI_CAN_DO_ADMA2; 47137ccd46SJerry Huang } 48137ccd46SJerry Huang 49137ccd46SJerry Huang return ret; 50137ccd46SJerry Huang } 51137ccd46SJerry Huang 527657c3a7SAlbert Herranz static u16 esdhc_readw(struct sdhci_host *host, int reg) 537657c3a7SAlbert Herranz { 547657c3a7SAlbert Herranz u16 ret; 55e51cbc9eSXu lei int base = reg & ~0x3; 56e51cbc9eSXu lei int shift = (reg & 0x2) * 8; 577657c3a7SAlbert Herranz 587657c3a7SAlbert Herranz if (unlikely(reg == SDHCI_HOST_VERSION)) 59e51cbc9eSXu lei ret = in_be32(host->ioaddr + base) & 0xffff; 607657c3a7SAlbert Herranz else 61e51cbc9eSXu lei ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff; 62e51cbc9eSXu lei return ret; 63e51cbc9eSXu lei } 64e51cbc9eSXu lei 65e51cbc9eSXu lei static u8 esdhc_readb(struct sdhci_host *host, int reg) 66e51cbc9eSXu lei { 67e51cbc9eSXu lei int base = reg & ~0x3; 68e51cbc9eSXu lei int shift = (reg & 0x3) * 8; 69e51cbc9eSXu lei u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff; 70ba8c4dc9SRoy Zang 71ba8c4dc9SRoy Zang /* 72ba8c4dc9SRoy Zang * "DMA select" locates at offset 0x28 in SD specification, but on 73ba8c4dc9SRoy Zang * P5020 or P3041, it locates at 0x29. 74ba8c4dc9SRoy Zang */ 75ba8c4dc9SRoy Zang if (reg == SDHCI_HOST_CONTROL) { 76ba8c4dc9SRoy Zang u32 dma_bits; 77ba8c4dc9SRoy Zang 78ba8c4dc9SRoy Zang dma_bits = in_be32(host->ioaddr + reg); 79ba8c4dc9SRoy Zang /* DMA select is 22,23 bits in Protocol Control Register */ 80ba8c4dc9SRoy Zang dma_bits = (dma_bits >> 5) & SDHCI_CTRL_DMA_MASK; 81ba8c4dc9SRoy Zang 82ba8c4dc9SRoy Zang /* fixup the result */ 83ba8c4dc9SRoy Zang ret &= ~SDHCI_CTRL_DMA_MASK; 84ba8c4dc9SRoy Zang ret |= dma_bits; 85ba8c4dc9SRoy Zang } 86ba8c4dc9SRoy Zang 877657c3a7SAlbert Herranz return ret; 887657c3a7SAlbert Herranz } 897657c3a7SAlbert Herranz 90a4071fbbSHaijun Zhang static void esdhc_writel(struct sdhci_host *host, u32 val, int reg) 91a4071fbbSHaijun Zhang { 92a4071fbbSHaijun Zhang /* 93a4071fbbSHaijun Zhang * Enable IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE] 94a4071fbbSHaijun Zhang * when SYSCTL[RSTD]) is set for some special operations. 95a4071fbbSHaijun Zhang * No any impact other operation. 96a4071fbbSHaijun Zhang */ 97a4071fbbSHaijun Zhang if (reg == SDHCI_INT_ENABLE) 98a4071fbbSHaijun Zhang val |= SDHCI_INT_BLK_GAP; 99a4071fbbSHaijun Zhang sdhci_be32bs_writel(host, val, reg); 100a4071fbbSHaijun Zhang } 101a4071fbbSHaijun Zhang 1027657c3a7SAlbert Herranz static void esdhc_writew(struct sdhci_host *host, u16 val, int reg) 1037657c3a7SAlbert Herranz { 1047657c3a7SAlbert Herranz if (reg == SDHCI_BLOCK_SIZE) { 1057657c3a7SAlbert Herranz /* 1067657c3a7SAlbert Herranz * Two last DMA bits are reserved, and first one is used for 1077657c3a7SAlbert Herranz * non-standard blksz of 4096 bytes that we don't support 1087657c3a7SAlbert Herranz * yet. So clear the DMA boundary bits. 1097657c3a7SAlbert Herranz */ 1107657c3a7SAlbert Herranz val &= ~SDHCI_MAKE_BLKSZ(0x7, 0); 1117657c3a7SAlbert Herranz } 1127657c3a7SAlbert Herranz sdhci_be32bs_writew(host, val, reg); 1137657c3a7SAlbert Herranz } 1147657c3a7SAlbert Herranz 1157657c3a7SAlbert Herranz static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg) 1167657c3a7SAlbert Herranz { 117ba8c4dc9SRoy Zang /* 118ba8c4dc9SRoy Zang * "DMA select" location is offset 0x28 in SD specification, but on 119ba8c4dc9SRoy Zang * P5020 or P3041, it's located at 0x29. 120ba8c4dc9SRoy Zang */ 121ba8c4dc9SRoy Zang if (reg == SDHCI_HOST_CONTROL) { 122ba8c4dc9SRoy Zang u32 dma_bits; 123ba8c4dc9SRoy Zang 124dcaff04dSOded Gabbay /* 125dcaff04dSOded Gabbay * If host control register is not standard, exit 126dcaff04dSOded Gabbay * this function 127dcaff04dSOded Gabbay */ 128dcaff04dSOded Gabbay if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL) 129dcaff04dSOded Gabbay return; 130dcaff04dSOded Gabbay 131ba8c4dc9SRoy Zang /* DMA select is 22,23 bits in Protocol Control Register */ 132ba8c4dc9SRoy Zang dma_bits = (val & SDHCI_CTRL_DMA_MASK) << 5; 133ba8c4dc9SRoy Zang clrsetbits_be32(host->ioaddr + reg , SDHCI_CTRL_DMA_MASK << 5, 134ba8c4dc9SRoy Zang dma_bits); 135ba8c4dc9SRoy Zang val &= ~SDHCI_CTRL_DMA_MASK; 136ba8c4dc9SRoy Zang val |= in_be32(host->ioaddr + reg) & SDHCI_CTRL_DMA_MASK; 137ba8c4dc9SRoy Zang } 138ba8c4dc9SRoy Zang 1397657c3a7SAlbert Herranz /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */ 1407657c3a7SAlbert Herranz if (reg == SDHCI_HOST_CONTROL) 1417657c3a7SAlbert Herranz val &= ~ESDHC_HOST_CONTROL_RES; 1427657c3a7SAlbert Herranz sdhci_be32bs_writeb(host, val, reg); 1437657c3a7SAlbert Herranz } 1447657c3a7SAlbert Herranz 145a4071fbbSHaijun Zhang /* 146a4071fbbSHaijun Zhang * For Abort or Suspend after Stop at Block Gap, ignore the ADMA 147a4071fbbSHaijun Zhang * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC]) 148a4071fbbSHaijun Zhang * and Block Gap Event(IRQSTAT[BGE]) are also set. 149a4071fbbSHaijun Zhang * For Continue, apply soft reset for data(SYSCTL[RSTD]); 150a4071fbbSHaijun Zhang * and re-issue the entire read transaction from beginning. 151a4071fbbSHaijun Zhang */ 152a4071fbbSHaijun Zhang static void esdhci_of_adma_workaround(struct sdhci_host *host, u32 intmask) 153a4071fbbSHaijun Zhang { 154a4071fbbSHaijun Zhang u32 tmp; 155a4071fbbSHaijun Zhang bool applicable; 156a4071fbbSHaijun Zhang dma_addr_t dmastart; 157a4071fbbSHaijun Zhang dma_addr_t dmanow; 158a4071fbbSHaijun Zhang 159a4071fbbSHaijun Zhang tmp = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); 160a4071fbbSHaijun Zhang tmp = (tmp & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; 161a4071fbbSHaijun Zhang 162a4071fbbSHaijun Zhang applicable = (intmask & SDHCI_INT_DATA_END) && 163a4071fbbSHaijun Zhang (intmask & SDHCI_INT_BLK_GAP) && 164a4071fbbSHaijun Zhang (tmp == VENDOR_V_23); 165a4071fbbSHaijun Zhang if (!applicable) 166a4071fbbSHaijun Zhang return; 167a4071fbbSHaijun Zhang 168a4071fbbSHaijun Zhang host->data->error = 0; 169a4071fbbSHaijun Zhang dmastart = sg_dma_address(host->data->sg); 170a4071fbbSHaijun Zhang dmanow = dmastart + host->data->bytes_xfered; 171a4071fbbSHaijun Zhang /* 172a4071fbbSHaijun Zhang * Force update to the next DMA block boundary. 173a4071fbbSHaijun Zhang */ 174a4071fbbSHaijun Zhang dmanow = (dmanow & ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) + 175a4071fbbSHaijun Zhang SDHCI_DEFAULT_BOUNDARY_SIZE; 176a4071fbbSHaijun Zhang host->data->bytes_xfered = dmanow - dmastart; 177a4071fbbSHaijun Zhang sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS); 178a4071fbbSHaijun Zhang } 179a4071fbbSHaijun Zhang 18080872e21SWolfram Sang static int esdhc_of_enable_dma(struct sdhci_host *host) 1817657c3a7SAlbert Herranz { 1827657c3a7SAlbert Herranz setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP); 1837657c3a7SAlbert Herranz return 0; 1847657c3a7SAlbert Herranz } 1857657c3a7SAlbert Herranz 18680872e21SWolfram Sang static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host) 1877657c3a7SAlbert Herranz { 188e307148fSShawn Guo struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 1897657c3a7SAlbert Herranz 190e307148fSShawn Guo return pltfm_host->clock; 1917657c3a7SAlbert Herranz } 1927657c3a7SAlbert Herranz 19380872e21SWolfram Sang static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) 1947657c3a7SAlbert Herranz { 195e307148fSShawn Guo struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 1967657c3a7SAlbert Herranz 197e307148fSShawn Guo return pltfm_host->clock / 256 / 16; 1987657c3a7SAlbert Herranz } 1997657c3a7SAlbert Herranz 200f060bc9cSJerry Huang static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) 201f060bc9cSJerry Huang { 202bd455029SJoakim Tjernlund int pre_div = 1; 203d31fc00aSDong Aisheng int div = 1; 204d31fc00aSDong Aisheng u32 temp; 205d31fc00aSDong Aisheng 2061650d0c7SRussell King host->mmc->actual_clock = 0; 2071650d0c7SRussell King 208d31fc00aSDong Aisheng if (clock == 0) 209373073efSRussell King return; 210d31fc00aSDong Aisheng 211f060bc9cSJerry Huang /* Workaround to reduce the clock frequency for p1010 esdhc */ 212f060bc9cSJerry Huang if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) { 213f060bc9cSJerry Huang if (clock > 20000000) 214f060bc9cSJerry Huang clock -= 5000000; 215f060bc9cSJerry Huang if (clock > 40000000) 216f060bc9cSJerry Huang clock -= 5000000; 217f060bc9cSJerry Huang } 218f060bc9cSJerry Huang 219d31fc00aSDong Aisheng temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 220d31fc00aSDong Aisheng temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN 221d31fc00aSDong Aisheng | ESDHC_CLOCK_MASK); 222d31fc00aSDong Aisheng sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 223d31fc00aSDong Aisheng 224d31fc00aSDong Aisheng while (host->max_clk / pre_div / 16 > clock && pre_div < 256) 225d31fc00aSDong Aisheng pre_div *= 2; 226d31fc00aSDong Aisheng 227d31fc00aSDong Aisheng while (host->max_clk / pre_div / div > clock && div < 16) 228d31fc00aSDong Aisheng div++; 229d31fc00aSDong Aisheng 230d31fc00aSDong Aisheng dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", 231e76b8559SDong Aisheng clock, host->max_clk / pre_div / div); 232bd455029SJoakim Tjernlund host->mmc->actual_clock = host->max_clk / pre_div / div; 233d31fc00aSDong Aisheng pre_div >>= 1; 234d31fc00aSDong Aisheng div--; 235d31fc00aSDong Aisheng 236d31fc00aSDong Aisheng temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); 237d31fc00aSDong Aisheng temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN 238d31fc00aSDong Aisheng | (div << ESDHC_DIVIDER_SHIFT) 239d31fc00aSDong Aisheng | (pre_div << ESDHC_PREDIV_SHIFT)); 240d31fc00aSDong Aisheng sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 241d31fc00aSDong Aisheng mdelay(1); 242f060bc9cSJerry Huang } 243f060bc9cSJerry Huang 24463ef5d8cSJerry Huang static void esdhc_of_platform_init(struct sdhci_host *host) 24563ef5d8cSJerry Huang { 24663ef5d8cSJerry Huang u32 vvn; 24763ef5d8cSJerry Huang 24863ef5d8cSJerry Huang vvn = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); 24963ef5d8cSJerry Huang vvn = (vvn & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; 25063ef5d8cSJerry Huang if (vvn == VENDOR_V_22) 25163ef5d8cSJerry Huang host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23; 2523cf38833SJerry Huang 2533cf38833SJerry Huang if (vvn > VENDOR_V_22) 2543cf38833SJerry Huang host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; 25563ef5d8cSJerry Huang } 25663ef5d8cSJerry Huang 2572317f56cSRussell King static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width) 25866b50a00SOded Gabbay { 25966b50a00SOded Gabbay u32 ctrl; 26066b50a00SOded Gabbay 26166b50a00SOded Gabbay switch (width) { 26266b50a00SOded Gabbay case MMC_BUS_WIDTH_8: 26366b50a00SOded Gabbay ctrl = ESDHC_CTRL_8BITBUS; 26466b50a00SOded Gabbay break; 26566b50a00SOded Gabbay 26666b50a00SOded Gabbay case MMC_BUS_WIDTH_4: 26766b50a00SOded Gabbay ctrl = ESDHC_CTRL_4BITBUS; 26866b50a00SOded Gabbay break; 26966b50a00SOded Gabbay 27066b50a00SOded Gabbay default: 27166b50a00SOded Gabbay ctrl = 0; 27266b50a00SOded Gabbay break; 27366b50a00SOded Gabbay } 27466b50a00SOded Gabbay 27566b50a00SOded Gabbay clrsetbits_be32(host->ioaddr + SDHCI_HOST_CONTROL, 27666b50a00SOded Gabbay ESDHC_CTRL_BUSWIDTH_MASK, ctrl); 27766b50a00SOded Gabbay } 27866b50a00SOded Gabbay 279304f0a98SAlessio Igor Bogani static void esdhc_reset(struct sdhci_host *host, u8 mask) 280304f0a98SAlessio Igor Bogani { 281304f0a98SAlessio Igor Bogani sdhci_reset(host, mask); 282304f0a98SAlessio Igor Bogani 283304f0a98SAlessio Igor Bogani sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); 284304f0a98SAlessio Igor Bogani sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); 285304f0a98SAlessio Igor Bogani } 286304f0a98SAlessio Igor Bogani 287c915568dSLars-Peter Clausen static const struct sdhci_ops sdhci_esdhc_ops = { 288137ccd46SJerry Huang .read_l = esdhc_readl, 289dc297c92SMatt Fleming .read_w = esdhc_readw, 290e51cbc9eSXu lei .read_b = esdhc_readb, 291a4071fbbSHaijun Zhang .write_l = esdhc_writel, 292dc297c92SMatt Fleming .write_w = esdhc_writew, 293dc297c92SMatt Fleming .write_b = esdhc_writeb, 294f060bc9cSJerry Huang .set_clock = esdhc_of_set_clock, 29580872e21SWolfram Sang .enable_dma = esdhc_of_enable_dma, 29680872e21SWolfram Sang .get_max_clock = esdhc_of_get_max_clock, 29780872e21SWolfram Sang .get_min_clock = esdhc_of_get_min_clock, 29863ef5d8cSJerry Huang .platform_init = esdhc_of_platform_init, 299a4071fbbSHaijun Zhang .adma_workaround = esdhci_of_adma_workaround, 3002317f56cSRussell King .set_bus_width = esdhc_pltfm_set_bus_width, 301304f0a98SAlessio Igor Bogani .reset = esdhc_reset, 30296d7b78cSRussell King .set_uhs_signaling = sdhci_set_uhs_signaling, 303e307148fSShawn Guo }; 304e307148fSShawn Guo 305723f7924SRussell King #ifdef CONFIG_PM 306723f7924SRussell King 307723f7924SRussell King static u32 esdhc_proctl; 308723f7924SRussell King static int esdhc_of_suspend(struct device *dev) 309723f7924SRussell King { 310723f7924SRussell King struct sdhci_host *host = dev_get_drvdata(dev); 311723f7924SRussell King 312723f7924SRussell King esdhc_proctl = sdhci_be32bs_readl(host, SDHCI_HOST_CONTROL); 313723f7924SRussell King 314723f7924SRussell King return sdhci_suspend_host(host); 315723f7924SRussell King } 316723f7924SRussell King 31706732b84SUlf Hansson static int esdhc_of_resume(struct device *dev) 318723f7924SRussell King { 319723f7924SRussell King struct sdhci_host *host = dev_get_drvdata(dev); 320723f7924SRussell King int ret = sdhci_resume_host(host); 321723f7924SRussell King 322723f7924SRussell King if (ret == 0) { 323723f7924SRussell King /* Isn't this already done by sdhci_resume_host() ? --rmk */ 324723f7924SRussell King esdhc_of_enable_dma(host); 325723f7924SRussell King sdhci_be32bs_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL); 326723f7924SRussell King } 327723f7924SRussell King 328723f7924SRussell King return ret; 329723f7924SRussell King } 330723f7924SRussell King 331723f7924SRussell King static const struct dev_pm_ops esdhc_pmops = { 33206732b84SUlf Hansson .suspend = esdhc_of_suspend, 33306732b84SUlf Hansson .resume = esdhc_of_resume, 334723f7924SRussell King }; 335723f7924SRussell King #define ESDHC_PMOPS (&esdhc_pmops) 336723f7924SRussell King #else 337723f7924SRussell King #define ESDHC_PMOPS NULL 338723f7924SRussell King #endif 339723f7924SRussell King 3401db5eebfSLars-Peter Clausen static const struct sdhci_pltfm_data sdhci_esdhc_pdata = { 341137ccd46SJerry Huang /* 342137ccd46SJerry Huang * card detection could be handled via GPIO 343137ccd46SJerry Huang * eSDHC cannot support End Attribute in NOP ADMA descriptor 344137ccd46SJerry Huang */ 345e307148fSShawn Guo .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION 346137ccd46SJerry Huang | SDHCI_QUIRK_NO_CARD_NO_RESET 347137ccd46SJerry Huang | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 348e307148fSShawn Guo .ops = &sdhci_esdhc_ops, 3497657c3a7SAlbert Herranz }; 35038576af1SShawn Guo 351c3be1efdSBill Pemberton static int sdhci_esdhc_probe(struct platform_device *pdev) 35238576af1SShawn Guo { 35366b50a00SOded Gabbay struct sdhci_host *host; 354dcaff04dSOded Gabbay struct device_node *np; 35566b50a00SOded Gabbay int ret; 35666b50a00SOded Gabbay 35766b50a00SOded Gabbay host = sdhci_pltfm_init(pdev, &sdhci_esdhc_pdata, 0); 35866b50a00SOded Gabbay if (IS_ERR(host)) 35966b50a00SOded Gabbay return PTR_ERR(host); 36066b50a00SOded Gabbay 36166b50a00SOded Gabbay sdhci_get_of_property(pdev); 36266b50a00SOded Gabbay 363dcaff04dSOded Gabbay np = pdev->dev.of_node; 364*74fd5e30SYangbo Lu if (of_device_is_compatible(np, "fsl,p5040-esdhc") || 365*74fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p5020-esdhc") || 366*74fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p4080-esdhc") || 367*74fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,p1020-esdhc") || 368*74fd5e30SYangbo Lu of_device_is_compatible(np, "fsl,t1040-esdhc")) 369*74fd5e30SYangbo Lu host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; 370*74fd5e30SYangbo Lu 371dcaff04dSOded Gabbay if (of_device_is_compatible(np, "fsl,p2020-esdhc")) { 372dcaff04dSOded Gabbay /* 373dcaff04dSOded Gabbay * Freescale messed up with P2020 as it has a non-standard 374dcaff04dSOded Gabbay * host control register 375dcaff04dSOded Gabbay */ 376dcaff04dSOded Gabbay host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL; 377dcaff04dSOded Gabbay } 378dcaff04dSOded Gabbay 37966b50a00SOded Gabbay /* call to generic mmc_of_parse to support additional capabilities */ 380f0991408SUlf Hansson ret = mmc_of_parse(host->mmc); 381f0991408SUlf Hansson if (ret) 382f0991408SUlf Hansson goto err; 383f0991408SUlf Hansson 384490104acSHaijun Zhang mmc_of_parse_voltage(np, &host->ocr_mask); 38566b50a00SOded Gabbay 38666b50a00SOded Gabbay ret = sdhci_add_host(host); 38766b50a00SOded Gabbay if (ret) 388f0991408SUlf Hansson goto err; 38966b50a00SOded Gabbay 390f0991408SUlf Hansson return 0; 391f0991408SUlf Hansson err: 392f0991408SUlf Hansson sdhci_pltfm_free(pdev); 39366b50a00SOded Gabbay return ret; 39438576af1SShawn Guo } 39538576af1SShawn Guo 39638576af1SShawn Guo static const struct of_device_id sdhci_esdhc_of_match[] = { 39738576af1SShawn Guo { .compatible = "fsl,mpc8379-esdhc" }, 39838576af1SShawn Guo { .compatible = "fsl,mpc8536-esdhc" }, 39938576af1SShawn Guo { .compatible = "fsl,esdhc" }, 40038576af1SShawn Guo { } 40138576af1SShawn Guo }; 40238576af1SShawn Guo MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match); 40338576af1SShawn Guo 40438576af1SShawn Guo static struct platform_driver sdhci_esdhc_driver = { 40538576af1SShawn Guo .driver = { 40638576af1SShawn Guo .name = "sdhci-esdhc", 40738576af1SShawn Guo .of_match_table = sdhci_esdhc_of_match, 408723f7924SRussell King .pm = ESDHC_PMOPS, 40938576af1SShawn Guo }, 41038576af1SShawn Guo .probe = sdhci_esdhc_probe, 411caebcae9SKevin Hao .remove = sdhci_pltfm_unregister, 41238576af1SShawn Guo }; 41338576af1SShawn Guo 414d1f81a64SAxel Lin module_platform_driver(sdhci_esdhc_driver); 41538576af1SShawn Guo 41638576af1SShawn Guo MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC"); 41738576af1SShawn Guo MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, " 41838576af1SShawn Guo "Anton Vorontsov <avorontsov@ru.mvista.com>"); 41938576af1SShawn Guo MODULE_LICENSE("GPL v2"); 420