Skip to contentSkip to conversation

sunxi: clk/mmc: Fix T113-s3 MMC performance

PATCH In review Andre Przywara 4 participants 9 messages Feb 26, 2025 – Feb 27, 2025

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

cover sunxi: clk/mmc: Fix T113-s3 MMC performance

Hi,

as Kuba reported, the MMC performance of the Allwinner T113-s3 chips in mainline Linux is only half of what's expected. Checking that in U-Boot revealed that's actually only one fourth there, since on top of the same bug as in the kernel, we also calculate the base PLL frequency wrongly.

Fix that by halving the frequency as reported by the clock function, and apply an extra divider of two in the MMC code - to compensate for that missing hidden divider (which is the same bug as in Linux). Seeing only one fourth of the base frequency makes the calculated internal divider go up by the factor of 4, so we get the MMC performance back its expected levels: from around 5.8 MB/s to ~23 MB/s.

Cheers,
Andre

Andre Przywara (2):
sunxi: mmc: Fix T113-s3 MMC clock divider
sunxi: sun50i_h6: clock: fix PLL_PERIPH0 rate calculation

 arch/arm/mach-sunxi/clock_sun50i_h6.c | 15 ++++++++++-----
 drivers/mmc/sunxi_mmc.c               |  7 +++++++
 2 files changed, 17 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 sunxi: mmc: Fix T113-s3 MMC clock divider

On the Allwinner D1/R528/T113-s3 SoCs the MMC clock source selected by mux value 1 is PLL_PERIPH0(1x), not (2x), as in the other SoCs. But we have still the hidden divisor of 2 in the MMC mod clock, so need to explicitly compensate for that on those SoCs.

This leads to the actually programmed clock rate to be double compared to before, which increases the MMC performance on those SoCs.

---
 drivers/mmc/sunxi_mmc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/sunxi_mmc.c +7 -0
index 0b56d1405be..8f72d758e46 100644
@@ -92,6 +92,13 @@ static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz)
 		pll = CCM_MMC_CTRL_PLL6;
 		pll_hz = clock_get_pll6();
 #endif
+		/*
+		 * On the D1/R528/T113 mux source 1 refers to PLL_PERIPH0(1x),
+		 * like for the older SoCs. However we still have the hidden
+		 * divider of 2x, so compensate for that here.
+		 */
+		if (IS_ENABLED(CONFIG_MACH_SUN8I_R528))
+			pll_hz /= 2;
 	}
 
 	div = pll_hz / hz;
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

Dne sreda, 26. februar 2025 ob 12:37:11 Srednjeevropski standardni čas je Andre Przywara napisal(a):

Quoted 10 lines

On the Allwinner D1/R528/T113-s3 SoCs the MMC clock source selected by mux value 1 is PLL_PERIPH0(1x), not (2x), as in the other SoCs. But we have still the hidden divisor of 2 in the MMC mod clock, so need to explicitly compensate for that on those SoCs.

This leads to the actually programmed clock rate to be double compared to before, which increases the MMC performance on those SoCs.

Best regards,
Jernej

#3 lore raw

RE: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

In reply to Andre Przywara

Hi Andre,

Quoted 32 lines

Subject: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

On the Allwinner D1/R528/T113-s3 SoCs the MMC clock source selected by mux value 1 is PLL_PERIPH0(1x), not (2x), as in the other SoCs.
But we have still the hidden divisor of 2 in the MMC mod clock, so need to explicitly compensate for that on those SoCs.

This leads to the actually programmed clock rate to be double compared to before, which increases the MMC performance on those SoCs.

---
 drivers/mmc/sunxi_mmc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/sunxi_mmc.c +3 -0
index 0b56d1405be..8f72d758e46 100644
@@ -92,6 +92,13 @@ static int mmc_set_mod_clk(struct
 sunxi_mmc_priv *priv, unsigned int hz)
 		pll = CCM_MMC_CTRL_PLL6;
 		pll_hz = clock_get_pll6();
 #endif
+		/*
+		 * On the D1/R528/T113 mux source 1 refers to
 PLL_PERIPH0(1x),
+		 * like for the older SoCs. However we still have the

hidden

drivers/mmc/sunxi_mmc.c static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz) · line 100

Quoted 3 lines
drivers/mmc/sunxi_mmc.c +3 -0
+		 * divider of 2x, so compensate for that here.
+		 */
+		if (IS_ENABLED(CONFIG_MACH_SUN8I_R528))

Use CONFIG_IS_ENABLED(MACH_SUN8I_R528)?

Regards,
Peng.

Quoted 6 lines
drivers/mmc/sunxi_mmc.c +1 -1
+			pll_hz /= 2;
 	}
 
 	div = pll_hz / hz;
--

2.25.1

#4 lore raw

Re: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

Quoted 31 lines · Peng Fan

Hi Andre,

Quoted 29 lines

Subject: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

On the Allwinner D1/R528/T113-s3 SoCs the MMC clock source selected by mux value 1 is PLL_PERIPH0(1x), not (2x), as in the other SoCs.
But we have still the hidden divisor of 2 in the MMC mod clock, so need to explicitly compensate for that on those SoCs.

This leads to the actually programmed clock rate to be double compared to before, which increases the MMC performance on those SoCs.

---
 drivers/mmc/sunxi_mmc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/sunxi_mmc.c +2 -0
index 0b56d1405be..8f72d758e46 100644
@@ -92,6 +92,13 @@ static int mmc_set_mod_clk(struct
 sunxi_mmc_priv *priv, unsigned int hz)
 		pll = CCM_MMC_CTRL_PLL6;
 		pll_hz = clock_get_pll6();
 #endif
+		/*
+		 * On the D1/R528/T113 mux source 1 refers to
Quoted 8 lines

drivers/mmc/sunxi_mmc.c static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz) · line 100

Quoted 6 lines
drivers/mmc/sunxi_mmc.c +1 -0
 PLL_PERIPH0(1x),
+		 * like for the older SoCs. However we still have the

hidden

drivers/mmc/sunxi_mmc.c +3 -0
+		 * divider of 2x, so compensate for that here.
+		 */
+		if (IS_ENABLED(CONFIG_MACH_SUN8I_R528))

Use CONFIG_IS_ENABLED(MACH_SUN8I_R528)?

No, either is fine, IS_ENABLED(CONFIG_FOO) is less confusing for the case where there's never a CONFIG_xPL_FOO.

Signature · 1 line
Tom
Reviewed-by
#5 lore raw

RE: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

Quoted 46 lines

Subject: Re: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

Quoted 5 lines · Peng Fan

Hi Andre,

Quoted 3 lines

Subject: [PATCH 1/2] sunxi: mmc: Fix T113-s3 MMC clock divider

On the Allwinner D1/R528/T113-s3 SoCs the MMC clock source

selected

Quoted 6 lines
Quoted 6 lines

by mux value 1 is PLL_PERIPH0(1x), not (2x), as in the other SoCs. But we have still the hidden divisor of 2 in the MMC mod clock, so need to explicitly compensate for that on those SoCs.

This leads to the actually programmed clock rate to be double compared to before, which increases the MMC performance on

those

Quoted 9 lines

drivers/mmc/sunxi_mmc.c

Quoted 9 lines

SoCs.

---
 drivers/mmc/sunxi_mmc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/sunxi_mmc.c +0 -0

index

Quoted 4 lines

drivers/mmc/sunxi_mmc.c static int mmc_set_mod_clk(struct

Quoted 4 lines

0b56d1405be..8f72d758e46 100644

drivers/mmc/sunxi_mmc.c +0 -0
@@ -92,6 +92,13 @@ static int mmc_set_mod_clk(struct

sunxi_mmc_priv

Quoted 6 lines
Quoted 6 lines
drivers/mmc/sunxi_mmc.c +2 -0
 *priv, unsigned int hz)
 		pll = CCM_MMC_CTRL_PLL6;
 		pll_hz = clock_get_pll6();
 #endif
+		/*
+		 * On the D1/R528/T113 mux source 1 refers to
Quoted 8 lines

drivers/mmc/sunxi_mmc.c static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz) · line 100

Quoted 6 lines
drivers/mmc/sunxi_mmc.c +1 -0
 PLL_PERIPH0(1x),
+		 * like for the older SoCs. However we still have the

hidden

drivers/mmc/sunxi_mmc.c +3 -0
+		 * divider of 2x, so compensate for that here.
+		 */
+		if (IS_ENABLED(CONFIG_MACH_SUN8I_R528))

Use CONFIG_IS_ENABLED(MACH_SUN8I_R528)?

Quoted 2 lines

No, either is fine, IS_ENABLED(CONFIG_FOO) is less confusing for the case where there's never a CONFIG_xPL_FOO.

I see.

Quoted 3 lines

--
Tom

#6 lore raw

PATCH 2/2 sunxi: sun50i_h6: clock: fix PLL_PERIPH0 rate calculation

In reply to Andre Przywara

On the Allwinner D1/R528/T113-s3 SoCs (NCAT2) the factors encoded in the PLL register describe the doubled clock rate, as in the other SoCs.

Correct for that by always dividing the calculated rate by 2, except on the H6, where we need a divisor of 4 (no change here).

This corrects the PERIPH0 clock rate as read by the MMC driver, and actually doubles the MMC performance on those NCAT2 chips.

---
 arch/arm/mach-sunxi/clock_sun50i_h6.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm/mach-sunxi/clock_sun50i_h6.c +10 -5
index b424a7893ea..359513d1669 100644
@@ -147,15 +147,20 @@ unsigned int clock_get_pll6(void)
 	if (IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2)) {
 		div1 = ((rval & CCM_PLL6_CTRL_P0_MASK) >>
 			CCM_PLL6_CTRL_P0_SHIFT) + 1;
-		m = 1;
 	} else {
 		div1 = ((rval & CCM_PLL6_CTRL_DIV1_MASK) >>
 			CCM_PLL6_CTRL_DIV1_SHIFT) + 1;
-		if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
-			m = 4;
-		else
-			m = 2;
 	}
 
