Skip to contentSkip to conversation

sunxi: Fix pll1 clock calculation

PATCH New Stefan Mavrodiev 2 participants 4 messages Jul 31, 2019 – Oct 16, 2019

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

PATCH 1/1 sunxi: Fix pll1 clock calculation

clock_sun6i.c is used for sun6i, sun8i and sun50i SoC families. PLL1 clock sets the default system clock, defined as:
sun6i: 1008000000
sun8i: 1008000000
sun50i: 816000000

With the current calculation, m = 2 and k = 3. Solving for n, this results 28. Solving back:
(24MHz * 28 * 3) / 2 = 1008MHz

However if the requested clock is 816, n is 22.66 rounded to 22, which results:
(24MHz * 28 * 3) / 2 = 792MHz

Changing k to 4 satisfies both system clocks:
(24E6 * 21 * 4) / 2 = 1008MHz
(24E6 * 17 * 4) / 2 = 816MHz

---
 arch/arm/mach-sunxi/clock_sun6i.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-sunxi/clock_sun6i.c +1 -1
index 1628f3a7b6..6ca38f73d9 100644
@@ -118,7 +118,7 @@ void clock_set_pll1(unsigned int clk)
 	if (clk > 1152000000) {
 		k = 2;
 	} else if (clk > 768000000) {
-		k = 3;
+		k = 4;
 		m = 2;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 sunxi: Fix pll1 clock calculation

Can someone review this patch?

Best regards,
Stefan

Quoted 36 lines · Stefan Mavrodiev

clock_sun6i.c is used for sun6i, sun8i and sun50i SoC families. PLL1 clock sets the default system clock, defined as:

   sun6i: 1008000000
   sun8i: 1008000000
   sun50i: 816000000

With the current calculation, m = 2 and k = 3. Solving for n, this results 28. Solving back:

   (24MHz * 28 * 3) / 2 = 1008MHz

However if the requested clock is 816, n is 22.66 rounded to 22, which results:

   (24MHz * 28 * 3) / 2 = 792MHz

Changing k to 4 satisfies both system clocks:

   (24E6 * 21 * 4) / 2 = 1008MHz
   (24E6 * 17 * 4) / 2 = 816MHz
---
  arch/arm/mach-sunxi/clock_sun6i.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-sunxi/clock_sun6i.c +1 -1
index 1628f3a7b6..6ca38f73d9 100644
@@ -118,7 +118,7 @@ void clock_set_pll1(unsigned int clk)
  	if (clk > 1152000000) {
  		k = 2;
  	} else if (clk > 768000000) {
-		k = 3;
+		k = 4;
  		m = 2;
  	}
 
#2 lore raw

PATCH 1/1 sunxi: Fix pll1 clock calculation

In reply to Stefan Mavrodiev
Quoted 15 lines · Stefan Mavrodiev

clock_sun6i.c is used for sun6i, sun8i and sun50i SoC families. PLL1 clock sets the default system clock, defined as:
sun6i: 1008000000
sun8i: 1008000000
sun50i: 816000000

With the current calculation, m = 2 and k = 3. Solving for n, this results 28. Solving back:
(24MHz * 28 * 3) / 2 = 1008MHz

However if the requested clock is 816, n is 22.66 rounded to 22, which results:
(24MHz * 28 * 3) / 2 = 792MHz

Quoted 6 lines

Changing k to 4 satisfies both system clocks:
(24E6 * 21 * 4) / 2 = 1008MHz
(24E6 * 17 * 4) / 2 = 816MHz

---

Need to test on respective sun boards, any results?

#3 lore raw

PATCH 1/1 sunxi: Fix pll1 clock calculation

Quoted 17 lines · Jagan Teki
Quoted 15 lines · Stefan Mavrodiev

clock_sun6i.c is used for sun6i, sun8i and sun50i SoC families. PLL1 clock sets the default system clock, defined as:
sun6i: 1008000000
sun8i: 1008000000
sun50i: 816000000

With the current calculation, m = 2 and k = 3. Solving for n, this results 28. Solving back:
(24MHz * 28 * 3) / 2 = 1008MHz

However if the requested clock is 816, n is 22.66 rounded to 22, which results:
(24MHz * 28 * 3) / 2 = 792MHz

Quoted 8 lines
Quoted 6 lines

Changing k to 4 satisfies both system clocks:
(24E6 * 21 * 4) / 2 = 1008MHz
(24E6 * 17 * 4) / 2 = 816MHz

---

Applied to u-boot-sunxi/master