Message ID | 20210304221247.488173-2-linux@rasmusvillemoes.dk (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | [v2,1/3] clk: add devm_clk_prepare_enable() helper | expand |
On 3/4/21 2:12 PM, Rasmus Villemoes wrote: > Add a managed wrapper for clk_prepare_enable(). > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> That has been tried several times, including by yours truly, and has always been rejected. Just use devm_add_action_or_reset() like many other watchdog drivers. Guenter
On Mon, Mar 8, 2021 at 9:32 PM Guenter Roeck <linux@roeck-us.net> wrote: > > On 3/4/21 2:12 PM, Rasmus Villemoes wrote: > > Add a managed wrapper for clk_prepare_enable(). > > > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> > > That has been tried several times, including by yours truly, > and has always been rejected. > > Just use devm_add_action_or_reset() like many other watchdog > drivers. Can we apply the devm version for crying out loud? I do not see what benefit there is to force everyone open-code it with devm_add_action_or_reset(). By simply blocking it we are not making the kernel better and it's been stalled for a very long time. Thanks.
diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index cd8b6e657b94..8ee2557f9ad7 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -253,6 +253,7 @@ CLOCK devm_clk_hw_register() devm_of_clk_add_hw_provider() devm_clk_hw_register_clkdev() + devm_clk_prepare_enable() DMA dmaenginem_async_device_register() diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index be160764911b..d5bfa8cd7347 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -156,3 +156,32 @@ struct clk *devm_get_clk_from_child(struct device *dev, return clk; } EXPORT_SYMBOL(devm_get_clk_from_child); + +static void devm_clk_disable_unprepare(struct device *dev, void *res) +{ + clk_disable_unprepare(*(struct clk **)res); +} + +int devm_clk_prepare_enable(struct device *dev, struct clk *clk) +{ + struct clk **ptr; + int ret; + + if (!clk) + return 0; + + ptr = devres_alloc(devm_clk_disable_unprepare, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = clk_prepare_enable(clk); + if (!ret) { + *ptr = clk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return ret; +} +EXPORT_SYMBOL(devm_clk_prepare_enable); diff --git a/include/linux/clk.h b/include/linux/clk.h index 266e8de3cb51..04d135520480 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -485,6 +485,19 @@ struct clk *devm_clk_get_optional(struct device *dev, const char *id); */ struct clk *devm_get_clk_from_child(struct device *dev, struct device_node *np, const char *con_id); +/** + * devm_clk_prepare_enable - prepare and enable a clock source + * @dev: device for clock "consumer" + * @clk: clock source + * + * This function calls clk_prepare_enable() on @clk, and ensures the + * clock will automatically be disabled and unprepared when the device + * is unbound from the bus. + * + * Must not be called from within atomic context. + */ +int devm_clk_prepare_enable(struct device *dev, struct clk *clk); + /** * clk_rate_exclusive_get - get exclusivity over the rate control of a * producer
Add a managed wrapper for clk_prepare_enable(). Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> --- .../driver-api/driver-model/devres.rst | 1 + drivers/clk/clk-devres.c | 29 +++++++++++++++++++ include/linux/clk.h | 13 +++++++++ 3 files changed, 43 insertions(+)