devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-04  1:36 Kuninori Morimoto
  2016-07-07  0:43 ` Michael Turquette
  0 siblings, 1 reply; 16+ messages in thread
From: Kuninori Morimoto @ 2016-07-04  1:36 UTC (permalink / raw)
  To: Russell King, Rob Herring, Mark Brown
  Cc: Linux-Kernel, Linux-DT, Linux-ARM, Linux-ALSA, linux-clk

This is based on devm_clk_get()

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

 - added "static" and "inline" on header

 drivers/clk/clkdev.c | 26 ++++++++++++++++++++++++++
 include/linux/clk.h  |  7 +++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 89cc700..93a613b 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -55,6 +55,32 @@ struct clk *of_clk_get(struct device_node *np, int index)
 }
 EXPORT_SYMBOL(of_clk_get);
 
+static void devm_of_clk_release(struct device *dev, void *res)
+{
+	clk_put(*(struct clk **)res);
+}
+
+struct clk *devm_of_clk_get(struct device *dev,
+			    struct device_node *np, int index)
+{
+	struct clk **ptr, *clk;
+
+	ptr = devres_alloc(devm_of_clk_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	clk = of_clk_get(np, index);
+	if (!IS_ERR(clk)) {
+		*ptr = clk;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return clk;
+}
+EXPORT_SYMBOL(devm_of_clk_get);
+
 static struct clk *__of_clk_get_by_name(struct device_node *np,
 					const char *dev_id,
 					const char *name)
diff --git a/include/linux/clk.h b/include/linux/clk.h
index a89ba4e..33cd540 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -502,6 +502,8 @@ struct of_phandle_args;
 
 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
 struct clk *of_clk_get(struct device_node *np, int index);
+struct clk *devm_of_clk_get(struct device *dev,
+			    struct device_node *np, int index);
 struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
 #else
@@ -509,6 +511,11 @@ static inline struct clk *of_clk_get(struct device_node *np, int index)
 {
 	return ERR_PTR(-ENOENT);
 }
+static inline struct clk *devm_of_clk_get(struct device *dev,
+			    struct device_node *np, int index)
+{
+	return ERR_PTR(-ENOENT);
+}
 static inline struct clk *of_clk_get_by_name(struct device_node *np,
 					     const char *name)
 {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-12-01  1:43 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-04  1:36 [PATCH v2] clkdev: add devm_of_clk_get() Kuninori Morimoto
2016-07-07  0:43 ` Michael Turquette
2016-07-07  9:54   ` Kuninori Morimoto
2016-07-07 12:26     ` Russell King - ARM Linux
2016-07-08  0:03       ` Kuninori Morimoto
2016-07-08  1:30         ` Michael Turquette
2016-07-08  3:18           ` Kuninori Morimoto
2016-07-27  0:51             ` [alsa-devel] " Kuninori Morimoto
2016-07-27  0:51             ` Kuninori Morimoto
2016-11-16  5:17               ` Kuninori Morimoto
2016-11-23 19:10                 ` Stephen Boyd
     [not found]                   ` <20161123191037.GE25626-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-24  1:45                     ` Kuninori Morimoto
2016-11-24  4:57                       ` Kuninori Morimoto
     [not found]                         ` <87y409cw71.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2016-11-29 21:05                           ` Stephen Boyd
     [not found]                             ` <20161129210556.GC6095-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-30  1:08                               ` Kuninori Morimoto
     [not found]                                 ` <874m2pbwsn.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2016-12-01  1:43                                   ` Kuninori Morimoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).