clk: add api to get clk consummer from clk_hw
PATCH 1/1 clk: add api to get clk consummer from clk_hw
clk_register() is deprecated. Using 'clk' member of struct clk_hw is discouraged. With this constrainst, it is difficult for driver to register clocks using the clk_hw API and then use the clock with the consummer API
This add a simple helper, clk_hw_get_clk(), to get a struct clk from a struct clk_hw. Like other clk_get() variant, each call to this helper must be balanced with a call to clk_put().
--- drivers/clk/clk.c | 17 +++++++++++++++++ include/linux/clk-provider.h | 1 + 2 files changed, 18 insertions(+)
drivers/clk/clk.c +17 -0
@@ -3625,6 +3625,23 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,return clk; } +/** +* clk_hw_get_clk: get clk consummer given an clk_hw +* @hw: clk_hw associated with the clk being consumed +* +* Returns: new clk consummer +* This is the function to be used by providers which need +* to get a consummer clk and act on the clock element +* Calls to this function must be balanced with calls clk_put() +*/ +struct clk *clk_hw_get_clk (struct clk_hw *hw) +{ +struct device *dev = hw->core->dev; + +return clk_hw_create_clk (dev, hw,dev_name (dev),NULL ); +} +EXPORT_SYMBOL (clk_hw_get_clk); +static int clk_cpy_name (const char **dst_p,const char *src,bool must_exist) {const char *dst;
include/linux/clk-provider.h +1 -0
@@ -1088,6 +1088,7 @@ static inline struct clk_hw *__clk_get_hw(struct clk *clk)return (struct clk_hw *)clk; }#endif +struct clk *clk_hw_get_clk (struct clk_hw *hw);unsigned int clk_hw_get_num_parents (const struct clk_hw *hw);struct clk_hw *clk_hw_get_parent (const struct clk_hw *hw); struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
Signature · 1 line
2.25.4
Stephen Boyd
maintainerQuoting Jerome Brunet (2020-05-19 10:04:40)
Quoted 2 lines
clk_register()is deprecated. Using 'clk' member of structclk_hwis discouraged. With this constrainst, it is difficult for driver to
s/constrainst/constraint/
Quoted 2 lines
register clocks using the
clk_hwAPI and then use the clock with the consummer API
s/consummer/consumer/
Quoted 7 lines
This add a simple helper,
clk_hw_get_clk(), to get a struct clk from a structclk_hw. Like otherclk_get()variant, each call to this helper must be balanced with a call toclk_put().Cc Martin Blumenstingl <[email protected]>Signed-off-by Jerome Brunet <[email protected]>
I like it!
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3629
Quoted 10 lines
drivers/clk/clk.c +2
-0@@ -3625,6 +3625,23 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,return clk; } +/** +* clk_hw_get_clk: get clk consummer given an clk_hw
s/consummer/consumer/
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3634
Quoted 5 lines
drivers/clk/clk.c +5
-0+* @hw: clk_hw associated with the clk being consumed +* +* Returns: new clk consummer +* This is the function to be used by providers which need +* to get a consummer clk and act on the clock element
s/consummer/consumer/
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3635
Quoted 1 line
drivers/clk/clk.c +1
-0+* Calls to this function must be balanced with calls clk_put()
calls to clk_put()
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3637
Quoted 2 lines
drivers/clk/clk.c +2
-0+*/ +struct clk *clk_hw_get_clk (struct clk_hw *hw)
Can it also take a const char *id argument? That will let us "name" the clk structure for situations where we want to keep track of who is using the clk pointer for things. If that doesn't seem useful then I suppose we can pass a string like "clk_hw_get_clk" for con_id below and hope it doesn't become useful later.
Quoted 10 lines
drivers/clk/clk.c +7
-0+{ +struct device *dev = hw->core->dev; + +return clk_hw_create_clk (dev, hw,dev_name (dev),NULL ); +} +EXPORT_SYMBOL (clk_hw_get_clk); +static int clk_cpy_name (const char **dst_p,const char *src,bool must_exist) {const char *dst;
Quoted 40 lines · Stephen Boyd
Quoting Jerome Brunet (2020-05-19 10:04:40)
Quoted 2 lines
clk_register()is deprecated. Using 'clk' member of structclk_hwis discouraged. With this constrainst, it is difficult for driver tos/constrainst/constraint/
Quoted 2 lines
register clocks using the
clk_hwAPI and then use the clock with the consummer APIs/consummer/consumer/
Quoted 7 lines
This add a simple helper,
clk_hw_get_clk(), to get a struct clk from a structclk_hw. Like otherclk_get()variant, each call to this helper must be balanced with a call toclk_put().Cc Martin Blumenstingl <[email protected]>Signed-off-by Jerome Brunet <[email protected]>I like it!
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3629
Quoted 10 lines
drivers/clk/clk.c +2
-0@@ -3625,6 +3625,23 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,return clk; } +/** +* clk_hw_get_clk: get clk consummer given an clk_hw s/consummer/consumer/
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3634
Quoted 5 lines
drivers/clk/clk.c +5
-0+* @hw: clk_hw associated with the clk being consumed +* +* Returns: new clk consummer +* This is the function to be used by providers which need +* to get a consummer clk and act on the clock element
Quoted 8 lines
s/consummer/consumer/
drivers/clk/clk.c struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, · line 3635
Quoted 1 line
drivers/clk/clk.c +1
-0+* Calls to this function must be balanced with calls clk_put() calls to
clk_put()Quoted 2 lines
drivers/clk/clk.c +2
-0+*/ +struct clk *clk_hw_get_clk (struct clk_hw *hw)
Sorry about all the typos ...
Quoted 6 lines
Can it also take a const char *id argument? That will let us "name" the clk structure for situations where we want to keep track of who is using the clk pointer for things. If that doesn't seem useful then I suppose we can pass a string like "
clk_hw_get_clk" forcon_idbelow and hope it doesn't become useful later.
Sure I can add the argument. no worries
Quoted 11 lines
Quoted 11 lines
drivers/clk/clk.c +7
-0+{ +struct device *dev = hw->core->dev; + +return clk_hw_create_clk (dev, hw,dev_name (dev),NULL ); +} +EXPORT_SYMBOL (clk_hw_get_clk); +static int clk_cpy_name (const char **dst_p,const char *src,bool must_exist) {const char *dst;
Hi Jerome,
On Tue, May 19, 2020 at 7:09 PM Jerome Brunet <[email protected]> wrote:
[...]
Quoted 3 lines
+ * Calls to this function must be balanced with calls
clk_put()
+ */
+struct clk *clk_hw_get_clk(structclk_hw*hw)
I haven't looked at it myself yet, but would it be hard to have a devm_ variant of this function as well?
a non-devm managed function would add boilerplate to the meson-mx-sdhc-mmc code
also this may or may not simplify how to fetch the struct device pointer for this use-case.
(that said, I only know about drivers for Amlogic related IP and there the devm_ variant can be used, but I don't know about other potential consumers of this new API)
Thank you!
Martin
Quoted 9 lines · Martin Blumenstingl
Hi Jerome,
On Tue, May 19, 2020 at 7:09 PM Jerome Brunet <[email protected]> wrote:
[...]Quoted 3 lines
+ * Calls to this function must be balanced with calls
clk_put()
+ */
+struct clk *clk_hw_get_clk(structclk_hw*hw)I haven't looked at it myself yet, but would it be hard to have a
devm_variant of this function as well?
Seems easy enough.
Stephen is this OK with you ?
I'm just wondering if this devm_ function should use the device pointer embedded in the clk_hw structure or have it as an argument ?
The 1st option seems simpler but I'm not sure it is correct.
Thoughts ?
Quoted 11 lines
a non-devm managed function would add boilerplate to the meson-mx-sdhc-mmc code
also this may or may not simplify how to fetch the struct device pointer for this use-case.
(that said, I only know about drivers for Amlogic related IP and there thedevm_variant can be used, but I don't know about other potential consumers of this new API)Thank you!
Martin
Stephen Boyd
maintainerQuoting Jerome Brunet (2020-05-28 11:58:45)
Quoted 16 lines · Martin Blumenstingl
Quoted 10 lines
Hi Jerome,
On Tue, May 19, 2020 at 7:09 PM Jerome Brunet <[email protected]> wrote:
[...]Quoted 3 lines
+ * Calls to this function must be balanced with calls
clk_put()
+ */
+struct clk *clk_hw_get_clk(structclk_hw*hw)I haven't looked at it myself yet, but would it be hard to have a
devm_variant of this function as well?Seems easy enough.
Stephen is this OK with you ?
Quoted 7 lines
I'm just wondering if this
devm_function should use the device pointer embedded in theclk_hwstructure or have it as an argument ?The 1st option seems simpler but I'm not sure it is correct.
Thoughts ?
devm API sounds OK to me. For now we can use the one embedded in the clk_hw structure and if we have to we can replace it with the one that the caller passes in. Hopefully we never need to do that because then it means we have drivers passing around clk_hw pointers instead of having the caller use proper clk_get() style APIs.