Skip to contentSkip to conversation

mmc: sdhci: make sure SDHCI_CLOCK_CARD_EN bit sticks

PATCH In review Jean-Francois Dagenais 3 participants 3 messages Feb 19, 2020 – Mar 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc: sdhci: make sure SDHCI_CLOCK_CARD_EN bit sticks

Regardless of the broken-cd quirk, when it silently doesn't stick, no clock is applied to the bus lines, yet the code continues to try to make CMDs and times out after 10 seconds for each. This process can take up to a minute as mmc_rescan_try_freq tries the different commands to discover the card.

Short of changing sdhci_enable_clk's signature chain in all dependent drivers, at least provide a hint that this might be the problem. This will save tons of time for system integrators.

---
Changes in v2:
* removed redundant wmb()

---
 drivers/mmc/host/sdhci.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/mmc/host/sdhci.c +14 -0
index 63db84481dff..42a02d034fda 100644
@@ -1894,6 +1894,20 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
 
 	clk |= SDHCI_CLOCK_CARD_EN;
 	sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+	clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	if (clk & SDHCI_CLOCK_CARD_EN)
+		return;
+
+	/* The controller will clear this bit if card absent condition is
+	 * detected. If card is indeed present, check platform configuration for
+	 * how CD is reported to the SDHCI host controller. There may be an
+	 * "assume present" mechanism in the platform registers, or your pin mux
+	 * may be incorrect.
+	 */
+	pr_err("%s: SDHCI_CLOCK_CARD_EN bit did not stick. Card absent?\n",
+		mmc_hostname(host->mmc));
+	sdhci_dumpregs(host);
 }
 EXPORT_SYMBOL_GPL(sdhci_enable_clk);
 
Signature · 1 line
2.25.0
#1 lore raw
Quoted 7 lines · Jean-Francois Dagenais

Regardless of the broken-cd quirk, when it silently doesn't stick, no clock is applied to the bus lines, yet the code continues to try to make CMDs and times out after 10 seconds for each. This process can take up to a minute as mmc_rescan_try_freq tries the different commands to discover the card.

Quoted 5 lines

Short of changing sdhci_enable_clk's signature chain in all dependent drivers, at least provide a hint that this might be the problem. This will save tons of time for system integrators.

The change looks reasonable to me. However I would like to get an ack by Adrian before applying, as I may not have thought of all the consequences this change may have.

Kind regards
Uffe

Quoted 35 lines

---
Changes in v2:
* removed redundant wmb()

---
 drivers/mmc/host/sdhci.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/mmc/host/sdhci.c +14 -1
index 63db84481dff..42a02d034fda 100644
@@ -1894,6 +1894,20 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
 
        clk |= SDHCI_CLOCK_CARD_EN;
        sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       if (clk & SDHCI_CLOCK_CARD_EN)
+               return;
+
+       /* The controller will clear this bit if card absent condition is
+        * detected. If card is indeed present, check platform configuration for
+        * how CD is reported to the SDHCI host controller. There may be an
+        * "assume present" mechanism in the platform registers, or your pin mux
+        * may be incorrect.
+        */
+       pr_err("%s: SDHCI_CLOCK_CARD_EN bit did not stick. Card absent?\n",
+               mmc_hostname(host->mmc));
+       sdhci_dumpregs(host);
 }
 EXPORT_SYMBOL_GPL(sdhci_enable_clk);
 
--

2.25.0

maintainer
#2 lore raw
Quoted 36 lines · Ulf Hansson
Quoted 7 lines · Jean-Francois Dagenais

Regardless of the broken-cd quirk, when it silently doesn't stick, no clock is applied to the bus lines, yet the code continues to try to make CMDs and times out after 10 seconds for each. This process can take up to a minute as mmc_rescan_try_freq tries the different commands to discover the card.

Quoted 5 lines

Short of changing sdhci_enable_clk's signature chain in all dependent drivers, at least provide a hint that this might be the problem. This will save tons of time for system integrators.

The change looks reasonable to me. However I would like to get an ack by Adrian before applying, as I may not have thought of all the consequences this change may have.

Kind regards
Uffe

Quoted 13 lines

---
Changes in v2:
* removed redundant wmb()

---
 drivers/mmc/host/sdhci.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/mmc/host/sdhci.c +0 -0
index 63db84481dff..42a02d034fda 100644
@@ -1894,6 +1894,20 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
 
Quoted 8 lines

drivers/mmc/host/sdhci.c void sdhci_enable_clk(struct sdhci_host *host, u16 clk) · line 1902

Quoted 8 lines
drivers/mmc/host/sdhci.c +6 -0
        clk |= SDHCI_CLOCK_CARD_EN;
        sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+       if (clk & SDHCI_CLOCK_CARD_EN)
+               return;
+
+       /* The controller will clear this bit if card absent condition is

Please make the comment style consistent with the rest of sdhci.c e.g.

	/*
	 * The controller blah...
	 * blah ...
	 */
Quoted 8 lines

drivers/mmc/host/sdhci.c void sdhci_enable_clk(struct sdhci_host *host, u16 clk) · line 1910

Quoted 8 lines
drivers/mmc/host/sdhci.c +8 -0
+        * detected. If card is indeed present, check platform configuration for
+        * how CD is reported to the SDHCI host controller. There may be an
+        * "assume present" mechanism in the platform registers, or your pin mux
+        * may be incorrect.
+        */
+       pr_err("%s: SDHCI_CLOCK_CARD_EN bit did not stick. Card absent?\n",
+               mmc_hostname(host->mmc));
+       sdhci_dumpregs(host);

The error message is ok, but for some controllers this could happen normally if the card is removed suddenly, so let's not also do a register dump.

Quoted 6 lines
Quoted 6 lines
drivers/mmc/host/sdhci.c +0 -1
 }
 EXPORT_SYMBOL_GPL(sdhci_enable_clk);
 
--

2.25.0