]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: clk: Define clk_get_by_id() for clk operations
authorLukasz Majewski <lukma@denx.de>
Mon, 24 Jun 2019 13:50:44 +0000 (15:50 +0200)
committerStefano Babic <sbabic@denx.de>
Fri, 19 Jul 2019 12:50:30 +0000 (14:50 +0200)
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@denx.de>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
drivers/clk/clk-uclass.c
include/clk.h

index 899b2dda6f318e26d865fdfc60288e6ff5c356ec..506ba6014c973cb6b517aba2ce2002322560e186 100644 (file)
@@ -491,6 +491,28 @@ int clk_disable_bulk(struct clk_bulk *bulk)
        return 0;
 }
 
+int clk_get_by_id(ulong id, struct clk **clkp)
+{
+       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 = dev_get_clk_ptr(dev);
+
+               if (clk && clk->id == id) {
+                       *clkp = clk;
+                       return 0;
+               }
+       }
+
+       return -ENOENT;
+}
+
 UCLASS_DRIVER(clk) = {
        .id             = UCLASS_CLK,
        .name           = "clk",
index 7b2ff8ebe602fbcb4c1e32778c40fe8a95d75f14..f8f56d9cf01db92094fa91960120e31f35a48d21 100644 (file)
@@ -345,4 +345,15 @@ static inline bool clk_valid(struct clk *clk)
 {
        return !!clk->dev;
 }
+
+/**
+ * clk_get_by_id() - Get the clock by its ID
+ *
+ * @id:        The clock ID to search for
+ *
+ * @clkp:      A pointer to clock struct that has been found among added clocks
+ *              to UCLASS_CLK
+ * @return zero on success, or -ENOENT on error
+ */
+int clk_get_by_id(ulong id, struct clk **clkp);
 #endif