diff mbox

[RFC,06/16] Add DEVM_CLOCK()

Message ID 1437486658-28365-7-git-send-email-tomeu.vizoso@collabora.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tomeu Vizoso July 21, 2015, 1:50 p.m. UTC
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---

 drivers/clk/clk.c   | 13 +++++++++++++
 include/linux/clk.h | 10 ++++++++++
 2 files changed, 23 insertions(+)
diff mbox

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 1b5fe3da6b55..b51b54846284 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2705,6 +2705,19 @@  void devm_clk_unregister(struct device *dev, struct clk *clk)
 }
 EXPORT_SYMBOL_GPL(devm_clk_unregister);
 
+int devm_acquire_clock(struct device *dev,
+		       const struct devm_resource *resource)
+{
+	struct clk **clkp = dev_get_drvdata(dev) + resource->offset;
+
+	*clkp = devm_clk_get(dev, resource->name);
+	if (IS_ERR(*clkp))
+		return PTR_ERR(*clkp);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_acquire_clock);
+
 /*
  * clkdev helpers
  */
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 0df4a51e1a78..1084776efc28 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -17,6 +17,7 @@ 
 #include <linux/notifier.h>
 
 struct device;
+struct devm_resource;
 
 struct clk;
 
@@ -138,6 +139,15 @@  int clk_get_phase(struct clk *clk);
  */
 bool clk_is_match(const struct clk *p, const struct clk *q);
 
+int devm_acquire_clock(struct device *dev,
+		       const struct devm_resource *resource);
+
+#define DEVM_CLOCK(_struct, _member, _name) {	 			\
+	.initfunc = devm_acquire_clock,				 	\
+	.offset = offsetof_t(struct _struct, _member, struct clk *),	\
+	.name = _name,							\
+}
+
 #else
 
 static inline long clk_get_accuracy(struct clk *clk)