From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 5/8] clk: imx: pllv3: use 64-bit arithmetic in fractional PLL recalc_rate
Date: Mon, 31 Aug 2026 21:35:52 +0200 [thread overview]
Message-ID: <20260831193605.1474749-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260831193605.1474749-1-a.fatoum@pengutronix.de>
From: Ahmad Fatoum <a.fatoum@barebox.org>
(parent_rate / mfd) * mfn truncates the intermediate division in
clk_pllv3_av_recalc_rate() and clk_pllv3_sys_vf610_recalc_rate(). Use
u64 multiplication and do_div, as Linux does since commit ba7f4f557eb6
("clk: imx: correct AV PLL rate formula") and 5c2f117a22e4 ("clk: imx:
fix integer overflow in AV PLL round rate"), the latter having widened
the truncated result from u32 to unsigned long.
Fixes: 809549b1bf93 ("ARM i.MX: initial clk support")
Fixes: 7a8d295cdf60 ("i.MX: clk: Add IMX_PLLV3_SYS_VF610 subtype")
Reported-by: Claude:opus-4.6
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/clk/imx/clk-pllv3.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
index eb806e7f9892..8d41b76df826 100644
--- a/drivers/clk/imx/clk-pllv3.c
+++ b/drivers/clk/imx/clk-pllv3.c
@@ -192,7 +192,12 @@ static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw,
u32 mfd = readl(pll->base + PLL_DENOM_OFFSET);
u32 div = readl(pll->base) & pll->div_mask;
- return (parent_rate * div) + ((parent_rate / mfd) * mfn);
+ u64 temp64 = (u64)parent_rate;
+
+ temp64 *= mfn;
+ do_div(temp64, mfd);
+
+ return parent_rate * div + (unsigned long)temp64;
}
static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
@@ -293,7 +298,12 @@ static unsigned long clk_pllv3_sys_vf610_recalc_rate(struct clk_hw *hw,
u32 mfd = readl(pll->base + SYS_VF610_PLL_OFFSET + PLL_DENOM_OFFSET);
u32 div = (readl(pll->base) & pll->div_mask) ? 22 : 20;
- return (parent_rate * div) + ((parent_rate / mfd) * mfn);
+ u64 temp64 = (u64)parent_rate;
+
+ temp64 *= mfn;
+ do_div(temp64, mfd);
+
+ return parent_rate * div + (unsigned long)temp64;
}
static long clk_pllv3_sys_vf610_round_rate(struct clk_hw *hw, unsigned long rate,
--
2.47.3
next prev parent reply other threads:[~2026-08-31 19:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 19:35 [PATCH 1/8] clk: stm32f4: allow building under COMPILE_TEST and fix the build Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 2/8] clk: at91: sam9x60-pll: " Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 3/8] clk: composite: return ERR_PTR on registration failure Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 4/8] clk: fixed-factor: use 64-bit arithmetic in recalc_rate Ahmad Fatoum
2026-08-31 19:35 ` Ahmad Fatoum [this message]
2026-08-31 19:35 ` [PATCH 6/8] clk: divider: use 64-bit division in _div_round_up and divider_get_val Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 7/8] clk: divider: round up when searching for the best divider Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 8/8] clk: divider: fix calculation of maximal parent rate for a given divider Ahmad Fatoum
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=20260831193605.1474749-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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