[PATCH RFC RFT v3 08/13] clk: meson: g12a: Model the PLL pre-divider as a divider clock
Jian Hu
jian.hu at amlogic.com
Wed Dec 2 18:30:17 PST 2026
On 12/1/2026 5:19 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] clk: meson: g12a: CLK_GET_RATE_NOCACHE on prediv clocks does
> not update children
> --
>
> commit 1cb730ae65d6d705f933c3659db77a276e9bbf91
> Author: Jian Hu <jian.hu at amlogic.com>
>
> clk: meson: g12a: Model the PLL pre-divider as a divider clock
>
> This commit replaces the embedded n pre-divider parameter on G12A/G12B/SM1
> PLL DCO clocks with standalone clk_regmap divider clocks wired as parents of
> each PLL DCO.
>
>> diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c
>> index beed610e4a825..09eb842e0b1aa 100644
>> --- a/drivers/clk/meson/g12a.c
>> +++ b/drivers/clk/meson/g12a.c
> [ ... ]
>> @@ -609,6 +704,32 @@ static struct clk_regmap g12a_hifi_pll = {
>> },
>> };
>>
>> +static struct clk_regmap g12a_pcie_prediv = {
>> + .data = &(struct clk_regmap_div_data){
>> + .offset = HHI_PCIE_PLL_CNTL0,
>> + .shift = 10,
>> + .width = 5,
>> + .table = g12a_pll_prediv_div_table,
>> + .flags = CLK_DIVIDER_INVALID_ZERO,
>> + },
>> + .hw.init = &(struct clk_init_data){
>> + .name = "pcie_prediv",
>> + .ops = &clk_regmap_divider_ops,
>> + .parent_data = &(const struct clk_parent_data) {
>> + .fw_name = "xtal",
>> + },
>> + .num_parents = 1,
>> + /*
>> + * The PCIe prediv register reads zero on power-on.
>> + * CLK_DIVIDER_INVALID_ZERO makes the first rate return 0 Hz,
>> + * which gets cached by CCF. The PCIe PLL enable callback
>> + * later writes a valid non-zero divider value. Use
>> + * CLK_GET_RATE_NOCACHE to avoid stale cached rate.
>> + */
>> + .flags = CLK_GET_RATE_NOCACHE,
>> + },
>> +};
> [ ... ]
>> @@ -674,10 +790,11 @@ static struct clk_regmap g12a_pcie_pll_dco = {
>> .hw.init = &(struct clk_init_data){
>> .name = "pcie_pll_dco",
>> .ops = &meson_clk_pcie_pll_ops,
>> - .parent_data = &(const struct clk_parent_data) {
>> - .fw_name = "xtal",
>> + .parent_hws = (const struct clk_hw *[]) {
>> + &g12a_pcie_prediv.hw
>> },
>> .num_parents = 1,
>> + .flags = CLK_SET_RATE_PARENT,
>> },
>> };
>>
>> @@ -729,6 +846,33 @@ static struct clk_fixed_factor g12a_pcie_pll = {
>> },
>> };
>>
>> +static struct clk_regmap g12a_hdmi_prediv = {
>> + .data = &(struct clk_regmap_div_data){
>> + .offset = HHI_HDMI_PLL_CNTL0,
>> + .shift = 10,
>> + .width = 5,
>> + /*
>> + * The pre-divider register reads zero until the display driver
>> + * programs the HDMI PLL, so a zero divisor is not a fault here:
>> + * treat it as a bypass instead of warning at registration.
>> + */
>> + .flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO,
>> + },
>> + .hw.init = &(struct clk_init_data){
>> + .name = "hdmi_prediv",
>> + .ops = &clk_regmap_divider_ro_ops,
>> + .parent_data = &(const struct clk_parent_data) {
>> + .fw_name = "xtal",
>> + },
>> + .num_parents = 1,
>> + /*
>> + * Display directly handle hdmi pll registers ATM, we need
>> + * NOCACHE to keep our view of the clock as accurate as possible
>> + */
>> + .flags = CLK_GET_RATE_NOCACHE,
>> + },
>> +};
> [Severity: Medium]
> Does setting CLK_GET_RATE_NOCACHE on g12a_pcie_prediv and g12a_hdmi_prediv
> actually refresh their rates when clk_get_rate() is called on descendant
> clocks such as CLKID_PCIE_PLL or CLKID_HDMI_PLL?
>
> In clk_core_get_rate_recalc(), CCF only invokes __clk_recalc_rates() if
> CLK_GET_RATE_NOCACHE is set on the queried clock itself, and
> __clk_recalc_rates() walks downward using core->parent->rate from the parent's
> cache without walking upward to recalculate ancestors:
>
> drivers/clk/clk.c:clk_core_get_rate_recalc() {
> if (core && (core->flags & CLK_GET_RATE_NOCACHE))
> __clk_recalc_rates(core, false, 0);
>
> return clk_core_get_rate_nolock(core);
> }
>
> For PCIe, HHI_PCIE_PLL_CNTL0 reads 0 at boot, so g12a_pcie_prediv and its
> descendants register with a cached rate of 0 Hz. Because meson_clk_pcie_pll_ops
> has no .set_rate callback and only writes g12a_pcie_pll_init_regs in .enable
> (meson_clk_pcie_pll_enable()), and none of g12a_pcie_pll_dco..g12a_pcie_pll
> carry CLK_GET_RATE_NOCACHE, CLKID_PCIE_PLL remains cached at 0 Hz even after
> clk_prepare_enable(). At this commit (prior to commit "clk: meson: pll:
> Remove the dedicated n parameter" adding parent rate negotiation to
> meson_clk_pll_determine_rate()), clk_set_rate(CLKID_PCIE_PLL, 100000000) from
> assigned-clock-rates on usb3_pcie_phy also fails with -EINVAL because
> req->best_parent_rate is 0.
>
> Similarly, for HDMI, calling clk_get_rate() on g12a_hdmi_pll_dco or
> g12a_hdmi_pll after the display driver directly updates HHI_HDMI_PLL_CNTL0
> recalculates from g12a_hdmi_prediv's cached rate rather than re-reading the
> pre-divider register.
The scenario you described indeed does not require 'CLK_GET_RATE_NOCACHE'.
Only debugfs reads this prediv clock, and it walks clocks top-down.
Without the `CLK_GET_RATE_NOCACHE` flag, the hdmi_prediv clock cached rate
will become stale when registers are written directly by DRM.
This leads to incorrect rate values when cat
/sys/kernel/debug/clk/clk_summary.
The same applies to the g12a_pcie_prediv.
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com?part=8
More information about the linux-amlogic
mailing list