From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH 2/4] clk: rockchip: Treat fractional PLL coefficient as two's complement
Date: Fri, 4 Dec 2026 15:34:56 +0300 [thread overview]
Message-ID: <20261204123458.3787582-3-eagle.alexander923@gmail.com> (raw)
In-Reply-To: <20261204123458.3787582-1-eagle.alexander923@gmail.com>
The fractional PLL coefficient k is a 16-bit two's complement value, but
it was declared as unsigned. Negative coefficients were therefore
impossible to express and recalculated rates were off by Fin / (p * 2^s)
whenever k was meant to be negative.
Declare k as s16 and do the fractional rate arithmetic signed. Fractional
PLL rates are not used by any current consumers, so this is a correctness
fix that matters for DisplayPort output once it is supported.
Ported from Linux commit 581478883477 ("clk: rockchip: Fractional PLL
coefficient on RK3588/RK3576 is two's complement"), with the rate table
updates split into the following patch.
Fixes: 9bc05092e9b3 ("clk: rockchip: Add rk3588 support")
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/clk/rockchip/clk-pll.c | 5 ++---
drivers/clk/rockchip/clk.h | 8 ++++----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index f07c71462a..1268ec0589 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -916,11 +916,10 @@ static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned
if (cur.k) {
/* fractional mode */
- u64 frac_rate64 = prate * cur.k;
+ s64 frac_rate64 = (s64)prate * cur.k;
postdiv = cur.p * 65536;
- do_div(frac_rate64, postdiv);
- rate64 += frac_rate64;
+ rate64 += div_s64(frac_rate64, postdiv);
}
rate64 = rate64 >> cur.s;
diff --git a/drivers/clk/rockchip/clk.h b/drivers/clk/rockchip/clk.h
index a56a42aaf5..d0e4870acb 100644
--- a/drivers/clk/rockchip/clk.h
+++ b/drivers/clk/rockchip/clk.h
@@ -589,10 +589,10 @@ struct rockchip_pll_rate_table {
};
struct {
/* for RK3588 */
- unsigned int m;
- unsigned int p;
- unsigned int s;
- unsigned int k;
+ unsigned int m; /* main divider, 10 bit unsigned */
+ unsigned int p; /* pre-divider, 6 bit unsigned */
+ unsigned int s; /* scaler, 3 bit unsigned */
+ s16 k; /* fractional part, 16 bit two's complement */
};
};
};
--
2.56.1
next prev parent reply other threads:[~2026-12-04 13:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 12:34 [PATCH 0/4] clk: rockchip: Fix RK3588/RK3576 fractional PLL handling Alexander Shiyan
2026-12-04 12:34 ` [PATCH 1/4] clk: rockchip: Fix the fractional part denominator on RK3588/RK3576 PLLs Alexander Shiyan
2026-12-04 12:34 ` Alexander Shiyan [this message]
2026-12-04 12:34 ` [PATCH 3/4] clk: rockchip: Use two's complement coefficients in RK3588/RK3576 PLL tables Alexander Shiyan
2026-12-04 12:34 ` [PATCH 4/4] clk: rockchip: Return twice the configured rate for pll_rk3588_ddr Alexander Shiyan
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=20261204123458.3787582-3-eagle.alexander923@gmail.com \
--to=eagle.alexander923@gmail.com \
--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