diff mbox series

[U-Boot,v3,1/7] clk: add support for clk_is_match()

Message ID 20190801134301.2870-2-nsekhar@ti.com
State Accepted
Commit acbb7cd4d34caec36ff6d044a8f55325fa27459f
Delegated to: Tom Rini
Headers show
Series Add PCIe root complex support for AM654x SoC | expand

Commit Message

Sekhar Nori Aug. 1, 2019, 1:42 p.m. UTC
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 | 13 +++++++++++++
 include/clk.h            | 12 ++++++++++++
 test/dm/clk.c            |  1 +
 3 files changed, 26 insertions(+)

Comments

Fabio Estevam Aug. 1, 2019, 1:47 p.m. UTC | #1
Hi Sekhar,

On Thu, Aug 1, 2019 at 10:44 AM Sekhar Nori <nsekhar@ti.com> wrote:
>
> Add support for clk_is_match() which is required to
> know if two clock pointers point to the same exact
> physical clock.

I would suggest adding a note that this is inspired from the
clk_is_match() implementation from the Linux kernel.

Thanks
Sekhar Nori Aug. 1, 2019, 1:54 p.m. UTC | #2
Hi Fabio,

On 01/08/19 7:17 PM, Fabio Estevam wrote:
> Hi Sekhar,
> 
> On Thu, Aug 1, 2019 at 10:44 AM Sekhar Nori <nsekhar@ti.com> wrote:
>>
>> Add support for clk_is_match() which is required to
>> know if two clock pointers point to the same exact
>> physical clock.
> 
> I would suggest adding a note that this is inspired from the
> clk_is_match() implementation from the Linux kernel.

Sure. I assume this goes into the commit description?

Tom, should I resend or this is something that you can fix while applying?

Thanks,
Sekhar
Fabio Estevam Aug. 1, 2019, 1:55 p.m. UTC | #3
Hi Sekhar,

On Thu, Aug 1, 2019 at 10:54 AM Sekhar Nori <nsekhar@ti.com> wrote:

> Sure. I assume this goes into the commit description?

Yes, correct. Thanks
Tom Rini Aug. 1, 2019, 3:50 p.m. UTC | #4
On Thu, Aug 01, 2019 at 07:24:27PM +0530, Sekhar Nori wrote:
> Hi Fabio,
> 
> On 01/08/19 7:17 PM, Fabio Estevam wrote:
> > Hi Sekhar,
> > 
> > On Thu, Aug 1, 2019 at 10:44 AM Sekhar Nori <nsekhar@ti.com> wrote:
> >>
> >> Add support for clk_is_match() which is required to
> >> know if two clock pointers point to the same exact
> >> physical clock.
> > 
> > I would suggest adding a note that this is inspired from the
> > clk_is_match() implementation from the Linux kernel.
> 
> Sure. I assume this goes into the commit description?
> 
> Tom, should I resend or this is something that you can fix while applying?

Please v4 this part as I'm sure I'll otherwise forget, thanks!
Tom Rini Aug. 13, 2019, 4:51 p.m. UTC | #5
On Thu, Aug 01, 2019 at 07:12:55PM +0530, Sekhar Nori wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 85dfe712f5ac..1409c03ea174 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -515,6 +515,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",
diff --git a/include/clk.h b/include/clk.h
index f8f56d9cf01d..f50e5caa2206 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -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);
 
 /**
diff --git a/test/dm/clk.c b/test/dm/clk.c
index f301ecbb459d..676ef217f093 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -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;