Skip to contentSkip to conversation

mmc: sdhci: Fix the SD clock stop sequence

PATCH New Wenyou Yang 2 participants 2 messages Sep 22, 2015 – Nov 3, 2015 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc: sdhci: Fix the SD clock stop sequence

According to the SDHC specification, stopping the SD Clock is by setting the SD Clock Enable bit in the Clock Control register at 0, instead of setting all bits at 0.

Before stopping the SD clock, we need to make sure all SD transactions to complete, so add checking the CMD and DAT bits in the Presen State register, before stopping the SD clock.

---

Changes in v2:
- Add timeout to wait for the cmd & data inhibit bit

 drivers/mmc/sdhci.c |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/mmc/sdhci.c +18 -2
index d89e302..02d71b9 100644
@@ -286,9 +286,25 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
 static int sdhci_set_clock(struct mmc *mmc, unsigned int clock)
 {
 	struct sdhci_host *host = mmc->priv;
-	unsigned int div, clk, timeout;
+	unsigned int div, clk, timeout, reg;
 
-	sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
+	/* Wait max 20 ms */
+	timeout = 200;
+	while (sdhci_readl(host, SDHCI_PRESENT_STATE) &
+			   (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) {
+		if (timeout == 0) {
+			printf("%s: Timeout to wait cmd & data inhibit\n",
+			       __func__);
+			return -1;
+		}
+
+		timeout--;
+		udelay(100);
+	}
+
+	reg = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	reg &= ~SDHCI_CLOCK_CARD_EN;
+	sdhci_writew(host, reg, SDHCI_CLOCK_CONTROL);
 
 	if (clock == 0)
 		return 0;
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/1 mmc: sdhci: Fix the SD clock stop sequence

Dear Wenyou Yang,

Quoted 8 lines · Wenyou Yang

According to the SDHC specification, stopping the SD Clock is by setting the SD Clock Enable bit in the Clock Control register at 0, instead of setting all bits at 0.

Before stopping the SD clock, we need to make sure all SD transactions to complete, so add checking the CMD and DAT bits in the Presen State register, before stopping the SD clock.

Quoted 8 lines

---

Changes in v2:
- Add timeout to wait for the cmd & data inhibit bit

drivers/mmc/sdhci.c | 20 ++++++++++++++++++--

1 file changed, 18 insertions(+), 2 deletions(-)

applied to u-boot-atmel/master, thanks!

Best regards,
Andreas Bie?mann