+	/*
+	 * The factors encoded in the register describe the doubled clock
+	 * frequency, expect for the H6, where it's the quadrupled frequency.
+	 * Compensate for that here.
+	 */
+	if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
+		m = 4;
+	else
+		m = 2;
+
 	return 24000000U * n / m / div1 / div2;
 }
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] sunxi: sun50i_h6: clock: fix PLL_PERIPH0 rate calculation

Dne sreda, 26. februar 2025 ob 12:37:12 Srednjeevropski standardni čas je Andre Przywara napisal(a):

Quoted 11 lines

On the Allwinner D1/R528/T113-s3 SoCs (NCAT2) the factors encoded in the PLL register describe the doubled clock rate, as in the other SoCs.

Correct for that by always dividing the calculated rate by 2, except on the H6, where we need a divisor of 4 (no change here).

This corrects the PERIPH0 clock rate as read by the MMC driver, and actually doubles the MMC performance on those NCAT2 chips.

Best regards,
Jernej

Reviewed-by on v1 2/2
#8 lore raw

RE: [PATCH 2/2] sunxi: sun50i_h6: clock: fix PLL_PERIPH0 rate calculation

In reply to Andre Przywara
Quoted 42 lines

Subject: [PATCH 2/2] sunxi: sun50i_h6: clock: fix PLL_PERIPH0 rate calculation

On the Allwinner D1/R528/T113-s3 SoCs (NCAT2) the factors encoded in the PLL register describe the doubled clock rate, as in the other SoCs.

Correct for that by always dividing the calculated rate by 2, except on the H6, where we need a divisor of 4 (no change here).

This corrects the PERIPH0 clock rate as read by the MMC driver, and actually doubles the MMC performance on those NCAT2 chips.

---
 arch/arm/mach-sunxi/clock_sun50i_h6.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm/mach- renamed from arch/arm/mach-sunxi/clock_sun50i_h6.c +0 -0

sunxi/clock_sun50i_h6.c
index b424a7893ea..359513d1669 100644

arch/arm/mach-sunxi/clock_sun50i_h6.c +2 -5
@@ -147,15 +147,20 @@ unsigned int clock_get_pll6(void)
 	if (IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2)) {
 		div1 = ((rval & CCM_PLL6_CTRL_P0_MASK) >>
 			CCM_PLL6_CTRL_P0_SHIFT) + 1;
-		m = 1;
 	} else {
 		div1 = ((rval & CCM_PLL6_CTRL_DIV1_MASK) >>
 			CCM_PLL6_CTRL_DIV1_SHIFT) + 1;
-		if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
-			m = 4;
-		else
-			m = 2;
 	}
 
+	/*
+	 * The factors encoded in the register describe the doubled

clock

arch/arm/mach-sunxi/clock_sun50i_h6.c +1 -0
+	 * frequency, expect for the H6, where it's the quadrupled

frequency.

arch/arm/mach-sunxi/clock_sun50i_h6.c unsigned int clock_get_pll6(void) · line 164

Quoted 7 lines
arch/arm/mach-sunxi/clock_sun50i_h6.c +7 -0
+	 * Compensate for that here.
+	 */
+	if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
+		m = 4;
+	else
+		m = 2;
+

Nit: not sure you need CONFIG_IS_ENABLED or not.

Regards
Peng

Quoted 3 lines

return 24000000U * n / m / div1 / div2; }
--
2.25.1