mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: Jian Hu <jian.hu@amlogic.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org,
	devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	neil.armstrong@linaro.org
Subject: Re: [PATCH RFC RFT v3 08/13] clk: meson: g12a: Model the PLL pre-divider as a divider clock
Date: Thu, 3 Dec 2026 10:30:17 +0800	[thread overview]
Message-ID: <4ed58097-d557-46c1-a55c-6fcd4dcc1562@amlogic.com> (raw)
In-Reply-To: <sashiko-outbox-242950@kernel.org>


On 12/1/2026 5:19 PM, sashiko-bot@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@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

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-12-03  2:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor " 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-03  7:58     ` Jian Hu
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-02  9:19     ` Jian Hu
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-03  2:30     ` Jian Hu [this message]
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

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=4ed58097-d557-46c1-a55c-6fcd4dcc1562@amlogic.com \
    --to=jian.hu@amlogic.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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

all inboxes | Powered by JetHome®