From: Jian Hu <jian.hu@amlogic.com>
To: Jerome Brunet <jbrunet@baylibre.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Kevin Hilman <khilman@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH RFC RFT v2 2/3] clk: divider: add CLK_DIVIDER_INVALID_ZERO flag
Date: Fri, 20 Nov 2026 16:24:01 +0800 [thread overview]
Message-ID: <f70ae730-57d8-4b94-b1c1-d1e247f0c192@amlogic.com> (raw)
In-Reply-To: <179390104085.2573818.16461908615505096359.b4-review@b4>
On 11/6/2026 1:50 AM, Jerome Brunet wrote:
>> When a divider register reads zero, divider_recalc_rate() currently
>> emits a warning (unless CLK_DIVIDER_ALLOW_ZERO is set) and returns
>> the parent rate.
>>
>> This behaviour assumes a zero divisor acts as a pass-through, which
>> does not apply to all hardware. Some dividers, for example PLL
>> pre-dividers on Amlogic SoCs, come out of reset with a zero value
>> that does not produce a usable clock. Returning the parent rate
>> hides this fault behind an incorrect, plausible value.
>>
>> CLK_DIVIDER_ALLOW_ZERO only suppresses the warning while still
>> reporting the parent rate, so it cannot represent this hardware
>> behaviour.
>>
>> Add CLK_DIVIDER_INVALID_ZERO for dividers where a zero divisor value
>> is invalid. When this flag is set, recalc_rate() returns 0, making
>> the faulty state visible to the clock framework rather than hiding it
>> as a pass-through.
>>
>> Signed-off-by: Jian Hu <jian.hu@amlogic.com>
>> ---
>> drivers/clk/clk-divider.c | 3 +++
>> include/linux/clk-provider.h | 6 ++++++
>> 2 files changed, 9 insertions(+)
>>
>> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
>> index f68216c65d3d..6c1523d22477 100644
>> --- a/drivers/clk/clk-divider.c
>> +++ b/drivers/clk/clk-divider.c
>> @@ -143,6 +143,9 @@ unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
>>
>> div = _get_div(table, val, flags, width);
>> if (!div) {
>> + if (flags & CLK_DIVIDER_INVALID_ZERO)
>> + return 0;
> While I think CLK_DIVIDER_INVALID_ZERO really makes sense for a writeable divider
> only, to gracefully handle a reset value at zero that we would later correct,
> we should still handle all paths correctly. This include a RO divider and its
> determine rate path. I'll try to send something for this soon.
You are right, and I agree: a change in the core divider code has to be
correct for every user, not only for the cases this series happens to use it
for. I understand the RO divider / determine_rate path is the part that
still
needs handling.
I will drop the 2/3 patch in v3 since you will submit it separately.
>> +
>> WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO),
>> "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n",
>> clk_hw_get_name(hw));
>> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
>> index dc8e161f9c2c..fe2dbbba49e3 100644
>> --- a/include/linux/clk-provider.h
>> +++ b/include/linux/clk-provider.h
>> @@ -744,6 +744,11 @@ struct clk_div_table {
>> * big endian.
>> * CLK_DIVIDER_EVEN_INTEGERS - clock divisor is 2, 4, 6, 8, 10, etc.
>> * Formula is 2 * (value read from hardware + 1).
>> + * CLK_DIVIDER_INVALID_ZERO - a zero value read from the register is not a
>> + * divide by one / bypass but an invalid setting which does not produce
>> + * a usable clock. recalc_rate() returns 0 so that the broken state is
>> + * reported to the framework instead of the parent rate, without
>> + * triggering the CLK_DIVIDER_ALLOW_ZERO warning.
>
> CLK_DIVIDER_INVALID_ZERO - a zero divisor is an invalid setting with no
> usable output. recalc_rate() returns 0 instead of the parent rate.
> Takes precedence over CLK_DIVIDER_ALLOW_ZERO.
Ok, it is short and clear.
> --
> Jerome
--
Jian
next prev parent reply other threads:[~2026-11-20 8:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 9:30 [PATCH RFC RFT v2 0/3] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-10-29 9:30 ` [PATCH RFC RFT v2 1/3] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
2026-10-29 9:30 ` [PATCH RFC RFT v2 2/3] clk: divider: add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
2026-11-05 17:50 ` Jerome Brunet
2026-11-20 8:24 ` Jian Hu [this message]
2026-10-29 9:30 ` [PATCH RFC RFT v2 3/3] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay
2026-11-05 17:50 ` Jerome Brunet
2026-11-05 17:50 ` [PATCH RFC RFT v2 0/3] clk: meson: Refactor PLL pre-divider as a divider clock Jerome Brunet
2026-11-09 8:55 ` Jian Hu
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=f70ae730-57d8-4b94-b1c1-d1e247f0c192@amlogic.com \
--to=jian.hu@amlogic.com \
--cc=bmasney+clk@redhat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jbrunet+clk@baylibre.com \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
/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®