Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ettore Chimenti" <ettore.chimenti@linaro.org>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH 2/4] clk: ti: fapll: Fix clock speed calculation
Date: Thu, 15 Oct 2026 17:05:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-173231@kernel.org> (raw)
In-Reply-To: <20261015-patch-ektor5-dm8168-clk-v1-2-8b99c5cd5541@linaro.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] clk: ti: fapll: set_frac_rate uses incorrect 10000000 base causing clock mismatch
- [High] clk: ti: fapll: mismatched set/get fractional bases and off-by-one denominator
--

commit 1dcae77615d6eede1d731b41214f02cb5834c02c
Author: Andrew Goodbody <andrew.goodbody@linaro.org>

clk: ti: fapll: Fix clock speed calculation

The fractional part of the divider was being treated as 1/10000000 wheras
it is in fact 1/16777215. This led to incorrect clock speeds being
reported when a fractional divider was in use. Correct it.

> The fractional part of the divider was being treated as 1/10000000 wheras

[Severity: Low]
This isn't a bug, but there is a typo (wheras) in the commit message.

diff --git a/drivers/clk/ti/fapll.c b/drivers/clk/ti/fapll.c
index ae2f6fed10f66..008a61f45ac14 100644
--- a/drivers/clk/ti/fapll.c
+++ b/drivers/clk/ti/fapll.c
@@ -336,8 +336,8 @@ 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 * 16777215) + synth_frac_div;
+		rate *= 16777215;

[Severity: High]
Is the new 16777215 denominator an off-by-one error?

Standard 24-bit hardware dividers typically use a base of 16,777,216 (2^24).
While 0xffffff is the maximum 24-bit value, the fractional denominator is
usually the full 2^24.

[Severity: High]
Does this create a mismatch between calculating the rate and setting the rate?

Looking at ti_fapll_synth_set_frac_rate() which was not updated in this patch,
it still uses the 10000000 base to calculate the divider:

drivers/clk/ti/fapll.c:ti_fapll_synth_set_frac_rate() {
	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,
						 rate * post_div_m);
		synth_frac_div = synth_int_div % 10000000;
		synth_int_div /= 10000000;

		if (synth_int_div <= SYNTH_MAX_INT_DIV)
			break;
	}
	...
}

If a clock rate is set using ti_fapll_synth_set_frac_rate(), the programmed
hardware fractional divider will use the 10000000 base. However,
ti_fapll_synth_recalc_rate() will interpret that same register using the new
16777215 denominator. Should ti_fapll_synth_set_frac_rate() also be updated
to use the new denominator?

 		do_div(rate, synth_div_freq);
 		rate *= SYNTH_PHASE_K;
 	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-patch-ektor5-dm8168-clk-v1-0-8b99c5cd5541@linaro.org?part=2

  reply	other threads:[~2026-10-15 17:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 16:54 [PATCH 0/4] clk: ti: fapll/dm816x: clock tree and calculation fixes Ettore Chimenti
2026-10-15 16:54 ` [PATCH 1/4] clk: ti: fapll: remove ti_dt_clk_name helper Ettore Chimenti
2026-10-15 16:54 ` [PATCH 2/4] clk: ti: fapll: Fix clock speed calculation Ettore Chimenti
2026-10-15 17:05   ` sashiko-bot [this message]
2026-10-15 16:54 ` [PATCH 3/4] clk: ti: fapll: print clock name that fails to register Ettore Chimenti
2026-10-15 16:54 ` [PATCH 4/4] clk-816x: add sys_ck clock as sys_clkin_ck alias Ettore Chimenti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-173231@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ettore.chimenti@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox