Skip to contentSkip to conversation

clk: stm32f: fix setting of division factor for LCD_CLK

PATCH In review Dario Binacchi 2 participants 6 messages Nov 11, 2023 – Dec 15, 2023

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

PATCH 1/2 clk: stm32f: fix setting of division factor for LCD_CLK

The value to be written to the register must be appropriately shifted, as is correctly done in other parts of the code.

Fixes 5e993508cb25 ("clk: clk_stm32f: Add set_rate for LTDC clock")

---

 drivers/clk/stm32/clk-stm32f.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/stm32/clk-stm32f.c +2 -1
index ed7660196ef0..4c1864193357 100644
@@ -530,7 +530,8 @@ static ulong stm32_set_rate(struct clk *clk, ulong rate)
 			/* set pll_saidivr with found value */
 			clrsetbits_le32(&regs->dckcfgr,
 					RCC_DCKCFGR_PLLSAIDIVR_MASK,
-					pllsaidivr_table[i]);
+					pllsaidivr_table[i] <<
+					RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
 			return rate;
 		}
 
Signature · 1 line
2.42.0
#1 lore raw

PATCH 2/2 clk: stm32f: fix setting of LCD clock

Set pllsaidivr only if the PLLSAIR output frequency is an exact multiple of the pixel clock rate. Otherwise, we search through all combinations of pllsaidivr * pllsair and use the one which gives the rate closest to requested one.

Fixes 5e993508cb25 ("clk: clk_stm32f: Add set_rate for LTDC clock")

---

 drivers/clk/stm32/clk-stm32f.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/clk/stm32/clk-stm32f.c +14 -12
index 4c1864193357..d68c75ed2013 100644
@@ -522,18 +522,20 @@ static ulong stm32_set_rate(struct clk *clk, ulong rate)
 
 	/* get the current PLLSAIR output freq */
 	pllsair_rate = stm32_clk_get_pllsai_rate(priv, PLLSAIR);
