[PATCH 3/4] clk: of: make of_clk_init() safe for being called multiple times
Sascha Hauer
s.hauer at pengutronix.de
Wed Mar 22 01:32:44 PDT 2023
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 at 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
More information about the barebox
mailing list