Devicetree
 help / color / mirror / Atom feed
From: Carlo Caione <ccaione@baylibre.com>
To: jian.hu@amlogic.com
Cc: Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	 Jerome Brunet <jbrunet+clk@baylibre.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	 Jerome Brunet <jbrunet@baylibre.com>,
	Kevin Hilman <khilman@baylibre.com>,
	 Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	linux-clk@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-amlogic@lists.infradead.org,
	 linux-arm-kernel@lists.infradead.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter
Date: Tue, 1 Dec 2026 14:16:06 +0100	[thread overview]
Message-ID: <aw7E7eNBSLZiezDu@macbook> (raw)
In-Reply-To: <20261201-meson_refactor_n-v3-13-f85a4460fd80@amlogic.com>

On Tue, Dec 01, 2026 at 16:56:26 +0100, Jian Hu via B4 Relay wrote:
> From: Jian Hu <jian.hu@amlogic.com>

Hi Jian,

> The Meson PLL framework models the PLL pre-divider (N) using a dedicated
> field in struct meson_clk_pll_data. Since the common clock framework
> already provides a generic divider implementation, there is no need to
> keep PLL-specific support for it.
> 
> Remove the dedicated n parameter from the framework and simplify the PLL
> rate calculation accordingly.
> 
> The parent rate is now negotiated on every rate request: the middle of the
> multiplier range is tried first, then the boundary the computed multiplier
> overflowed, and the request is rejected if the multiplier still does not fit.
> 
> The PLL tables are arrays of struct pll_params_table entries, which only
> carry a multiplier now that the pre-divider is gone. Replace them with
> 0-terminated arrays of unsigned int.
> 
> Signed-off-by: Jian Hu <jian.hu@amlogic.com>
> ---
>  drivers/clk/meson/axg.c     |  10 +-
>  drivers/clk/meson/clk-pll.c | 241 +++++++++++++++++++++++++-------------------
>  drivers/clk/meson/clk-pll.h |  14 +--
>  drivers/clk/meson/g12a.c    |   7 +-
>  drivers/clk/meson/meson8b.c |  58 ++---------
>  5 files changed, 150 insertions(+), 180 deletions(-)
> 

[...]
> +	/*
> +	 * The pre-divider is a regular clock now, so the parent rate must be
> +	 * negotiated. Aim for the middle of the multiplier range first, so a
> +	 * divider parent, which can only round down, still leaves the
> +	 * multiplier within [m_min, m_max].
> +	 */
> +	ret = meson_clk_get_pll_parent_rate(req,
> +					    DIV_ROUND_UP(m_min + m_max, 2),
> +					    &parent_rate, &m, pll);
>  	if (ret)
>  		return ret;
>  
> -	round = __pll_params_to_rate(req->best_parent_rate, m, n, 0, pll);
> +	/* Parent rounded too far: retry from the other end of the range */
> +	if (m > m_max)
> +		ret = meson_clk_get_pll_parent_rate(req, m_min, &parent_rate,
> +						    &m, pll);
> +	else if (!m || m < m_min)
> +		ret = meson_clk_get_pll_parent_rate(req, m_max, &parent_rate,
> +						    &m, pll);
> +	if (ret)
> +		return ret;
> +
> +	if (!m || m < m_min || m > m_max)
> +		return -EINVAL;
> +

Doesn't the m > m_max check prevent the upper clamp in
meson_clk_get_pll_range() from doing its job?

I'm asking this because on S7 GP0, a 4 GHz VCO request used to round to
3191999909 Hz while with this v3 I get -EINVAL on the board (I have a
test for that since my work on S7).

I think it also affects the output divider because comparing the
callbacks in software an 800 MHz request used to give 797999978 Hz but
now rounds to 0.

The /1 and /2 candidates need a VCO below its minimum and /4 asks
for 3.2 GHz which previously got clamped. With this v3 none of the
candidates work and the same happens at 400 and 1600 MHz.

In theory (and on my tests on S7) dropping just m > m_max restores the
old results in the fixed-parent cases I checked. I'd keep the lower
check because removing it makes an S7 GP0 VCO request of 1 GHz succeed
at 1608 MHz whereas it used to fail.

> +	/*
> +	 * -ENODATA only means the multiplier was clamped to one of the range
> +	 * boundaries, which is a usable setting.
> +	 */
> +	ret = meson_clk_get_pll_mult(req->rate, parent_rate, &m, pll);
> +	if (ret && ret != -ENODATA)
> +		return ret;
> +
> +	req->best_parent_rate = parent_rate;
> +	round = __pll_params_to_rate(parent_rate, m, 0, pll);
>  
>  	if (!MESON_PARM_APPLICABLE(&pll->frac) || req->rate == round) {
>  		req->rate = round;
> @@ -270,8 +305,8 @@ static int meson_clk_pll_determine_rate(struct clk_hw *hw,
>  	 * The rate provided by the setting is not an exact match, let's
>  	 * try to improve the result using the fractional parameter
>  	 */
> -	frac = __pll_params_with_frac(req->rate, req->best_parent_rate, m, n, pll);
> -	req->rate = __pll_params_to_rate(req->best_parent_rate, m, n, frac, pll);
> +	frac = __pll_params_with_frac(req->rate, parent_rate, m, pll);
> +	req->rate = __pll_params_to_rate(parent_rate, m, frac, pll);
>  
>  	return 0;
>  }
 
Ciao,

--
Carlo Caione

      parent reply	other threads:[~2026-12-01 13:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
2026-12-01  9:10   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 02/13] clk: meson: clk-regmap: Widen the divider flags to 16 bits Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 03/13] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-12-01  9:11   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 05/13] clk: meson: a1: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 06/13] clk: meson: c3: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 07/13] clk: meson: gxbb: " Jian Hu via B4 Relay
2026-12-01  9:16   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 08/13] clk: meson: g12a: " Jian Hu via B4 Relay
2026-12-01  9:19   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 09/13] clk: meson: meson8: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 10/13] clk: meson: s4: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 11/13] clk: meson: s7: " Jian Hu via B4 Relay
2026-12-01 11:37   ` Carlo Caione
2026-12-01  8:56 ` [PATCH RFC RFT v3 12/13] clk: meson: t7: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay
2026-12-01  9:28   ` sashiko-bot
2026-12-01 13:16   ` Carlo Caione [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=aw7E7eNBSLZiezDu@macbook \
    --to=ccaione@baylibre.com \
    --cc=bmasney+clk@redhat.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jbrunet+clk@baylibre.com \
    --cc=jbrunet@baylibre.com \
    --cc=jian.hu@amlogic.com \
    --cc=khilman@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --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