Skip to content

Commit 45334ee

Browse files
Haibo Chenstorulf
authored andcommitted
mmc: sdhci-esdhc-imx: Select the correct mode for auto tuning
USDHC hardware auto tuning circuit support check 1/4/8 data lines and cmd line. Out of reset uSDHC, it default select check 4 data lines and do not check cmd line. This is incorrect if we use 8 data lines. So need to config the auto tuning mode according to current bus width. Signed-off-by: Haibo Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent a0dbbdc commit 45334ee

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

drivers/mmc/host/sdhci-esdhc-imx.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494

9595
#define ESDHC_VEND_SPEC2 0xc8
9696
#define ESDHC_VEND_SPEC2_EN_BUSY_IRQ (1 << 8)
97+
#define ESDHC_VEND_SPEC2_AUTO_TUNE_8BIT_EN (1 << 4)
98+
#define ESDHC_VEND_SPEC2_AUTO_TUNE_4BIT_EN (0 << 4)
99+
#define ESDHC_VEND_SPEC2_AUTO_TUNE_1BIT_EN (2 << 4)
100+
#define ESDHC_VEND_SPEC2_AUTO_TUNE_CMD_EN (1 << 6)
101+
#define ESDHC_VEND_SPEC2_AUTO_TUNE_MODE_MASK (7 << 4)
97102

98103
#define ESDHC_TUNING_CTRL 0xcc
99104
#define ESDHC_STD_TUNING_EN (1 << 24)
@@ -114,6 +119,7 @@
114119
#define ESDHC_CTRL_4BITBUS (0x1 << 1)
115120
#define ESDHC_CTRL_8BITBUS (0x2 << 1)
116121
#define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
122+
#define USDHC_GET_BUSWIDTH(c) (c & ESDHC_CTRL_BUSWIDTH_MASK)
117123

118124
/*
119125
* There is an INT DMA ERR mismatch between eSDHC and STD SDHC SPEC:
@@ -407,6 +413,30 @@ static inline void esdhc_wait_for_card_clock_gate_off(struct sdhci_host *host)
407413
dev_warn(mmc_dev(host->mmc), "%s: card clock still not gate off in 100us!.\n", __func__);
408414
}
409415

416+
/* Enable the auto tuning circuit to check the CMD line and BUS line */
417+
static inline void usdhc_auto_tuning_mode_sel(struct sdhci_host *host)
418+
{
419+
u32 buswidth, auto_tune_buswidth;
420+
421+
buswidth = USDHC_GET_BUSWIDTH(readl(host->ioaddr + SDHCI_HOST_CONTROL));
422+
423+
switch (buswidth) {
424+
case ESDHC_CTRL_8BITBUS:
425+
auto_tune_buswidth = ESDHC_VEND_SPEC2_AUTO_TUNE_8BIT_EN;
426+
break;
427+
case ESDHC_CTRL_4BITBUS:
428+
auto_tune_buswidth = ESDHC_VEND_SPEC2_AUTO_TUNE_4BIT_EN;
429+
break;
430+
default: /* 1BITBUS */
431+
auto_tune_buswidth = ESDHC_VEND_SPEC2_AUTO_TUNE_1BIT_EN;
432+
break;
433+
}
434+
435+
esdhc_clrset_le(host, ESDHC_VEND_SPEC2_AUTO_TUNE_MODE_MASK,
436+
auto_tune_buswidth | ESDHC_VEND_SPEC2_AUTO_TUNE_CMD_EN,
437+
ESDHC_VEND_SPEC2);
438+
}
439+
410440
static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
411441
{
412442
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -643,6 +673,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
643673
v |= ESDHC_MIX_CTRL_EXE_TUNE;
644674
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
645675
m |= ESDHC_MIX_CTRL_AUTO_TUNE_EN;
676+
usdhc_auto_tuning_mode_sel(host);
646677
} else {
647678
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
648679
}
@@ -1012,6 +1043,8 @@ static void esdhc_post_tuning(struct sdhci_host *host)
10121043
{
10131044
u32 reg;
10141045

1046+
usdhc_auto_tuning_mode_sel(host);
1047+
10151048
reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
10161049
reg &= ~ESDHC_MIX_CTRL_EXE_TUNE;
10171050
reg |= ESDHC_MIX_CTRL_AUTO_TUNE_EN;

0 commit comments

Comments
 (0)