From: Xukai Wang <kingxukai@zohomail.com>
To: Vivian Wang <wangruikang@iscas.ac.cn>, Yao Zi <ziyao@disroot.org>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Conor Dooley <conor@kernel.org>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
Samuel Holland <samuel.holland@sifive.com>,
Troy Mitchell <TroyMitchell988@gmail.com>
Subject: Re: [PATCH v8 2/3] clk: canaan: Add clock driver for Canaan K230
Date: Wed, 10 Sep 2025 16:38:11 +0800 [thread overview]
Message-ID: <9a0eedb5-1d90-4bdb-9bc3-4b3ade29cc2f@zohomail.com> (raw)
In-Reply-To: <8ca70773-42b0-4dcc-8b54-338594e9a8ea@iscas.ac.cn>
On 2025/9/9 15:02, Vivian Wang wrote:
> On 9/8/25 22:13, Xukai Wang wrote:
>>>> [...]
>>>>
>>>> +
>>>> +static int k230_clk_set_rate_mul_div(struct clk_hw *hw, unsigned long rate,
>>>> + unsigned long parent_rate)
>>>> +{
>>>> + struct k230_clk_rate *clk = hw_to_k230_clk_rate(hw);
>>>> + struct k230_clk_rate_self *rate_self = &clk->clk;
>>>> + u32 div, mul, div_reg, mul_reg;
>>>> +
>>>> + if (rate > parent_rate)
>>>> + return -EINVAL;
>>>> +
>>>> + if (rate_self->read_only)
>>>> + return 0;
>>>> +
>>>> + if (k230_clk_find_approximate_mul_div(rate_self->mul_min, rate_self->mul_max,
>>>> + rate_self->div_min, rate_self->div_max,
>>>> + rate, parent_rate, &div, &mul))
>>>> + return -EINVAL;
>>>> +
>>>> + guard(spinlock)(rate_self->lock);
>>>> +
>>>> + div_reg = readl(rate_self->reg + clk->div_reg_off);
>>>> + div_reg |= ((div - 1) & rate_self->div_mask) << (rate_self->div_shift);
>>>> + div_reg |= BIT(rate_self->write_enable_bit);
>>>> + writel(div_reg, rate_self->reg + clk->div_reg_off);
>>>> +
>>>> + mul_reg = readl(rate_self->reg + clk->mul_reg_off);
>>>> + mul_reg |= ((mul - 1) & rate_self->mul_mask) << (rate_self->mul_shift);
>>>> + mul_reg |= BIT(rate_self->write_enable_bit);
>>>> + writel(mul_reg, rate_self->reg + clk->mul_reg_off);
>>>> +
>>>> + return 0;
>>>> +}
>>> There are three variants of rate clocks, mul-only, div-only and mul-div
>>> ones, which are similar to clk-multiplier, clk-divider,
>>> clk-fractional-divider.
>>>
>>> The only difference is to setup new parameters for K230's rate clocks,
>>> a register bit, described as k230_clk_rate_self.write_enable_bit, must
>>> be set first.
>> Actually, I think the differences are not limited to just the
>> write_enable_bit. There are also distinct mul_min, mul_max, div_min, and
>> div_max values, which are not typically just 1 and (1 << bit_width) as
>> in standard clock divider or multiplier structures.
> So the part I have been thinking about is, consider just checking the
> {mul,div}_{min,max} values to determine which kind it is? As is this is
> just redundant information, since you can infer whether there is a
> configurable multiplier by checking if mul_{min,max} are equal. Same for
> div_{min,max}.
>
> Vivian "dramforever" Wang
Thanks for pointing it out. I see your idea, but I don’t think it’s
necessary to determine the clock type from {mul,div}_{min,max}
dynamically since we already statically specify each mul, div, and
mul-div clock by different macros.
next prev parent reply other threads:[~2025-09-10 8:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 3:10 [PATCH v8 0/3] riscv: canaan: Add support for K230 clock Xukai Wang
2025-09-05 3:10 ` [PATCH v8 1/3] dt-bindings: clock: Add bindings for Canaan K230 clock controller Xukai Wang
2025-09-05 3:10 ` [PATCH v8 2/3] clk: canaan: Add clock driver for Canaan K230 Xukai Wang
2025-09-05 4:12 ` Xukai Wang
2025-09-07 3:13 ` Yao Zi
2025-09-07 3:17 ` Yao Zi
2025-09-08 14:13 ` Xukai Wang
2025-09-09 2:51 ` Yao Zi
2025-09-09 5:01 ` Xukai Wang
2025-09-09 7:02 ` Vivian Wang
2025-09-10 8:38 ` Xukai Wang [this message]
2025-09-05 3:10 ` [PATCH v8 3/3] riscv: dts: canaan: Add clock definition for K230 Xukai Wang
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=9a0eedb5-1d90-4bdb-9bc3-4b3ade29cc2f@zohomail.com \
--to=kingxukai@zohomail.com \
--cc=TroyMitchell988@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=conor@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mturquette@baylibre.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=samuel.holland@sifive.com \
--cc=sboyd@kernel.org \
--cc=wangruikang@iscas.ac.cn \
--cc=ziyao@disroot.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;
as well as URLs for NNTP newsgroup(s).