Re: [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter

From: Carlo Caione

Date: Tue Dec 01 2026 - 08:16:22 EST


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

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@xxxxxxxxxxx>
> ---
> 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