Skip to contentSkip to conversation

clk: bulk: call of_clk_get() when id is NULL

PATCH New Shawn Guo 3 participants 10 messages Aug 9, 2017 – Sep 11, 2017

Subsystems (2)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

From: Shawn Guo <[email protected]>

Most of clk API users have their clocks defined in device tree, and client drivers will have to parse clk ids from DT 'clock-names' property before using clk_bulk_get(). This is a burden for client driver code. And 'clock-names' being an optional DT property makes it even worse. The client driver will have no way to provide clock id.

The patch makes a little improvement on clk_bulk_get() to call of_clk_get() with index for DT users, if clock id is not available, so that client drivers working with DT can use clk_bulk_get() to retrieve clocks more easily.

---
 drivers/clk/clk-bulk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-bulk.c +4 -1
index c834f5abfc49..65cee595a67e 100644
@@ -39,7 +39,10 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks,
 		clks[i].clk = NULL;
 
 	for (i = 0; i < num_clks; i++) {
-		clks[i].clk = clk_get(dev, clks[i].id);
+		if (clks[i].id)
+			clks[i].clk = clk_get(dev, clks[i].id);
+		else if (dev->of_node)
+			clks[i].clk = of_clk_get(dev->of_node, i);
 		if (IS_ERR(clks[i].clk)) {
 			ret = PTR_ERR(clks[i].clk);
 			dev_err(dev, "Failed to get clk '%s': %d\n",
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Quoted 24 lines · Shawn Guo

From: Shawn Guo <[email protected]>

Most of clk API users have their clocks defined in device tree, and client drivers will have to parse clk ids from DT 'clock-names' property before using clk_bulk_get(). This is a burden for client driver code. And 'clock-names' being an optional DT property makes it even worse. The client driver will have no way to provide clock id.

The patch makes a little improvement on clk_bulk_get() to call of_clk_get() with index for DT users, if clock id is not available, so that client drivers working with DT can use clk_bulk_get() to retrieve clocks more easily.

---
 drivers/clk/clk-bulk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-bulk.c +0 -0
index c834f5abfc49..65cee595a67e 100644

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev, int num_clks, · line 45

Quoted 8 lines
drivers/clk/clk-bulk.c +4 -1
@@ -39,7 +39,10 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks,
 		clks[i].clk = NULL;
 
 	for (i = 0; i < num_clks; i++) {
-		clks[i].clk = clk_get(dev, clks[i].id);
+		if (clks[i].id)
+			clks[i].clk = clk_get(dev, clks[i].id);
+		else if (dev->of_node)
+			clks[i].clk = of_clk_get(dev->of_node, i);

This seems a little too magical. The omission of an id in an array of clks would mean that only that one clk is acquired through of_clk_get(). We could have a mixture of ids and no ids for some device, and then do very odd things.

How about we add a flag to clk_bulk_data that indicates we want it to use of_clk_get() instead of clk_get() for all of the clks? Then the id is ignored for the entire function.

Also, this patch needs to document the new behavior somewhere in the kernel-doc for this function.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#2 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Hi Stephen,

Thanks for the review comments.

Quoted 27 lines · Stephen Boyd
Quoted 26 lines · Shawn Guo

From: Shawn Guo <[email protected]>

Most of clk API users have their clocks defined in device tree, and client drivers will have to parse clk ids from DT 'clock-names' property before using clk_bulk_get(). This is a burden for client driver code. And 'clock-names' being an optional DT property makes it even worse. The client driver will have no way to provide clock id.

The patch makes a little improvement on clk_bulk_get() to call of_clk_get() with index for DT users, if clock id is not available, so that client drivers working with DT can use clk_bulk_get() to retrieve clocks more easily.

---
 drivers/clk/clk-bulk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-bulk.c +0 -0
index c834f5abfc49..65cee595a67e 100644
@@ -39,7 +39,10 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks,
 		clks[i].clk = NULL;
 
Quoted 11 lines

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev, int num_clks, · line 45

Quoted 6 lines
drivers/clk/clk-bulk.c +4 -1
 	for (i = 0; i < num_clks; i++) {
-		clks[i].clk = clk_get(dev, clks[i].id);
+		if (clks[i].id)
+			clks[i].clk = clk_get(dev, clks[i].id);
+		else if (dev->of_node)
+			clks[i].clk = of_clk_get(dev->of_node, i);

This seems a little too magical. The omission of an id in an array of clks would mean that only that one clk is acquired through of_clk_get(). We could have a mixture of ids and no ids for some device, and then do very odd things.

Yes, I agree.

Quoted 3 lines

How about we add a flag to clk_bulk_data that indicates we want it to use of_clk_get() instead of clk_get() for all of the clks? Then the id is ignored for the entire function.

Good suggestion.

Quoted 2 lines

Also, this patch needs to document the new behavior somewhere in the kernel-doc for this function.

Okay, I will take care of it with the new version.

Shawn

author
#3 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

In reply to Stephen Boyd

Hi Stephen,

Quoted 19 lines · Stephen Boyd

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev, int num_clks, · line 45

Quoted 13 lines
drivers/clk/clk-bulk.c +4 -1
index c834f5abfc49..65cee595a67e 100644
@@ -39,7 +39,10 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks,
 		clks[i].clk = NULL;
 
 	for (i = 0; i < num_clks; i++) {
-		clks[i].clk = clk_get(dev, clks[i].id);
+		if (clks[i].id)
+			clks[i].clk = clk_get(dev, clks[i].id);
+		else if (dev->of_node)
+			clks[i].clk = of_clk_get(dev->of_node, i);

This seems a little too magical. The omission of an id in an array of clks would mean that only that one clk is acquired through of_clk_get(). We could have a mixture of ids and no ids for some device, and then do very odd things.

Quoted 3 lines

How about we add a flag to clk_bulk_data that indicates we want it to use of_clk_get() instead of clk_get() for all of the clks? Then the id is ignored for the entire function.

I have sent v2 to add a flag to clk_bulk_data to address your comments. But I just found it might not be what you want exactly, because the current bulk clk APIs defines clk_bulk_data in a different way from what you are asking here.

It seems that you think clk_bulk_data represents all the clocks that bulk APIs manage, but actually it only represents one of the multiple clocks. Callers need to prepare an array of clk_bulk_data to represent multiple clocks. That said, the flag we add to clk_bulk_data only affects one clock instead of all clocks.

I feel this is something we can improve. clk_bulk_data can be used to represent all clocks, something like below. In this case, bulk clk APIs do not need to take num_clks as a separate parameter, and callers do not need to maintain multiple clk_bulk_data instances. Since we do not have any in tree users of bulk clk APIs yet, we can make this semantic change quickly. Thoughts?

include/linux/clk.h +7 -4
index 31fee2e8d4a2..ddc4812758f6 100644
@@ -80,8 +80,10 @@ struct clk_notifier_data {
 /**
  * struct clk_bulk_data - Data used for bulk clk operations.
  *
- * @id: clock consumer ID
- * @clk: struct clk * to store the associated clock
+ * @ids: array of clock consumer IDs which should be provided by caller.
+ * @clks: array of struct clk * to store the associated clocks, which will be
+ *     allocated by clk_bulk_get() and freed by clk_bulk_put().
+ * @num_clks: number of clocks that caller wants bulk API to manage.
  * @flags: bulk clk operation flags
  *
  * The CLK APIs provide a series of clk_bulk_() API calls as
@@ -93,8 +95,9 @@ struct clk_notifier_data {
  *     clk_bulk_get() API will call of_clk_get() to find clock by index.
  */
 struct clk_bulk_data {
-       const char              *id;
-       struct clk              *clk;
+       const char              **ids;
+       struct clk              **clks;
+       unsigned int            num_clks;
        unsigned long           flags;
 };
#4 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Quoted 46 lines

-----Original Message-----
From: Shawn Guo [mailto:shawnguo at kernel.org]
Sent: Sunday, August 13, 2017 10:19 PM
To: Stephen Boyd
Cc: Michael Turquette; A.s. Dong; linux-clk at vger.kernel.org; linux-arm- kernel at lists.infradead.org; Shawn Guo
Subject: Re: [PATCH] clk: bulk: call of_clk_get() when id is NULL

Hi Stephen,

Quoted 5 lines · Stephen Boyd

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev,

Quoted 5 lines
drivers/clk/clk-bulk.c index renamed from drivers/clk/clk-bulk.c +0 -0

c834f5abfc49..65cee595a67e 100644

drivers/clk/clk-bulk.c +0 -0
@@ -39,7 +39,10 @@ int __must_check clk_bulk_get(struct device *dev,

int num_clks,

Quoted 14 lines

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev, · line 45

Quoted 8 lines
drivers/clk/clk-bulk.c +4 -1
 		clks[i].clk = NULL;
 
 	for (i = 0; i < num_clks; i++) {
-		clks[i].clk = clk_get(dev, clks[i].id);
+		if (clks[i].id)
+			clks[i].clk = clk_get(dev, clks[i].id);
+		else if (dev->of_node)
+			clks[i].clk = of_clk_get(dev->of_node, i);

This seems a little too magical. The omission of an id in an array of clks would mean that only that one clk is acquired through of_clk_get(). We could have a mixture of ids and no ids for some device, and then do very odd things.

Quoted 3 lines

How about we add a flag to clk_bulk_data that indicates we want it to use of_clk_get() instead of clk_get() for all of the clks? Then the id is ignored for the entire function.

I have sent v2 to add a flag to clk_bulk_data to address your comments. But I just found it might not be what you want exactly, because the current bulk clk APIs defines clk_bulk_data in a different way from what you are asking here.

It seems that you think clk_bulk_data represents all the clocks that bulk APIs manage, but actually it only represents one of the multiple clocks. Callers need to prepare an array of clk_bulk_data to represent multiple clocks. That said, the flag we add to clk_bulk_data only affects one clock instead of all clocks.

Quoted 7 lines

I feel this is something we can improve. clk_bulk_data can be used to represent all clocks, something like below. In this case, bulk clk APIs do not need to take num_clks as a separate parameter, and callers do not need to maintain multiple clk_bulk_data instances. Since we do not have any in tree users of bulk clk APIs yet, we can make this semantic change quickly. Thoughts?

Flags may be better used for extending per clk feature support in the future.

IMHO how about implement a of_clk_bulk_get() to handle this issue as we already have a of_clk_get?
e.g.

int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
struct clk_bulk_data *clks)

{
        for (i = 0; i < num_clks; i++) {
                clks[i].clk = of_clk_get(dev, clks[i].id);

...

}

Then it's less intrusive.

Regards
Dong Aisheng

Quoted 29 lines
include/linux/clk.h index renamed from include/linux/clk.h +0 -0

31fee2e8d4a2..ddc4812758f6 100644

include/linux/clk.h +2 -2
@@ -80,8 +80,10 @@ struct clk_notifier_data {
 /**
  * struct clk_bulk_data - Data used for bulk clk operations.
  *
- * @id: clock consumer ID
- * @clk: struct clk * to store the associated clock
+ * @ids: array of clock consumer IDs which should be provided by caller.
+ * @clks: array of struct clk * to store the associated clocks, which

will be
+ * allocated by clk_bulk_get() and freed by clk_bulk_put().
+ * @num_clks: number of clocks that caller wants bulk API to manage.
* @flags: bulk clk operation flags
*
* The CLK APIs provide a series of clk_bulk_() API calls as @@ -93,8
+95,9 @@ struct clk_notifier_data {
* clk_bulk_get() API will call of_clk_get() to find clock by index.
*/
struct clk_bulk_data {

include/linux/clk.h +3 -2
-       const char              *id;
-       struct clk              *clk;
+       const char              **ids;
+       struct clk              **clks;
+       unsigned int            num_clks;
        unsigned long           flags;
 };
#5 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Quoted 62 lines · A.s. Dong
Quoted 46 lines

-----Original Message-----
From: Shawn Guo [mailto:shawnguo at kernel.org]
Sent: Sunday, August 13, 2017 10:19 PM
To: Stephen Boyd
Cc: Michael Turquette; A.s. Dong; linux-clk at vger.kernel.org; linux-arm- kernel at lists.infradead.org; Shawn Guo
Subject: Re: [PATCH] clk: bulk: call of_clk_get() when id is NULL

Hi Stephen,

Quoted 5 lines · Stephen Boyd

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev,

Quoted 5 lines
drivers/clk/clk-bulk.c index renamed from drivers/clk/clk-bulk.c +0 -0

c834f5abfc49..65cee595a67e 100644

drivers/clk/clk-bulk.c +0 -0
@@ -39,7 +39,10 @@ int __must_check clk_bulk_get(struct device *dev,

int num_clks,

Quoted 14 lines

drivers/clk/clk-bulk.c int __must_check clk_bulk_get(struct device *dev, · line 45

Quoted 8 lines
drivers/clk/clk-bulk.c +4 -1
 		clks[i].clk = NULL;
 
 	for (i = 0; i < num_clks; i++) {
-		clks[i].clk = clk_get(dev, clks[i].id);
+		if (clks[i].id)
+			clks[i].clk = clk_get(dev, clks[i].id);
+		else if (dev->of_node)
+			clks[i].clk = of_clk_get(dev->of_node, i);

This seems a little too magical. The omission of an id in an array of clks would mean that only that one clk is acquired through of_clk_get(). We could have a mixture of ids and no ids for some device, and then do very odd things.

Quoted 3 lines

How about we add a flag to clk_bulk_data that indicates we want it to use of_clk_get() instead of clk_get() for all of the clks? Then the id is ignored for the entire function.

I have sent v2 to add a flag to clk_bulk_data to address your comments. But I just found it might not be what you want exactly, because the current bulk clk APIs defines clk_bulk_data in a different way from what you are asking here.

It seems that you think clk_bulk_data represents all the clocks that bulk APIs manage, but actually it only represents one of the multiple clocks. Callers need to prepare an array of clk_bulk_data to represent multiple clocks. That said, the flag we add to clk_bulk_data only affects one clock instead of all clocks.

Quoted 7 lines

I feel this is something we can improve. clk_bulk_data can be used to represent all clocks, something like below. In this case, bulk clk APIs do not need to take num_clks as a separate parameter, and callers do not need to maintain multiple clk_bulk_data instances. Since we do not have any in tree users of bulk clk APIs yet, we can make this semantic change quickly. Thoughts?

Flags may be better used for extending per clk feature support in the future.

IMHO how about implement a of_clk_bulk_get() to handle this issue as we already have a of_clk_get?
e.g.

int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
struct clk_bulk_data *clks)

Quoted 9 lines
{
        for (i = 0; i < num_clks; i++) {
                clks[i].clk = of_clk_get(dev, clks[i].id);

...

}

Then it's less intrusive.

This looks ok too. Go ahead and send this version instead.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#6 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Hi Shawn,

Quoted 9 lines

-----Original Message-----
From: Stephen Boyd [mailto:sboyd at codeaurora.org]
Sent: Thursday, August 31, 2017 1:27 PM
To: A.s. Dong
Cc: Shawn Guo; Michael Turquette; linux-clk at vger.kernel.org; linux-arm- kernel at lists.infradead.org; Shawn Guo
Subject: Re: [PATCH] clk: bulk: call of_clk_get() when id is NULL

On 08/30, A.s. Dong wrote:

[...]

Quoted 12 lines
Quoted 1 line

Flags may be better used for extending per clk feature support in the

future.

Quoted 10 lines

IMHO how about implement a of_clk_bulk_get() to handle this issue as we already have a of_clk_get?
e.g.

int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,

                              struct clk_bulk_data *clks) {
        for (i = 0; i < num_clks; i++) {
                clks[i].clk = of_clk_get(dev, clks[i].id); ...
Quoted 7 lines
Quoted 4 lines

}

Then it's less intrusive.

This looks ok too. Go ahead and send this version instead.

I did not see you send a update version.
If you will not do it, would you mind me to help send it with a Reported-by: tag from you?

Regards
Dong Aisheng

Quoted 3 lines

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

author
#7 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Quoted 28 lines · A.s. Dong

Hi Shawn,

Quoted 9 lines

-----Original Message-----
From: Stephen Boyd [mailto:sboyd at codeaurora.org]
Sent: Thursday, August 31, 2017 1:27 PM
To: A.s. Dong
Cc: Shawn Guo; Michael Turquette; linux-clk at vger.kernel.org; linux-arm- kernel at lists.infradead.org; Shawn Guo
Subject: Re: [PATCH] clk: bulk: call of_clk_get() when id is NULL

On 08/30, A.s. Dong wrote:

[...]

Quoted 14 lines
Quoted 1 line

Flags may be better used for extending per clk feature support in the

future.

Quoted 12 lines

IMHO how about implement a of_clk_bulk_get() to handle this issue as we already have a of_clk_get?
e.g.

int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,

                              struct clk_bulk_data *clks) {
        for (i = 0; i < num_clks; i++) {
                clks[i].clk = of_clk_get(dev, clks[i].id); ...

}

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Then it's less intrusive.

This looks ok too. Go ahead and send this version instead.

I did not see you send a update version.
If you will not do it, would you mind me to help send it with a Reported-by: tag from you?

Sure, go ahead.

Shawn

author
#8 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

In reply to A.s. Dong
Quoted 9 lines · A.s. Dong

IMHO how about implement a of_clk_bulk_get() to handle this issue as we already have a of_clk_get?
e.g.

int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
struct clk_bulk_data *clks)

{
        for (i = 0; i < num_clks; i++) {
                clks[i].clk = of_clk_get(dev, clks[i].id);

The of_clk_get() takes clock index rather than name/id as the second parameter.

Shawn

Quoted 3 lines

...

}

#9 lore raw

PATCH 1/1 clk: bulk: call of_clk_get() when id is NULL

Quoted 13 lines

-----Original Message-----
From: Shawn Guo [mailto:shawnguo at kernel.org]
Sent: Thursday, August 31, 2017 3:01 PM
To: A.s. Dong
Cc: Stephen Boyd; Michael Turquette; linux-clk at vger.kernel.org; linux-arm- kernel at lists.infradead.org; Shawn Guo
Subject: Re: [PATCH] clk: bulk: call of_clk_get() when id is NULL

Quoted 4 lines · A.s. Dong

IMHO how about implement a of_clk_bulk_get() to handle this issue as we already have a of_clk_get?
e.g.

Quoted 8 lines
Quoted 4 lines

int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,

                              struct clk_bulk_data *clks) {
        for (i = 0; i < num_clks; i++) {
                clks[i].clk = of_clk_get(dev, clks[i].id);

The of_clk_get() takes clock index rather than name/id as the second parameter.

You're right.
It's for only an idea demonstration, so sent too quick! :-)

Regards
Dong Aisheng

Quoted 5 lines

Shawn

Quoted 3 lines

...

}