From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] clk: of: make of_clk_init() safe for being called multiple times
Date: Wed, 22 Mar 2023 09:32:44 +0100 [thread overview]
Message-ID: <20230322083245.251340-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230322083245.251340-1-s.hauer@pengutronix.de>
Applying device tree overlays to the barebox live tree currently works
for devices handled by regular drivers, but not for clocks which do
not have a regular driver, but instead are declared with CLK_OF_DECLARE.
To support adding such clocks with a device tree overlay we have to
call of_clk_init() again. This patch makes of_clk_init() safe for being
called multiple times. For this we have to make sure we do not register
clocks for nodes which already have a clock.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/clk/clk.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index c7ee6878c2..7406dba260 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -847,6 +847,18 @@ static int parent_ready(struct device_node *np)
}
}
+static LIST_HEAD(probed_clks);
+
+static bool of_clk_probed(struct device_node *np)
+{
+ struct clock_provider *clk_provider;
+
+ list_for_each_entry(clk_provider, &probed_clks, node)
+ if (clk_provider->np == np)
+ return true;
+ return false;
+}
+
/**
* of_clk_init() - Scan and init clock providers from the DT
*
@@ -875,6 +887,11 @@ int of_clk_init(void)
if (!of_device_is_available(root))
continue;
+ if (of_clk_probed(root)) {
+ pr_debug("%s: already probed: %pOF\n", __func__, root);
+ continue;
+ }
+
parent = xzalloc(sizeof(*parent));
parent->clk_init_cb = match->data;
@@ -894,8 +911,7 @@ int of_clk_init(void)
clk_provider->clk_init_cb(np);
of_clk_set_defaults(np, true);
- list_del(&clk_provider->node);
- free(clk_provider);
+ list_move_tail(&clk_provider->node, &probed_clks);
is_init_done = true;
}
}
--
2.30.2
next prev parent reply other threads:[~2023-03-22 8:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 8:32 [PATCH 0/4] Allow to probe clks added in overlays Sascha Hauer
2023-03-22 8:32 ` [PATCH 1/4] clk: clk-gpio: Turn into driver Sascha Hauer
2023-03-22 8:32 ` [PATCH 2/4] clk: of: drop arguments from of_clk_init() Sascha Hauer
2023-03-22 8:32 ` Sascha Hauer [this message]
2023-03-22 8:32 ` [PATCH 4/4] commands: of_overlay: Allow to register clocks from overlay Sascha Hauer
2023-03-22 9:25 ` Sascha Hauer
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=20230322083245.251340-4-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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