* [PATCH 0/2] clk: eswin: Fix the EIC7700 PLL post-divider
@ 2026-11-24 18:41 Han Gao via B4 Relay
2026-11-24 18:41 ` [PATCH 1/2] " Han Gao via B4 Relay
2026-11-24 18:41 ` [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate Han Gao via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: Han Gao via B4 Relay @ 2026-11-24 18:41 UTC (permalink / raw)
To: Yifeng Huang, Xuyang Dong, Stephen Boyd, Brian Masney,
Jerome Brunet
Cc: Brian Masney, Han Gao, linux-clk, Han Gao, Jingkun Zheng
clk_pll_set_rate() sets a post-divider the rate math doesn't know
about, so the P550 CPU ran at half speed. Patch 1 fixes that, patch 2
makes recalc_rate use the full formula from the TRM.
Tested on a HiFive Premier P550: all CPU operating points, and setting
and reading back the audio PLL rate.
Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
---
Han Gao (2):
clk: eswin: Fix the EIC7700 PLL post-divider
clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate
drivers/clk/eswin/clk.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261125-eic7700-cpu-pll-postdiv-24d1c98f1d10
Best regards,
--
Han Gao <gaohan@iscas.ac.cn>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 1/2] clk: eswin: Fix the EIC7700 PLL post-divider 2026-11-24 18:41 [PATCH 0/2] clk: eswin: Fix the EIC7700 PLL post-divider Han Gao via B4 Relay @ 2026-11-24 18:41 ` Han Gao via B4 Relay 2026-11-25 8:12 ` Xuyang Dong 2026-11-24 18:41 ` [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate Han Gao via B4 Relay 1 sibling, 1 reply; 5+ messages in thread From: Han Gao via B4 Relay @ 2026-11-24 18:41 UTC (permalink / raw) To: Yifeng Huang, Xuyang Dong, Stephen Boyd, Brian Masney, Jerome Brunet Cc: Brian Masney, Han Gao, linux-clk, Han Gao, Jingkun Zheng From: Han Gao <gaohan@iscas.ac.cn> Both PLL clocks are FOUT1 of their PLL. Per the TRM: FOUT1 = FREF * (FBDIV + FRAC / 2^24) / (4 * REFDIV * (POSTDIV1_A + 1) * (POSTDIV1_B + 1)) The driver leaves the post-dividers out of its rate math, but clk_pll_set_rate() sets POSTDIV1_A (bits 10:8) to 1, which halves the output. It also writes bits 18:16 as "POSTDIV2", which is really POSTDIV2_A for FOUT2. On the HiFive Premier P550 the CPU ran at 699 MHz when CPUFreq set 1.4 GHz. Clear POSTDIV1_A and POSTDIV1_B (bits 14:12) instead, and leave FOUT2 alone. Fixes: cd44f127c1d4 ("clk: eswin: Add eic7700 clock driver") Reported-by: Jingkun Zheng <zhengjingkun@iscas.ac.cn> Link: https://github.com/eswincomputing/EIC7700X-SoC-Technical-Reference-Manual/releases/download/v1.0.0-20250103/EIC7700X_SoC_Technical_Reference_Manual_Part1.pdf Signed-off-by: Han Gao <gaohan@iscas.ac.cn> --- drivers/clk/eswin/clk.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/clk/eswin/clk.c b/drivers/clk/eswin/clk.c index e8851283ccdbf0ea57002511f991c9d68a7f4788..7d51d3a8fc06d7b4a0d7435aeb0cb0e58e16708e 100644 --- a/drivers/clk/eswin/clk.c +++ b/drivers/clk/eswin/clk.c @@ -21,8 +21,8 @@ #define PLL_REFDIV_MASK GENMASK(17, 12) #define PLL_FBDIV_MASK GENMASK(31, 20) #define PLL_FRAC_MASK GENMASK(27, 4) -#define PLL_POSTDIV1_MASK GENMASK(10, 8) -#define PLL_POSTDIV2_MASK GENMASK(18, 16) +#define PLL_POSTDIV1_A_MASK GENMASK(10, 8) +#define PLL_POSTDIV1_B_MASK GENMASK(14, 12) struct eswin_clock_data *eswin_clk_init(struct platform_device *pdev, size_t nr_clks) @@ -110,10 +110,9 @@ static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, val |= FIELD_PREP(PLL_FRAC_MASK, frac_val); writel_relaxed(val, clk->ctrl_reg1); + /* eswin_calc_pll() assumes FOUT1 is not post-divided */ val = readl_relaxed(clk->ctrl_reg2); - val &= ~(PLL_POSTDIV1_MASK | PLL_POSTDIV2_MASK); - val |= FIELD_PREP(PLL_POSTDIV1_MASK, 1); - val |= FIELD_PREP(PLL_POSTDIV2_MASK, 1); + val &= ~(PLL_POSTDIV1_A_MASK | PLL_POSTDIV1_B_MASK); writel_relaxed(val, clk->ctrl_reg2); /* Last, enable pll */ -- 2.47.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] clk: eswin: Fix the EIC7700 PLL post-divider 2026-11-24 18:41 ` [PATCH 1/2] " Han Gao via B4 Relay @ 2026-11-25 8:12 ` Xuyang Dong 0 siblings, 0 replies; 5+ messages in thread From: Xuyang Dong @ 2026-11-25 8:12 UTC (permalink / raw) To: gaohan, Stephen Boyd, Brian Masney, Jerome Brunet Cc: Brian Masney, Han Gao, linux-clk, Jingkun Zheng, Yifeng Huang, Pinkesh Vaghela, Min Lin > > Both PLL clocks are FOUT1 of their PLL. Per the TRM: > > FOUT1 = FREF * (FBDIV + FRAC / 2^24) / > (4 * REFDIV * (POSTDIV1_A + 1) * (POSTDIV1_B + 1)) > > The driver leaves the post-dividers out of its rate math, but > clk_pll_set_rate() sets POSTDIV1_A (bits 10:8) to 1, which halves the > output. It also writes bits 18:16 as "POSTDIV2", which is really > POSTDIV2_A for FOUT2. > > On the HiFive Premier P550 the CPU ran at 699 MHz when CPUFreq set > 1.4 GHz. > > Clear POSTDIV1_A and POSTDIV1_B (bits 14:12) instead, and leave FOUT2 > alone. > > Fixes: cd44f127c1d4 ("clk: eswin: Add eic7700 clock driver") > Reported-by: Jingkun Zheng <zhengjingkun@iscas.ac.cn> > Link: https://github.com/eswincomputing/EIC7700X-SoC-Technical-Reference-Manual/releases/download/v1.0.0-20250103/EIC7700X_SoC_Technical_Reference_Manual_Part1.pdf > Signed-off-by: Han Gao <gaohan@iscas.ac.cn> > --- > drivers/clk/eswin/clk.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/clk/eswin/clk.c b/drivers/clk/eswin/clk.c > index e8851283ccdbf0ea57002511f991c9d68a7f4788..7d51d3a8fc06d7b4a0d7435aeb0cb0e58e16708e 100644 > --- a/drivers/clk/eswin/clk.c > +++ b/drivers/clk/eswin/clk.c > @@ -21,8 +21,8 @@ > #define PLL_REFDIV_MASK GENMASK(17, 12) > #define PLL_FBDIV_MASK GENMASK(31, 20) > #define PLL_FRAC_MASK GENMASK(27, 4) > -#define PLL_POSTDIV1_MASK GENMASK(10, 8) > -#define PLL_POSTDIV2_MASK GENMASK(18, 16) > +#define PLL_POSTDIV1_A_MASK GENMASK(10, 8) > +#define PLL_POSTDIV1_B_MASK GENMASK(14, 12) > > struct eswin_clock_data *eswin_clk_init(struct platform_device *pdev, > size_t nr_clks) > @@ -110,10 +110,9 @@ static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, > val |= FIELD_PREP(PLL_FRAC_MASK, frac_val); > writel_relaxed(val, clk->ctrl_reg1); > > + /* eswin_calc_pll() assumes FOUT1 is not post-divided */ > val = readl_relaxed(clk->ctrl_reg2); > - val &= ~(PLL_POSTDIV1_MASK | PLL_POSTDIV2_MASK); > - val |= FIELD_PREP(PLL_POSTDIV1_MASK, 1); > - val |= FIELD_PREP(PLL_POSTDIV2_MASK, 1); > + val &= ~(PLL_POSTDIV1_A_MASK | PLL_POSTDIV1_B_MASK); > writel_relaxed(val, clk->ctrl_reg2); > > /* Last, enable pll */ > Thanks for catching this. You're right - the register usage and configuration here are incorrect. The fix as described looks good to me. Acked-by: Xuyang Dong <dongxuyang@eswincomputing.com> Thanks, Xuyang Dong ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate 2026-11-24 18:41 [PATCH 0/2] clk: eswin: Fix the EIC7700 PLL post-divider Han Gao via B4 Relay 2026-11-24 18:41 ` [PATCH 1/2] " Han Gao via B4 Relay @ 2026-11-24 18:41 ` Han Gao via B4 Relay 2026-11-25 8:12 ` Xuyang Dong 1 sibling, 1 reply; 5+ messages in thread From: Han Gao via B4 Relay @ 2026-11-24 18:41 UTC (permalink / raw) To: Yifeng Huang, Xuyang Dong, Stephen Boyd, Brian Masney, Jerome Brunet Cc: Brian Masney, Han Gao, linux-clk, Han Gao From: Han Gao <gaohan@iscas.ac.cn> clk_pll_recalc_rate() ignores REFDIV and the FOUT1 post-dividers, so it reports the wrong rate if firmware set them. Use the full formula from the TRM. Link: https://github.com/eswincomputing/EIC7700X-SoC-Technical-Reference-Manual/releases/download/v1.0.0-20250103/EIC7700X_SoC_Technical_Reference_Manual_Part1.pdf Signed-off-by: Han Gao <gaohan@iscas.ac.cn> --- drivers/clk/eswin/clk.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/clk/eswin/clk.c b/drivers/clk/eswin/clk.c index 7d51d3a8fc06d7b4a0d7435aeb0cb0e58e16708e..51d816c6d19b8a22045b147a863b39c9f3c9a7f1 100644 --- a/drivers/clk/eswin/clk.c +++ b/drivers/clk/eswin/clk.c @@ -135,9 +135,10 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, { struct eswin_clk_pll *clk = to_pll_clk(hw); u64 fbdiv_val, frac_val, tmp; - u32 rem, val; + u32 refdiv, postdiv_a, postdiv_b, rem, val; val = readl_relaxed(clk->ctrl_reg0); + refdiv = FIELD_GET(PLL_REFDIV_MASK, val); val &= PLL_FBDIV_MASK; fbdiv_val = (val >> clk->fbdiv_shift); @@ -145,7 +146,17 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, val &= PLL_FRAC_MASK; frac_val = (val >> clk->frac_shift); - /* rate = 24000000 * (fbdiv + frac / (2 ^ 24)) / 4 */ + val = readl_relaxed(clk->ctrl_reg2); + postdiv_a = FIELD_GET(PLL_POSTDIV1_A_MASK, val); + postdiv_b = FIELD_GET(PLL_POSTDIV1_B_MASK, val); + + if (!refdiv) + return 0; + + /* + * rate = parent_rate * (fbdiv + frac / 2^24) / + * (4 * refdiv * (postdiv_a + 1) * (postdiv_b + 1)) + */ tmp = parent_rate * frac_val; rem = do_div(tmp, BIT(24)); if (rem) @@ -153,7 +164,7 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, else tmp = parent_rate * fbdiv_val + tmp; - do_div(tmp, 4); + do_div(tmp, 4 * refdiv * (postdiv_a + 1) * (postdiv_b + 1)); return tmp; } -- 2.47.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate 2026-11-24 18:41 ` [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate Han Gao via B4 Relay @ 2026-11-25 8:12 ` Xuyang Dong 0 siblings, 0 replies; 5+ messages in thread From: Xuyang Dong @ 2026-11-25 8:12 UTC (permalink / raw) To: gaohan, Stephen Boyd, Brian Masney, Jerome Brunet Cc: Brian Masney, Han Gao, linux-clk, Yifeng Huang, Pinkesh Vaghela, Min Lin > > clk_pll_recalc_rate() ignores REFDIV and the FOUT1 post-dividers, so > it reports the wrong rate if firmware set them. Use the full formula > from the TRM. > > Link: https://github.com/eswincomputing/EIC7700X-SoC-Technical-Reference-Manual/releases/download/v1.0.0-20250103/EIC7700X_SoC_Technical_Reference_Manual_Part1.pdf > Signed-off-by: Han Gao <gaohan@iscas.ac.cn> > --- > drivers/clk/eswin/clk.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/drivers/clk/eswin/clk.c b/drivers/clk/eswin/clk.c > index 7d51d3a8fc06d7b4a0d7435aeb0cb0e58e16708e..51d816c6d19b8a22045b147a863b39c9f3c9a7f1 100644 > --- a/drivers/clk/eswin/clk.c > +++ b/drivers/clk/eswin/clk.c > @@ -135,9 +135,10 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, > { > struct eswin_clk_pll *clk = to_pll_clk(hw); > u64 fbdiv_val, frac_val, tmp; > - u32 rem, val; > + u32 refdiv, postdiv_a, postdiv_b, rem, val; > > val = readl_relaxed(clk->ctrl_reg0); > + refdiv = FIELD_GET(PLL_REFDIV_MASK, val); > val &= PLL_FBDIV_MASK; > fbdiv_val = (val >> clk->fbdiv_shift); > > @@ -145,7 +146,17 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, > val &= PLL_FRAC_MASK; > frac_val = (val >> clk->frac_shift); > > - /* rate = 24000000 * (fbdiv + frac / (2 ^ 24)) / 4 */ > + val = readl_relaxed(clk->ctrl_reg2); > + postdiv_a = FIELD_GET(PLL_POSTDIV1_A_MASK, val); > + postdiv_b = FIELD_GET(PLL_POSTDIV1_B_MASK, val); > + > + if (!refdiv) > + return 0; > + > + /* > + * rate = parent_rate * (fbdiv + frac / 2^24) / > + * (4 * refdiv * (postdiv_a + 1) * (postdiv_b + 1)) > + */ > tmp = parent_rate * frac_val; > rem = do_div(tmp, BIT(24)); > if (rem) > @@ -153,7 +164,7 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, > else > tmp = parent_rate * fbdiv_val + tmp; > > - do_div(tmp, 4); > + do_div(tmp, 4 * refdiv * (postdiv_a + 1) * (postdiv_b + 1)); > > return tmp; > } > Acked-by: Xuyang Dong <dongxuyang@eswincomputing.com> Thanks, Xuyang Dong ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-25 8:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-24 18:41 [PATCH 0/2] clk: eswin: Fix the EIC7700 PLL post-divider Han Gao via B4 Relay 2026-11-24 18:41 ` [PATCH 1/2] " Han Gao via B4 Relay 2026-11-25 8:12 ` Xuyang Dong 2026-11-24 18:41 ` [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate Han Gao via B4 Relay 2026-11-25 8:12 ` Xuyang Dong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox