[PATCH v3 2/4] clk: ti: fapll: Fix clock speed calculation

From: Ettore Chimenti

Date: Fri Nov 13 2026 - 19:19:34 EST


From: Andrew Goodbody <andrew.goodbody@xxxxxxxxxx>

The fractional part of the divider was being treated as 1/10000000
whereas it is in fact 1/2^24 (1/16777216). This led to incorrect clock
speeds being reported when a fractional divider was in use. Correct it.
As well as fixing the clock speed calculation when read, also update the
calculation on set in a similar manner.

Fixes: 163152cbbe32 ("clk: ti: Add support for FAPLL on dm816x")
Signed-off-by: Andrew Goodbody <andrew.goodbody@xxxxxxxxxx>
Signed-off-by: Ettore Chimenti <ettore.chimenti@xxxxxxxxxx>
---
drivers/clk/ti/fapll.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/ti/fapll.c b/drivers/clk/ti/fapll.c
index ae2f6fed10f6..bb9986508578 100644
--- a/drivers/clk/ti/fapll.c
+++ b/drivers/clk/ti/fapll.c
@@ -54,6 +54,9 @@
#define SYNTH_MAX_INT_DIV 0xf
#define SYNTH_MAX_DIV_M 0xff

+#define SYNTH_FRAC_DIV_BITS 24
+#define SYNTH_FRAC_DIV_SCALE BIT(SYNTH_FRAC_DIV_BITS)
+
struct fapll_data {
struct clk_hw hw;
void __iomem *base;
@@ -336,8 +339,9 @@ static unsigned long ti_fapll_synth_recalc_rate(struct clk_hw *hw,
v = readl_relaxed(synth->freq);
synth_int_div = (v >> 24) & 0xf;
synth_frac_div = v & 0xffffff;
- synth_div_freq = (synth_int_div * 10000000) + synth_frac_div;
- rate *= 10000000;
+ synth_div_freq = (synth_int_div * SYNTH_FRAC_DIV_SCALE)
+ + synth_frac_div;
+ rate *= SYNTH_FRAC_DIV_SCALE;
do_div(rate, synth_div_freq);
rate *= SYNTH_PHASE_K;
}
@@ -378,10 +382,10 @@ static u32 ti_fapll_synth_set_frac_rate(struct fapll_synth *synth,
for (; post_div_m < SYNTH_MAX_DIV_M; post_div_m++) {
synth_int_div = DIV_ROUND_UP_ULL((u64)parent_rate *
SYNTH_PHASE_K *
- 10000000,
+ SYNTH_FRAC_DIV_SCALE,
rate * post_div_m);
- synth_frac_div = synth_int_div % 10000000;
- synth_int_div /= 10000000;
+ synth_frac_div = synth_int_div % SYNTH_FRAC_DIV_SCALE;
+ synth_int_div /= SYNTH_FRAC_DIV_SCALE;

if (synth_int_div <= SYNTH_MAX_INT_DIV)
break;

--
2.56.1