From: "Xuyang Dong" <dongxuyang@eswincomputing.com>
To: gaohan@iscas.ac.cn, "Stephen Boyd" <sboyd@kernel.org>,
"Brian Masney" <bmasney+clk@redhat.com>,
"Jerome Brunet" <jbrunet+clk@baylibre.com>
Cc: "Brian Masney" <bmasney@redhat.com>,
"Han Gao" <rabenda.cn@gmail.com>,
linux-clk@vger.kernel.org,
"Yifeng Huang" <huangyifeng@eswincomputing.com>,
"Pinkesh Vaghela" <pinkesh.vaghela@einfochips.com>,
"Min Lin" <linmin@eswincomputing.com>
Subject: Re: [PATCH 2/2] clk: eswin: Use REFDIV and the post-dividers in the EIC7700 PLL rate
Date: Wed, 25 Nov 2026 16:12:18 +0800 (GMT+08:00) [thread overview]
Message-ID: <16529f.d68.1a211c3400b.Coremail.dongxuyang@eswincomputing.com> (raw)
In-Reply-To: <20261125-eic7700-cpu-pll-postdiv-v1-2-b1ccd6339a20@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;
> }
>
Acked-by: Xuyang Dong <dongxuyang@eswincomputing.com>
Thanks,
Xuyang Dong
prev parent reply other threads:[~2026-11-25 8:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=16529f.d68.1a211c3400b.Coremail.dongxuyang@eswincomputing.com \
--to=dongxuyang@eswincomputing.com \
--cc=bmasney+clk@redhat.com \
--cc=bmasney@redhat.com \
--cc=gaohan@iscas.ac.cn \
--cc=huangyifeng@eswincomputing.com \
--cc=jbrunet+clk@baylibre.com \
--cc=linmin@eswincomputing.com \
--cc=linux-clk@vger.kernel.org \
--cc=pinkesh.vaghela@einfochips.com \
--cc=rabenda.cn@gmail.com \
--cc=sboyd@kernel.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