diff options
author | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2024-08-05 10:57:31 +0200 |
---|---|---|
committer | Stephen Boyd <sboyd@kernel.org> | 2024-09-05 22:51:46 +0200 |
commit | 9934a1bd45b2b03f6d1204a6ae2780d3b009799f (patch) | |
tree | 33a14d653dbbc2ba7d1e4246737800953c51ca20 /drivers/clk/clk-devres.c | |
parent | clk: fixed-rate: add devm_clk_hw_register_fixed_rate_parent_data() (diff) | |
download | linux-9934a1bd45b2b03f6d1204a6ae2780d3b009799f.tar.xz linux-9934a1bd45b2b03f6d1204a6ae2780d3b009799f.zip |
clk: provide devm_clk_get_optional_enabled_with_rate()
There are clock users in the kernel that can't use
devm_clk_get_optional_enabled() as they need to set rate after getting
the clock and before enabling it. Provide a managed helper that wraps
these operations in the correct order.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://lore.kernel.org/r/20240805-clk-new-helper-v2-1-e5fdd1e1d729@linaro.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Diffstat (limited to 'drivers/clk/clk-devres.c')
-rw-r--r-- | drivers/clk/clk-devres.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 90e6078fb6e1..82ae1f26e634 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -99,6 +99,34 @@ struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id) } EXPORT_SYMBOL_GPL(devm_clk_get_optional_enabled); +struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev, + const char *id, + unsigned long rate) +{ + struct clk *clk; + int ret; + + clk = __devm_clk_get(dev, id, clk_get_optional, NULL, + clk_disable_unprepare); + if (IS_ERR(clk)) + return ERR_CAST(clk); + + ret = clk_set_rate(clk, rate); + if (ret) + goto out_put_clk; + + ret = clk_prepare_enable(clk); + if (ret) + goto out_put_clk; + + return clk; + +out_put_clk: + devm_clk_put(dev, clk); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(devm_clk_get_optional_enabled_with_rate); + struct clk_bulk_devres { struct clk_bulk_data *clks; int num_clks; |