Skip to contentSkip to conversation

mmc: sdhci-esdhc: clean up register definitions

PATCH Applied Yangbo Lu 3 participants 10 messages Dec 26, 2016 – Jan 17, 2017

Subsystems (2)
lore
Share & tools
lore

Yangbo Lu

author
#0 lore raw

PATCH v2 1/2 mmc: sdhci-esdhc: clean up register definitions

The eSDHC register definitions in header file were messy and confusing. This patch is to clean up these definitions.

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +20 -19
index de132e2..8cd8449 100644
@@ -24,30 +24,31 @@
 				SDHCI_QUIRK_PIO_NEEDS_DELAY | \
 				SDHCI_QUIRK_NO_HISPD_BIT)
 
-#define ESDHC_PROCTL		0x28
-
-#define ESDHC_SYSTEM_CONTROL	0x2c
-#define ESDHC_CLOCK_MASK	0x0000fff0
-#define ESDHC_PREDIV_SHIFT	8
-#define ESDHC_DIVIDER_SHIFT	4
-#define ESDHC_CLOCK_PEREN	0x00000004
-#define ESDHC_CLOCK_HCKEN	0x00000002
-#define ESDHC_CLOCK_IPGEN	0x00000001
-
 /* pltfm-specific */
 #define ESDHC_HOST_CONTROL_LE	0x20
 
 /*
- * P2020 interpretation of the SDHCI_HOST_CONTROL register
+ * eSDHC register definition
  */
-#define ESDHC_CTRL_4BITBUS          (0x1 << 1)
-#define ESDHC_CTRL_8BITBUS          (0x2 << 1)
-#define ESDHC_CTRL_BUSWIDTH_MASK    (0x3 << 1)
-
-/* OF-specific */
-#define ESDHC_DMA_SYSCTL	0x40c
-#define ESDHC_DMA_SNOOP		0x00000040
 
-#define ESDHC_HOST_CONTROL_RES	0x01
+/* Protocol Control Register */
+#define ESDHC_PROCTL			0x28
+#define ESDHC_CTRL_4BITBUS		(0x1 << 1)
+#define ESDHC_CTRL_8BITBUS		(0x2 << 1)
+#define ESDHC_CTRL_BUSWIDTH_MASK	(0x3 << 1)
+#define ESDHC_HOST_CONTROL_RES		0x01
+
+/* System Control Register */
+#define ESDHC_SYSTEM_CONTROL		0x2c
+#define ESDHC_CLOCK_MASK		0x0000fff0
+#define ESDHC_PREDIV_SHIFT		8
+#define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_PEREN		0x00000004
+#define ESDHC_CLOCK_HCKEN		0x00000002
+#define ESDHC_CLOCK_IPGEN		0x00000001
+
+/* Control Register for DMA transfer */
+#define ESDHC_DMA_SYSCTL		0x40c
+#define ESDHC_DMA_SNOOP			0x00000040
 
 #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
Signature · 1 line
2.1.0.27.g96db324
author
#1 lore raw

PATCH v2 2/2 mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

The eSDHC_PRSSTAT[SDSTB] bit indicates whether the internal card clock is stable. This bit is for the host driver to poll clock status when changing the clock frequency. It is recommended to clear eSDHC_SYSCTL[SDCLKEN] to remove glitch on the card clock when the frequency is changing. This patch is to disable SDCLKEN bit before changing frequency and enable it after SDSTB bit is set.

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h    |  5 +++++
 drivers/mmc/host/sdhci-of-esdhc.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +5 -0
index 8cd8449..ece8b37 100644
@@ -31,6 +31,10 @@
  * eSDHC register definition
  */
 
+/* Present State Register */
+#define ESDHC_PRSSTAT			0x24
+#define ESDHC_CLOCK_STABLE		0x00000008
+
 /* Protocol Control Register */
 #define ESDHC_PROCTL			0x28
 #define ESDHC_CTRL_4BITBUS		(0x1 << 1)
@@ -43,6 +47,7 @@
 #define ESDHC_CLOCK_MASK		0x0000fff0
 #define ESDHC_PREDIV_SHIFT		8
 #define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_SDCLKEN		0x00000008
 #define ESDHC_CLOCK_PEREN		0x00000004
 #define ESDHC_CLOCK_HCKEN		0x00000002
 #define ESDHC_CLOCK_IPGEN		0x00000001
drivers/mmc/host/sdhci-of-esdhc.c +18 -3
index 9a6eb44..0849885 100644
@@ -431,6 +431,7 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 	struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
 	int pre_div = 1;
 	int div = 1;
+	u32 timeout;
 	u32 temp;
 
 	host->mmc->actual_clock = 0;
@@ -451,8 +452,8 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 	}
 
 	temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-	temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-		| ESDHC_CLOCK_MASK);
+	temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN |
+		  ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 
 	while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
@@ -472,7 +473,21 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 		| (div << ESDHC_DIVIDER_SHIFT)
 		| (pre_div << ESDHC_PREDIV_SHIFT));
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-	mdelay(1);
+
+	/* Wait max 20 ms */
+	timeout = 20;
+	while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
+		if (timeout == 0) {
+			pr_err("%s: Internal clock never stabilised.\n",
+				mmc_hostname(host->mmc));
+			return;
+		}
+		timeout--;
+		mdelay(1);
+	}
+
+	temp |= ESDHC_CLOCK_SDCLKEN;
+	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 }
 
 static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
Signature · 1 line
2.1.0.27.g96db324
maintainer
#2 lore raw

Re: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

Quoted 69 lines · Yangbo Lu

The eSDHC_PRSSTAT[SDSTB] bit indicates whether the internal card clock is stable. This bit is for the host driver to poll clock status when changing the clock frequency. It is recommended to clear eSDHC_SYSCTL[SDCLKEN] to remove glitch on the card clock when the frequency is changing. This patch is to disable SDCLKEN bit before changing frequency and enable it after SDSTB bit is set.

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h    |  5 +++++
 drivers/mmc/host/sdhci-of-esdhc.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +5 -0
index 8cd8449..ece8b37 100644
@@ -31,6 +31,10 @@
  * eSDHC register definition
  */
 
+/* Present State Register */
+#define ESDHC_PRSSTAT			0x24
+#define ESDHC_CLOCK_STABLE		0x00000008
+
 /* Protocol Control Register */
 #define ESDHC_PROCTL			0x28
 #define ESDHC_CTRL_4BITBUS		(0x1 << 1)
@@ -43,6 +47,7 @@
 #define ESDHC_CLOCK_MASK		0x0000fff0
 #define ESDHC_PREDIV_SHIFT		8
 #define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_SDCLKEN		0x00000008
 #define ESDHC_CLOCK_PEREN		0x00000004
 #define ESDHC_CLOCK_HCKEN		0x00000002
 #define ESDHC_CLOCK_IPGEN		0x00000001
drivers/mmc/host/sdhci-of-esdhc.c +5 -3
index 9a6eb44..0849885 100644
@@ -431,6 +431,7 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 	struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
 	int pre_div = 1;
 	int div = 1;
+	u32 timeout;
 	u32 temp;
 
 	host->mmc->actual_clock = 0;
@@ -451,8 +452,8 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 	}
 
 	temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-	temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-		| ESDHC_CLOCK_MASK);
+	temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN |
+		  ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 
 	while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
@@ -472,7 +473,21 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 		| (div << ESDHC_DIVIDER_SHIFT)
 		| (pre_div << ESDHC_PREDIV_SHIFT));
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-	mdelay(1);
+
+	/* Wait max 20 ms */

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) · line 487

Quoted 10 lines
drivers/mmc/host/sdhci-of-esdhc.c +10 -0
+	timeout = 20;
+	while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
+		if (timeout == 0) {
+			pr_err("%s: Internal clock never stabilised.\n",
+				mmc_hostname(host->mmc));
+			return;
+		}
+		timeout--;
+		mdelay(1);
+	}

Please try to do this with readx_poll_timeout_atomic(). However we are not racing with anything (and one of the things that needs doing in SDHCI is to reduce the use of the spin lock) so you could drop the spin lock while using readx_poll_timeout() instead.

Quoted 7 lines
drivers/mmc/host/sdhci-of-esdhc.c +3 -0
+
+	temp |= ESDHC_CLOCK_SDCLKEN;
+	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 }
 
 static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
author
#3 lore raw

RE: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

Hi Adrian,

Thanks a lot for reviewing my patches.
Please see my comments inline.

Best regards,
Yangbo Lu

Quoted 90 lines

-----Original Message-----
From: Adrian Hunter [mailto:[email protected]]
Sent: Thursday, January 12, 2017 3:09 PM
To: Y.B. Lu; [email protected]; [email protected]
Subject: Re: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host

Quoted 45 lines · Yangbo Lu

The eSDHC_PRSSTAT[SDSTB] bit indicates whether the internal card clock is stable. This bit is for the host driver to poll clock status when changing the clock frequency. It is recommended to clear eSDHC_SYSCTL[SDCLKEN] to remove glitch on the card clock when the frequency is changing. This patch is to disable SDCLKEN bit before changing frequency and enable it after SDSTB bit is set.

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h    |  5 +++++
 drivers/mmc/host/sdhci-of-esdhc.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/mmc/host/sdhci-esdhc.h index 8cd8449..ece8b37 100644

drivers/mmc/host/sdhci-esdhc.h +5 -0
@@ -31,6 +31,10 @@
  * eSDHC register definition
  */
 
+/* Present State Register */
+#define ESDHC_PRSSTAT			0x24
+#define ESDHC_CLOCK_STABLE		0x00000008
+
 /* Protocol Control Register */
 #define ESDHC_PROCTL			0x28
 #define ESDHC_CTRL_4BITBUS		(0x1 << 1)
@@ -43,6 +47,7 @@
 #define ESDHC_CLOCK_MASK		0x0000fff0
 #define ESDHC_PREDIV_SHIFT		8
 #define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_SDCLKEN		0x00000008
 #define ESDHC_CLOCK_PEREN		0x00000004
 #define ESDHC_CLOCK_HCKEN		0x00000002
 #define ESDHC_CLOCK_IPGEN		0x00000001
drivers/mmc/host/sdhci-of-esdhc.c +0 -0
index 9a6eb44..0849885 100644
@@ -431,6 +431,7 @@ static void esdhc_of_set_clock(struct sdhci_host

*host, unsigned int clock)

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host

Quoted 8 lines
drivers/mmc/host/sdhci-of-esdhc.c +1 -0
 	struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
 	int pre_div = 1;
 	int div = 1;
+	u32 timeout;
 	u32 temp;
 
 	host->mmc->actual_clock = 0;
@@ -451,8 +452,8 @@ static void esdhc_of_set_clock(struct sdhci_host

*host, unsigned int clock)

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)

Quoted 6 lines
drivers/mmc/host/sdhci-of-esdhc.c +1 -2
 	}
 
 	temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-	temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-		| ESDHC_CLOCK_MASK);
+	temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN |

ESDHC_CLOCK_HCKEN |

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)

Quoted 5 lines
drivers/mmc/host/sdhci-of-esdhc.c +1 -1
+		  ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 
 	while (host->max_clk / pre_div / 16 > clock && pre_div < 256) @@
-472,7 +473,21 @@ static void esdhc_of_set_clock(struct sdhci_host

*host, unsigned int clock)

Quoted 14 lines
drivers/mmc/host/sdhci-of-esdhc.c +10 -1
 		| (div << ESDHC_DIVIDER_SHIFT)
 		| (pre_div << ESDHC_PREDIV_SHIFT));
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-	mdelay(1);
+
+	/* Wait max 20 ms */
+	timeout = 20;
+	while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
+		if (timeout == 0) {
+			pr_err("%s: Internal clock never stabilised.\n",
+				mmc_hostname(host->mmc));
+			return;
+		}
+		timeout--;
Quoted 9 lines

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) · line 487

Quoted 2 lines
drivers/mmc/host/sdhci-of-esdhc.c +2 -0
+		mdelay(1);
+	}

Please try to do this with readx_poll_timeout_atomic(). However we are not racing with anything (and one of the things that needs doing in SDHCI is to reduce the use of the spin lock) so you could drop the spin lock while using
readx_poll_timeout() instead.

[Lu Yangbo-B47093] The function readx_poll_timeout_atomic() periodically polls an address, but the addr must be the only argument for op. Our sdhci_readl has two arguments. Any suggestion for this?

readx_poll_timeout_atomic(op, addr, val, cond, delay_us, timeout_us)

Thanks :)

Quoted 8 lines
Quoted 8 lines
drivers/mmc/host/sdhci-of-esdhc.c +3 -0
+
+	temp |= ESDHC_CLOCK_SDCLKEN;
+	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 }
 
 static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int

width)

maintainer
#4 lore raw

Re: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

Quoted 108 lines · Y.B. Lu

Hi Adrian,

Thanks a lot for reviewing my patches.
Please see my comments inline.

Best regards,
Yangbo Lu

Quoted 90 lines

-----Original Message-----
From: Adrian Hunter [mailto:[email protected]]
Sent: Thursday, January 12, 2017 3:09 PM
To: Y.B. Lu; [email protected]; [email protected]
Subject: Re: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host

Quoted 45 lines · Yangbo Lu

The eSDHC_PRSSTAT[SDSTB] bit indicates whether the internal card clock is stable. This bit is for the host driver to poll clock status when changing the clock frequency. It is recommended to clear eSDHC_SYSCTL[SDCLKEN] to remove glitch on the card clock when the frequency is changing. This patch is to disable SDCLKEN bit before changing frequency and enable it after SDSTB bit is set.

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h    |  5 +++++
 drivers/mmc/host/sdhci-of-esdhc.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/mmc/host/sdhci-esdhc.h index 8cd8449..ece8b37 100644

drivers/mmc/host/sdhci-esdhc.h +5 -0
@@ -31,6 +31,10 @@
  * eSDHC register definition
  */
 
+/* Present State Register */
+#define ESDHC_PRSSTAT			0x24
+#define ESDHC_CLOCK_STABLE		0x00000008
+
 /* Protocol Control Register */
 #define ESDHC_PROCTL			0x28
 #define ESDHC_CTRL_4BITBUS		(0x1 << 1)
@@ -43,6 +47,7 @@
 #define ESDHC_CLOCK_MASK		0x0000fff0
 #define ESDHC_PREDIV_SHIFT		8
 #define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_SDCLKEN		0x00000008
 #define ESDHC_CLOCK_PEREN		0x00000004
 #define ESDHC_CLOCK_HCKEN		0x00000002
 #define ESDHC_CLOCK_IPGEN		0x00000001
drivers/mmc/host/sdhci-of-esdhc.c +0 -0
index 9a6eb44..0849885 100644
@@ -431,6 +431,7 @@ static void esdhc_of_set_clock(struct sdhci_host

*host, unsigned int clock)

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host

Quoted 8 lines
drivers/mmc/host/sdhci-of-esdhc.c +1 -0
 	struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
 	int pre_div = 1;
 	int div = 1;
+	u32 timeout;
 	u32 temp;
 
 	host->mmc->actual_clock = 0;
@@ -451,8 +452,8 @@ static void esdhc_of_set_clock(struct sdhci_host

*host, unsigned int clock)

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)

Quoted 6 lines
drivers/mmc/host/sdhci-of-esdhc.c +1 -2
 	}
 
 	temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-	temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-		| ESDHC_CLOCK_MASK);
+	temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN |

ESDHC_CLOCK_HCKEN |

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)

Quoted 5 lines
drivers/mmc/host/sdhci-of-esdhc.c +1 -1
+		  ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 
 	while (host->max_clk / pre_div / 16 > clock && pre_div < 256) @@
-472,7 +473,21 @@ static void esdhc_of_set_clock(struct sdhci_host

*host, unsigned int clock)

Quoted 14 lines
drivers/mmc/host/sdhci-of-esdhc.c +10 -1
 		| (div << ESDHC_DIVIDER_SHIFT)
 		| (pre_div << ESDHC_PREDIV_SHIFT));
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-	mdelay(1);
+
+	/* Wait max 20 ms */
+	timeout = 20;
+	while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
+		if (timeout == 0) {
+			pr_err("%s: Internal clock never stabilised.\n",
+				mmc_hostname(host->mmc));
+			return;
+		}
+		timeout--;
Quoted 9 lines

drivers/mmc/host/sdhci-of-esdhc.c static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) · line 487

Quoted 2 lines
drivers/mmc/host/sdhci-of-esdhc.c +2 -0
+		mdelay(1);
+	}

Please try to do this with readx_poll_timeout_atomic(). However we are not racing with anything (and one of the things that needs doing in SDHCI is to reduce the use of the spin lock) so you could drop the spin lock while using
readx_poll_timeout() instead.

Quoted 4 lines

[Lu Yangbo-B47093] The function readx_poll_timeout_atomic() periodically polls an address, but the addr must be the only argument for op. Our sdhci_readl has two arguments. Any suggestion for this?

readx_poll_timeout_atomic(op, addr, val, cond, delay_us, timeout_us)

Yeah, I forgot about that, sorry.

maintainer Acked-by on v2 2/2
#5 lore raw

Re: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

In reply to Yangbo Lu
Quoted 8 lines · Yangbo Lu

The eSDHC_PRSSTAT[SDSTB] bit indicates whether the internal card clock is stable. This bit is for the host driver to poll clock status when changing the clock frequency. It is recommended to clear eSDHC_SYSCTL[SDCLKEN] to remove glitch on the card clock when the frequency is changing. This patch is to disable SDCLKEN bit before changing frequency and enable it after SDSTB bit is set.

Quoted 78 lines

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h    |  5 +++++
 drivers/mmc/host/sdhci-of-esdhc.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +5 -0
index 8cd8449..ece8b37 100644
@@ -31,6 +31,10 @@
  * eSDHC register definition
  */
 
+/* Present State Register */
+#define ESDHC_PRSSTAT			0x24
+#define ESDHC_CLOCK_STABLE		0x00000008
+
 /* Protocol Control Register */
 #define ESDHC_PROCTL			0x28
 #define ESDHC_CTRL_4BITBUS		(0x1 << 1)
@@ -43,6 +47,7 @@
 #define ESDHC_CLOCK_MASK		0x0000fff0
 #define ESDHC_PREDIV_SHIFT		8
 #define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_SDCLKEN		0x00000008
 #define ESDHC_CLOCK_PEREN		0x00000004
 #define ESDHC_CLOCK_HCKEN		0x00000002
 #define ESDHC_CLOCK_IPGEN		0x00000001
drivers/mmc/host/sdhci-of-esdhc.c +18 -3
index 9a6eb44..0849885 100644
@@ -431,6 +431,7 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 	struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
 	int pre_div = 1;
 	int div = 1;
+	u32 timeout;
 	u32 temp;
 
 	host->mmc->actual_clock = 0;
@@ -451,8 +452,8 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 	}
 
 	temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-	temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-		| ESDHC_CLOCK_MASK);
+	temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN |
+		  ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 
 	while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
@@ -472,7 +473,21 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 		| (div << ESDHC_DIVIDER_SHIFT)
 		| (pre_div << ESDHC_PREDIV_SHIFT));
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-	mdelay(1);
+
+	/* Wait max 20 ms */
+	timeout = 20;
+	while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
+		if (timeout == 0) {
+			pr_err("%s: Internal clock never stabilised.\n",
+				mmc_hostname(host->mmc));
+			return;
+		}
+		timeout--;
+		mdelay(1);
+	}
+
+	temp |= ESDHC_CLOCK_SDCLKEN;
+	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 }
 
 static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
