* [PATCH 0/4] clk: rockchip: Fix RK3588/RK3576 fractional PLL handling
@ 2026-12-04 12:34 Alexander Shiyan
2026-12-04 12:34 ` [PATCH 1/4] clk: rockchip: Fix the fractional part denominator on RK3588/RK3576 PLLs Alexander Shiyan
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Alexander Shiyan @ 2026-12-04 12:34 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
The fractional PLL support for the RK3588 and RK3576 PLLs was ported from
Linux but three defects were carried over with it, and a fourth PLL type
was half-wired.
First, the fractional denominator was off by one. The PLL register field
holds values in the range 1..65535 while the reference implementation
divides by 65536, so every fractional rate was computed with a slightly
too small denominator.
Second, the fractional coefficient k is a signed 16-bit value in two's
complement. Barebox declared it unsigned, which made negative coefficients
impossible to express, so rates needing a negative correction were
recalculated with the wrong sign.
Third, the two RK3588/RK3576 fractional rate table entries that need a
negative coefficient were written as if the field were unsigned. They are
converted to the two's complement representation now that the type allows
it.
Finally, the RK3576 PPLL is registered with a PLL type that runs at twice
the configured rate. The type and its ops existed, but recalc_rate did not
apply the factor of two, so PPLL consumers saw half of the real clock.
None of the current boards enable fractional PLL rates, and RK3576 PPLL
consumers are not enabled in barebox either, so this is a correctness fix
without an observable regression risk today. It matters for DisplayPort
output (fractional rates) and for PCIe/MPHY reference dividers on RK3576
once those are enabled.
Ported from the corresponding Linux commits, listed in each patch.
Alexander Shiyan (4):
clk: rockchip: Fix the fractional part denominator on RK3588/RK3576
PLLs
clk: rockchip: Treat fractional PLL coefficient as two's complement
clk: rockchip: Use two's complement coefficients in RK3588/RK3576 PLL
tables
clk: rockchip: Return twice the configured rate for pll_rk3588_ddr
drivers/clk/rockchip/clk-pll.c | 19 ++++++++++++++-----
drivers/clk/rockchip/clk-rk3576.c | 4 ++--
drivers/clk/rockchip/clk-rk3588.c | 4 ++--
drivers/clk/rockchip/clk.h | 8 ++++----
4 files changed, 22 insertions(+), 13 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] clk: rockchip: Fix the fractional part denominator on RK3588/RK3576 PLLs
2026-12-04 12:34 [PATCH 0/4] clk: rockchip: Fix RK3588/RK3576 fractional PLL handling Alexander Shiyan
@ 2026-12-04 12:34 ` Alexander Shiyan
2026-12-04 12:34 ` [PATCH 2/4] clk: rockchip: Treat fractional PLL coefficient as two's complement Alexander Shiyan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2026-12-04 12:34 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
According to the TRM, the fractional PLL coefficient should be divided by
65536 rather than 65535 to obtain the output rate.
Fix the denominator and add a comment with the TRM provided clock formulae
for future reference.
See RK3576 TRM Part 1 V1.2 section 2.13.1.4 Setting Guide on P, M, S and K
or equivalently RK3588 TRM part 1 V1.0 section 2.17.1.4 Setting Guide on P,
M, S and K.
Ported from Linux commit 52aef653c3d0 ("clk: rockchip: Fix the fractional
part denominator on RK3588/RK3576 PLLs").
Fixes: 9bc05092e9b3 ("clk: rockchip: Add rk3588 support")
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/clk/rockchip/clk-pll.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index ddb8d613e0..f07c71462a 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -896,6 +896,13 @@ static void rockchip_rk3588_pll_get_params(struct rockchip_clk_pll *pll,
rate->k = ((pllcon >> RK3588_PLLCON2_K_SHIFT) & RK3588_PLLCON2_K_MASK);
}
+/*
+ * 2250 MHz <= Fvco <= 4500 MHz
+ * For Fvco > 3 GHz: period jitter +-1% frac PLL, +-0.75% int PLL
+ * For Fvco < 3 GHz: period jitter +-2% frac PLL, +-1.50% int PLL
+ * Fvco = ((m + k / 65536) * Fin) / p
+ * Fout = ((m + k / 65536) * Fin) / (p * 2^s)
+ */
static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned long prate)
{
struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw);
@@ -911,7 +918,7 @@ static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned
/* fractional mode */
u64 frac_rate64 = prate * cur.k;
- postdiv = cur.p * 65535;
+ postdiv = cur.p * 65536;
do_div(frac_rate64, postdiv);
rate64 += frac_rate64;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] clk: rockchip: Treat fractional PLL coefficient as two's complement
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
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
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2026-12-04 12:34 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] clk: rockchip: Use two's complement coefficients in RK3588/RK3576 PLL tables
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 ` [PATCH 2/4] clk: rockchip: Treat fractional PLL coefficient as two's complement Alexander Shiyan
@ 2026-12-04 12:34 ` Alexander Shiyan
2026-12-04 12:34 ` [PATCH 4/4] clk: rockchip: Return twice the configured rate for pll_rk3588_ddr Alexander Shiyan
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2026-12-04 12:34 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
The two affected rates used large positive k values that only describe the
same frequency because the coefficient was treated as unsigned. With k now
being signed, subtract the fractional part from the next larger integer
multiplier and encode k as a negative two's complement value.
Ported from Linux commit 581478883477 ("clk: rockchip: Fractional PLL
coefficient on RK3588/RK3576 is two's complement").
Fixes: 9bc05092e9b3 ("clk: rockchip: Add rk3588 support")
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/clk/rockchip/clk-rk3576.c | 4 ++--
drivers/clk/rockchip/clk-rk3588.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/rockchip/clk-rk3576.c b/drivers/clk/rockchip/clk-rk3576.c
index 3ca08fac84..f30cbe4282 100644
--- a/drivers/clk/rockchip/clk-rk3576.c
+++ b/drivers/clk/rockchip/clk-rk3576.c
@@ -102,13 +102,13 @@ static struct rockchip_pll_rate_table rk3576_pll_rates[] = {
RK3588_PLL_RATE(1008000000, 2, 336, 2, 0),
RK3588_PLL_RATE(1000000000, 3, 500, 2, 0),
RK3588_PLL_RATE(983040000, 4, 655, 2, 23592),
- RK3588_PLL_RATE(955520000, 3, 477, 2, 49806),
+ RK3588_PLL_RATE(955520000, 3, 478, 2, -15730),
RK3588_PLL_RATE(903168000, 6, 903, 2, 11009),
RK3588_PLL_RATE(900000000, 2, 300, 2, 0),
RK3588_PLL_RATE(816000000, 2, 272, 2, 0),
RK3588_PLL_RATE(786432000, 2, 262, 2, 9437),
RK3588_PLL_RATE(786000000, 1, 131, 2, 0),
- RK3588_PLL_RATE(785560000, 3, 392, 2, 51117),
+ RK3588_PLL_RATE(785560000, 3, 393, 2, -14419),
RK3588_PLL_RATE(722534400, 8, 963, 2, 24850),
RK3588_PLL_RATE(600000000, 2, 200, 2, 0),
RK3588_PLL_RATE(594000000, 2, 198, 2, 0),
diff --git a/drivers/clk/rockchip/clk-rk3588.c b/drivers/clk/rockchip/clk-rk3588.c
index eb6b4fde14..167f9c56f7 100644
--- a/drivers/clk/rockchip/clk-rk3588.c
+++ b/drivers/clk/rockchip/clk-rk3588.c
@@ -101,14 +101,14 @@ static struct rockchip_pll_rate_table rk3588_pll_rates[] = {
RK3588_PLL_RATE(1008000000, 2, 336, 2, 0),
RK3588_PLL_RATE(1000000000, 3, 500, 2, 0),
RK3588_PLL_RATE(983040000, 4, 655, 2, 23592),
- RK3588_PLL_RATE(955520000, 3, 477, 2, 49806),
+ RK3588_PLL_RATE(955520000, 3, 478, 2, -15730),
RK3588_PLL_RATE(903168000, 6, 903, 2, 11009),
RK3588_PLL_RATE(900000000, 2, 300, 2, 0),
RK3588_PLL_RATE(850000000, 3, 425, 2, 0),
RK3588_PLL_RATE(816000000, 2, 272, 2, 0),
RK3588_PLL_RATE(786432000, 2, 262, 2, 9437),
RK3588_PLL_RATE(786000000, 1, 131, 2, 0),
- RK3588_PLL_RATE(785560000, 3, 392, 2, 51117),
+ RK3588_PLL_RATE(785560000, 3, 393, 2, -14419),
RK3588_PLL_RATE(722534400, 8, 963, 2, 24850),
RK3588_PLL_RATE(600000000, 2, 200, 2, 0),
RK3588_PLL_RATE(594000000, 2, 198, 2, 0),
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] clk: rockchip: Return twice the configured rate for pll_rk3588_ddr
2026-12-04 12:34 [PATCH 0/4] clk: rockchip: Fix RK3588/RK3576 fractional PLL handling Alexander Shiyan
` (2 preceding siblings ...)
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 ` Alexander Shiyan
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2026-12-04 12:34 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
The RK3576 PPLL is registered as pll_rk3588_ddr, which shares the RK3588
register layout but runs at twice the configured rate. Barebox enabled
the type for the ops selection, yet recalc_rate still returned the
unmodified value, so PPLL consumers, including the PCIe and MPHY reference
dividers, saw half of the real clock.
Multiply the recalculated rate by two for this PLL type.
Ported from Linux commit e781bffc2967 ("clk: rockchip: Add new pll type
pll_rk3588_ddr").
Fixes: 81b2c56c7e9d ("ARM: Initial support for Rockchip RK3576")
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/clk/rockchip/clk-pll.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index 1268ec0589..77012f795e 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -923,7 +923,10 @@ static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned
}
rate64 = rate64 >> cur.s;
- return (unsigned long)rate64;
+ if (pll->type == pll_rk3588_ddr)
+ return (unsigned long)rate64 * 2;
+ else
+ return (unsigned long)rate64;
}
static int rockchip_rk3588_pll_set_params(struct rockchip_clk_pll *pll,
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 13:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/4] clk: rockchip: Treat fractional PLL coefficient as two's complement Alexander Shiyan
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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.