-	best_div = pllsair_rate / rate;
-
-	/* look into pllsaidivr_table if this divider is available*/
-	for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
-		if (best_div == pllsaidivr_table[i]) {
-			/* set pll_saidivr with found value */
-			clrsetbits_le32(&regs->dckcfgr,
-					RCC_DCKCFGR_PLLSAIDIVR_MASK,
-					pllsaidivr_table[i] <<
-					RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
-			return rate;
-		}
+	if ((pllsair_rate % rate) == 0) {
+		best_div = pllsair_rate / rate;
+
+		/* look into pllsaidivr_table if this divider is available */
+		for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
+			if (best_div == pllsaidivr_table[i]) {
+				/* set pll_saidivr with found value */
+				clrsetbits_le32(&regs->dckcfgr,
+						RCC_DCKCFGR_PLLSAIDIVR_MASK,
+						pllsaidivr_table[i] <<
+						RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
+				return rate;
+			}
+	}
 
 	/*
 	 * As no pllsaidivr value is suitable to obtain requested freq,
Signature · 1 line
2.42.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] clk: stm32f: fix setting of LCD clock

Quoted 40 lines · Dario Binacchi

Set pllsaidivr only if the PLLSAIR output frequency is an exact multiple of the pixel clock rate. Otherwise, we search through all combinations of pllsaidivr * pllsair and use the one which gives the rate closest to requested one.

Fixes 5e993508cb25 ("clk: clk_stm32f: Add set_rate for LTDC clock")

---

 drivers/clk/stm32/clk-stm32f.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/clk/stm32/clk-stm32f.c +7 -12
index 4c1864193357..d68c75ed2013 100644
@@ -522,18 +522,20 @@ static ulong stm32_set_rate(struct clk *clk, ulong rate)
 
 	/* get the current PLLSAIR output freq */
 	pllsair_rate = stm32_clk_get_pllsai_rate(priv, PLLSAIR);
-	best_div = pllsair_rate / rate;
-
-	/* look into pllsaidivr_table if this divider is available*/
-	for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
-		if (best_div == pllsaidivr_table[i]) {
-			/* set pll_saidivr with found value */
-			clrsetbits_le32(&regs->dckcfgr,
-					RCC_DCKCFGR_PLLSAIDIVR_MASK,
-					pllsaidivr_table[i] <<
-					RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
-			return rate;
-		}
+	if ((pllsair_rate % rate) == 0) {
+		best_div = pllsair_rate / rate;
+
+		/* look into pllsaidivr_table if this divider is available */
+		for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
+			if (best_div == pllsaidivr_table[i]) {
+				/* set pll_saidivr with found value */

drivers/clk/stm32/clk-stm32f.c static ulong stm32_set_rate(struct clk *clk, ulong rate) · line 541

Quoted 10 lines
drivers/clk/stm32/clk-stm32f.c +7 -0
+				clrsetbits_le32(&regs->dckcfgr,
+						RCC_DCKCFGR_PLLSAIDIVR_MASK,
+						pllsaidivr_table[i] <<
+						RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
+				return rate;
+			}
+	}
 
 	/*
 	 * As no pllsaidivr value is suitable to obtain requested freq,

Thanks
Patrice

#3 lore raw

Re: [PATCH 2/2] clk: stm32f: fix setting of LCD clock

In reply to Dario Binacchi
Quoted 40 lines · Dario Binacchi

Set pllsaidivr only if the PLLSAIR output frequency is an exact multiple of the pixel clock rate. Otherwise, we search through all combinations of pllsaidivr * pllsair and use the one which gives the rate closest to requested one.

Fixes 5e993508cb25 ("clk: clk_stm32f: Add set_rate for LTDC clock")

---

 drivers/clk/stm32/clk-stm32f.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/clk/stm32/clk-stm32f.c +7 -12
index 4c1864193357..d68c75ed2013 100644
@@ -522,18 +522,20 @@ static ulong stm32_set_rate(struct clk *clk, ulong rate)
 
 	/* get the current PLLSAIR output freq */
 	pllsair_rate = stm32_clk_get_pllsai_rate(priv, PLLSAIR);
-	best_div = pllsair_rate / rate;
-
-	/* look into pllsaidivr_table if this divider is available*/
-	for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
-		if (best_div == pllsaidivr_table[i]) {
-			/* set pll_saidivr with found value */
-			clrsetbits_le32(&regs->dckcfgr,
-					RCC_DCKCFGR_PLLSAIDIVR_MASK,
-					pllsaidivr_table[i] <<
-					RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
-			return rate;
-		}
+	if ((pllsair_rate % rate) == 0) {
+		best_div = pllsair_rate / rate;
+
+		/* look into pllsaidivr_table if this divider is available */
+		for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
+			if (best_div == pllsaidivr_table[i]) {
+				/* set pll_saidivr with found value */

drivers/clk/stm32/clk-stm32f.c static ulong stm32_set_rate(struct clk *clk, ulong rate) · line 541

Quoted 10 lines
drivers/clk/stm32/clk-stm32f.c +7 -0
+				clrsetbits_le32(&regs->dckcfgr,
+						RCC_DCKCFGR_PLLSAIDIVR_MASK,
+						pllsaidivr_table[i] <<
+						RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
+				return rate;
+			}
+	}
 
 	/*
 	 * As no pllsaidivr value is suitable to obtain requested freq,

Applied to u-boot-stm32/next

Thanks
Patrice

Reviewed-by on v1 1/2
#4 lore raw
In reply to Dario Binacchi
Quoted 15 lines · Dario Binacchi

The value to be written to the register must be appropriately shifted, as is correctly done in other parts of the code.

Fixes 5e993508cb25 ("clk: clk_stm32f: Add set_rate for LTDC clock")

---

 drivers/clk/stm32/clk-stm32f.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/stm32/clk-stm32f.c +0 -0
index ed7660196ef0..4c1864193357 100644

drivers/clk/stm32/clk-stm32f.c static ulong stm32_set_rate(struct clk *clk, ulong rate) · line 537

Quoted 9 lines
drivers/clk/stm32/clk-stm32f.c +2 -1
@@ -530,7 +530,8 @@ static ulong stm32_set_rate(struct clk *clk, ulong rate)
 			/* set pll_saidivr with found value */
 			clrsetbits_le32(&regs->dckcfgr,
 					RCC_DCKCFGR_PLLSAIDIVR_MASK,
-					pllsaidivr_table[i]);
+					pllsaidivr_table[i] <<
+					RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
 			return rate;
 		}
 

Thanks
Patrice

#5 lore raw
In reply to Dario Binacchi
Quoted 15 lines · Dario Binacchi

The value to be written to the register must be appropriately shifted, as is correctly done in other parts of the code.

Fixes 5e993508cb25 ("clk: clk_stm32f: Add set_rate for LTDC clock")

---

 drivers/clk/stm32/clk-stm32f.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/stm32/clk-stm32f.c +0 -0
index ed7660196ef0..4c1864193357 100644

drivers/clk/stm32/clk-stm32f.c static ulong stm32_set_rate(struct clk *clk, ulong rate) · line 537

Quoted 9 lines
drivers/clk/stm32/clk-stm32f.c +2 -1
@@ -530,7 +530,8 @@ static ulong stm32_set_rate(struct clk *clk, ulong rate)
 			/* set pll_saidivr with found value */
 			clrsetbits_le32(&regs->dckcfgr,
 					RCC_DCKCFGR_PLLSAIDIVR_MASK,
-					pllsaidivr_table[i]);
+					pllsaidivr_table[i] <<
+					RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
 			return rate;
 		}
 

Applied to u-boot-stm32/next

Thanks
Patrice