[U-Boot] [PATCH v3 7/9] clk: clk-uclass: add clk_get_by_output_name

Philipp Tomsich philipp.tomsich at theobroma-systems.com
Wed Mar 1 21:20:06 UTC 2017


Signed-off-by: Philipp Tomsich <philipp.tomsich at theobroma-systems.com>
---
 drivers/clk/clk-uclass.c | 30 ++++++++++++++++++++++++++++++
 include/clk.h            | 22 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 6fcfd69..a6a65b2 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -10,6 +10,7 @@
 #include <clk.h>
 #include <clk-uclass.h>
 #include <dm.h>
+#include <dm/uclass-internal.h>
 #include <dt-structs.h>
 #include <errno.h>
 
@@ -113,6 +114,35 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
 
 	return clk_get_by_index(dev, index, clk);
 }
+
+int clk_get_by_output_name(const char *output_name, struct clk *clk)
+{
+	struct udevice *dev;
+	int idx;
+	int ret;
+
+	debug("%s(output=%s, clk==%p)\n", __func__, output_name, clk);
+
+	/* Try to find the clock among the already registered devices */
+	for (ret = uclass_find_first_device(UCLASS_CLK, &dev); dev;
+	     ret = uclass_find_next_device(&dev)) {
+		if (ret)
+			continue;
+
+		idx = fdt_stringlist_search(gd->fdt_blob,
+					    dev_of_offset(dev),
+					    "clock-output-names",
+					    output_name);
+		if (idx < 0)
+			continue;
+
+		clk->dev = dev;
+		clk->id = idx;
+		return idx;
+	}
+
+	return -ENOENT;
+}
 #endif /* OF_CONTROL */
 
 int clk_request(struct udevice *dev, struct clk *clk)
diff --git a/include/clk.h b/include/clk.h
index 5a5c2ff..d12b896 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -98,6 +98,22 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk);
  * @return 0 if OK, or a negative error code.
  */
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
+
+/**
+ * clk_get_by_output_name - Get a clock by its output name
+ *
+ * This looks up a clock from the bound clock-devices. The output_name
+ * is a string that should be present in the 'clock-output-names' list
+ * of one of those clocks.
+ *
+ * @output_name: A name contained in the output-name list of the node
+ *               associated with the target node.
+ * @clk:         A pointer to a clock structure to initialize.
+ * @return the index (of the name in the output-name list) if found, or
+ *             a negative error code.
+ */
+
+int clk_get_by_output_name(const char *output_name, struct clk *clk);
 #else
 static inline int clk_get_by_index(struct udevice *dev, int index,
 				   struct clk *clk)
@@ -110,6 +126,12 @@ static inline int clk_get_by_name(struct udevice *dev, const char *name,
 {
 	return -ENOSYS;
 }
+
+static inline int clk_get_by_output_name(const char *output_name,
+					 struct clk *clk)
+{
+	return -ENOSYS;
+}
 #endif
 
 /**
-- 
1.9.1



More information about the U-Boot mailing list