[U-Boot] [PATCH v2 04/17] dm: clk: Define clk_get_by_id() for clk operations
Lukasz Majewski
lukma at denx.de
Thu Jan 31 09:03:22 UTC 2019
This commit adds the clk_get_by_id() function, which is responsible
for getting the udevice with matching clk->id. Such approach allows
re-usage of inherit DM list relationship for the same class (UCLASS_CLK).
As a result - we don't need any other external list - it is just enough
to look for UCLASS_CLK related udevices.
Signed-off-by: Lukasz Majewski <lukma at denx.de>
---
Changes in v2: None
drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++
include/clk.h | 11 +++++++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index f1640dda67..12ec0baa74 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -455,6 +455,28 @@ int clk_disable_bulk(struct clk_bulk *bulk)
return 0;
}
+int clk_get_by_id(ulong id, struct clk **c)
+{
+ struct udevice *dev;
+ struct uclass *uc;
+ int ret;
+
+ ret = uclass_get(UCLASS_CLK, &uc);
+ if (ret)
+ return ret;
+
+ uclass_foreach_dev(dev, uc) {
+ struct clk *clk = (struct clk *)dev_get_driver_data(dev);
+
+ if (clk->id == id) {
+ *c = clk;
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
+
UCLASS_DRIVER(clk) = {
.id = UCLASS_CLK,
.name = "clk",
diff --git a/include/clk.h b/include/clk.h
index 8224295ec3..045e60357d 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -315,4 +315,15 @@ static inline bool clk_valid(struct clk *clk)
{
return !!clk->dev;
}
+
+/**
+ * clk_get_by_id() - Get the clock by knowing its ID
+ *
+ * @id: The clock ID to search for
+ *
+ * @c: A pointer to clock struct that has been found among added clocks
+ * to UCLASS_CLK
+ * @return zero on success, or -ve error code.
+ */
+int clk_get_by_id(ulong id, struct clk **c);
#endif
--
2.11.0
More information about the U-Boot
mailing list