[PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter
Jerome Brunet
jbrunet at baylibre.com
Thu Dec 3 07:31:04 PST 2026
> 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 at 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(-)
>
> diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c
> index 8c5a2640324c..55c0f4ffb075 100644
> --- a/drivers/clk/meson/axg.c
> +++ b/drivers/clk/meson/axg.c
> @@ -838,13 +838,7 @@ static struct clk_regmap axg_pcie_prediv = {
> },
> };
>
> -static const struct pll_params_table axg_pcie_pll_params_table[] = {
> - {
> - .m = 200,
> - .n = 3,
> - },
> - { /* sentinel */ },
> -};
> +static const unsigned int axg_pcie_pll_mult_table[] = { 200, 0 };
>
> static const struct reg_sequence axg_pcie_pll_init_regs[] = {
> { .reg = HHI_PCIE_PLL_CNTL1, .def = 0x0084a2aa },
> @@ -883,7 +877,7 @@ static struct clk_regmap axg_pcie_pll_dco = {
> .shift = 29,
> .width = 1,
> },
> - .table = axg_pcie_pll_params_table,
> + .table = axg_pcie_pll_mult_table,
> .init_regs = axg_pcie_pll_init_regs,
> .init_count = ARRAY_SIZE(axg_pcie_pll_init_regs),
> },
> diff --git a/drivers/clk/meson/clk-pll.c b/drivers/clk/meson/clk-pll.c
> index 29b5222983df..cbe1da6fe636 100644
> --- a/drivers/clk/meson/clk-pll.c
> +++ b/drivers/clk/meson/clk-pll.c
> @@ -14,7 +14,7 @@
> * +--------------------------------+
> * | |
> * | +--+ |
> - * in >>-----[ /N ]--->| | +-----+ |
> + * in >>-------------->| | +-----+ |
> * | | |------| DCO |---->> out
> * | +--------->| | +--v--+ |
> * | | +--+ | |
> @@ -23,7 +23,7 @@
> * | |
> * +--------------------------------+
> *
> - * out = in * (m + frac / frac_max) / n
> + * out = in * (m + frac / frac_max)
> */
>
> #include <linux/clk-provider.h>
> @@ -31,6 +31,7 @@
> #include <linux/err.h>
> #include <linux/io.h>
> #include <linux/math64.h>
> +#include <linux/minmax.h>
> #include <linux/module.h>
>
> #include "clk-regmap.h"
> @@ -52,8 +53,7 @@ static int __pll_round_closest_mult(struct meson_clk_pll_data *pll)
> }
>
> static unsigned long __pll_params_to_rate(unsigned long parent_rate,
> - unsigned int m, unsigned int n,
> - unsigned int frac,
> + unsigned int m, unsigned int frac,
> struct meson_clk_pll_data *pll)
> {
> u64 rate = (u64)parent_rate * m;
> @@ -66,7 +66,7 @@ static unsigned long __pll_params_to_rate(unsigned long parent_rate,
> rate += DIV_ROUND_UP_ULL(frac_rate, frac_max);
> }
>
> - return DIV_ROUND_UP_ULL(rate, n);
> + return rate;
> }
>
> static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw,
> @@ -74,19 +74,7 @@ static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw,
> {
> struct clk_regmap *clk = to_clk_regmap(hw);
> struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
> - unsigned int m, n, frac;
> -
> - n = MESON_PARM_APPLICABLE(&pll->n) ?
> - meson_parm_read(clk->map, &pll->n) :
> - 1;
> -
> - /*
> - * On some HW, N is set to zero on init. This value is invalid as
> - * it would result in a division by zero. The rate can't be
> - * calculated in this case
> - */
> - if (n == 0)
> - return 0;
> + unsigned int m, frac;
>
> m = meson_parm_read(clk->map, &pll->m);
>
> @@ -94,21 +82,20 @@ static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw,
> meson_parm_read(clk->map, &pll->frac) :
> 0;
>
> - return __pll_params_to_rate(parent_rate, m, n, frac, pll);
> + return __pll_params_to_rate(parent_rate, m, frac, pll);
> }
>
> static unsigned int __pll_params_with_frac(unsigned long rate,
> unsigned long parent_rate,
> unsigned int m,
> - unsigned int n,
> struct meson_clk_pll_data *pll)
> {
> unsigned int frac_max = pll->frac_max ? pll->frac_max :
> (1 << pll->frac.width);
> - u64 val = (u64)rate * n;
> + u64 val = (u64)rate;
>
> /* Bail out if we are already over the requested rate */
> - if (rate < parent_rate * m / n)
> + if (rate < parent_rate * m)
> return 0;
>
> if (pll->flags & CLK_MESON_PLL_ROUND_CLOSEST)
> @@ -139,58 +126,77 @@ static bool meson_clk_pll_is_better(unsigned long rate,
> return false;
> }
>
> -static int meson_clk_get_pll_table_index(unsigned int index,
> - unsigned int *m,
> - unsigned int *n,
> - struct meson_clk_pll_data *pll)
> +static unsigned int meson_clk_pll_min_mult(struct meson_clk_pll_data *pll)
> {
> - if (!pll->table[index].n)
> - return -EINVAL;
> + unsigned int i, min_mult = UINT_MAX;
>
> - *m = pll->table[index].m;
> - *n = pll->table[index].n;
> + if (pll->range)
> + return pll->range->min;
>
> - return 0;
> + for (i = 0; pll->table && pll->table[i]; i++)
> + min_mult = min(min_mult, pll->table[i]);
> +
> + return min_mult == UINT_MAX ? 0 : min_mult;
> }
>
> -static unsigned int meson_clk_get_pll_range_m(unsigned long rate,
> - unsigned long parent_rate,
> - unsigned int n,
> - struct meson_clk_pll_data *pll)
> +static unsigned int meson_clk_pll_max_mult(struct meson_clk_pll_data *pll)
> {
> - u64 val = (u64)rate * n;
> + unsigned int i, max_mult = 0;
> +
> + if (pll->range)
> + return pll->range->max;
> +
> + for (i = 0; pll->table && pll->table[i]; i++)
> + max_mult = max(max_mult, pll->table[i]);
> +
> + return max_mult;
> +}
>
> +static unsigned int meson_clk_pll_rate_to_mult(unsigned long rate,
> + unsigned long parent_rate,
> + struct meson_clk_pll_data *pll)
> +{
> if (__pll_round_closest_mult(pll))
> - return DIV_ROUND_CLOSEST_ULL(val, parent_rate);
> + return DIV_ROUND_CLOSEST_ULL(rate, parent_rate);
>
> - return div_u64(val, parent_rate);
> + return div_u64(rate, parent_rate);
> }
>
> -static int meson_clk_get_pll_range_index(unsigned long rate,
> - unsigned long parent_rate,
> - unsigned int index,
> +/* m_hint must be non-zero */
> +static int meson_clk_get_pll_parent_rate(struct clk_rate_request *req,
> + unsigned int m_hint,
> + unsigned long *parent_rate,
> unsigned int *m,
> - unsigned int *n,
> struct meson_clk_pll_data *pll)
> {
> - *n = index + 1;
> + unsigned long pr;
>
> - /* Check the predivider range */
> - if (*n >= (MESON_PARM_APPLICABLE(&pll->n) ? 1 << pll->n.width : 2))
> + pr = clk_hw_round_rate(req->best_parent_hw,
> + DIV_ROUND_UP_ULL(req->rate, m_hint));
> + if (!pr)
> return -EINVAL;
>
> - if (*n == 1) {
> - /* Get the boundaries out the way */
> - if (rate <= pll->range->min * parent_rate) {
> - *m = pll->range->min;
> - return -ENODATA;
The correct error would be EINVAL and what you are doing is incorrect
CCF determine rate is a best effort operation so you don't error out
on this. Simply compute the multiplication resquested and round it
to the best the PLL can acheive according the tables, values, frac
and boundary.
--
Jerome
More information about the linux-arm-kernel
mailing list