Devicetree
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Chuanhong Guo <gch981213@gmail.com>
Cc: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney@redhat.com>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 4/4] clk: add support for siflower sf21-topcrm
Date: Fri, 22 May 2026 15:44:40 +0000	[thread overview]
Message-ID: <ahB46uuoFQxKgr7r@pie> (raw)
In-Reply-To: <CAJsYDVJZW2VYFaxzJRg2+CJZbvqq_iRXaf7+zYvidQn0AiviKQ@mail.gmail.com>

On Mon, May 18, 2026 at 09:34:17PM +0800, Chuanhong Guo wrote:
> Hi!
> 
> On Mon, May 18, 2026 at 8:22 PM Yao Zi <me@ziyao.cc> wrote:
> >
> > On Sun, May 17, 2026 at 10:12:58PM +0800, Chuanhong Guo wrote:

...

> >
> > [...]
> >
> > Besides field/register offsets, the only difference I could tell between
> > cmnpll_postdiv and pciepll_fout is that pciepll_fout clocks could be
> > gated.
> >
> > Would it be a good idea to describe the gating function separately as a
> > clock, and merge the common part of pciepll_fout and cmnpll_postdiv? In
> > which way you could save a lot of mostly duplicated code.
> 
> I don't think so. Since the majority of the existing code are register
> operations, and the register bit layout are completely different,
> there isn't much to share between these two PLLs.
> Writing a struct to describe both register layouts together seems
> unnecessarily complicated and harder to read.

I'm not suggesting merging the implementation of the two PLLs
themselves, but only the two types of clocks derived from them,
i.e. cmnpll_postdiv and pciepll_fout.

> BTW the CMNPLL and PCIEPLL are actually different hardware.
> The former is an integer PLL while the latter actually supports
> fractional operations. I didn't add support for the fractional part
> due to the lack of use cases and documentation. PCIE and GMAC
> clocks are fed by this PLL and require exact clock frequencies
> which can be achieved using only the integer mode.
> 
> >
> > > +     .recalc_rate = sf21_pciepll_fout_recalc_rate,
> > > +     .determine_rate = sf21_pciepll_fout_determine_rate,
> > > +     .set_rate = sf21_pciepll_fout_set_rate,
> > > +};
> > [...]
> > > +
> > > +     spin_lock_irqsave(cmn_priv->lock, flags);
> > > +     if (index)
> > > +             sf_rmw(cmn_priv, mux_reg, 0, BIT(mux_offs));
> > > +     else
> > > +             sf_rmw(cmn_priv, mux_reg, BIT(mux_offs), 0);
> > > +
> > > +     spin_unlock_irqrestore(cmn_priv->lock, flags);
> > > +     return 0;
> > > +}
> >
> > I believe besides the divider reloading part, clk_mux_ops,
> > clk_divider_ops, and clk_gate_ops have already provided the logic
> > you implemented here. So it might be a better option to composite them
> > together to implement your clocks instead of building from scratch.
> 
> The divider reloading is the exact reason I chose to not compose them
> with the function you mentioned. The reloading bit need to be set on
> both clock divider change and clock enabling, because the clock divider
> loading only happens when the clock is running. Since I already have
> to write two of the three parts you mentioned, trying to reuse
> clk_mux_ops doesn't seem to reduce the code complexity here.

You don't have to write divider/gate operations from scratch, but only
wrappers that first call clk_{divider,gate}_ops.* then trigger frequency
reloading.

> It's just trading get_parent and set_parent call with one more level
> in the clock tree for every clock and more code to wire them together
> in the probe function.
> 
> >
> > > +static const struct clk_ops sf21_clk_muxdiv_ops = {
> > > +     .enable = sf21_muxdiv_enable,
> > > +     .disable = sf21_muxdiv_disable,
> > > +     .is_enabled = sf21_muxdiv_is_enabled,
> > > +     .recalc_rate = sf21_muxdiv_recalc_rate,
> > > +     .determine_rate = sf21_muxdiv_determine_rate,
> > > +     .set_rate = sf21_muxdiv_set_rate,
> > > +     .get_parent = sf21_muxdiv_get_parent,
> > > +     .set_parent = sf21_muxdiv_set_parent,
> > > +};

Regards,
Yao Zi

      reply	other threads:[~2026-05-22 15:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-17 14:12 [PATCH 0/4] clk: add Siflower SF21 topcrm support Chuanhong Guo
2026-05-17 14:12 ` [PATCH 1/4] riscv: add Siflower RISC-V SoC family Kconfig support Chuanhong Guo
2026-05-17 14:31   ` sashiko-bot
2026-05-17 20:46     ` Conor Dooley
2026-05-18 14:17       ` Chuanhong Guo
2026-05-17 14:12 ` [PATCH 2/4] dt-bindings: clock: add binding header for sf21-topcrm Chuanhong Guo
2026-05-17 14:36   ` sashiko-bot
2026-05-17 20:47   ` Conor Dooley
2026-05-17 20:51     ` Conor Dooley
2026-05-18 11:42       ` Chuanhong Guo
2026-05-18 11:04   ` Yao Zi
2026-05-18 11:43     ` Chuanhong Guo
2026-05-17 14:12 ` [PATCH 3/4] dt-bindings: clock: add doc for Siflower sf21-topcrm Chuanhong Guo
2026-05-17 15:35   ` Rob Herring (Arm)
2026-05-17 20:50   ` Conor Dooley
2026-05-18 12:12     ` Chuanhong Guo
2026-05-18 12:28       ` Yao Zi
2026-05-17 14:12 ` [PATCH 4/4] clk: add support for siflower sf21-topcrm Chuanhong Guo
2026-05-17 15:09   ` sashiko-bot
2026-05-18 14:12     ` Chuanhong Guo
2026-05-18 12:21   ` Yao Zi
2026-05-18 13:34     ` Chuanhong Guo
2026-05-22 15:44       ` Yao Zi [this message]

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=ahB46uuoFQxKgr7r@pie \
    --to=me@ziyao.cc \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=bmasney@redhat.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gch981213@gmail.com \
    --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=p.zabel@pengutronix.de \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.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