Applied
#6 lore raw

Re: [v2, 2/2] mmc: sdhci-of-esdhc: avoid clock glitch when frequency is changing

In reply to Yangbo Lu
Quoted 8 lines · Yangbo Lu

The eSDHC_PRSSTAT[SDSTB] bit indicates whether the internal card clock is stable. This bit is for the host driver to poll clock status when changing the clock frequency. It is recommended to clear eSDHC_SYSCTL[SDCLKEN] to remove glitch on the card clock when the frequency is changing. This patch is to disable SDCLKEN bit before changing frequency and enable it after SDSTB bit is set.

Thanks, applied for next!

Kind regards
Uffe

Quoted 80 lines

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h    |  5 +++++
 drivers/mmc/host/sdhci-of-esdhc.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +5 -0
index 8cd8449..ece8b37 100644
@@ -31,6 +31,10 @@
  * eSDHC register definition
  */
 
+/* Present State Register */
+#define ESDHC_PRSSTAT                  0x24
+#define ESDHC_CLOCK_STABLE             0x00000008
+
 /* Protocol Control Register */
 #define ESDHC_PROCTL                   0x28
 #define ESDHC_CTRL_4BITBUS             (0x1 << 1)
@@ -43,6 +47,7 @@
 #define ESDHC_CLOCK_MASK               0x0000fff0
 #define ESDHC_PREDIV_SHIFT             8
 #define ESDHC_DIVIDER_SHIFT            4
+#define ESDHC_CLOCK_SDCLKEN            0x00000008
 #define ESDHC_CLOCK_PEREN              0x00000004
 #define ESDHC_CLOCK_HCKEN              0x00000002
 #define ESDHC_CLOCK_IPGEN              0x00000001
drivers/mmc/host/sdhci-of-esdhc.c +18 -4
index 9a6eb44..0849885 100644
@@ -431,6 +431,7 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
        struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
        int pre_div = 1;
        int div = 1;
+       u32 timeout;
        u32 temp;
 
        host->mmc->actual_clock = 0;
@@ -451,8 +452,8 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
        }
 
        temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-       temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-               | ESDHC_CLOCK_MASK);
+       temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN |
+                 ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
        sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 
        while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
@@ -472,7 +473,21 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
                | (div << ESDHC_DIVIDER_SHIFT)
                | (pre_div << ESDHC_PREDIV_SHIFT));
        sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-       mdelay(1);
+
+       /* Wait max 20 ms */
+       timeout = 20;
+       while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
+               if (timeout == 0) {
+                       pr_err("%s: Internal clock never stabilised.\n",
+                               mmc_hostname(host->mmc));
+                       return;
+               }
+               timeout--;
+               mdelay(1);
+       }
+
+       temp |= ESDHC_CLOCK_SDCLKEN;
+       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
 }
 
 static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
--

2.1.0.27.g96db324

author
#7 lore raw
In reply to Yangbo Lu

Hi Adrian and Uffe,

Could you give comments on these two patches?
Thank you very much. :)

Best regards,
Yangbo Lu

Quoted 76 lines

-----Original Message-----
From: Yangbo Lu [mailto:[email protected]]
Sent: Monday, December 26, 2016 5:46 PM
To: [email protected]; [email protected]; Adrian Hunter
Cc: Y.B. Lu
Subject: [v2, 1/2] mmc: sdhci-esdhc: clean up register definitions

The eSDHC register definitions in header file were messy and confusing. This patch is to clean up these definitions.

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h | 39 ++++++++++++++++++++----------------
---
 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/mmc/host/sdhci- renamed from drivers/mmc/host/sdhci-esdhc.h +0 -0

esdhc.h index de132e2..8cd8449 100644

drivers/mmc/host/sdhci-esdhc.h +20 -20
@@ -24,30 +24,31 @@
 				SDHCI_QUIRK_PIO_NEEDS_DELAY | \
 				SDHCI_QUIRK_NO_HISPD_BIT)
 
