diff mbox series

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

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

Commit Message

Sekhar Nori June 3, 2019, 1:22 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            | 13 +++++++++++++
 test/dm/clk.c            |  1 +
 3 files changed, 27 insertions(+)

Comments

Simon Glass June 22, 2019, 7:10 p.m. UTC | #1
On Mon, 3 Jun 2019 at 14:23, 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.
>
> 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            | 13 +++++++++++++
>  test/dm/clk.c            |  1 +
>  3 files changed, 27 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini July 27, 2019, 1:48 a.m. UTC | #2
On Mon, Jun 03, 2019 at 06:52:46PM +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>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
>  drivers/clk/clk-uclass.c | 13 +++++++++++++
>  include/clk.h            | 13 +++++++++++++
>  test/dm/clk.c            |  1 +
>  3 files changed, 27 insertions(+)

This test currently fails in sandbox, please address, thanks!
Sekhar Nori July 29, 2019, 9:13 a.m. UTC | #3
Hi Tom,

On 27/07/19 7:18 AM, Tom Rini wrote:
> On Mon, Jun 03, 2019 at 06:52:46PM +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>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>> ---
>>  drivers/clk/clk-uclass.c | 13 +++++++++++++
>>  include/clk.h            | 13 +++++++++++++
>>  test/dm/clk.c            |  1 +
>>  3 files changed, 27 insertions(+)
> 
> This test currently fails in sandbox, please address, thanks!

Do you have this patch applied?

https://patchwork.ozlabs.org/patch/1130714/

The test had passed for me when I submitted the patches. Later on I
discovered the issue the patch above fixes (on actual hardware).

This might be the same thing you are seeing on sandbox too.

Thanks,
Sekhar
Tom Rini July 29, 2019, 11:51 a.m. UTC | #4
On Mon, Jul 29, 2019 at 02:43:13PM +0530, Sekhar Nori wrote:
> Hi Tom,
> 
> On 27/07/19 7:18 AM, Tom Rini wrote:
> > On Mon, Jun 03, 2019 at 06:52:46PM +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>
> >> Reviewed-by: Simon Glass <sjg@chromium.org>
> >> ---
> >>  drivers/clk/clk-uclass.c | 13 +++++++++++++
> >>  include/clk.h            | 13 +++++++++++++
> >>  test/dm/clk.c            |  1 +
> >>  3 files changed, 27 insertions(+)
> > 
> > This test currently fails in sandbox, please address, thanks!
> 
> Do you have this patch applied?
> 
> https://patchwork.ozlabs.org/patch/1130714/
> 
> The test had passed for me when I submitted the patches. Later on I
> discovered the issue the patch above fixes (on actual hardware).
> 
> This might be the same thing you are seeing on sandbox too.

Yes, that patch is applied (I just re-checked), thanks!
Sekhar Nori Aug. 1, 2019, 1:44 p.m. UTC | #5
On 29/07/19 5:21 PM, Tom Rini wrote:
> On Mon, Jul 29, 2019 at 02:43:13PM +0530, Sekhar Nori wrote:
>> Hi Tom,
>>
>> On 27/07/19 7:18 AM, Tom Rini wrote:
>>> On Mon, Jun 03, 2019 at 06:52:46PM +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>
>>>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>>> ---
>>>>  drivers/clk/clk-uclass.c | 13 +++++++++++++
>>>>  include/clk.h            | 13 +++++++++++++
>>>>  test/dm/clk.c            |  1 +
>>>>  3 files changed, 27 insertions(+)
>>>
>>> This test currently fails in sandbox, please address, thanks!
>>
>> Do you have this patch applied?
>>
>> https://patchwork.ozlabs.org/patch/1130714/
>>
>> The test had passed for me when I submitted the patches. Later on I
>> discovered the issue the patch above fixes (on actual hardware).
>>
>> This might be the same thing you are seeing on sandbox too.
> 
> Yes, that patch is applied (I just re-checked), thanks!

Tom, this was a real issue. I sent a v3. Not sure how it passed when I
originally added the unit test. Anyway..

Thanks,
Sekhar
diff mbox series

Patch

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 79b3b0494c65..823be2bcb624 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -453,6 +453,19 @@  int clk_disable_bulk(struct clk_bulk *bulk)
 	return 0;
 }
 
+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 d24e99713a35..e657da038398 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -309,6 +309,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);
 
 /**
@@ -321,4 +333,5 @@  static inline bool clk_valid(struct clk *clk)
 {
 	return !!clk->dev;
 }
+
 #endif
diff --git a/test/dm/clk.c b/test/dm/clk.c
index f301ecbb459d..8468fd45d464 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_assertok(clk_is_match(&clk_method1, &clk_method2));
 	ut_asserteq(clk_method1.id, clk_method2.id);
 
 	return 0;