Linux clock framework development
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Brian Masney <masneyb@kernel.org>
Cc: Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Felix Fietkau <nbd@nbd.name>,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v15 4/5] clk: en7523: generalize register clocks function
Date: Mon, 30 Nov 2026 01:31:47 +0100	[thread overview]
Message-ID: <6b0cc405.f0979b8b.82d75.69b8@mx.google.com> (raw)
In-Reply-To: <179599621643.201962.10048110742781718297.b4-review@b4>

On Sun, Nov 29, 2026 at 06:50:16PM -0500, Brian Masney wrote:
> Hi Christian,
> 
> > Airoha AN7583 SoC will use the same logic used by Airoha EN7581 SoC to
> > register clocks. Generalize it to register clocks defined in soc_data.
> > 
> > Add the clocks definition in EN7581 SoC to support this new implementation.
> > 
> > Rework the .num_clocks value to declare the number of base clocks and
> > increase internally if PCIe OPs is_enabled is defined.
> > 
> > EN751221 is updated to address the new num_clocks meaning.
> > 
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> >  drivers/clk/clk-en7523.c | 29 +++++++++++++++++++----------
> >  1 file changed, 19 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> > index 280918ec25e3..d2cc25f30561 100644
> > --- a/drivers/clk/clk-en7523.c
> > +++ b/drivers/clk/clk-en7523.c
> > @@ -147,6 +147,7 @@ struct en_clk_priv {
> >  
> >  struct en_clk_soc_data {
> >  	u32 num_clocks;
> > +	const struct en_clk_desc *base_clks;
> >  	const struct clk_ops pcie_ops;
> >  	int (*hw_init)(struct platform_device *pdev,
> >  		       struct clk_hw_onecell_data *clk_data);
> > @@ -799,12 +800,15 @@ static int en7523_clk_hw_init(struct platform_device *pdev,
> >  static void en7581_register_clocks(struct device *dev, struct clk_hw_onecell_data *clk_data,
> >  				   struct regmap *map, void __iomem *base)
> >  {
> > +	const struct en_clk_soc_data *soc_data;
> >  	struct clk_hw *hw;
> >  	u32 rate;
> >  	int i;
> >  
> > -	for (i = 0; i < ARRAY_SIZE(en7581_base_clks); i++) {
> > -		const struct en_clk_desc *desc = &en7581_base_clks[i];
> > +	soc_data = device_get_match_data(dev);
> > +
> > +	for (i = 0; i < soc_data->num_clocks; i++) {
> > +		const struct en_clk_desc *desc = &soc_data->base_clks[i];
> >  		u32 val, reg = desc->div_reg ? desc->div_reg : desc->base_reg;
> >  		int err;
> >  
> > @@ -1246,7 +1250,7 @@ static int en7523_clk_probe(struct platform_device *pdev)
> >  	const struct en_clk_soc_data *soc_data;
> >  	struct clk_hw_onecell_data *clk_data;
> >  	struct en_clk_priv *priv;
> > -	int r;
> > +	int num_clocks, r;
> >  
> >  	soc_data = device_get_match_data(&pdev->dev);
> >  
> > @@ -1256,15 +1260,18 @@ static int en7523_clk_probe(struct platform_device *pdev)
> >  
> >  	spin_lock_init(&priv->lock);
> >  
> > -	clk_data = devm_kzalloc(&pdev->dev,
> > -				struct_size(clk_data, hws, soc_data->num_clocks),
> > -				GFP_KERNEL);
> > +	num_clocks = soc_data->num_clocks;
> > +	/* Num clocks are incremented by 1 if PCIe clock is supported */
> > +	if (soc_data->pcie_ops.is_enabled)
> > +		num_clocks++;
> 
> Why can't soc_data->num_clocks store the actual count? Or in a different
> variable? Below you have to subtract one, and this is very fragile.
> 

I agree it's very fragile.

> > +
> > +	clk_data = devm_kzalloc_flex(&pdev->dev, *clk_data, hws, num_clocks);
> >  	if (!clk_data)
> >  		return -ENOMEM;
> >  
> >  	platform_set_drvdata(pdev, priv);
> >  
> > -	clk_data->num = soc_data->num_clocks;
> > +	clk_data->num = num_clocks;
> >  	r = soc_data->hw_init(pdev, clk_data);
> >  	if (r)
> >  		return r;
> > @@ -1273,7 +1280,7 @@ static int en7523_clk_probe(struct platform_device *pdev)
> >  }
> >  
> >  static const struct en_clk_soc_data en7523_data = {
> > -	.num_clocks = ARRAY_SIZE(en7523_base_clks) + 1,
> > +	.num_clocks = ARRAY_SIZE(en7523_base_clks),
> >  	.pcie_ops = {
> >  		.is_enabled = en7523_pci_is_enabled,
> >  		.prepare = en7523_pci_prepare,
> > @@ -1284,8 +1291,8 @@ static const struct en_clk_soc_data en7523_data = {
> >  };
> >  
> >  static const struct en_clk_soc_data en7581_data = {
> > -	/* We increment num_clocks by 1 to account for additional PCIe clock */
> > -	.num_clocks = ARRAY_SIZE(en7581_base_clks) + 1,
> > +	.base_clks = en7581_base_clks,
> > +	.num_clocks = ARRAY_SIZE(en7581_base_clks),
> >  	.pcie_ops = {
> >  		.is_enabled = en7581_pci_is_enabled,
> >  		.enable = en7581_pci_enable,
> > @@ -1295,7 +1302,8 @@ static const struct en_clk_soc_data en7581_data = {
> >  };
> >  
> >  static const struct en_clk_soc_data en751221_data = {
> > -	.num_clocks = EN751221_MAX_CLKS,
> > +	/* Decrease of one as PCIe is incremented internally with PCIe OPs */
> > +	.num_clocks = EN751221_MAX_CLKS - 1,
> 
> Here's where it's decremented again.
> 

Maybe you can also help here... the main problem is that there is this
special handling for the PCIe clock that is handled outside all the other
clocks... but for EN751221 it's included in the define... it was to not
change the resto of the code to align to the new define meaning...

Seems wasteful to introduce a dedicated variable for all the clocks and one
for only the SCU one.

But up to you what you prefer.

-- 
	Ansuel

  reply	other threads:[~2026-11-30  0:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 21:27 [PATCH v15 0/5] clk: add support for Airoha AN7583 clock Christian Marangi
2026-11-21 21:27 ` [PATCH v15 1/5] dt-bindings: clock: airoha: Document support for " Christian Marangi
2026-11-21 21:27 ` [PATCH v15 2/5] clk: en7523: use devm variant for clk_hw_register and fixed clock Christian Marangi
2026-11-21 21:27 ` [PATCH v15 3/5] clk: en7523: protect concurrent access to reset and PCI register Christian Marangi
2026-11-29 23:50   ` Brian Masney
2026-11-21 21:27 ` [PATCH v15 4/5] clk: en7523: generalize register clocks function Christian Marangi
2026-11-29 23:50   ` Brian Masney
2026-11-30  0:31     ` Christian Marangi [this message]
2026-11-21 21:27 ` [PATCH v15 5/5] clk: en7523: add support for Airoha AN7583 clock Christian Marangi
2026-11-21 21:33   ` sashiko-bot
2026-11-29 23:50   ` Brian Masney

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=6b0cc405.f0979b8b.82d75.69b8@mx.google.com \
    --to=ansuelsmth@gmail.com \
    --cc=bmasney+clk@redhat.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jbrunet+clk@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masneyb@kernel.org \
    --cc=nbd@nbd.name \
    --cc=p.zabel@pengutronix.de \
    --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