-#define ESDHC_PROCTL		0x28
-
-#define ESDHC_SYSTEM_CONTROL	0x2c
-#define ESDHC_CLOCK_MASK	0x0000fff0
-#define ESDHC_PREDIV_SHIFT	8
-#define ESDHC_DIVIDER_SHIFT	4
-#define ESDHC_CLOCK_PEREN	0x00000004
-#define ESDHC_CLOCK_HCKEN	0x00000002
-#define ESDHC_CLOCK_IPGEN	0x00000001
-
 /* pltfm-specific */
 #define ESDHC_HOST_CONTROL_LE	0x20
 
 /*
- * P2020 interpretation of the SDHCI_HOST_CONTROL register
+ * eSDHC register definition
  */
-#define ESDHC_CTRL_4BITBUS          (0x1 << 1)
-#define ESDHC_CTRL_8BITBUS          (0x2 << 1)
-#define ESDHC_CTRL_BUSWIDTH_MASK    (0x3 << 1)
-
-/* OF-specific */
-#define ESDHC_DMA_SYSCTL	0x40c
-#define ESDHC_DMA_SNOOP		0x00000040
 
-#define ESDHC_HOST_CONTROL_RES	0x01
+/* Protocol Control Register */
+#define ESDHC_PROCTL			0x28
+#define ESDHC_CTRL_4BITBUS		(0x1 << 1)
+#define ESDHC_CTRL_8BITBUS		(0x2 << 1)
+#define ESDHC_CTRL_BUSWIDTH_MASK	(0x3 << 1)
+#define ESDHC_HOST_CONTROL_RES		0x01
+
+/* System Control Register */
+#define ESDHC_SYSTEM_CONTROL		0x2c
+#define ESDHC_CLOCK_MASK		0x0000fff0
+#define ESDHC_PREDIV_SHIFT		8
+#define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_PEREN		0x00000004
+#define ESDHC_CLOCK_HCKEN		0x00000002
+#define ESDHC_CLOCK_IPGEN		0x00000001
+
+/* Control Register for DMA transfer */
+#define ESDHC_DMA_SYSCTL		0x40c
+#define ESDHC_DMA_SNOOP			0x00000040
 
 #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
--

2.1.0.27.g96db324

maintainer Acked-by on v2 1/2
#8 lore raw
In reply to Yangbo Lu
Quoted 4 lines · Yangbo Lu

The eSDHC register definitions in header file were messy and confusing. This patch is to clean up these definitions.

Quoted 63 lines

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +20 -19
index de132e2..8cd8449 100644
@@ -24,30 +24,31 @@
 				SDHCI_QUIRK_PIO_NEEDS_DELAY | \
 				SDHCI_QUIRK_NO_HISPD_BIT)
 
-#define ESDHC_PROCTL		0x28
-
-#define ESDHC_SYSTEM_CONTROL	0x2c
-#define ESDHC_CLOCK_MASK	0x0000fff0
-#define ESDHC_PREDIV_SHIFT	8
-#define ESDHC_DIVIDER_SHIFT	4
-#define ESDHC_CLOCK_PEREN	0x00000004
-#define ESDHC_CLOCK_HCKEN	0x00000002
-#define ESDHC_CLOCK_IPGEN	0x00000001
-
 /* pltfm-specific */
 #define ESDHC_HOST_CONTROL_LE	0x20
 
 /*
- * P2020 interpretation of the SDHCI_HOST_CONTROL register
+ * eSDHC register definition
  */
-#define ESDHC_CTRL_4BITBUS          (0x1 << 1)
-#define ESDHC_CTRL_8BITBUS          (0x2 << 1)
-#define ESDHC_CTRL_BUSWIDTH_MASK    (0x3 << 1)
-
-/* OF-specific */
-#define ESDHC_DMA_SYSCTL	0x40c
-#define ESDHC_DMA_SNOOP		0x00000040
 
