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/mmc/host.h>
26 #include "sdhci-pltfm.h"
27 #include "sdhci-esdhc.h"
29 #define VENDOR_V_22 0x12
30 #define VENDOR_V_23 0x13
35 bool quirk_incorrect_hostver
;
36 unsigned int peripheral_clock
;
40 * esdhc_read*_fixup - Fixup the value read from incompatible eSDHC register
41 * to make it compatible with SD spec.
43 * @host: pointer to sdhci_host
44 * @spec_reg: SD spec register address
45 * @value: 32bit eSDHC register value on spec_reg address
47 * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC
48 * registers are 32 bits. There are differences in register size, register
49 * address, register function, bit position and function between eSDHC spec
52 * Return a fixed up register value
54 static u32
esdhc_readl_fixup(struct sdhci_host
*host
,
55 int spec_reg
, u32 value
)
57 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
58 struct sdhci_esdhc
*esdhc
= sdhci_pltfm_priv(pltfm_host
);
62 * The bit of ADMA flag in eSDHC is not compatible with standard
63 * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is
65 * And for many FSL eSDHC controller, the reset value of field
66 * SDHCI_CAN_DO_ADMA1 is 1, but some of them can't support ADMA,
67 * only these vendor version is greater than 2.2/0x12 support ADMA.
69 if ((spec_reg
== SDHCI_CAPABILITIES
) && (value
& SDHCI_CAN_DO_ADMA1
)) {
70 if (esdhc
->vendor_ver
> VENDOR_V_22
) {
71 ret
= value
| SDHCI_CAN_DO_ADMA2
;
76 * The DAT[3:0] line signal levels and the CMD line signal level are
77 * not compatible with standard SDHC register. The line signal levels
78 * DAT[7:0] are at bits 31:24 and the command line signal level is at
79 * bit 23. All other bits are the same as in the standard SDHC
82 if (spec_reg
== SDHCI_PRESENT_STATE
) {
83 ret
= value
& 0x000fffff;
84 ret
|= (value
>> 4) & SDHCI_DATA_LVL_MASK
;
85 ret
|= (value
<< 1) & SDHCI_CMD_LVL
;
90 * DTS properties of mmc host are used to enable each speed mode
91 * according to soc and board capability. So clean up
92 * SDR50/SDR104/DDR50 support bits here.
94 if (spec_reg
== SDHCI_CAPABILITIES_1
) {
95 ret
= value
& ~(SDHCI_SUPPORT_SDR50
| SDHCI_SUPPORT_SDR104
|
104 static u16
esdhc_readw_fixup(struct sdhci_host
*host
,
105 int spec_reg
, u32 value
)
107 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
108 struct sdhci_esdhc
*esdhc
= sdhci_pltfm_priv(pltfm_host
);
110 int shift
= (spec_reg
& 0x2) * 8;
112 if (spec_reg
== SDHCI_HOST_VERSION
)
113 ret
= value
& 0xffff;
115 ret
= (value
>> shift
) & 0xffff;
116 /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect
117 * vendor version and spec version information.
119 if ((spec_reg
== SDHCI_HOST_VERSION
) &&
120 (esdhc
->quirk_incorrect_hostver
))
121 ret
= (VENDOR_V_23
<< SDHCI_VENDOR_VER_SHIFT
) | SDHCI_SPEC_200
;
125 static u8
esdhc_readb_fixup(struct sdhci_host
*host
,
126 int spec_reg
, u32 value
)
130 int shift
= (spec_reg
& 0x3) * 8;
132 ret
= (value
>> shift
) & 0xff;
135 * "DMA select" locates at offset 0x28 in SD specification, but on
136 * P5020 or P3041, it locates at 0x29.
138 if (spec_reg
== SDHCI_HOST_CONTROL
) {
139 /* DMA select is 22,23 bits in Protocol Control Register */
140 dma_bits
= (value
>> 5) & SDHCI_CTRL_DMA_MASK
;
141 /* fixup the result */
142 ret
&= ~SDHCI_CTRL_DMA_MASK
;
149 * esdhc_write*_fixup - Fixup the SD spec register value so that it could be
150 * written into eSDHC register.
152 * @host: pointer to sdhci_host
153 * @spec_reg: SD spec register address
154 * @value: 8/16/32bit SD spec register value that would be written
155 * @old_value: 32bit eSDHC register value on spec_reg address
157 * In SD spec, there are 8/16/32/64 bits registers, while all of eSDHC
158 * registers are 32 bits. There are differences in register size, register
159 * address, register function, bit position and function between eSDHC spec
162 * Return a fixed up register value
164 static u32
esdhc_writel_fixup(struct sdhci_host
*host
,
165 int spec_reg
, u32 value
, u32 old_value
)
170 * Enabling IRQSTATEN[BGESEN] is just to set IRQSTAT[BGE]
171 * when SYSCTL[RSTD] is set for some special operations.
172 * No any impact on other operation.
174 if (spec_reg
== SDHCI_INT_ENABLE
)
175 ret
= value
| SDHCI_INT_BLK_GAP
;
182 static u32
esdhc_writew_fixup(struct sdhci_host
*host
,
183 int spec_reg
, u16 value
, u32 old_value
)
185 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
186 int shift
= (spec_reg
& 0x2) * 8;
190 case SDHCI_TRANSFER_MODE
:
192 * Postpone this write, we must do it together with a
193 * command write that is down below. Return old value.
195 pltfm_host
->xfer_mode_shadow
= value
;
198 ret
= (value
<< 16) | pltfm_host
->xfer_mode_shadow
;
202 ret
= old_value
& (~(0xffff << shift
));
203 ret
|= (value
<< shift
);
205 if (spec_reg
== SDHCI_BLOCK_SIZE
) {
207 * Two last DMA bits are reserved, and first one is used for
208 * non-standard blksz of 4096 bytes that we don't support
209 * yet. So clear the DMA boundary bits.
211 ret
&= (~SDHCI_MAKE_BLKSZ(0x7, 0));
216 static u32
esdhc_writeb_fixup(struct sdhci_host
*host
,
217 int spec_reg
, u8 value
, u32 old_value
)
222 int shift
= (spec_reg
& 0x3) * 8;
225 * eSDHC doesn't have a standard power control register, so we do
226 * nothing here to avoid incorrect operation.
228 if (spec_reg
== SDHCI_POWER_CONTROL
)
231 * "DMA select" location is offset 0x28 in SD specification, but on
232 * P5020 or P3041, it's located at 0x29.
234 if (spec_reg
== SDHCI_HOST_CONTROL
) {
236 * If host control register is not standard, exit
239 if (host
->quirks2
& SDHCI_QUIRK2_BROKEN_HOST_CONTROL
)
242 /* DMA select is 22,23 bits in Protocol Control Register */
243 dma_bits
= (value
& SDHCI_CTRL_DMA_MASK
) << 5;
244 ret
= (old_value
& (~(SDHCI_CTRL_DMA_MASK
<< 5))) | dma_bits
;
245 tmp
= (value
& (~SDHCI_CTRL_DMA_MASK
)) |
246 (old_value
& SDHCI_CTRL_DMA_MASK
);
247 ret
= (ret
& (~0xff)) | tmp
;
249 /* Prevent SDHCI core from writing reserved bits (e.g. HISPD) */
250 ret
&= ~ESDHC_HOST_CONTROL_RES
;
254 ret
= (old_value
& (~(0xff << shift
))) | (value
<< shift
);
258 static u32
esdhc_be_readl(struct sdhci_host
*host
, int reg
)
263 if (reg
== SDHCI_CAPABILITIES_1
)
264 value
= ioread32be(host
->ioaddr
+ ESDHC_CAPABILITIES_1
);
266 value
= ioread32be(host
->ioaddr
+ reg
);
268 ret
= esdhc_readl_fixup(host
, reg
, value
);
273 static u32
esdhc_le_readl(struct sdhci_host
*host
, int reg
)
278 if (reg
== SDHCI_CAPABILITIES_1
)
279 value
= ioread32(host
->ioaddr
+ ESDHC_CAPABILITIES_1
);
281 value
= ioread32(host
->ioaddr
+ reg
);
283 ret
= esdhc_readl_fixup(host
, reg
, value
);
288 static u16
esdhc_be_readw(struct sdhci_host
*host
, int reg
)
292 int base
= reg
& ~0x3;
294 value
= ioread32be(host
->ioaddr
+ base
);
295 ret
= esdhc_readw_fixup(host
, reg
, value
);
299 static u16
esdhc_le_readw(struct sdhci_host
*host
, int reg
)
303 int base
= reg
& ~0x3;
305 value
= ioread32(host
->ioaddr
+ base
);
306 ret
= esdhc_readw_fixup(host
, reg
, value
);
310 static u8
esdhc_be_readb(struct sdhci_host
*host
, int reg
)
314 int base
= reg
& ~0x3;
316 value
= ioread32be(host
->ioaddr
+ base
);
317 ret
= esdhc_readb_fixup(host
, reg
, value
);
321 static u8
esdhc_le_readb(struct sdhci_host
*host
, int reg
)
325 int base
= reg
& ~0x3;
327 value
= ioread32(host
->ioaddr
+ base
);
328 ret
= esdhc_readb_fixup(host
, reg
, value
);
332 static void esdhc_be_writel(struct sdhci_host
*host
, u32 val
, int reg
)
336 value
= esdhc_writel_fixup(host
, reg
, val
, 0);
337 iowrite32be(value
, host
->ioaddr
+ reg
);
340 static void esdhc_le_writel(struct sdhci_host
*host
, u32 val
, int reg
)
344 value
= esdhc_writel_fixup(host
, reg
, val
, 0);
345 iowrite32(value
, host
->ioaddr
+ reg
);
348 static void esdhc_be_writew(struct sdhci_host
*host
, u16 val
, int reg
)
350 int base
= reg
& ~0x3;
354 value
= ioread32be(host
->ioaddr
+ base
);
355 ret
= esdhc_writew_fixup(host
, reg
, val
, value
);
356 if (reg
!= SDHCI_TRANSFER_MODE
)
357 iowrite32be(ret
, host
->ioaddr
+ base
);
360 static void esdhc_le_writew(struct sdhci_host
*host
, u16 val
, int reg
)
362 int base
= reg
& ~0x3;
366 value
= ioread32(host
->ioaddr
+ base
);
367 ret
= esdhc_writew_fixup(host
, reg
, val
, value
);
368 if (reg
!= SDHCI_TRANSFER_MODE
)
369 iowrite32(ret
, host
->ioaddr
+ base
);
372 static void esdhc_be_writeb(struct sdhci_host
*host
, u8 val
, int reg
)
374 int base
= reg
& ~0x3;
378 value
= ioread32be(host
->ioaddr
+ base
);
379 ret
= esdhc_writeb_fixup(host
, reg
, val
, value
);
380 iowrite32be(ret
, host
->ioaddr
+ base
);
383 static void esdhc_le_writeb(struct sdhci_host
*host
, u8 val
, int reg
)
385 int base
= reg
& ~0x3;
389 value
= ioread32(host
->ioaddr
+ base
);
390 ret
= esdhc_writeb_fixup(host
, reg
, val
, value
);
391 iowrite32(ret
, host
->ioaddr
+ base
);
395 * For Abort or Suspend after Stop at Block Gap, ignore the ADMA
396 * error(IRQSTAT[ADMAE]) if both Transfer Complete(IRQSTAT[TC])
397 * and Block Gap Event(IRQSTAT[BGE]) are also set.
398 * For Continue, apply soft reset for data(SYSCTL[RSTD]);
399 * and re-issue the entire read transaction from beginning.
401 static void esdhc_of_adma_workaround(struct sdhci_host
*host
, u32 intmask
)
403 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
404 struct sdhci_esdhc
*esdhc
= sdhci_pltfm_priv(pltfm_host
);
409 applicable
= (intmask
& SDHCI_INT_DATA_END
) &&
410 (intmask
& SDHCI_INT_BLK_GAP
) &&
411 (esdhc
->vendor_ver
== VENDOR_V_23
);
415 host
->data
->error
= 0;
416 dmastart
= sg_dma_address(host
->data
->sg
);
417 dmanow
= dmastart
+ host
->data
->bytes_xfered
;
419 * Force update to the next DMA block boundary.
421 dmanow
= (dmanow
& ~(SDHCI_DEFAULT_BOUNDARY_SIZE
- 1)) +
422 SDHCI_DEFAULT_BOUNDARY_SIZE
;
423 host
->data
->bytes_xfered
= dmanow
- dmastart
;
424 sdhci_writel(host
, dmanow
, SDHCI_DMA_ADDRESS
);
427 static int esdhc_of_enable_dma(struct sdhci_host
*host
)
431 value
= sdhci_readl(host
, ESDHC_DMA_SYSCTL
);
432 value
|= ESDHC_DMA_SNOOP
;
433 sdhci_writel(host
, value
, ESDHC_DMA_SYSCTL
);
437 static unsigned int esdhc_of_get_max_clock(struct sdhci_host
*host
)
439 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
440 struct sdhci_esdhc
*esdhc
= sdhci_pltfm_priv(pltfm_host
);
442 if (esdhc
->peripheral_clock
)
443 return esdhc
->peripheral_clock
;
445 return pltfm_host
->clock
;
448 static unsigned int esdhc_of_get_min_clock(struct sdhci_host
*host
)
450 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
451 struct sdhci_esdhc
*esdhc
= sdhci_pltfm_priv(pltfm_host
);
454 if (esdhc
->peripheral_clock
)
455 clock
= esdhc
->peripheral_clock
;
457 clock
= pltfm_host
->clock
;
458 return clock
/ 256 / 16;
461 static void esdhc_of_set_clock(struct sdhci_host
*host
, unsigned int clock
)
463 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
464 struct sdhci_esdhc
*esdhc
= sdhci_pltfm_priv(pltfm_host
);
470 host
->mmc
->actual_clock
= 0;
475 /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */
476 if (esdhc
->vendor_ver
< VENDOR_V_23
)
480 * Limit SD clock to 167MHz for ls1046a according to its datasheet
482 if (clock
> 167000000 &&
483 of_find_compatible_node(NULL
, NULL
, "fsl,ls1046a-esdhc"))
487 * Limit SD clock to 125MHz for ls1012a according to its datasheet
489 if (clock
> 125000000 &&
490 of_find_compatible_node(NULL
, NULL
, "fsl,ls1012a-esdhc"))
493 /* Workaround to reduce the clock frequency for p1010 esdhc */
494 if (of_find_compatible_node(NULL
, NULL
, "fsl,p1010-esdhc")) {
495 if (clock
> 20000000)
497 if (clock
> 40000000)
501 temp
= sdhci_readl(host
, ESDHC_SYSTEM_CONTROL
);
502 temp
&= ~(ESDHC_CLOCK_SDCLKEN
| ESDHC_CLOCK_IPGEN
| ESDHC_CLOCK_HCKEN
|
503 ESDHC_CLOCK_PEREN
| ESDHC_CLOCK_MASK
);
504 sdhci_writel(host
, temp
, ESDHC_SYSTEM_CONTROL
);
506 while (host
->max_clk
/ pre_div
/ 16 > clock
&& pre_div
< 256)
509 while (host
->max_clk
/ pre_div
/ div
> clock
&& div
< 16)
512 dev_dbg(mmc_dev(host
->mmc
), "desired SD clock: %d, actual: %d\n",
513 clock
, host
->max_clk
/ pre_div
/ div
);
514 host
->mmc
->actual_clock
= host
->max_clk
/ pre_div
/ div
;
518 temp
= sdhci_readl(host
, ESDHC_SYSTEM_CONTROL
);
519 temp
|= (ESDHC_CLOCK_IPGEN
| ESDHC_CLOCK_HCKEN
| ESDHC_CLOCK_PEREN
520 | (div
<< ESDHC_DIVIDER_SHIFT
)
521 | (pre_div
<< ESDHC_PREDIV_SHIFT
));
522 sdhci_writel(host
, temp
, ESDHC_SYSTEM_CONTROL
);
525 timeout
= ktime_add_ms(ktime_get(), 20);
526 while (!(sdhci_readl(host
, ESDHC_PRSSTAT
) & ESDHC_CLOCK_STABLE
)) {
527 if (ktime_after(ktime_get(), timeout
)) {
528 pr_err("%s: Internal clock never stabilised.\n",
529 mmc_hostname(host
->mmc
));
535 temp
|= ESDHC_CLOCK_SDCLKEN
;
536 sdhci_writel(host
, temp
, ESDHC_SYSTEM_CONTROL
);
539 static void esdhc_pltfm_set_bus_width(struct sdhci_host
*host
, int width
)
543 ctrl
= sdhci_readl(host
, ESDHC_PROCTL
);
544 ctrl
&= (~ESDHC_CTRL_BUSWIDTH_MASK
);
546 case MMC_BUS_WIDTH_8
:
547 ctrl
|= ESDHC_CTRL_8BITBUS
;
550 case MMC_BUS_WIDTH_4
:
551 ctrl
|= ESDHC_CTRL_4BITBUS
;
558 sdhci_writel(host
, ctrl
, ESDHC_PROCTL
);
561 static void esdhc_clock_enable(struct sdhci_host
*host
, bool enable
)
566 val
= sdhci_readl(host
, ESDHC_SYSTEM_CONTROL
);
569 val
|= ESDHC_CLOCK_SDCLKEN
;
571 val
&= ~ESDHC_CLOCK_SDCLKEN
;
573 sdhci_writel(host
, val
, ESDHC_SYSTEM_CONTROL
);
576 timeout
= ktime_add_ms(ktime_get(), 20);
577 val
= ESDHC_CLOCK_STABLE
;
578 while (!(sdhci_readl(host
, ESDHC_PRSSTAT
) & val
)) {
579 if (ktime_after(ktime_get(), timeout
)) {
580 pr_err("%s: Internal clock never stabilised.\n",
581 mmc_hostname(host
->mmc
));
588 static void esdhc_reset(struct sdhci_host
*host
, u8 mask
)
590 sdhci_reset(host
, mask
);
592 sdhci_writel(host
, host
->ier
, SDHCI_INT_ENABLE
);
593 sdhci_writel(host
, host
->ier
, SDHCI_SIGNAL_ENABLE
);
596 /* The SCFG, Supplemental Configuration Unit, provides SoC specific
597 * configuration and status registers for the device. There is a
598 * SDHC IO VSEL control register on SCFG for some platforms. It's
599 * used to support SDHC IO voltage switching.
601 static const struct of_device_id scfg_device_ids
[] = {
602 { .compatible
= "fsl,t1040-scfg", },
603 { .compatible
= "fsl,ls1012a-scfg", },
604 { .compatible
= "fsl,ls1046a-scfg", },
608 /* SDHC IO VSEL control register definition */
609 #define SCFG_SDHCIOVSELCR 0x408
610 #define SDHCIOVSELCR_TGLEN 0x80000000
611 #define SDHCIOVSELCR_VSELVAL 0x60000000
612 #define SDHCIOVSELCR_SDHC_VS 0x00000001
614 static int esdhc_signal_voltage_switch(struct mmc_host
*mmc
,
617 struct sdhci_host
*host
= mmc_priv(mmc
);
618 struct device_node
*scfg_node
;
619 void __iomem
*scfg_base
= NULL
;
624 * Signal Voltage Switching is only applicable for Host Controllers
627 if (host
->version
< SDHCI_SPEC_300
)
630 val
= sdhci_readl(host
, ESDHC_PROCTL
);
632 switch (ios
->signal_voltage
) {
633 case MMC_SIGNAL_VOLTAGE_330
:
634 val
&= ~ESDHC_VOLT_SEL
;
635 sdhci_writel(host
, val
, ESDHC_PROCTL
);
637 case MMC_SIGNAL_VOLTAGE_180
:
638 scfg_node
= of_find_matching_node(NULL
, scfg_device_ids
);
640 scfg_base
= of_iomap(scfg_node
, 0);
642 sdhciovselcr
= SDHCIOVSELCR_TGLEN
|
643 SDHCIOVSELCR_VSELVAL
;
644 iowrite32be(sdhciovselcr
,
645 scfg_base
+ SCFG_SDHCIOVSELCR
);
647 val
|= ESDHC_VOLT_SEL
;
648 sdhci_writel(host
, val
, ESDHC_PROCTL
);
651 sdhciovselcr
= SDHCIOVSELCR_TGLEN
|
652 SDHCIOVSELCR_SDHC_VS
;
653 iowrite32be(sdhciovselcr
,
654 scfg_base
+ SCFG_SDHCIOVSELCR
);
657 val
|= ESDHC_VOLT_SEL
;
658 sdhci_writel(host
, val
, ESDHC_PROCTL
);
666 static int esdhc_execute_tuning(struct mmc_host
*mmc
, u32 opcode
)
668 struct sdhci_host
*host
= mmc_priv(mmc
);
671 /* Use tuning block for tuning procedure */
672 esdhc_clock_enable(host
, false);
673 val
= sdhci_readl(host
, ESDHC_DMA_SYSCTL
);
674 val
|= ESDHC_FLUSH_ASYNC_FIFO
;
675 sdhci_writel(host
, val
, ESDHC_DMA_SYSCTL
);
677 val
= sdhci_readl(host
, ESDHC_TBCTL
);
679 sdhci_writel(host
, val
, ESDHC_TBCTL
);
680 esdhc_clock_enable(host
, true);
682 return sdhci_execute_tuning(mmc
, opcode
);
685 #ifdef CONFIG_PM_SLEEP
686 static u32 esdhc_proctl
;
687 static int esdhc_of_suspend(struct device
*dev
)
689 struct sdhci_host
*host
= dev_get_drvdata(dev
);
691 esdhc_proctl
= sdhci_readl(host
, SDHCI_HOST_CONTROL
);
693 if (host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
694 mmc_retune_needed(host
->mmc
);
696 return sdhci_suspend_host(host
);
699 static int esdhc_of_resume(struct device
*dev
)
701 struct sdhci_host
*host
= dev_get_drvdata(dev
);
702 int ret
= sdhci_resume_host(host
);
705 /* Isn't this already done by sdhci_resume_host() ? --rmk */
706 esdhc_of_enable_dma(host
);
707 sdhci_writel(host
, esdhc_proctl
, SDHCI_HOST_CONTROL
);
713 static SIMPLE_DEV_PM_OPS(esdhc_of_dev_pm_ops
,
717 static const struct sdhci_ops sdhci_esdhc_be_ops
= {
718 .read_l
= esdhc_be_readl
,
719 .read_w
= esdhc_be_readw
,
720 .read_b
= esdhc_be_readb
,
721 .write_l
= esdhc_be_writel
,
722 .write_w
= esdhc_be_writew
,
723 .write_b
= esdhc_be_writeb
,
724 .set_clock
= esdhc_of_set_clock
,
725 .enable_dma
= esdhc_of_enable_dma
,
726 .get_max_clock
= esdhc_of_get_max_clock
,
727 .get_min_clock
= esdhc_of_get_min_clock
,
728 .adma_workaround
= esdhc_of_adma_workaround
,
729 .set_bus_width
= esdhc_pltfm_set_bus_width
,
730 .reset
= esdhc_reset
,
731 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
734 static const struct sdhci_ops sdhci_esdhc_le_ops
= {
735 .read_l
= esdhc_le_readl
,
736 .read_w
= esdhc_le_readw
,
737 .read_b
= esdhc_le_readb
,
738 .write_l
= esdhc_le_writel
,
739 .write_w
= esdhc_le_writew
,
740 .write_b
= esdhc_le_writeb
,
741 .set_clock
= esdhc_of_set_clock
,
742 .enable_dma
= esdhc_of_enable_dma
,
743 .get_max_clock
= esdhc_of_get_max_clock
,
744 .get_min_clock
= esdhc_of_get_min_clock
,
745 .adma_workaround
= esdhc_of_adma_workaround
,
746 .set_bus_width
= esdhc_pltfm_set_bus_width
,
747 .reset
= esdhc_reset
,
748 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
751 static const struct sdhci_pltfm_data sdhci_esdhc_be_pdata
= {
752 .quirks
= ESDHC_DEFAULT_QUIRKS
|
754 SDHCI_QUIRK_BROKEN_CARD_DETECTION
|
756 SDHCI_QUIRK_NO_CARD_NO_RESET
|
757 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
758 .ops
= &sdhci_esdhc_be_ops
,
761 static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata
= {
762 .quirks
= ESDHC_DEFAULT_QUIRKS
|
763 SDHCI_QUIRK_NO_CARD_NO_RESET
|
764 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
765 .ops
= &sdhci_esdhc_le_ops
,
768 static struct soc_device_attribute soc_incorrect_hostver
[] = {
769 { .family
= "QorIQ T4240", .revision
= "1.0", },
770 { .family
= "QorIQ T4240", .revision
= "2.0", },
774 static void esdhc_init(struct platform_device
*pdev
, struct sdhci_host
*host
)
776 struct sdhci_pltfm_host
*pltfm_host
;
777 struct sdhci_esdhc
*esdhc
;
778 struct device_node
*np
;
783 pltfm_host
= sdhci_priv(host
);
784 esdhc
= sdhci_pltfm_priv(pltfm_host
);
786 host_ver
= sdhci_readw(host
, SDHCI_HOST_VERSION
);
787 esdhc
->vendor_ver
= (host_ver
& SDHCI_VENDOR_VER_MASK
) >>
788 SDHCI_VENDOR_VER_SHIFT
;
789 esdhc
->spec_ver
= host_ver
& SDHCI_SPEC_VER_MASK
;
790 if (soc_device_match(soc_incorrect_hostver
))
791 esdhc
->quirk_incorrect_hostver
= true;
793 esdhc
->quirk_incorrect_hostver
= false;
795 np
= pdev
->dev
.of_node
;
796 clk
= of_clk_get(np
, 0);
799 * esdhc->peripheral_clock would be assigned with a value
800 * which is eSDHC base clock when use periperal clock.
801 * For ls1046a, the clock value got by common clk API is
802 * peripheral clock while the eSDHC base clock is 1/2
805 if (of_device_is_compatible(np
, "fsl,ls1046a-esdhc"))
806 esdhc
->peripheral_clock
= clk_get_rate(clk
) / 2;
808 esdhc
->peripheral_clock
= clk_get_rate(clk
);
813 if (esdhc
->peripheral_clock
) {
814 esdhc_clock_enable(host
, false);
815 val
= sdhci_readl(host
, ESDHC_DMA_SYSCTL
);
816 val
|= ESDHC_PERIPHERAL_CLK_SEL
;
817 sdhci_writel(host
, val
, ESDHC_DMA_SYSCTL
);
818 esdhc_clock_enable(host
, true);
822 static int sdhci_esdhc_probe(struct platform_device
*pdev
)
824 struct sdhci_host
*host
;
825 struct device_node
*np
;
826 struct sdhci_pltfm_host
*pltfm_host
;
827 struct sdhci_esdhc
*esdhc
;
830 np
= pdev
->dev
.of_node
;
832 if (of_property_read_bool(np
, "little-endian"))
833 host
= sdhci_pltfm_init(pdev
, &sdhci_esdhc_le_pdata
,
834 sizeof(struct sdhci_esdhc
));
836 host
= sdhci_pltfm_init(pdev
, &sdhci_esdhc_be_pdata
,
837 sizeof(struct sdhci_esdhc
));
840 return PTR_ERR(host
);
842 host
->mmc_host_ops
.start_signal_voltage_switch
=
843 esdhc_signal_voltage_switch
;
844 host
->mmc_host_ops
.execute_tuning
= esdhc_execute_tuning
;
845 host
->tuning_delay
= 1;
847 esdhc_init(pdev
, host
);
849 sdhci_get_of_property(pdev
);
851 pltfm_host
= sdhci_priv(host
);
852 esdhc
= sdhci_pltfm_priv(pltfm_host
);
853 if (esdhc
->vendor_ver
== VENDOR_V_22
)
854 host
->quirks2
|= SDHCI_QUIRK2_HOST_NO_CMD23
;
856 if (esdhc
->vendor_ver
> VENDOR_V_22
)
857 host
->quirks
&= ~SDHCI_QUIRK_NO_BUSY_IRQ
;
859 if (of_device_is_compatible(np
, "fsl,p5040-esdhc") ||
860 of_device_is_compatible(np
, "fsl,p5020-esdhc") ||
861 of_device_is_compatible(np
, "fsl,p4080-esdhc") ||
862 of_device_is_compatible(np
, "fsl,p1020-esdhc") ||
863 of_device_is_compatible(np
, "fsl,t1040-esdhc"))
864 host
->quirks
&= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION
;
866 if (of_device_is_compatible(np
, "fsl,ls1021a-esdhc"))
867 host
->quirks
|= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
;
869 if (of_device_is_compatible(np
, "fsl,p2020-esdhc")) {
871 * Freescale messed up with P2020 as it has a non-standard
872 * host control register
874 host
->quirks2
|= SDHCI_QUIRK2_BROKEN_HOST_CONTROL
;
877 /* call to generic mmc_of_parse to support additional capabilities */
878 ret
= mmc_of_parse(host
->mmc
);
882 mmc_of_parse_voltage(np
, &host
->ocr_mask
);
884 ret
= sdhci_add_host(host
);
890 sdhci_pltfm_free(pdev
);
894 static const struct of_device_id sdhci_esdhc_of_match
[] = {
895 { .compatible
= "fsl,mpc8379-esdhc" },
896 { .compatible
= "fsl,mpc8536-esdhc" },
897 { .compatible
= "fsl,esdhc" },
900 MODULE_DEVICE_TABLE(of
, sdhci_esdhc_of_match
);
902 static struct platform_driver sdhci_esdhc_driver
= {
904 .name
= "sdhci-esdhc",
905 .of_match_table
= sdhci_esdhc_of_match
,
906 .pm
= &esdhc_of_dev_pm_ops
,
908 .probe
= sdhci_esdhc_probe
,
909 .remove
= sdhci_pltfm_unregister
,
912 module_platform_driver(sdhci_esdhc_driver
);
914 MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
915 MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
916 "Anton Vorontsov <avorontsov@ru.mvista.com>");
917 MODULE_LICENSE("GPL v2");