Linux clock framework development
 help / color / mirror / Atom feed
From: Pengfei Li <pengfei.li_1@nxp.com>
To: krzk+dt@kernel.org, robh@kernel.org, abelvesa@kernel.org,
	mturquette@baylibre.com, sboyd@kernel.org, conor+dt@kernel.org,
	shawnguo@kernel.org, s.hauer@pengutronix.de, ping.bai@nxp.com,
	ye.li@nxp.com, peng.fan@nxp.com, aisheng.dong@nxp.com,
	frank.li@nxp.com
Cc: kernel@pengutronix.de, festevam@gmail.com,
	linux-clk@vger.kernel.org, imx@lists.linux.dev,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] clk: imx93: Drop macro IMX93_CLK_END
Date: Tue, 25 Jun 2024 10:51:46 -0700	[thread overview]
Message-ID: <20240625175147.94985-2-pengfei.li_1@nxp.com> (raw)
In-Reply-To: <20240625175147.94985-1-pengfei.li_1@nxp.com>

IMX93_CLK_END was previously defined in imx93-clock.h to
indicate the number of clocks, but it is not part of the
ABI, so it should be dropped.

Now, the driver gets the number of clks by querying the
maximum index in the clk array. Due to the discontinuity
in the definition of clk index, with some gaps present,
the total count cannot be obtained by summing the array
size.

Signed-off-by: Pengfei Li <pengfei.li_1@nxp.com>
---
 drivers/clk/imx/clk-imx93.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c
index c6a9bc8ecc1f..68c929512e16 100644
--- a/drivers/clk/imx/clk-imx93.c
+++ b/drivers/clk/imx/clk-imx93.c
@@ -257,6 +257,20 @@ static const struct imx93_clk_ccgr {
 static struct clk_hw_onecell_data *clk_hw_data;
 static struct clk_hw **clks;
 
+static int imx_clks_get_num(void)
+{
+	u32 val = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(root_array); i++)
+		val = max_t(u32, val, root_array[i].clk);
+
+	for (i = 0; i < ARRAY_SIZE(ccgr_array); i++)
+		val = max_t(u32, val, ccgr_array[i].clk);
+
+	return val + 1;
+}
+
 static int imx93_clocks_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -264,14 +278,17 @@ static int imx93_clocks_probe(struct platform_device *pdev)
 	const struct imx93_clk_root *root;
 	const struct imx93_clk_ccgr *ccgr;
 	void __iomem *base, *anatop_base;
+	int clks_num;
 	int i, ret;
 
+	clks_num = imx_clks_get_num();
+
 	clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws,
-					  IMX93_CLK_END), GFP_KERNEL);
+					  clks_num), GFP_KERNEL);
 	if (!clk_hw_data)
 		return -ENOMEM;
 
-	clk_hw_data->num = IMX93_CLK_END;
+	clk_hw_data->num = clks_num;
 	clks = clk_hw_data->hws;
 
 	clks[IMX93_CLK_DUMMY] = imx_clk_hw_fixed("dummy", 0);
@@ -335,7 +352,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
 						  clks[IMX93_CLK_ARM_PLL]->clk,
 						  clks[IMX93_CLK_A55_GATE]->clk);
 
-	imx_check_clk_hws(clks, IMX93_CLK_END);
+	imx_check_clk_hws(clks, clks_num);
 
 	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
 	if (ret < 0) {
@@ -348,7 +365,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
 	return 0;
 
 unregister_hws:
-	imx_unregister_hw_clocks(clks, IMX93_CLK_END);
+	imx_unregister_hw_clocks(clks, clks_num);
 
 	return ret;
 }
-- 
2.34.1


  parent reply	other threads:[~2024-06-25  1:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25 17:51 [PATCH 0/2] clk: imx93: Drop macro IMX93_CLK_END Pengfei Li
2024-06-25  7:45 ` Krzysztof Kozlowski
2024-06-25 17:51 ` Pengfei Li [this message]
2024-06-25  2:06   ` [PATCH 1/2] " Peng Fan
2024-06-25  7:44   ` Krzysztof Kozlowski
2024-06-25 10:43     ` Pengfei Li
2024-06-25 13:40       ` Krzysztof Kozlowski
2024-06-28  1:17         ` Peng Fan
2024-06-28  6:21           ` Krzysztof Kozlowski
2024-06-28  6:28             ` Peng Fan
2024-06-25 17:51 ` [PATCH 2/2] dt-bindings: clock: imx93: Drop IMX93_CLK_END macro definition Pengfei Li
2024-06-25  2:07   ` Peng Fan
2024-06-25  7:44   ` Krzysztof Kozlowski

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=20240625175147.94985-2-pengfei.li_1@nxp.com \
    --to=pengfei.li_1@nxp.com \
    --cc=abelvesa@kernel.org \
    --cc=aisheng.dong@nxp.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=frank.li@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=peng.fan@nxp.com \
    --cc=ping.bai@nxp.com \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=ye.li@nxp.com \
    /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