-#define ESDHC_HOST_CONTROL_RES	0x01
+/* Protocol Control Register */
+#define ESDHC_PROCTL			0x28
+#define ESDHC_CTRL_4BITBUS		(0x1 << 1)
+#define ESDHC_CTRL_8BITBUS		(0x2 << 1)
+#define ESDHC_CTRL_BUSWIDTH_MASK	(0x3 << 1)
+#define ESDHC_HOST_CONTROL_RES		0x01
+
+/* System Control Register */
+#define ESDHC_SYSTEM_CONTROL		0x2c
+#define ESDHC_CLOCK_MASK		0x0000fff0
+#define ESDHC_PREDIV_SHIFT		8
+#define ESDHC_DIVIDER_SHIFT		4
+#define ESDHC_CLOCK_PEREN		0x00000004
+#define ESDHC_CLOCK_HCKEN		0x00000002
+#define ESDHC_CLOCK_IPGEN		0x00000001
+
+/* Control Register for DMA transfer */
+#define ESDHC_DMA_SYSCTL		0x40c
+#define ESDHC_DMA_SNOOP			0x00000040
 
 #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
Applied
#9 lore raw
In reply to Yangbo Lu
Quoted 4 lines · Yangbo Lu

The eSDHC register definitions in header file were messy and confusing. This patch is to clean up these definitions.

Thanks, applied for next!

Kind regards
Uffe

Quoted 65 lines

---
Changes for v2:
- added Adrian into to list

---
 drivers/mmc/host/sdhci-esdhc.h | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/mmc/host/sdhci-esdhc.h +20 -20
index de132e2..8cd8449 100644
@@ -24,30 +24,31 @@
                                SDHCI_QUIRK_PIO_NEEDS_DELAY | \
                                SDHCI_QUIRK_NO_HISPD_BIT)
 
-#define ESDHC_PROCTL           0x28
-
-#define ESDHC_SYSTEM_CONTROL   0x2c
-#define ESDHC_CLOCK_MASK       0x0000fff0
-#define ESDHC_PREDIV_SHIFT     8
-#define ESDHC_DIVIDER_SHIFT    4
-#define ESDHC_CLOCK_PEREN      0x00000004
-#define ESDHC_CLOCK_HCKEN      0x00000002
-#define ESDHC_CLOCK_IPGEN      0x00000001
-
 /* pltfm-specific */
 #define ESDHC_HOST_CONTROL_LE  0x20
 
 /*
- * P2020 interpretation of the SDHCI_HOST_CONTROL register
+ * eSDHC register definition
  */
-#define ESDHC_CTRL_4BITBUS          (0x1 << 1)
-#define ESDHC_CTRL_8BITBUS          (0x2 << 1)
-#define ESDHC_CTRL_BUSWIDTH_MASK    (0x3 << 1)
-
-/* OF-specific */
-#define ESDHC_DMA_SYSCTL       0x40c
-#define ESDHC_DMA_SNOOP                0x00000040
 
-#define ESDHC_HOST_CONTROL_RES 0x01
+/* Protocol Control Register */
+#define ESDHC_PROCTL                   0x28
+#define ESDHC_CTRL_4BITBUS             (0x1 << 1)
+#define ESDHC_CTRL_8BITBUS             (0x2 << 1)
+#define ESDHC_CTRL_BUSWIDTH_MASK       (0x3 << 1)
+#define ESDHC_HOST_CONTROL_RES         0x01
+
+/* System Control Register */
+#define ESDHC_SYSTEM_CONTROL           0x2c
+#define ESDHC_CLOCK_MASK               0x0000fff0
+#define ESDHC_PREDIV_SHIFT             8
+#define ESDHC_DIVIDER_SHIFT            4
+#define ESDHC_CLOCK_PEREN              0x00000004
+#define ESDHC_CLOCK_HCKEN              0x00000002
+#define ESDHC_CLOCK_IPGEN              0x00000001
+
+/* Control Register for DMA transfer */
+#define ESDHC_DMA_SYSCTL               0x40c
+#define ESDHC_DMA_SNOOP                        0x00000040
 
 #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
--

2.1.0.27.g96db324