Re: [PATCH RFC RFT v3 09/13] clk: meson: meson8: Model the PLL pre-divider as a divider clock

From: Jerome Brunet

Date: Thu Dec 03 2026 - 10:31:40 EST


> The pre-divider is currently described by a dedicated n parameter,
> although it is a plain divider between the input clock and the DCO.
>
> Model it as a regular divider clock and make it the parent of the DCO.

Martin, you've been the most active meson8 user. Any chance you could try this and
let us know what you think ?

>
> Signed-off-by: Jian Hu <jian.hu@xxxxxxxxxxx>
> ---
> drivers/clk/meson/meson8-ddr.c | 33 +++++++--
> drivers/clk/meson/meson8b.c | 153 +++++++++++++++++++++++++++++++----------
> 2 files changed, 144 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/clk/meson/meson8-ddr.c b/drivers/clk/meson/meson8-ddr.c
> index 0f93774f7371..4bf40fb86dbe 100644
> --- a/drivers/clk/meson/meson8-ddr.c
> +++ b/drivers/clk/meson/meson8-ddr.c
> @@ -23,6 +23,29 @@
> #define DDR_CLK_CNTL 0x18
> #define DDR_CLK_STS 0x1c
>
> +static struct clk_regmap meson8_ddr_prediv = {
> + .data = &(struct clk_regmap_div_data){
> + .offset = AM_DDR_PLL_CNTL,
> + .shift = 9,
> + .width = 5,
> + /*
> + * CLK_DIVIDER_ONE_BASED: the register value is the divisor
> + * itself, so a value of 1 gives a divisor of 1 and the PLL
> + * input is not divided. The hardware keeps this pre-divider
> + * at 1, which minimizes the PLL jitter.
> + */
> + .flags = CLK_DIVIDER_ONE_BASED,
> + },
> + .hw.init = &(struct clk_init_data){
> + .name = "ddr_prediv",
> + .ops = &clk_regmap_divider_ro_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "xtal",
> + },
> + .num_parents = 1,
> + },
> +};
> +
> static struct clk_regmap meson8_ddr_pll_dco = {
> .data = &(struct meson_clk_pll_data){
> .en = {
> @@ -35,11 +58,6 @@ static struct clk_regmap meson8_ddr_pll_dco = {
> .shift = 0,
> .width = 9,
> },
> - .n = {
> - .reg_off = AM_DDR_PLL_CNTL,
> - .shift = 9,
> - .width = 5,
> - },
> .l = {
> .reg_off = AM_DDR_PLL_CNTL,
> .shift = 31,
> @@ -54,8 +72,8 @@ static struct clk_regmap meson8_ddr_pll_dco = {
> .hw.init = &(struct clk_init_data){
> .name = "ddr_pll_dco",
> .ops = &meson_clk_pll_ro_ops,
> - .parent_data = &(const struct clk_parent_data) {
> - .fw_name = "xtal",
> + .parent_hws = (const struct clk_hw *[]) {
> + &meson8_ddr_prediv.hw
> },
> .num_parents = 1,
> },
> @@ -79,6 +97,7 @@ static struct clk_regmap meson8_ddr_pll = {
> };
>
> static struct clk_hw *meson8_ddr_hw_clks[] = {
> + [DDR_CLKID_DDR_PREDIV] = &meson8_ddr_prediv.hw,
> [DDR_CLKID_DDR_PLL_DCO] = &meson8_ddr_pll_dco.hw,
> [DDR_CLKID_DDR_PLL] = &meson8_ddr_pll.hw,
> };
> diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
> index bc029c6ab622..ae2bab501597 100644
> --- a/drivers/clk/meson/meson8b.c
> +++ b/drivers/clk/meson/meson8b.c
> @@ -119,6 +119,31 @@ static const struct pll_params_table sys_pll_params_table[] = {
> { /* sentinel */ },
> };
>
> +static struct clk_regmap meson8b_fixed_prediv = {
> + .data = &(struct clk_regmap_div_data){
> + .offset = HHI_MPLL_CNTL,
> + .shift = 9,
> + .width = 5,
> + /*
> + * CLK_DIVIDER_ONE_BASED: the register value is the divisor
> + * itself, so a value of 4 gives a divisor of 4.
> + * The hardware design sets the division factor of this prescaler
> + * to 4 to produce a 2.55G output.
> + */
> + .flags = CLK_DIVIDER_ONE_BASED,
> + },
> + .hw.init = &(struct clk_init_data){
> + .name = "fixed_prediv",
> + .ops = &clk_regmap_divider_ro_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "xtal",
> + .name = "xtal",
> + .index = -1,
> + },
> + .num_parents = 1,
> + },
> +};
> +
> static struct clk_regmap meson8b_fixed_pll_dco = {
> .data = &(struct meson_clk_pll_data){
> .en = {
> @@ -131,11 +156,6 @@ static struct clk_regmap meson8b_fixed_pll_dco = {
> .shift = 0,
> .width = 9,
> },
> - .n = {
> - .reg_off = HHI_MPLL_CNTL,
> - .shift = 9,
> - .width = 5,
> - },
> .frac = {
> .reg_off = HHI_MPLL_CNTL2,
> .shift = 0,
> @@ -155,10 +175,8 @@ static struct clk_regmap meson8b_fixed_pll_dco = {
> .hw.init = &(struct clk_init_data){
> .name = "fixed_pll_dco",
> .ops = &meson_clk_pll_ro_ops,
> - .parent_data = &(const struct clk_parent_data) {
> - .fw_name = "xtal",
> - .name = "xtal",
> - .index = -1,
> + .parent_hws = (const struct clk_hw *[]) {
> + &meson8b_fixed_prediv.hw
> },
> .num_parents = 1,
> },
> @@ -185,17 +203,42 @@ static struct clk_regmap meson8b_fixed_pll = {
> },
> };
>
> +/* Force the pre-divider at 1 to minimize PLL jitter */
> +static const struct clk_div_table meson8b_pll_prediv_div_table[] = {
> + { .val = 1, .div = 1 },
> + { /* sentinel */ }
> +};
> +
> +static struct clk_regmap meson8b_hdmi_prediv = {
> + .data = &(struct clk_regmap_div_data){
> + .offset = HHI_VID_PLL_CNTL,
> + .shift = 10,
> + .width = 5,
> + .table = meson8b_pll_prediv_div_table,
> + .flags = CLK_DIVIDER_INVALID_ZERO,
> + },
> + .hw.init = &(struct clk_init_data){
> + .name = "hdmi_prediv",
> + .ops = &clk_regmap_divider_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "xtal",
> + .index = -1,
> + },
> + .num_parents = 1,
> + },
> +};
> +
> static struct clk_fixed_factor hdmi_pll_dco_in = {
> .mult = 2,
> .div = 1,
> .hw.init = &(struct clk_init_data){
> .name = "hdmi_pll_dco_in",
> .ops = &clk_fixed_factor_ops,
> - .parent_data = &(const struct clk_parent_data) {
> - .fw_name = "xtal",
> - .index = -1,
> + .parent_hws = (const struct clk_hw *[]) {
> + &meson8b_hdmi_prediv.hw
> },
> .num_parents = 1,
> + .flags = CLK_SET_RATE_PARENT,
> },
> };
>
> @@ -247,11 +290,6 @@ static struct clk_regmap meson8b_hdmi_pll_dco = {
> .shift = 0,
> .width = 9,
> },
> - .n = {
> - .reg_off = HHI_VID_PLL_CNTL,
> - .shift = 10,
> - .width = 5,
> - },
> .frac = {
> .reg_off = HHI_VID_PLL_CNTL2,
> .shift = 0,
> @@ -279,6 +317,7 @@ static struct clk_regmap meson8b_hdmi_pll_dco = {
> &hdmi_pll_dco_in.hw
> },
> .num_parents = 1,
> + .flags = CLK_SET_RATE_PARENT,
> },
> };
>
> @@ -318,6 +357,26 @@ static struct clk_regmap meson8b_hdmi_pll_hdmi_out = {
> },
> };
>
> +static struct clk_regmap meson8b_sys_prediv = {
> + .data = &(struct clk_regmap_div_data){
> + .offset = HHI_SYS_PLL_CNTL,
> + .shift = 9,
> + .width = 5,
> + .table = meson8b_pll_prediv_div_table,
> + .flags = CLK_DIVIDER_INVALID_ZERO,
> + },
> + .hw.init = &(struct clk_init_data){
> + .name = "sys_prediv",
> + .ops = &clk_regmap_divider_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "xtal",
> + .name = "xtal",
> + .index = -1,
> + },
> + .num_parents = 1,
> + },
> +};
> +
> static struct clk_regmap meson8b_sys_pll_dco = {
> .data = &(struct meson_clk_pll_data){
> .en = {
> @@ -330,11 +389,6 @@ static struct clk_regmap meson8b_sys_pll_dco = {
> .shift = 0,
> .width = 9,
> },
> - .n = {
> - .reg_off = HHI_SYS_PLL_CNTL,
> - .shift = 9,
> - .width = 5,
> - },
> .l = {
> .reg_off = HHI_SYS_PLL_CNTL,
> .shift = 31,
> @@ -350,12 +404,11 @@ static struct clk_regmap meson8b_sys_pll_dco = {
> .hw.init = &(struct clk_init_data){
> .name = "sys_pll_dco",
> .ops = &meson_clk_pll_ops,
> - .parent_data = &(const struct clk_parent_data) {
> - .fw_name = "xtal",
> - .name = "xtal",
> - .index = -1,
> + .parent_hws = (const struct clk_hw *[]) {
> + &meson8b_sys_prediv.hw
> },
> .num_parents = 1,
> + .flags = CLK_SET_RATE_PARENT,
> },
> };
>
> @@ -2035,6 +2088,32 @@ static struct clk_regmap meson8b_mali = {
> },
> };
>
> +/* The GP PLL needs pre-divider 3 to achieve the target frequency 364Mhz */
> +static const struct clk_div_table meson8b_gp_prediv_div_table[] = {
> + { .val = 3, .div = 3 },
> + { /* sentinel */ }
> +};
> +
> +static struct clk_regmap meson8m2_gp_prediv = {
> + .data = &(struct clk_regmap_div_data){
> + .offset = HHI_GP_PLL_CNTL,
> + .shift = 9,
> + .width = 5,
> + .table = meson8b_gp_prediv_div_table,

You are going to divide by 3 an extra time with table unmodified

--
Jerome