[PATCH 1/2] clk: Add a devm variant of clk_rate_exclusive_get()
Uwe Kleine-König
u.kleine-koenig at pengutronix.de
Tue Dec 12 10:09:42 PST 2023
This allows to simplify drivers that use clk_rate_exclusive_get()
in their probe routine as calling clk_rate_exclusive_put() is cared for
automatically.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
drivers/clk/clk.c | 15 +++++++++++++++
include/linux/clk.h | 12 ++++++++++++
2 files changed, 27 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index af2011c2a93b..78249ca2341c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -937,6 +937,21 @@ void clk_rate_exclusive_get(struct clk *clk)
}
EXPORT_SYMBOL_GPL(clk_rate_exclusive_get);
+static void devm_clk_rate_exclusive_put(void *data)
+{
+ struct clk *clk = data;
+
+ clk_rate_exclusive_put(clk);
+}
+
+int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk)
+{
+ clk_rate_exclusive_get(clk);
+
+ return devm_add_action_or_reset(dev, devm_clk_rate_exclusive_put, clk);
+}
+EXPORT_SYMBOL_GPL(devm_clk_rate_exclusive_get);
+
static void clk_core_unprepare(struct clk_core *core)
{
lockdep_assert_held(&prepare_lock);
diff --git a/include/linux/clk.h b/include/linux/clk.h
index f88c407925f8..5a749459c3a3 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -199,6 +199,18 @@ bool clk_is_match(const struct clk *p, const struct clk *q);
*/
void clk_rate_exclusive_get(struct clk *clk);
+/**
+ * devm_clk_rate_exclusive_get - devm variant of clk_rate_exclusive_get
+ * @dev: device the exclusivity is bound to
+ * @clk: clock source
+ *
+ * Calls clk_rate_exclusive_get() on @clk and registers a devm cleanup handler
+ * on @dev to cal clk_rate_exclusive_put().
+ *
+ * Must not be called from within atomic context.
+ */
+int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk);
+
/**
* clk_rate_exclusive_put - release exclusivity over the rate control of a
* producer
--
2.42.0
More information about the linux-arm-kernel
mailing list