Skip to contentSkip to conversation

clkdev: Implement managed clk_get()

PATCH In review Mark Brown 3 participants 5 messages Apr 2, 2012 – Apr 4, 2012

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 clkdev: Implement managed clk_get()

Allow clk API users to simplify their cleanup paths by providing a managed version of clk_get() and clk_put().

---
 Documentation/driver-model/devres.txt |    3 ++
 drivers/clk/clkdev.c                  |   45 +++++++++++++++++++++++++++++++++
 include/linux/clk.h                   |   32 +++++++++++++++++++++++
 3 files changed, 80 insertions(+), 0 deletions(-)
Documentation/driver-model/devres.txt +3 -0
index 2a596a4..3a10848 100644
@@ -276,3 +276,6 @@ REGULATOR
   devm_regulator_get()
   devm_regulator_put()
   devm_regulator_bulk_get()
+
+CLOCK
+  devm_clk_get()
drivers/clk/clkdev.c +45 -0

51 lines not on this page · raw message

include/linux/clk.h +32 -0
index c9547d9..62b0bb0 100644
@@ -101,6 +101,26 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
 struct clk *clk_get(struct device *dev, const char *id);
 
 /**
+ * devm_clk_get - lookup and obtain a managed reference to a clock producer.
+ * @dev: device for clock "consumer"
+ * @id: clock comsumer ID
+ *
+ * Returns 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.)
+ *
+ * Drivers must assume that the clock source is not enabled.
+ *
+ * devm_clk_get should not be called from within interrupt context.
+ *
+ * The clock will automatically be freed when the device is unbound
+ * from the bus.
+ */
+struct clk *devm_clk_get(struct device *dev, const char *id);
+
+/**
  * clk_prepare - prepare a clock source
  * @clk: clock source
  *
@@ -206,6 +226,18 @@ unsigned long clk_get_rate(struct clk *clk);
  */
 void clk_put(struct clk *clk);
 
+/**
+ * clk_put	- "free" a managed clock source
+ * @dev: device used to acuqire the clock
+ * @clk: clock source acquired with devm_clk_get()
+ *
+ * Note: drivers must ensure that all clk_enable calls made on this
+ * clock source are balanced by clk_disable calls prior to calling
+ * this function.
+ *
+ * clk_put should not be called from within interrupt context.
+ */
+void devm_clk_put(struct device *dev, struct clk *clk);
 
 /*
  * The remaining APIs are optional for machine class support.
Signature · 1 line
1.7.9.1
#1 lore raw
Quoted 4 lines · Mark Brown

Allow clk API users to simplify their cleanup paths by providing a managed version of clk_get() and clk_put().

Much better, thanks. One minor comment...

Quoted 11 lines
---
 Documentation/driver-model/devres.txt |    3 ++
 drivers/clk/clkdev.c                  |   45 +++++++++++++++++++++++++++++++++
 include/linux/clk.h                   |   32 +++++++++++++++++++++++
 3 files changed, 80 insertions(+), 0 deletions(-)
Documentation/driver-model/devres.txt +0 -0
index 2a596a4..3a10848 100644

Documentation/driver-model/devres.txt REGULATOR · line 281

Quoted 6 lines
Documentation/driver-model/devres.txt +3 -0
@@ -276,3 +276,6 @@ REGULATOR
   devm_regulator_get()
   devm_regulator_put()
   devm_regulator_bulk_get()
+
+CLOCK
+  devm_clk_get()

devm_clk_put() ?

author
#2 lore raw
Quoted 6 lines · Russell King - ARM Linux

Documentation/driver-model/devres.txt REGULATOR · line 281

Quoted 2 lines · Mark Brown
Documentation/driver-model/devres.txt +2 -0
+CLOCK
+  devm_clk_get()

devm_clk_put() ?

Yeah, I noticed that immediately after I sent when it turned up in my
inbox and have already fixed locally - it'll be in any future version
I send out.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120402/60805c4e/attachment.sig>

#3 lore raw
Quoted 11 lines · Mark Brown
Quoted 6 lines · Russell King - ARM Linux

Documentation/driver-model/devres.txt REGULATOR · line 281

Quoted 2 lines · Mark Brown
Documentation/driver-model/devres.txt +2 -0
+CLOCK
+  devm_clk_get()

devm_clk_put() ?

Yeah, I noticed that immediately after I sent when it turned up in my inbox and have already fixed locally - it'll be in any future version I send out.

The kerneldoc comment for devm_clk_put() also needs updating in case you haven't fixed it already.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120404/3a417da3/attachment.sig>