[U-Boot] [PATCH v5 10/18] dm: clk: Define clk_get_by_id() for clk operations

2019-07-20 Thread sbabic
> 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 
> Reviewed-by: Peng Fan 

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 10/18] dm: clk: Define clk_get_by_id() for clk operations

2019-06-24 Thread Lukasz Majewski
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 
Reviewed-by: Peng Fan 

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- Replace -ENODEV with -ENOENT
- Use **clkp instead of **c
- Replace dev->driver_data with dev_get_clk_ptr() wrapper on uclas_priv

 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 899b2dda6f..506ba6014c 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -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, );
+   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",
diff --git a/include/clk.h b/include/clk.h
index 7b2ff8ebe6..f8f56d9cf0 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -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
-- 
2.11.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot