Add clk_resolve_parent_clk() to resolve parent clock udevice name
based on clock-names DT property. This is used in SoC clock drivers
to look up the clock name in clock tables, which matches a clock
name in DT clock-names property, and convert it into udevice name
which is used by U-Boot clock framework to look up parent clock in
e.g. clk_register() using uclass_get_device_by_name(UCLASS_CLK,
parent_name, &parent);

Signed-off-by: Marek Vasut <ma...@denx.de>
---
Cc: Adam Ford <aford...@gmail.com>
Cc: Christoph Niedermaier <cniederma...@dh-electronics.com>
Cc: Dong Aisheng <aisheng.d...@nxp.com>
Cc: Fabio Estevam <feste...@denx.de>
Cc: Hou Zhiqiang <zhiqiang....@nxp.com>
Cc: Michael Trimarchi <mich...@amarulasolutions.com>
Cc: Peng Fan <peng....@nxp.com>
Cc: Tim Harvey <thar...@gateworks.com>
Cc: Tom Rini <tr...@konsulko.com>
Cc: u-boot@lists.denx.de
Cc: uboot-...@nxp.com
---
V2: Rebase on u-boot/next with additional clock patches
---
 drivers/clk/clk-uclass.c | 18 ++++++++++++++++++
 include/clk.h            |  9 +++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 353ae476068..90b70529a47 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -420,6 +420,24 @@ int clk_get_by_name_nodev(ofnode node, const char *name, 
struct clk *clk)
        return clk_get_by_index_nodev(node, index, clk);
 }
 
+const char *
+clk_resolve_parent_clk(struct udevice *dev, const char *name)
+{
+       struct udevice *parent;
+       struct clk clk;
+       int ret;
+
+       ret = uclass_get_device_by_name(UCLASS_CLK, name, &parent);
+       if (!ret)
+               return name;
+
+       ret = clk_get_by_name(dev, name, &clk);
+       if (!clk.dev)
+               return name;
+
+       return clk.dev->name;
+}
+
 int clk_release_all(struct clk *clk, unsigned int count)
 {
        unsigned int i;
diff --git a/include/clk.h b/include/clk.h
index 045e923a529..a6ef4e02692 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -350,6 +350,15 @@ static inline int clk_get_by_name_nodev_optional(ofnode 
node, const char *name,
        return ret;
 }
 
+/**
+ * clk_resolve_parent_clk - Determine name of clock udevice based on 
clock-names
+ * @dev:       The client udevice.
+ * @name:      The name of the clock to look up.
+ *
+ * Return name of the clock udevice which represents clock with clock-names 
name.
+ */
+const char *clk_resolve_parent_clk(struct udevice *dev, const char *name);
+
 /**
  * enum clk_defaults_stage - What stage clk_set_defaults() is called at
  * @CLK_DEFAULTS_PRE: Called before probe. Setting of defaults for clocks owned
-- 
2.47.2

Reply via email to