2 * Freescale eSDHC controller driver.
4 * Copyright (c) 2007, 2010, 2012 Freescale Semiconductor, Inc.
5 * Copyright (c) 2009 MontaVista Software, Inc.
7 * Authors: Xiaobo Xie <X.Xie@freescale.com>
8 * Anton Vorontsov <avorontsov@ru.mvista.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
16 #include <linux/err.h>
19 #include <linux/of_address.h>
20 #include <linux/delay.h>
21 #include <linux/module.h>
22 #include <linux/sys_soc.h>
23 #include <linux/clk.h>
24 #include <linux/ktime.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/mmc/host.h>
27 #include "sdhci-pltfm.h"
28 #include "sdhci-esdhc.h"
30 #define VENDOR_V_22 0x12
31 #define VENDOR_V_23 0x13
33 #define MMC_TIMING_NUM (MMC_TIMING_MMC_HS400 + 1)
35 struct esdhc_clk_fixup {
36 const unsigned int sd_dflt_max_clk;
37 const unsigned int max_clk[MMC_TIMING_NUM];
40 static const struct esdhc_clk_fixup ls1021a_esdhc_clk = {
41 .sd_dflt_max_clk = 25000000,
42 .max_clk[MMC_TIMING_MMC_HS] = 46500000,
43 .max_clk[MMC_TIMING_SD_HS] = 46500000,
46 static const struct esdhc_clk_fixup ls1046a_esdhc_clk = {
47 .sd_dflt_max_clk = 25000000,
48 .max_clk[MMC_TIMING_UHS_SDR104] = 167000000,
49 .max_clk[MMC_TIMING_MMC_HS200] = 167000000,
52 static const struct esdhc_clk_fixup ls1012a_esdhc_clk = {
53 .sd_dflt_max_clk = 25000000,
54 .max_clk[MMC_TIMING_UHS_SDR104] = 125000000,
55 .max_clk[MMC_TIMING_MMC_HS200] = 125000000,
58 static const struct esdhc_clk_fixup p1010_esdhc_clk = {
59 .sd_dflt_max_clk = 20000000,
60 .max_clk[MMC_TIMING_LEGACY] = 20000000,
61 .max_clk[MMC_TIMING_MMC_HS] = 42000000,
62 .max_clk[MMC_TIMING_SD_HS] = 40000000,
65 static const struct of_device_id sdhci_esdhc_of_match[] = {
66 { .compatible = "fsl,ls1021a-esdhc", .data = &ls1021a_esdhc_clk},
67 { .compatible = "fsl,ls1046a-esdhc", .data = &ls1046a_esdhc_clk},
68 { .compatible = "fsl,ls1012a-esdhc", .data = &ls1012a_esdhc_clk},
69 { .compatible = "fsl,p1010-esdhc", .data = &p1010_esdhc_clk},
70 { .compatible = "fsl,mpc8379-esdhc" },
71 { .compatible = "fsl,mpc8536-esdhc" },
72 { .compatible = "fsl,esdhc" },
75 MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
80 bool quirk_incorrect_hostver;
81 unsigned int peripheral_clock;
82 const struct esdhc_clk_fixup *clk_fixup;
86 * esdhc_read*_fixup - Fixup the value read from incompatible eSDHC register
87 * to make it compatible with SD spec.
89 * @host: pointer to sdhci_host
90 * @spec_reg: SD spec register address
91 * @value: 32bit eSDHC register value on spec_reg address
93 * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC
94 * registers are 32 bits. There are differences in register size, register
95 * address, register function, bit position and function between eSDHC spec
98 * Return a fixed up register value
100 static u32 esdhc_readl_fixup(struct sdhci_host *host,
101 int spec_reg, u32 value)
103 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
104 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
108 * The bit of ADMA flag in eSDHC is not compatible with standard
109 * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is
110 * supported by eSDHC.
111 * And for many FSL eSDHC controller, the reset value of field
112 * SDHCI_CAN_DO_ADMA1 is 1, but some of them can't support ADMA,
113 * only these vendor version is greater than 2.2/0x12 support ADMA.
115 if ((spec_reg == SDHCI_CAPABILITIES) && (value & SDHCI_CAN_DO_ADMA1)) {
116 if (esdhc->vendor_ver > VENDOR_V_22) {
117 ret = value | SDHCI_CAN_DO_ADMA2;
122 * The DAT[3:0] line signal levels and the CMD line signal level are
123 * not compatible with standard SDHC register. The line signal levels
124 * DAT[7:0] are at bits 31:24 and the command line signal level is at
125 * bit 23. All other bits are the same as in the standard SDHC
128 if (spec_reg == SDHCI_PRESENT_STATE) {
129 ret = value & 0x000fffff;
130 ret |= (value >> 4) & SDHCI_DATA_LVL_MASK;
131 ret |= (value << 1) & SDHCI_CMD_LVL;
136 * DTS properties of mmc host are used to enable each speed mode
137 * according to soc and board capability. So clean up
138 * SDR50/SDR104/DDR50 support bits here.
140 if (spec_reg == SDHCI_CAPABILITIES_1) {
141 ret = value & ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
142 SDHCI_SUPPORT_DDR50);
150 static u16 esdhc_readw_fixup(struct sdhci_host *host,
151 int spec_reg, u32 value)
153 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
154 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
156 int shift = (spec_reg & 0x2) * 8;
158 if (spec_reg == SDHCI_HOST_VERSION)
159 ret = value & 0xffff;
161 ret = (value >> shift) & 0xffff;
162 /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect
163 * vendor version and spec version information.
165 if ((spec_reg == SDHCI_HOST_VERSION) &&
166 (esdhc->quirk_incorrect_hostver))
167 ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200;
171 static u8 esdhc_readb_fixup(struct sdhci_host *host,
172 int spec_reg, u32 value)
176 int shift = (spec_reg & 0x3) * 8;
178 ret = (value >> shift) & 0xff;
181 * "DMA select" locates at offset 0x28 in SD specification, but on
182 * P5020 or P3041, it locates at 0x29.
184 if (spec_reg == SDHCI_HOST_CONTROL) {
185 /* DMA select is 22,23 bits in Protocol Control Register */
186 dma_bits = (value >> 5) & SDHCI_CTRL_DMA_MASK;
187 /* fixup the result */
188 ret &= ~SDHCI_CTRL_DMA_MASK;
195 * esdhc_write*_fixup - Fixup the SD spec register value so that it could be
196 * written into eSDHC register.
198 * @host: pointer to sdhci_host
199 * @spec_reg: SD spec register address
200 * @value: 8/16/32bit SD spec register value that would be written
201 * @old_value: 32bit eSDHC register value on spec_reg address
203 * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC
204 * registers are 32 bits. There are differences in register size, register
205 * address, register function, bit position and function between eSDHC spec
208 * Return a fixed up register value
210 static u32 esdhc_writel_fixup(struct sdhci_host *host,
211 int spec_reg, u32 value, u32 old_value)
216 * Enabling IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE]
217 * when SYSCTL[RSTD] is set for some special operations.
218 * No any impact on other operation.
220 if (spec_reg == SDHCI_INT_ENABLE)
221 ret = value | SDHCI_INT_BLK_GAP;
228 static u32 esdhc_writew_fixup(struct sdhci_host *host,
229 int spec_reg, u16 value, u32 old_value)
231 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
232 int shift = (spec_reg & 0x2) * 8;
236 case SDHCI_TRANSFER_MODE:
238 * Postpone this write, we must do it together with a
239 * command write that is down below. Return old value.
241 pltfm_host->xfer_mode_shadow = value;
244 ret = (value << 16) | pltfm_host->xfer_mode_shadow;
248 ret = old_value & (~(0xffff << shift));
249 ret |= (value << shift);
251 if (spec_reg == SDHCI_BLOCK_SIZE) {
253 * Two last DMA bits are reserved, and first one is used for
254 * non-standard blksz of 4096 bytes that we don't support
255 * yet. So clear the DMA boundary bits.
257 ret &= (~SDHCI_MAKE_BLKSZ(0x7, 0));
262 static u32 esdhc_writeb_fixup(struct sdhci_host *host,
263 int spec_reg, u8 value, u32 old_value)
268 int shift = (spec_reg & 0x3) * 8;
271 * eSDHC doesn't have a standard power control register, so we do
272 * nothing here to avoid incorrect operation.
274 if (spec_reg == SDHCI_POWER_CONTROL)
277 * "DMA select" location is offset 0x28 in SD specification, but on
278 * P5020 or P3041, it's located at 0x29.
280 if (spec_reg == SDHCI_HOST_CONTROL) {
282 * If host control register is not standard, exit
285 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL)
288 /* DMA select is 22,23 bits in Protocol Control Register */
289 dma_bits = (value & SDHCI_CTRL_DMA_MASK) << 5;
290 ret = (old_value & (~(SDHCI_CTRL_DMA_MASK << 5))) | dma_bits;
291 tmp = (value & (~SDHCI_CTRL_DMA_MASK)) |
292 (old_value & SDHCI_CTRL_DMA_MASK);
293 ret = (ret & (~0xff)) | tmp;
295 /* Prevent SDHCI core from writing reserved bits (e.g. HISPD) */
296 ret &= ~ESDHC_HOST_CONTROL_RES;
300 ret = (old_value & (~(0xff << shift))) | (value << shift);
304 static u32 esdhc_be_readl(struct sdhci_host *host, int reg)
309 if (reg == SDHCI_CAPABILITIES_1)
310 value = ioread32be(host->ioaddr + ESDHC_CAPABILITIES_1);
312 value = ioread32be(host->ioaddr + reg);
314 ret = esdhc_readl_fixup(host, reg, value);
319 static u32 esdhc_le_readl(struct sdhci_host *host, int reg)
324 if (reg == SDHCI_CAPABILITIES_1)
325 value = ioread32(host->ioaddr + ESDHC_CAPABILITIES_1);
327 value = ioread32(host->ioaddr + reg);
329 ret = esdhc_readl_fixup(host, reg, value);
334 static u16 esdhc_be_readw(struct sdhci_host *host, int reg)
338 int base = reg & ~0x3;
340 value = ioread32be(host->ioaddr + base);
341 ret = esdhc_readw_fixup(host, reg, value);
345 static u16 esdhc_le_readw(struct sdhci_host *host, int reg)
349 int base = reg & ~0x3;
351 value = ioread32(host->ioaddr + base);
352 ret = esdhc_readw_fixup(host, reg, value);
356 static u8 esdhc_be_readb(struct sdhci_host *host, int reg)
360 int base = reg & ~0x3;
362 value = ioread32be(host->ioaddr + base);
363 ret = esdhc_readb_fixup(host, reg, value);
367 static u8 esdhc_le_readb(struct sdhci_host *host, int reg)
371 int base = reg & ~0x3;
373 value = ioread32(host->ioaddr + base);
374 ret = esdhc_readb_fixup(host, reg, value);
378 static void esdhc_be_writel(struct sdhci_host *host, u32 val, int reg)
382 value = esdhc_writel_fixup(host, reg, val, 0);
383 iowrite32be(value, host->ioaddr + reg);
386 static void esdhc_le_writel(struct sdhci_host *host, u32 val, int reg)
390 value = esdhc_writel_fixup(host, reg, val, 0);
391 iowrite32(value, host->ioaddr + reg);
394 static void esdhc_be_writew(struct sdhci_host *host, u16 val, int reg)
396 int base = reg & ~0x3;
400 value = ioread32be(host->ioaddr + base);
401 ret = esdhc_writew_fixup(host, reg, val, value);
402 if (reg != SDHCI_TRANSFER_MODE)
403 iowrite32be(ret, host->ioaddr + base);
406 static void esdhc_le_writew(struct sdhci_host *host, u16 val, int reg)
408 int base = reg & ~0x3;
412 value = ioread32(host->ioaddr + base);
413 ret = esdhc_writew_fixup(host, reg, val, value);
414 if (reg != SDHCI_TRANSFER_MODE)
415 iowrite32(ret, host->ioaddr + base);
418 static void esdhc_be_writeb(struct sdhci_host *host, u8 val, int reg)
420 int base = reg & ~0x3;
424 value = ioread32be(host->ioaddr + base);
425 ret = esdhc_writeb_fixup(host, reg, val, value);
426 iowrite32be(ret, host->ioaddr + base);
429 static void esdhc_le_writeb(struct sdhci_host *host, u8 val, int reg)
431 int base = reg & ~0x3;
435 value = ioread32(host->ioaddr + base);
436 ret = esdhc_writeb_fixup(host, reg, val, value);
437 iowrite32(ret, host->ioaddr + base);
441 * For Abort or Suspend after Stop at Block Gap, ignore the ADMA
442 * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC])
443 * and Block Gap Event(IRQSTAT[BGE]) are also set.
444 * For Continue, apply soft reset for data(SYSCTL[RSTD]);
445 * and re-issue the entire read transaction from beginning.
447 static void esdhc_of_adma_workaround(struct sdhci_host *host, u32 intmask)
449 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
450 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
455 applicable = (intmask & SDHCI_INT_DATA_END) &&
456 (intmask & SDHCI_INT_BLK_GAP) &&
457 (esdhc->vendor_ver == VENDOR_V_23);
461 host->data->error = 0;
462 dmastart = sg_dma_address(host->data->sg);
463 dmanow = dmastart + host->data->bytes_xfered;
465 * Force update to the next DMA block boundary.
467 dmanow = (dmanow & ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) +
468 SDHCI_DEFAULT_BOUNDARY_SIZE;
469 host->data->bytes_xfered = dmanow - dmastart;
470 sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
473 static int esdhc_of_enable_dma(struct sdhci_host *host)
477 struct device *dev = mmc_dev(host->mmc);
479 if (of_device_is_compatible(dev->of_node, "fsl,ls1043a-esdhc") ||
480 of_device_is_compatible(dev->of_node, "fsl,ls1046a-esdhc")) {
481 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40));
486 value = sdhci_readl(host, ESDHC_DMA_SYSCTL);
488 if (of_dma_is_coherent(dev->of_node))
489 value |= ESDHC_DMA_SNOOP;
491 value &= ~ESDHC_DMA_SNOOP;
493 sdhci_writel(host, value, ESDHC_DMA_SYSCTL);
497 static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
499 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
500 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
502 if (esdhc->peripheral_clock)
503 return esdhc->peripheral_clock;
505 return pltfm_host->clock;
508 static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
510 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
511 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
514 if (esdhc->peripheral_clock)
515 clock = esdhc->peripheral_clock;
517 clock = pltfm_host->clock;
518 return clock / 256 / 16;
521 static void esdhc_clock_enable(struct sdhci_host *host, bool enable)
526 val = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
529 val |= ESDHC_CLOCK_SDCLKEN;
531 val &= ~ESDHC_CLOCK_SDCLKEN;
533 sdhci_writel(host, val, ESDHC_SYSTEM_CONTROL);
536 timeout = ktime_add_ms(ktime_get(), 20);
537 val = ESDHC_CLOCK_STABLE;
539 bool timedout = ktime_after(ktime_get(), timeout);
541 if (sdhci_readl(host, ESDHC_PRSSTAT) & val)
544 pr_err("%s: Internal clock never stabilised.\n",
545 mmc_hostname(host->mmc));
552 static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
554 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
555 struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
562 host->mmc->actual_clock = 0;
565 esdhc_clock_enable(host, false);
569 /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */
570 if (esdhc->vendor_ver < VENDOR_V_23)
573 if (host->mmc->card && mmc_card_sd(host->mmc->card) &&
574 esdhc->clk_fixup && host->mmc->ios.timing == MMC_TIMING_LEGACY)
575 fixup = esdhc->clk_fixup->sd_dflt_max_clk;
576 else if (esdhc->clk_fixup)
577 fixup = esdhc->clk_fixup->max_clk[host->mmc->ios.timing];
579 if (fixup && clock > fixup)
582 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
583 temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN |
584 ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
585 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
587 while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
590 while (host->max_clk / pre_div / div > clock && div < 16)
593 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
594 clock, host->max_clk / pre_div / div);
595 host->mmc->actual_clock = host->max_clk / pre_div / div;
599 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
600 temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
601 | (div << ESDHC_DIVIDER_SHIFT)
602 | (pre_div << ESDHC_PREDIV_SHIFT));
603 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
606 timeout = ktime_add_ms(ktime_get(), 20);
608 bool timedout = ktime_after(ktime_get(), timeout);
610 if (sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)
613 pr_err("%s: Internal clock never stabilised.\n",
614 mmc_hostname(host->mmc));
620 temp |= ESDHC_CLOCK_SDCLKEN;
621 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
624 static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
628 ctrl = sdhci_readl(host, ESDHC_PROCTL);
629 ctrl &= (~ESDHC_CTRL_BUSWIDTH_MASK);
631 case MMC_BUS_WIDTH_8:
632 ctrl |= ESDHC_CTRL_8BITBUS;
635 case MMC_BUS_WIDTH_4:
636 ctrl |= ESDHC_CTRL_4BITBUS;
643 sdhci_writel(host, ctrl, ESDHC_PROCTL);
646 static void esdhc_reset(struct sdhci_host *host, u8 mask)
650 sdhci_reset(host, mask);
652 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
653 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
655 if (mask & SDHCI_RESET_ALL) {
656 val = sdhci_readl(host, ESDHC_TBCTL);
658 sdhci_writel(host, val, ESDHC_TBCTL);
662 /* The SCFG, Supplemental Configuration Unit, provides SoC specific
663 * configuration and status registers for the device. There is a
664 * SDHC IO VSEL control register on SCFG for some platforms. It's
665 * used to support SDHC IO voltage switching.
667 static const struct of_device_id scfg_device_ids[] = {
668 { .compatible = "fsl,t1040-scfg", },
669 { .compatible = "fsl,ls1012a-scfg", },
670 { .compatible = "fsl,ls1046a-scfg", },
674 /* SDHC IO VSEL control register definition */
675 #define SCFG_SDHCIOVSELCR 0x408
676 #define SDHCIOVSELCR_TGLEN 0x80000000
677 #define SDHCIOVSELCR_VSELVAL 0x60000000
678 #define SDHCIOVSELCR_SDHC_VS 0x00000001
680 static int esdhc_signal_voltage_switch(struct mmc_host *mmc,
683 struct sdhci_host *host = mmc_priv(mmc);
684 struct device_node *scfg_node;
685 void __iomem *scfg_base = NULL;
690 * Signal Voltage Switching is only applicable for Host Controllers
693 if (host->version < SDHCI_SPEC_300)
696 val = sdhci_readl(host, ESDHC_PROCTL);
698 switch (ios->signal_voltage) {
699 case MMC_SIGNAL_VOLTAGE_330:
700 val &= ~ESDHC_VOLT_SEL;
701 sdhci_writel(host, val, ESDHC_PROCTL);
703 case MMC_SIGNAL_VOLTAGE_180:
704 scfg_node = of_find_matching_node(NULL, scfg_device_ids);
706 scfg_base = of_iomap(scfg_node, 0);
707 of_node_put(scfg_node);
709 sdhciovselcr = SDHCIOVSELCR_TGLEN |
710 SDHCIOVSELCR_VSELVAL;
711 iowrite32be(sdhciovselcr,
712 scfg_base + SCFG_SDHCIOVSELCR);
714 val |= ESDHC_VOLT_SEL;
715 sdhci_writel(host, val, ESDHC_PROCTL);
718 sdhciovselcr = SDHCIOVSELCR_TGLEN |
719 SDHCIOVSELCR_SDHC_VS;
720 iowrite32be(sdhciovselcr,
721 scfg_base + SCFG_SDHCIOVSELCR);
724 val |= ESDHC_VOLT_SEL;
725 sdhci_writel(host, val, ESDHC_PROCTL);
733 static int esdhc_execute_tuning(struct mmc_host *mmc, u32 opcode)
735 struct sdhci_host *host = mmc_priv(mmc);
738 /* Use tuning block for tuning procedure */
739 esdhc_clock_enable(host, false);
740 val = sdhci_readl(host, ESDHC_DMA_SYSCTL);
741 val |= ESDHC_FLUSH_ASYNC_FIFO;
742 sdhci_writel(host, val, ESDHC_DMA_SYSCTL);
744 val = sdhci_readl(host, ESDHC_TBCTL);
746 sdhci_writel(host, val, ESDHC_TBCTL);
747 esdhc_clock_enable(host, true);
749 return sdhci_execute_tuning(mmc, opcode);
752 #ifdef CONFIG_PM_SLEEP
753 static u32 esdhc_proctl;
754 static int esdhc_of_suspend(struct device *dev)
756 struct sdhci_host *host = dev_get_drvdata(dev);
758 esdhc_proctl = sdhci_readl(host, SDHCI_HOST_CONTROL);
760 if (host->tuning_mode != SDHCI_TUNING_MODE_3)
761 mmc_retune_needed(host->mmc);
763 return sdhci_suspend_host(host);
766 static int esdhc_of_resume(struct device *dev)
768 struct sdhci_host *host = dev_get_drvdata(dev);
769 int ret = sdhci_resume_host(host);
772 /* Isn't this already done by sdhci_resume_host() ? --rmk */
773 esdhc_of_enable_dma(host);
774 sdhci_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL);
780 static SIMPLE_DEV_PM_OPS(esdhc_of_dev_pm_ops,
784 static const struct sdhci_ops sdhci_esdhc_be_ops = {
785 .read_l = esdhc_be_readl,
786 .read_w = esdhc_be_readw,
787 .read_b = esdhc_be_readb,
788 .write_l = esdhc_be_writel,
789 .write_w = esdhc_be_writew,
790 .write_b = esdhc_be_writeb,
791 .set_clock = esdhc_of_set_clock,
792 .enable_dma = esdhc_of_enable_dma,
793 .get_max_clock = esdhc_of_get_max_clock,
794 .get_min_clock = esdhc_of_get_min_clock,
795 .adma_workaround = esdhc_of_adma_workaround,
796 .set_bus_width = esdhc_pltfm_set_bus_width,
797 .reset = esdhc_reset,
798 .set_uhs_signaling = sdhci_set_uhs_signaling,
801 static const struct sdhci_ops sdhci_esdhc_le_ops = {
802 .read_l = esdhc_le_readl,
803 .read_w = esdhc_le_readw,
804 .read_b = esdhc_le_readb,
805 .write_l = esdhc_le_writel,
806 .write_w = esdhc_le_writew,
807 .write_b = esdhc_le_writeb,
808 .set_clock = esdhc_of_set_clock,
809 .enable_dma = esdhc_of_enable_dma,
810 .get_max_clock = esdhc_of_get_max_clock,
811 .get_min_clock = esdhc_of_get_min_clock,
812 .adma_workaround = esdhc_of_adma_workaround,
813 .set_bus_width = esdhc_pltfm_set_bus_width,
814 .reset = esdhc_reset,
815 .set_uhs_signaling = sdhci_set_uhs_signaling,
818 static const struct sdhci_pltfm_data sdhci_esdhc_be_pdata = {
819 .quirks = ESDHC_DEFAULT_QUIRKS |
821 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
823 SDHCI_QUIRK_NO_CARD_NO_RESET |
824 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
825 .ops = &sdhci_esdhc_be_ops,
828 static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = {
829 .quirks = ESDHC_DEFAULT_QUIRKS |
830 SDHCI_QUIRK_NO_CARD_NO_RESET |
831 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
832 .ops = &sdhci_esdhc_le_ops,
835 static struct soc_device_attribute soc_incorrect_hostver[] = {
836 { .family = "QorIQ T4240", .revision = "1.0", },
837 { .family = "QorIQ T4240", .revision = "2.0", },
841 static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
843 const struct of_device_id *match;
844 struct sdhci_pltfm_host *pltfm_host;
845 struct sdhci_esdhc *esdhc;
846 struct device_node *np;
851 pltfm_host = sdhci_priv(host);
852 esdhc = sdhci_pltfm_priv(pltfm_host);
854 host_ver = sdhci_readw(host, SDHCI_HOST_VERSION);
855 esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >>
856 SDHCI_VENDOR_VER_SHIFT;
857 esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK;
858 if (soc_device_match(soc_incorrect_hostver))
859 esdhc->quirk_incorrect_hostver = true;
861 esdhc->quirk_incorrect_hostver = false;
863 match = of_match_node(sdhci_esdhc_of_match, pdev->dev.of_node);
865 esdhc->clk_fixup = match->data;
866 np = pdev->dev.of_node;
867 clk = of_clk_get(np, 0);
870 * esdhc->peripheral_clock would be assigned with a value
871 * which is eSDHC base clock when use periperal clock.
872 * For ls1046a, the clock value got by common clk API is
873 * peripheral clock while the eSDHC base clock is 1/2
876 if (of_device_is_compatible(np, "fsl,ls1046a-esdhc"))
877 esdhc->peripheral_clock = clk_get_rate(clk) / 2;
879 esdhc->peripheral_clock = clk_get_rate(clk);
884 if (esdhc->peripheral_clock) {
885 esdhc_clock_enable(host, false);
886 val = sdhci_readl(host, ESDHC_DMA_SYSCTL);
887 val |= ESDHC_PERIPHERAL_CLK_SEL;
888 sdhci_writel(host, val, ESDHC_DMA_SYSCTL);
889 esdhc_clock_enable(host, true);
893 static int sdhci_esdhc_probe(struct platform_device *pdev)
895 struct sdhci_host *host;
896 struct device_node *np;
897 struct sdhci_pltfm_host *pltfm_host;
898 struct sdhci_esdhc *esdhc;
901 np = pdev->dev.of_node;
903 if (of_property_read_bool(np, "little-endian"))
904 host = sdhci_pltfm_init(pdev, &sdhci_esdhc_le_pdata,
905 sizeof(struct sdhci_esdhc));
907 host = sdhci_pltfm_init(pdev, &sdhci_esdhc_be_pdata,
908 sizeof(struct sdhci_esdhc));
911 return PTR_ERR(host);
913 host->mmc_host_ops.start_signal_voltage_switch =
914 esdhc_signal_voltage_switch;
915 host->mmc_host_ops.execute_tuning = esdhc_execute_tuning;
916 host->tuning_delay = 1;
918 esdhc_init(pdev, host);
920 sdhci_get_of_property(pdev);
922 pltfm_host = sdhci_priv(host);
923 esdhc = sdhci_pltfm_priv(pltfm_host);
924 if (esdhc->vendor_ver == VENDOR_V_22)
925 host->quirks2 |= SDHCI_QUIRK2_HOST_NO_CMD23;
927 if (esdhc->vendor_ver > VENDOR_V_22)
928 host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
930 if (of_find_compatible_node(NULL, NULL, "fsl,p2020-esdhc")) {
931 host->quirks |= SDHCI_QUIRK_RESET_AFTER_REQUEST;
932 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
935 if (of_device_is_compatible(np, "fsl,p5040-esdhc") ||
936 of_device_is_compatible(np, "fsl,p5020-esdhc") ||
937 of_device_is_compatible(np, "fsl,p4080-esdhc") ||
938 of_device_is_compatible(np, "fsl,p1020-esdhc") ||
939 of_device_is_compatible(np, "fsl,t1040-esdhc"))
940 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
942 if (of_device_is_compatible(np, "fsl,ls1021a-esdhc"))
943 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
945 if (of_device_is_compatible(np, "fsl,p2020-esdhc")) {
947 * Freescale messed up with P2020 as it has a non-standard
948 * host control register
950 host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL;
953 /* call to generic mmc_of_parse to support additional capabilities */
954 ret = mmc_of_parse(host->mmc);
958 mmc_of_parse_voltage(np, &host->ocr_mask);
960 ret = sdhci_add_host(host);
966 sdhci_pltfm_free(pdev);
970 static struct platform_driver sdhci_esdhc_driver = {
972 .name = "sdhci-esdhc",
973 .of_match_table = sdhci_esdhc_of_match,
974 .pm = &esdhc_of_dev_pm_ops,
976 .probe = sdhci_esdhc_probe,
977 .remove = sdhci_pltfm_unregister,
980 module_platform_driver(sdhci_esdhc_driver);
982 MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
983 MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
984 "Anton Vorontsov <avorontsov@ru.mvista.com>");
985 MODULE_LICENSE("GPL v2");