diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2023-09-13 14:08:06 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-09-14 09:51:12 +0200 |
commit | 80859f6fb63b14d63c8d8d85eaa3330a31a74269 (patch) | |
tree | b096cc58125241757662b323ac3ad7d143cceec0 | |
parent | 18078a8efa5305e06cbcbbb8688fb2ea41751109 (diff) | |
download | barebox-80859f6fb63b14d63c8d8d85eaa3330a31a74269.tar.gz barebox-80859f6fb63b14d63c8d8d85eaa3330a31a74269.tar.xz |
clk: implement clk_get_enabled helper
Kernel code increasingly uses devm_clk_get_enabled to make driver code
more compact. Port a devres-less version to barebox to make porting such
Linux code easier.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20230913120807.1869600-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | include/linux/clk.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/linux/clk.h b/include/linux/clk.h index 82022e78e3..61b4ff3127 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -951,4 +951,35 @@ static inline struct clk *clk_get_optional(struct device *dev, const char *id) return clk; } +/** + * clk_get_enabled - clk_get() + clk_prepare_enable() + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Return: a struct clk corresponding to the clock producer, or + * valid IS_ERR() condition containing errno. The implementation + * uses @dev and @id to determine the clock consumer, and thereby + * the clock producer. (IOW, @id may be identical strings, but + * clk_get may return different clock producers depending on @dev.) + * + * The returned clk (if valid) is enabled. + */ +static inline struct clk *clk_get_enabled(struct device *dev, const char *id) +{ + struct clk *clk; + int ret; + + clk = clk_get(dev, id); + if (IS_ERR(clk)) + return clk; + + ret = clk_enable(clk); + if (ret) { + clk_put(clk); + return ERR_PTR(ret); + } + + return clk; +} + #endif |