Skip to contentSkip to conversation

mmc: fsl_esdhc_imx: use VENDORSPEC_FRC_SDCLK_ON when necessary

PATCH Superseded [email protected] 5 participants 12 messages Feb 11, 2022 – Jul 27, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 mmc: fsl_esdhc_imx: use VENDORSPEC_FRC_SDCLK_ON when necessary

From: Haibo Chen <[email protected]>

After commit f132aab40327 ("Revert "mmc: fsl_esdhc_imx: use VENDORSPEC_FRC_SDCLK_ON to control card clock output""), it involve issue in mmc_switch_voltage(), because of the special design of usdhc.

For FSL_USDHC, it do not implement VENDORSPEC_CKEN/PEREN/HCKEN/IPGEN, these are reserved bits(Though RM contain the definition of these bits, but actually internal IC logic do not implement, already confirm with IC team). Instead, use VENDORSPEC_FRC_SDCLK_ON to gate on/off the card clock output. Here is the definition of this bit in RM:

[8] FRC_SDCLK_ON
Force CLK output active
Do not set this bit to 1 unless it is necessary. Also, make sure that this bit is cleared when uSDHC’s clock is about to be changed (frequency change, clock source change, or delay chain tuning).
0b - CLK active or inactive is fully controlled by the hardware. 1b - Force CLK active

In default, the FRC_SDCLK_ON is 0. This means, when there is no command or data transfer on bus, hardware will gate off the card clock. But in some case, we need the card clock keep on. Take IO voltage 1.8v switch as example, after IO voltage change to 1.8v, spec require gate off the card clock for 5ms, and gate on the clock back, once detect the card clock on, then the card will draw the dat0 to high immediately. If there is not clock gate off/on behavior, some card will keep the dat0 to low level. This is the reason we fail in mmc_switch_voltage().

To fix this issue, and concern that this is only the fsl usdhc hardware design limitation, set the bit FRC_SDCLK_ON in the beginning of the wait_dat0() and clear it in the end. To make sure the 1.8v IO voltage switch process align with SD specification.

For standard tuning process, usdhc specification also require the card clock keep on, so also add these behavior in fsl_esdhc_execute_tuning().

---
 drivers/mmc/fsl_esdhc_imx.c | 19 ++++++++++++++++++-
 include/fsl_esdhc_imx.h     |  2 ++
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/mmc/fsl_esdhc_imx.c +18 -1
index 9299635f50..362e3e13b6 100644
@@ -832,12 +832,15 @@ static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
 	u32 irqstaten = esdhc_read32(&regs->irqstaten);
 	u32 irqsigen = esdhc_read32(&regs->irqsigen);
 	int i, ret = -ETIMEDOUT;
-	u32 val, mixctrl;
+	u32 val, mixctrl, tmp;
 
 	/* clock tuning is not needed for upto 52MHz */
 	if (mmc->clock <= 52000000)
 		return 0;
 
+	/* make sure the card clock keep on */
+	esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
+
 	/* This is readw/writew SDHCI_HOST_CONTROL2 when tuning */
 	if (priv->flags & ESDHC_FLAG_STD_TUNING) {
 		val = esdhc_read32(&regs->autoc12err);
@@ -897,6 +900,11 @@ static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
 
 	esdhc_stop_tuning(mmc);
 
+	/* change to default setting, let host control the card clock */
+	esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
+	if (readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100))
+		pr_warn("fsl_esdhc_imx: card clock not gate off as expect.\n");
+
 	return ret;
 }
 #endif
@@ -1560,9 +1568,18 @@ static int fsl_esdhc_wait_dat0(struct udevice *dev, int state,
 	struct fsl_esdhc_priv *priv = dev_get_priv(dev);
 	struct fsl_esdhc *regs = priv->esdhc_regs;
 
+	/* make sure the card clock keep on */
+	esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
+
 	ret = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp,
 				!!(tmp & PRSSTAT_DAT0) == !!state,
 				timeout_us);
+
+	/* change to default setting, let host control the card clock */
+	esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
+	if (readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100))
+		pr_warn("fsl_esdhc_imx: card clock not gate off as expect.\n");
+
 	return ret;
 }
 
include/fsl_esdhc_imx.h +2 -0
index 2153f29bef..b8efd2a166 100644
@@ -37,6 +37,7 @@
 #define VENDORSPEC_HCKEN	0x00001000
 #define VENDORSPEC_IPGEN	0x00000800
 #define VENDORSPEC_INIT		0x20007809
+#define VENDORSPEC_FRC_SDCLK_ON 0x00000100
 
 #define IRQSTAT			0x0002e030
 #define IRQSTAT_DMAE		(0x10000000)
@@ -94,6 +95,7 @@
 #define PRSSTAT_CINS		(0x00010000)
 #define PRSSTAT_BREN		(0x00000800)
 #define PRSSTAT_BWEN		(0x00000400)
+#define PRSSTAT_SDOFF		(0x00000080)
 #define PRSSTAT_SDSTB		(0X00000008)
 #define PRSSTAT_DLA		(0x00000004)
 #define PRSSTAT_CICHB		(0x00000002)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 mmc: fsl_esdhc_imx: remove redundant ARCH_MXC

From: Haibo Chen <[email protected]>

Now original fsl_esdhc.c are split as fsl_esdhc.c and fsl_esdhc_imx.c. fsl_esdhc_imx.c only cover i.MX SoC. So ARCH_MXC is redundant.

---
 drivers/mmc/fsl_esdhc_imx.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/mmc/fsl_esdhc_imx.c +3 -12
index 362e3e13b6..0be7cae1e5 100644
@@ -596,16 +596,12 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
 	int sdhc_clk = priv->sdhc_clk;
 	uint clk;
 
-	if (IS_ENABLED(ARCH_MXC)) {
 #if IS_ENABLED(CONFIG_MX53)
-		/* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
-		pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
+	/* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
+	pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
 #else
-		pre_div = 1;
+	pre_div = 1;
 #endif
-	} else {
-		pre_div = 2;
-	}
 
 	while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
 		pre_div *= 2;
@@ -1016,11 +1012,6 @@ static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
 		esdhc_write32(&regs->dllctrl, 0x0);
 	}
 
-#ifndef ARCH_MXC
-	/* Enable cache snooping */
-	esdhc_write32(&regs->scr, 0x00000040);
-#endif
-
 	if (IS_ENABLED(CONFIG_FSL_USDHC))
 		esdhc_setbits32(&regs->vendorspec,
 				VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
Signature · 1 line
2.17.1
#3 lore raw

PATCH 2/3 mmc: fsl_esdhc_imx: remove redundant ARCH_MXC

In reply to [email protected]
Quoted 5 lines

From: Haibo Chen <[email protected]>
Now original fsl_esdhc.c are split as fsl_esdhc.c and fsl_esdhc_imx.c. fsl_esdhc_imx.c only cover i.MX SoC. So ARCH_MXC is redundant.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
#4 lore raw

PATCH 3/3 mmc: fsl_esdhc_imx: correct the actual card clock

In reply to [email protected]

From: Haibo Chen <[email protected]>

The original code logic can not show the correct card clock, and also has one risk when the div is 0. Because there is div -=1 before.

So move the operation before div -=1, and also involve ddr_pre_div to get the correct value.

---
 drivers/mmc/fsl_esdhc_imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/fsl_esdhc_imx.c +2 -1
index 0be7cae1e5..0ea7b0b50c 100644
@@ -609,6 +609,8 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
 	while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
 		div++;
 
+	mmc->clock = sdhc_clk / pre_div / div / ddr_pre_div;
+
 	pre_div >>= 1;
 	div -= 1;
 
@@ -630,7 +632,6 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
 	else
 		esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
 
-	mmc->clock = sdhc_clk / pre_div / div;
 	priv->clock = clock;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 3/3
#5 lore raw

Re: [PATCH 3/3] mmc: fsl_esdhc_imx: correct the actual card clock

Quoted 7 lines · On 2/11/22 12:16, [email protected] wrote:

From: Haibo Chen <[email protected]>

The original code logic can not show the correct card clock, and also has one risk when the div is 0. Because there is div -=1 before.

So move the operation before div -=1, and also involve ddr_pre_div to get the correct value.

Thanks !

#6 lore raw

PATCH 3/3 mmc: fsl_esdhc_imx: correct the actual card clock

In reply to [email protected]
Quoted 7 lines

From: Haibo Chen <[email protected]>
The original code logic can not show the correct card clock, and also has one risk when the div is 0. Because there is div -=1 before. So move the operation before div -=1, and also involve ddr_pre_div to get the correct value.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
#7 lore raw

Re: [PATCH 3/3] mmc: fsl_esdhc_imx: correct the actual card clock

In reply to [email protected]
Quoted 36 lines · On Fri, Feb 11, 2022 at 3:48 AM <[email protected]> wrote:

From: Haibo Chen <[email protected]>

The original code logic can not show the correct card clock, and also has one risk when the div is 0. Because there is div -=1 before.

So move the operation before div -=1, and also involve ddr_pre_div to get the correct value.

---
 drivers/mmc/fsl_esdhc_imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/fsl_esdhc_imx.c +2 -2
index 0be7cae1e5..0ea7b0b50c 100644
@@ -609,6 +609,8 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
        while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
                div++;
 
+       mmc->clock = sdhc_clk / pre_div / div / ddr_pre_div;
+
        pre_div >>= 1;
        div -= 1;
 
@@ -630,7 +632,6 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
        else
                esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
 
-       mmc->clock = sdhc_clk / pre_div / div;
        priv->clock = clock;
 }
 
--
Quoted 2 lines

2.17.1

Haibo,

I found that this particular patch keeps an imx8mm-venice-gw7901 board that has a viking vwsdinbdg4 eMMC from booting to Linux. While u-boot appears to work ok, as soon as I load a kernel (from emmc or even network) and boot to it I hang at 'starting kernel' even with early debug turned on.

u-boot=> mmc list
FSL_SDHC: 0
FSL_SDHC: 1
FSL_SDHC: 2 (eMMC)
u-boot=> mmc dev 2
switch to partitions #0, OK
mmc2(part 0) is current device
u-boot=> mmc info
Device: FSL_SDHC
Manufacturer ID: 45
OEM: 0
Name: DG4008
Bus Speed: 200000000
Mode: HS400ES (200MHz)
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 7.3 GiB
Bus Width: 8-bit DDR
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 7.3 GiB WRREL
Boot Capacity: 4 MiB ENH
RPMB Capacity: 4 MiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

I have other boards with a Micron MTFC8GAKAJCN non HS400ES that don't have any issue so it appears to be something to do with HS400ES support and I find if I disable CONFIG_MMC_HS400_ES_SUPPORT or revert this patch the issue goes away.

Any idea what might be going on here?

Best Regards,

Tim

author
#8 lore raw

RE: [PATCH 3/3] mmc: fsl_esdhc_imx: correct the actual card clock

Quoted 91 lines

-----Original Message-----
From: Tim Harvey <[email protected]>
Sent: 2022年7月23日 10:23
To: Bough Chen <[email protected]>
Cc: Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; Fabio Estevam <[email protected]>; Sean Anderson <[email protected]>; u-boot <[email protected]>; Marek Vasut <[email protected]>; Adam Ford <[email protected]>; Andrey Zhizhikin <[email protected]>; dl-uboot-imx <[email protected]>
Subject: Re: [PATCH 3/3] mmc: fsl_esdhc_imx: correct the actual card clock

drivers/mmc/fsl_esdhc_imx.c static void set_sysctl(struct fsl_esdhc_priv *priv, struct

Quoted 19 lines · On Fri, Feb 11, 2022 at 3:48 AM <[email protected]> wrote:

From: Haibo Chen <[email protected]>

The original code logic can not show the correct card clock, and also has one risk when the div is 0. Because there is div -=1 before.

So move the operation before div -=1, and also involve ddr_pre_div to get the correct value.

---
 drivers/mmc/fsl_esdhc_imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/fsl_esdhc_imx.c +0 -0
index 0be7cae1e5..0ea7b0b50c 100644
@@ -609,6 +609,8 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct

mmc *mmc, uint clock)

drivers/mmc/fsl_esdhc_imx.c static void set_sysctl(struct fsl_esdhc_priv *priv, struct

Quoted 9 lines
drivers/mmc/fsl_esdhc_imx.c +2 -0
        while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
                div++;
 
+       mmc->clock = sdhc_clk / pre_div / div / ddr_pre_div;
+
        pre_div >>= 1;
        div -= 1;
 
@@ -630,7 +632,6 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct

mmc *mmc, uint clock)

Quoted 11 lines
drivers/mmc/fsl_esdhc_imx.c +0 -2
        else
                esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN |
 SYSCTL_CKEN);
 
