Skip to contentSkip to conversation

mmc: sdhci-sprd: Wait until DLL locked after being configured

PATCH Superseded Chunyan Zhang 2 participants 2 messages Sep 23, 2021 – Sep 24, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chunyan Zhang

author reviewer
#0 lore raw

PATCH 1/1 mmc: sdhci-sprd: Wait until DLL locked after being configured

From: Zhenxiong Lai <[email protected]>

According to the specification, DLL status has to be locked before using it.

---
 drivers/mmc/host/sdhci-sprd.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-sprd.c +19 -1
index 11e375579cfb..83749c7a6db4 100644
@@ -39,6 +39,9 @@
 #define  SDHCI_SPRD_BIT_POSRD_DLY_INV		BIT(21)
 #define  SDHCI_SPRD_BIT_NEGRD_DLY_INV		BIT(29)
 
+#define SDHCI_SPRD_REG_32_DLL_STS0	0x210
+#define SDHCI_SPRD_DLL_LOCKED		BIT(18)
+
 #define SDHCI_SPRD_REG_32_BUSY_POSI		0x250
 #define  SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN	BIT(25)
 #define  SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN	BIT(24)
@@ -236,7 +239,7 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
 
 static void sdhci_sprd_enable_phy_dll(struct sdhci_host *host)
 {
-	u32 tmp;
+	u32 tmp, timeout = 1000;
 
 	tmp = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG);
 	tmp &= ~(SDHCI_SPRD_DLL_EN | SDHCI_SPRD_DLL_ALL_CPST_EN);
@@ -256,6 +259,21 @@ static void sdhci_sprd_enable_phy_dll(struct sdhci_host *host)
 	sdhci_writel(host, tmp, SDHCI_SPRD_REG_32_DLL_CFG);
 	/* wait 1ms */
 	usleep_range(1000, 1250);
+
+	while (--timeout) {
+		if ((sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_STS0) &
+		     SDHCI_SPRD_DLL_LOCKED))
+			break;
+		usleep_range(1000, 1250);
+	}
+
+	if (!timeout) {
+		pr_err("%s: DLL locked fail!\n", mmc_hostname(host->mmc));
+		pr_info("%s: DLL_STS0 : 0x%x, DLL_CFG : 0x%x\n",
+			 mmc_hostname(host->mmc),
+			 sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_STS0),
+			 sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG));
+	}
 }
 
 static void sdhci_sprd_set_clock(struct sdhci_host *host, unsigned int clock)
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 36 lines · Chunyan Zhang

From: Zhenxiong Lai <[email protected]>

According to the specification, DLL status has to be locked before using it.

---
 drivers/mmc/host/sdhci-sprd.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-sprd.c +4 -1
index 11e375579cfb..83749c7a6db4 100644
@@ -39,6 +39,9 @@
 #define  SDHCI_SPRD_BIT_POSRD_DLY_INV		BIT(21)
 #define  SDHCI_SPRD_BIT_NEGRD_DLY_INV		BIT(29)
 
+#define SDHCI_SPRD_REG_32_DLL_STS0	0x210
+#define SDHCI_SPRD_DLL_LOCKED		BIT(18)
+
 #define SDHCI_SPRD_REG_32_BUSY_POSI		0x250
 #define  SDHCI_SPRD_BIT_OUTR_CLK_AUTO_EN	BIT(25)
 #define  SDHCI_SPRD_BIT_INNR_CLK_AUTO_EN	BIT(24)
@@ -236,7 +239,7 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host,
 
 static void sdhci_sprd_enable_phy_dll(struct sdhci_host *host)
 {
-	u32 tmp;
+	u32 tmp, timeout = 1000;
 
 	tmp = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG);
 	tmp &= ~(SDHCI_SPRD_DLL_EN | SDHCI_SPRD_DLL_ALL_CPST_EN);
@@ -256,6 +259,21 @@ static void sdhci_sprd_enable_phy_dll(struct sdhci_host *host)
 	sdhci_writel(host, tmp, SDHCI_SPRD_REG_32_DLL_CFG);
 	/* wait 1ms */

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_enable_phy_dll(struct sdhci_host *host) · line 270

Quoted 10 lines
drivers/mmc/host/sdhci-sprd.c +9 -0
 	usleep_range(1000, 1250);
+
+	while (--timeout) {
+		if ((sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_STS0) &
+		     SDHCI_SPRD_DLL_LOCKED))
+			break;
+		usleep_range(1000, 1250);
+	}
+
+	if (!timeout) {

This could use read_poll_timeout() instead e.g.

	if (read_poll_timeout(sdhci_readl, tmp, (tmp & SDHCI_SPRD_DLL_LOCKED),
	    2000, USEC_PER_SEC, false, host, SDHCI_SPRD_REG_32_DLL_STS0)) {
Quoted 10 lines
drivers/mmc/host/sdhci-sprd.c +6 -0
+		pr_err("%s: DLL locked fail!\n", mmc_hostname(host->mmc));
+		pr_info("%s: DLL_STS0 : 0x%x, DLL_CFG : 0x%x\n",
+			 mmc_hostname(host->mmc),
+			 sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_STS0),
+			 sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG));
+	}
 }
 
 static void sdhci_sprd_set_clock(struct sdhci_host *host, unsigned int clock)