[U-Boot] [PATCH v6 04/11] clk: add clk_count()
patrice.chotard at st.com
patrice.chotard at st.com
Mon Jun 5 09:42:04 UTC 2017
From: Patrice Chotard <patrice.chotard at st.com>
Add clk_count() method to be able to get the number
of clocks contained into a clock property. This will allow
to allocate the right amount of memory in order to keep clock
reference. These clock reference can be used later on error path
or in .remove callback to release these clocks.
Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
---
v6: _ replace clk_get_by_index() by dev_read_phandle_with_args() in
clk_count()
v5: _ none
v4: _ add clk_count() method
drivers/clk/clk-uclass.c | 13 +++++++++++++
include/clk.h | 12 ++++++++++++
2 files changed, 25 insertions(+)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 83b6328..38d5f80 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -95,8 +95,21 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
return clk_request(dev_clk, clk);
}
+
# endif /* OF_PLATDATA */
+int clk_count(struct udevice *dev)
+{
+ int count;
+ struct ofnode_phandle_args args;
+
+ for (count = 0; ; count++) {
+ if (dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
+ count, &args))
+ return count;
+ }
+}
+
int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
{
int index;
diff --git a/include/clk.h b/include/clk.h
index 5a5c2ff..801920c 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -98,6 +98,18 @@ 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_count - Get clock count contained in the "clocks" property.
+ *
+ * This returns the count of clock found into the "clocks" property. This
+ * allows to allocate the right amount of memory to keep clock reference.
+ *
+ * @dev: The client device.
+ * @return number of clocks found.
+ */
+int clk_count(struct udevice *dev);
+
#else
static inline int clk_get_by_index(struct udevice *dev, int index,
struct clk *clk)
--
1.9.1
More information about the U-Boot
mailing list