diff mbox series

clk: clk-nspire: Use a more complete algorithm for divider calculation

Message ID 5001083.BWDE7HjgcL@linux-e202.suse.de (mailing list archive)
State Under Review
Headers show
Series clk: clk-nspire: Use a more complete algorithm for divider calculation | expand

Commit Message

Fabian Vogt March 24, 2021, 2:37 p.m. UTC
For some reason it implemented a mixture of the fixed base and variable
base paths. Those actually differ, which led to a division by zero in some
cases.

Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/clk/clk-nspire.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/clk/clk-nspire.c b/drivers/clk/clk-nspire.c
index 6305058dd0d3..97bad9423960 100644
--- a/drivers/clk/clk-nspire.c
+++ b/drivers/clk/clk-nspire.c
@@ -27,7 +27,7 @@ 
 #define CX_BASE_SHIFT		15
 #define CX_BASE_MASK		0x3F
 
-#define CX_UNKNOWN_SHIFT	21
+#define CX_UNKNOWN_SHIFT	30
 #define CX_UNKNOWN_MASK		0x03
 
 struct nspire_clk_info {
@@ -40,13 +40,17 @@  struct nspire_clk_info {
 #define EXTRACT(var, prop) (((var)>>prop##_SHIFT) & prop##_MASK)
 static void nspire_clkinfo_cx(u32 val, struct nspire_clk_info *clk)
 {
-	if (EXTRACT(val, FIXED_BASE))
+	if (EXTRACT(val, FIXED_BASE)) {
 		clk->base_clock = 48 * MHZ;
-	else
+		clk->base_cpu_ratio = 1 << EXTRACT(val, CX_UNKNOWN);
+		clk->base_ahb_ratio = clk->base_cpu_ratio * 2;
+	} else {
 		clk->base_clock = 6 * EXTRACT(val, CX_BASE) * MHZ;
-
-	clk->base_cpu_ratio = EXTRACT(val, BASE_CPU) * EXTRACT(val, CX_UNKNOWN);
-	clk->base_ahb_ratio = clk->base_cpu_ratio * (EXTRACT(val, CPU_AHB) + 1);
+		clk->base_cpu_ratio = 2;
+		if (EXTRACT(val, BASE_CPU))
+			clk->base_cpu_ratio = EXTRACT(val, BASE_CPU) * 2;
+		clk->base_ahb_ratio = clk->base_cpu_ratio * (EXTRACT(val, CPU_AHB) + 1);
+	}
 }
 
 static void nspire_clkinfo_classic(u32 val, struct nspire_clk_info *clk)