clk: add support for clk_is_match()
authorSekhar Nori <nsekhar@ti.com>
Thu, 1 Aug 2019 13:42:55 +0000 (19:12 +0530)
committerTom Rini <trini@konsulko.com>
Mon, 12 Aug 2019 17:33:38 +0000 (13:33 -0400)
Add support for clk_is_match() which is required to
know if two clock pointers point to the same exact
physical clock.

Also add a unit test for the new API.

Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
drivers/clk/clk-uclass.c
include/clk.h
test/dm/clk.c

index cee4d912b0e80cd35ae9760673a6b3871b92d766..c66b6f3c4ebb4417ce73ab1964d4487af3358dc2 100644 (file)
@@ -518,6 +518,19 @@ int clk_get_by_id(ulong id, struct clk **clkp)
        return -ENOENT;
 }
 
+bool clk_is_match(const struct clk *p, const struct clk *q)
+{
+       /* trivial case: identical struct clk's or both NULL */
+       if (p == q)
+               return true;
+
+       /* same device, id and data */
+       if (p->dev == q->dev && p->id == q->id && p->data == q->data)
+               return true;
+
+       return false;
+}
+
 UCLASS_DRIVER(clk) = {
        .id             = UCLASS_CLK,
        .name           = "clk",
index 2ebc905e04b5545c67df9e1a8f95267adde07f3d..3ca2796b5774990dae8560bb7f4e12fd3f135d8b 100644 (file)
@@ -333,6 +333,18 @@ int clk_disable(struct clk *clk);
  */
 int clk_disable_bulk(struct clk_bulk *bulk);
 
+/**
+ * clk_is_match - check if two clk's point to the same hardware clock
+ * @p: clk compared against q
+ * @q: clk compared against p
+ *
+ * Returns true if the two struct clk pointers both point to the same hardware
+ * clock node.
+ *
+ * Returns false otherwise. Note that two NULL clks are treated as matching.
+ */
+bool clk_is_match(const struct clk *p, const struct clk *q);
+
 int soc_clk_dump(void);
 
 /**
index f301ecbb459db5b2a145a44897de7caca8052407..676ef217f0931a2344c3e068375c0c935bbf668a 100644 (file)
@@ -24,6 +24,7 @@ static int dm_test_clk_base(struct unit_test_state *uts)
        /* Get the same clk port in 2 different ways and compare */
        ut_assertok(clk_get_by_index(dev, 1, &clk_method1));
        ut_assertok(clk_get_by_index_nodev(dev_ofnode(dev), 1, &clk_method2));
+       ut_asserteq(clk_is_match(&clk_method1, &clk_method2), true);
        ut_asserteq(clk_method1.id, clk_method2.id);
 
        return 0;