-       mmc->clock = sdhc_clk / pre_div / div;
        priv->clock = clock;
 }
 
--

2.17.1

Haibo,

I found that this particular patch keeps an imx8mm-venice-gw7901 board that has a viking vwsdinbdg4 eMMC from booting to Linux. While u-boot appears to work ok, as soon as I load a kernel (from emmc or even
network) and boot to it I hang at 'starting kernel' even with early debug turned on.

u-boot=> mmc list
FSL_SDHC: 0
FSL_SDHC: 1
FSL_SDHC: 2 (eMMC)
u-boot=> mmc dev 2
switch to partitions #0, OK
mmc2(part 0) is current device
u-boot=> mmc info
Device: FSL_SDHC
Manufacturer ID: 45
OEM: 0
Name: DG4008
Bus Speed: 200000000
Mode: HS400ES (200MHz)
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 7.3 GiB
Bus Width: 8-bit DDR
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 7.3 GiB WRREL
Boot Capacity: 4 MiB ENH
RPMB Capacity: 4 MiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

Quoted 6 lines

I have other boards with a Micron MTFC8GAKAJCN non HS400ES that don't have any issue so it appears to be something to do with HS400ES support and I find if I disable CONFIG_MMC_HS400_ES_SUPPORT or revert this patch the issue goes away.

Any idea what might be going on here?

Hi Tim,

I think this should be related with the HS400ES downgrade miss. Before boot linux, uboot will do some cleanup, remove all devices. Call mmc_blk_remove-> mmc_deinit-> mmc_select_mode_and_width-> mmc_set_card_speed(mmc, MMC_HS, true);

Please make sure in your environment, finally call mmc_set_card_speed(mmc, MMC_HS, true); which means the HS400ES mode first downgrade to HS mode, then switch to legacy mode. Otherwise, emmc mode switch may meet issue. Some emmc may hang in somewhere, we did meet that before. To debug this, you can enable the debug info, and see the detail steps of mmc related. Not sure in your side, you miss some config which cause this issue.

For why this is related with the clock related patch, I think the wrong clock config happed workaround it.

Best Regards
Haibo Chen

Quoted 4 lines

Best Regards,

Tim

Reviewed-by on v1 1/3
#9 lore raw
In reply to [email protected]

On 2/11/22 12:16, [email protected] wrote:

Hi,

[...]

drivers/mmc/fsl_esdhc_imx.c static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode) · line 905

Quoted 7 lines
drivers/mmc/fsl_esdhc_imx.c +3 -0
@@ -897,6 +900,11 @@ static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
 
  	esdhc_stop_tuning(mmc);
 
+	/* change to default setting, let host control the card clock */
+	esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
+	if (readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100))

Please propagate the error in both cases:

ret = readx_poll..();
if (ret)
dev_warn(...);

return ret;

Review static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode) · line 906

Quoted 1 line
(quoted diff) +1 -0
+		pr_warn("fsl_esdhc_imx: card clock not gate off as expect.\n");

btw. s@gate@gated@ , s@expect@expected@ (past tense)

With those small details fixed:

author
#10 lore raw

Hi Fabio,

Can you help test these 3 patches on imx6qdl-pico board or imx7s board on your side to double check whether these patches enlarge the total boot time?

Best Regards
Bough Chen

Quoted 42 lines

-----Original Message-----
From: Marek Vasut [mailto:[email protected]]
Sent: 2022年2月14日 5:53
To: Bough Chen <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: dl-uboot-imx <[email protected]>
Subject: Re: [PATCH 1/3] mmc: fsl_esdhc_imx: use VENDORSPEC_FRC_SDCLK_ON when necessary

On 2/11/22 12:16, [email protected] wrote:

Hi,

[...]

Review static int fsl_esdhc_execute_tuning(struct udevice

Quoted 1 line
(quoted diff) +0 -0
@@ -897,6 +900,11 @@ static int fsl_esdhc_execute_tuning(struct udevice

*dev, uint32_t opcode)

drivers/mmc/fsl_esdhc_imx.c static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)

Quoted 6 lines
drivers/mmc/fsl_esdhc_imx.c +3 -0
  	esdhc_stop_tuning(mmc);
 
+	/* change to default setting, let host control the card clock */
+	esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
+	if (readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp &

PRSSTAT_SDOFF, 100))

Please propagate the error in both cases:

ret = readx_poll..();
if (ret)
dev_warn(...);

return ret;

Review static int fsl_esdhc_execute_tuning(struct udevice · line 905

Quoted 1 line
(quoted diff) +1 -0
+		pr_warn("fsl_esdhc_imx: card clock not gate off as expect.\n");

btw. s@gate@gated@ , s@expect@expected@ (past tense)

With those small details fixed:

reviewer Tested-by
#11 lore raw

Hi Bough,

Quoted 4 lines · Bough Chen

Hi Fabio,

Can you help test these 3 patches on imx6qdl-pico board or imx7s board on your side to double check whether these patches enlarge the total boot time?

I have tested the series on an imx7s-warp and the previous issue of slow boot is no longer present, thanks: