All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  6:56 ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-11-28  6:56 UTC (permalink / raw)
  To: Stephen Boyd, Rob Herring, Linux-ALSA, Linux-DT,
	Michael Turquette, Russell King, Linux-Kernel, Mark Brown,
	linux-clk, Linux-ARM

Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
This patch adds it. This is based on devm_clk_get()

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

 - update git log

 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] 29+ messages in thread

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  6:56 ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-11-28  6:56 UTC (permalink / raw)
  To: Stephen Boyd, Rob Herring, Linux-ALSA, Linux-DT,
	Michael Turquette, Russell King, Linux-Kernel, Mark Brown,
	linux-clk, Linux-ARM

Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
This patch adds it. This is based on devm_clk_get()

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

 - update git log

 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] 29+ messages in thread

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  6:56 ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-11-28  6:56 UTC (permalink / raw)
  To: linux-arm-kernel

Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
This patch adds it. This is based on devm_clk_get()

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

 - update git log

 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] 29+ messages in thread

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-11-28  6:56 ` Kuninori Morimoto
@ 2016-11-28  9:14   ` Russell King - ARM Linux
  -1 siblings, 0 replies; 29+ messages in thread
From: Russell King - ARM Linux @ 2016-11-28  9:14 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: Stephen Boyd, Rob Herring, Linux-ALSA, Linux-DT,
	Michael Turquette, Linux-Kernel, Mark Brown, linux-clk,
	Linux-ARM

On Mon, Nov 28, 2016 at 06:56:52AM +0000, Kuninori Morimoto wrote:
> Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
> This patch adds it. This is based on devm_clk_get()
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Please put this in drivers/clk/clk-devres.c, where you'll find that
we have devm_clk_release() which is identical to your
devm_of_clk_release().  It'll also not need the dummy definition of
devm_of_clk_get().

Thanks.

> ---
> v1 -> v2
> 
>  - update git log
> 
>  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
> 

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  9:14   ` Russell King - ARM Linux
  0 siblings, 0 replies; 29+ messages in thread
From: Russell King - ARM Linux @ 2016-11-28  9:14 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Nov 28, 2016 at 06:56:52AM +0000, Kuninori Morimoto wrote:
> Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
> This patch adds it. This is based on devm_clk_get()
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Please put this in drivers/clk/clk-devres.c, where you'll find that
we have devm_clk_release() which is identical to your
devm_of_clk_release().  It'll also not need the dummy definition of
devm_of_clk_get().

Thanks.

> ---
> v1 -> v2
> 
>  - update git log
> 
>  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
> 

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  9:21     ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-11-28  9:21 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Stephen Boyd, Rob Herring, Linux-ALSA, Linux-DT,
	Michael Turquette, Linux-Kernel, Mark Brown, linux-clk,
	Linux-ARM


Hi Russell

> > Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
> > This patch adds it. This is based on devm_clk_get()
> > 
> > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> Please put this in drivers/clk/clk-devres.c, where you'll find that
> we have devm_clk_release() which is identical to your
> devm_of_clk_release().  It'll also not need the dummy definition of
> devm_of_clk_get().

OK, will do

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  9:21     ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-11-28  9:21 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Stephen Boyd, Rob Herring, Linux-ALSA, Linux-DT,
	Michael Turquette, Linux-Kernel, Mark Brown,
	linux-clk-u79uwXL29TY76Z2rM5mHXA, Linux-ARM


Hi Russell

> > Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
> > This patch adds it. This is based on devm_clk_get()
> > 
> > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
> 
> Please put this in drivers/clk/clk-devres.c, where you'll find that
> we have devm_clk_release() which is identical to your
> devm_of_clk_release().  It'll also not need the dummy definition of
> devm_of_clk_get().

OK, will do

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-11-28  9:21     ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-11-28  9:21 UTC (permalink / raw)
  To: linux-arm-kernel


Hi Russell

> > Current Linux has of_clk_get(), but doesn't have devm_of_clk_get().
> > This patch adds it. This is based on devm_clk_get()
> > 
> > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> Please put this in drivers/clk/clk-devres.c, where you'll find that
> we have devm_clk_release() which is identical to your
> devm_of_clk_release().  It'll also not need the dummy definition of
> devm_of_clk_get().

OK, will do

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-07-08  1:30           ` Michael Turquette
  (?)
@ 2016-07-08  3:18             ` Kuninori Morimoto
  -1 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-08  3:18 UTC (permalink / raw)
  To: Michael Turquette
  Cc: Russell King - ARM Linux, Rob Herring, Mark Brown, Linux-Kernel,
	Linux-DT, Linux-ARM, Linux-ALSA, linux-clk


Hi Michael

Thank you for your feedback

> > struct clk *clk_get(struct device *dev, const char *con_id)
> > {
> >         ...
> >         if (dev) {
> >                 clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
> >                                            ~~~~~~~~~~~~
> >                 ...
> >         }
> > }
> > 
> > I would like to select specific device_node.
> 
> Do you have access to the struct device that you want to target? Can you
> pass that device into either clk_get or devm_clk_get?

If my understanding was correct, I think I can't.
In below case, "sound_soc" has its *dev, but "cpu" and "codec" doesn't
have *dev, it has node only. Thus, we are using of_clk_get() for these now.

	clk = of_clk_get(cpu, xxx);
	clk = of_clk_get(codec, xxx);

	sound_soc {
		...
		cpu {
			...
=>			clocks = <&xxx>;
		};
		codec {
			...
=>			clocks = <&xxx>;
		};
	};

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-08  3:18             ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-08  3:18 UTC (permalink / raw)
  To: Michael Turquette
  Cc: Rob Herring, Linux-ALSA, Linux-DT, Russell King - ARM Linux,
	Linux-Kernel, Mark Brown, linux-clk, Linux-ARM


Hi Michael

Thank you for your feedback

> > struct clk *clk_get(struct device *dev, const char *con_id)
> > {
> >         ...
> >         if (dev) {
> >                 clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
> >                                            ~~~~~~~~~~~~
> >                 ...
> >         }
> > }
> > 
> > I would like to select specific device_node.
> 
> Do you have access to the struct device that you want to target? Can you
> pass that device into either clk_get or devm_clk_get?

If my understanding was correct, I think I can't.
In below case, "sound_soc" has its *dev, but "cpu" and "codec" doesn't
have *dev, it has node only. Thus, we are using of_clk_get() for these now.

	clk = of_clk_get(cpu, xxx);
	clk = of_clk_get(codec, xxx);

	sound_soc {
		...
		cpu {
			...
=>			clocks = <&xxx>;
		};
		codec {
			...
=>			clocks = <&xxx>;
		};
	};

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-08  3:18             ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-08  3:18 UTC (permalink / raw)
  To: linux-arm-kernel


Hi Michael

Thank you for your feedback

> > struct clk *clk_get(struct device *dev, const char *con_id)
> > {
> >         ...
> >         if (dev) {
> >                 clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
> >                                            ~~~~~~~~~~~~
> >                 ...
> >         }
> > }
> > 
> > I would like to select specific device_node.
> 
> Do you have access to the struct device that you want to target? Can you
> pass that device into either clk_get or devm_clk_get?

If my understanding was correct, I think I can't.
In below case, "sound_soc" has its *dev, but "cpu" and "codec" doesn't
have *dev, it has node only. Thus, we are using of_clk_get() for these now.

	clk = of_clk_get(cpu, xxx);
	clk = of_clk_get(codec, xxx);

	sound_soc {
		...
		cpu {
			...
=>			clocks = <&xxx>;
		};
		codec {
			...
=>			clocks = <&xxx>;
		};
	};

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-07-08  0:03         ` Kuninori Morimoto
  (?)
@ 2016-07-08  1:30           ` Michael Turquette
  -1 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-08  1:30 UTC (permalink / raw)
  To: Kuninori Morimoto, Russell King - ARM Linux
  Cc: Rob Herring, Mark Brown, Linux-Kernel, Linux-DT, Linux-ARM,
	Linux-ALSA, linux-clk

Quoting Kuninori Morimoto (2016-07-07 17:03:00)
> 
> Hi Russell
> 
> > > > > +struct clk *devm_of_clk_get(struct device *dev,
> > > > > +                           struct device_node *np, int index)
> > > > 
> > > > Any reason not to use devm_clk_get? Why do we need this helper?
> > > 
> > > Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
> > 
> > clk_get() should also work just fine.  clk_get() uses
> > __of_clk_get_by_name() internally, which uses "clock-names" to
> > locate the index if a connection id is given.  of_clk_get() allows
> > lookup of a clock by index only, omitting the name, which means
> > you need to coordinate the order of clocks in DT with the order
> > that the driver wants... which sounds error prone to me.
> 
> Thanks.
> 
> But, I have 1 issue on [devm_]clk_get().
> It can't select device_node on [devm_]clk_get(), it uses dev->of_node directly.
> 
> struct clk *clk_get(struct device *dev, const char *con_id)
> {
>         ...
>         if (dev) {
>                 clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
>                                            ~~~~~~~~~~~~
>                 ...
>         }
> }
> 
> I would like to select specific device_node.

Do you have access to the struct device that you want to target? Can you
pass that device into either clk_get or devm_clk_get?

Regards,
Mike

> 
>         sound_soc {
>                 ...
>                 cpu {
>                         ...
> =>                      clocks = <&xxx>;
>                 };
> 
>                 codec {
>                         ...
> =>                      clocks = <&xxx>;
>                 };
>         };
> 
> But, of_clk_get_by_name() / of_clk_get() doesn't have devm_xxx version

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-08  1:30           ` Michael Turquette
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-08  1:30 UTC (permalink / raw)
  To: Kuninori Morimoto, Russell King - ARM Linux
  Cc: Rob Herring, Mark Brown, Linux-Kernel, Linux-DT, Linux-ARM,
	Linux-ALSA, linux-clk

Quoting Kuninori Morimoto (2016-07-07 17:03:00)
> =

> Hi Russell
> =

> > > > > +struct clk *devm_of_clk_get(struct device *dev,
> > > > > +                           struct device_node *np, int index)
> > > > =

> > > > Any reason not to use devm_clk_get? Why do we need this helper?
> > > =

> > > Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
> > =

> > clk_get() should also work just fine.  clk_get() uses
> > __of_clk_get_by_name() internally, which uses "clock-names" to
> > locate the index if a connection id is given.  of_clk_get() allows
> > lookup of a clock by index only, omitting the name, which means
> > you need to coordinate the order of clocks in DT with the order
> > that the driver wants... which sounds error prone to me.
> =

> Thanks.
> =

> But, I have 1 issue on [devm_]clk_get().
> It can't select device_node on [devm_]clk_get(), it uses dev->of_node dir=
ectly.
> =

> struct clk *clk_get(struct device *dev, const char *con_id)
> {
>         ...
>         if (dev) {
>                 clk =3D __of_clk_get_by_name(dev->of_node, dev_id, con_id=
);
>                                            ~~~~~~~~~~~~
>                 ...
>         }
> }
> =

> I would like to select specific device_node.

Do you have access to the struct device that you want to target? Can you
pass that device into either clk_get or devm_clk_get?

Regards,
Mike

> =

>         sound_soc {
>                 ...
>                 cpu {
>                         ...
> =3D>                      clocks =3D <&xxx>;
>                 };
> =

>                 codec {
>                         ...
> =3D>                      clocks =3D <&xxx>;
>                 };
>         };
> =

> But, of_clk_get_by_name() / of_clk_get() doesn't have devm_xxx version

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-08  1:30           ` Michael Turquette
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-08  1:30 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Kuninori Morimoto (2016-07-07 17:03:00)
> 
> Hi Russell
> 
> > > > > +struct clk *devm_of_clk_get(struct device *dev,
> > > > > +                           struct device_node *np, int index)
> > > > 
> > > > Any reason not to use devm_clk_get? Why do we need this helper?
> > > 
> > > Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
> > 
> > clk_get() should also work just fine.  clk_get() uses
> > __of_clk_get_by_name() internally, which uses "clock-names" to
> > locate the index if a connection id is given.  of_clk_get() allows
> > lookup of a clock by index only, omitting the name, which means
> > you need to coordinate the order of clocks in DT with the order
> > that the driver wants... which sounds error prone to me.
> 
> Thanks.
> 
> But, I have 1 issue on [devm_]clk_get().
> It can't select device_node on [devm_]clk_get(), it uses dev->of_node directly.
> 
> struct clk *clk_get(struct device *dev, const char *con_id)
> {
>         ...
>         if (dev) {
>                 clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
>                                            ~~~~~~~~~~~~
>                 ...
>         }
> }
> 
> I would like to select specific device_node.

Do you have access to the struct device that you want to target? Can you
pass that device into either clk_get or devm_clk_get?

Regards,
Mike

> 
>         sound_soc {
>                 ...
>                 cpu {
>                         ...
> =>                      clocks = <&xxx>;
>                 };
> 
>                 codec {
>                         ...
> =>                      clocks = <&xxx>;
>                 };
>         };
> 
> But, of_clk_get_by_name() / of_clk_get() doesn't have devm_xxx version

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-07-07 12:26       ` Russell King - ARM Linux
  (?)
@ 2016-07-08  0:03         ` Kuninori Morimoto
  -1 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-08  0:03 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Michael Turquette, Rob Herring, Mark Brown, Linux-Kernel,
	Linux-DT, Linux-ARM, Linux-ALSA, linux-clk


Hi Russell

> > > > +struct clk *devm_of_clk_get(struct device *dev,
> > > > +                           struct device_node *np, int index)
> > > 
> > > Any reason not to use devm_clk_get? Why do we need this helper?
> > 
> > Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
> 
> clk_get() should also work just fine.  clk_get() uses
> __of_clk_get_by_name() internally, which uses "clock-names" to
> locate the index if a connection id is given.  of_clk_get() allows
> lookup of a clock by index only, omitting the name, which means
> you need to coordinate the order of clocks in DT with the order
> that the driver wants... which sounds error prone to me.

Thanks.

But, I have 1 issue on [devm_]clk_get().
It can't select device_node on [devm_]clk_get(), it uses dev->of_node directly.

struct clk *clk_get(struct device *dev, const char *con_id)
{
	...
	if (dev) {
		clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
		                           ~~~~~~~~~~~~
		...
	}
}

I would like to select specific device_node.

	sound_soc {
		...
		cpu {
			...
=>			clocks = <&xxx>;
		};

		codec {
			...
=>			clocks = <&xxx>;
		};
	};

But, of_clk_get_by_name() / of_clk_get() doesn't have devm_xxx version

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-08  0:03         ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-08  0:03 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Michael Turquette, Rob Herring, Mark Brown, Linux-Kernel,
	Linux-DT, Linux-ARM, Linux-ALSA, linux-clk


Hi Russell

> > > > +struct clk *devm_of_clk_get(struct device *dev,
> > > > +                           struct device_node *np, int index)
> > > 
> > > Any reason not to use devm_clk_get? Why do we need this helper?
> > 
> > Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
> 
> clk_get() should also work just fine.  clk_get() uses
> __of_clk_get_by_name() internally, which uses "clock-names" to
> locate the index if a connection id is given.  of_clk_get() allows
> lookup of a clock by index only, omitting the name, which means
> you need to coordinate the order of clocks in DT with the order
> that the driver wants... which sounds error prone to me.

Thanks.

But, I have 1 issue on [devm_]clk_get().
It can't select device_node on [devm_]clk_get(), it uses dev->of_node directly.

struct clk *clk_get(struct device *dev, const char *con_id)
{
	...
	if (dev) {
		clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
		                           ~~~~~~~~~~~~
		...
	}
}

I would like to select specific device_node.

	sound_soc {
		...
		cpu {
			...
=>			clocks = <&xxx>;
		};

		codec {
			...
=>			clocks = <&xxx>;
		};
	};

But, of_clk_get_by_name() / of_clk_get() doesn't have devm_xxx version

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-08  0:03         ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-08  0:03 UTC (permalink / raw)
  To: linux-arm-kernel


Hi Russell

> > > > +struct clk *devm_of_clk_get(struct device *dev,
> > > > +                           struct device_node *np, int index)
> > > 
> > > Any reason not to use devm_clk_get? Why do we need this helper?
> > 
> > Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
> 
> clk_get() should also work just fine.  clk_get() uses
> __of_clk_get_by_name() internally, which uses "clock-names" to
> locate the index if a connection id is given.  of_clk_get() allows
> lookup of a clock by index only, omitting the name, which means
> you need to coordinate the order of clocks in DT with the order
> that the driver wants... which sounds error prone to me.

Thanks.

But, I have 1 issue on [devm_]clk_get().
It can't select device_node on [devm_]clk_get(), it uses dev->of_node directly.

struct clk *clk_get(struct device *dev, const char *con_id)
{
	...
	if (dev) {
		clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
		                           ~~~~~~~~~~~~
		...
	}
}

I would like to select specific device_node.

	sound_soc {
		...
		cpu {
			...
=>			clocks = <&xxx>;
		};

		codec {
			...
=>			clocks = <&xxx>;
		};
	};

But, of_clk_get_by_name() / of_clk_get() doesn't have devm_xxx version

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-07-07  9:54     ` Kuninori Morimoto
@ 2016-07-07 12:26       ` Russell King - ARM Linux
  -1 siblings, 0 replies; 29+ messages in thread
From: Russell King - ARM Linux @ 2016-07-07 12:26 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: Michael Turquette, Rob Herring, Mark Brown, Linux-Kernel,
	Linux-DT, Linux-ARM, Linux-ALSA, linux-clk

On Thu, Jul 07, 2016 at 09:54:03AM +0000, Kuninori Morimoto wrote:
> 
> Hi Michael
> 
> > > +struct clk *devm_of_clk_get(struct device *dev,
> > > +                           struct device_node *np, int index)
> > 
> > Any reason not to use devm_clk_get? Why do we need this helper?
> 
> Because of_clk_get() can parse "clocks", "#clock-cells" on DT.

clk_get() should also work just fine.  clk_get() uses
__of_clk_get_by_name() internally, which uses "clock-names" to
locate the index if a connection id is given.  of_clk_get() allows
lookup of a clock by index only, omitting the name, which means
you need to coordinate the order of clocks in DT with the order
that the driver wants... which sounds error prone to me.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-07 12:26       ` Russell King - ARM Linux
  0 siblings, 0 replies; 29+ messages in thread
From: Russell King - ARM Linux @ 2016-07-07 12:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Jul 07, 2016 at 09:54:03AM +0000, Kuninori Morimoto wrote:
> 
> Hi Michael
> 
> > > +struct clk *devm_of_clk_get(struct device *dev,
> > > +                           struct device_node *np, int index)
> > 
> > Any reason not to use devm_clk_get? Why do we need this helper?
> 
> Because of_clk_get() can parse "clocks", "#clock-cells" on DT.

clk_get() should also work just fine.  clk_get() uses
__of_clk_get_by_name() internally, which uses "clock-names" to
locate the index if a connection id is given.  of_clk_get() allows
lookup of a clock by index only, omitting the name, which means
you need to coordinate the order of clocks in DT with the order
that the driver wants... which sounds error prone to me.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-07-07  0:43   ` Michael Turquette
  (?)
@ 2016-07-07  9:54     ` Kuninori Morimoto
  -1 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-07  9:54 UTC (permalink / raw)
  To: Michael Turquette
  Cc: Russell King, Rob Herring, Mark Brown, Linux-Kernel, Linux-DT,
	Linux-ARM, Linux-ALSA, linux-clk


Hi Michael

> > +struct clk *devm_of_clk_get(struct device *dev,
> > +                           struct device_node *np, int index)
> 
> Any reason not to use devm_clk_get? Why do we need this helper?

Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
And it can manage of_clk_provider.
But devm_clk_get() can't ?

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-07  9:54     ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-07  9:54 UTC (permalink / raw)
  To: Michael Turquette
  Cc: Russell King, Rob Herring, Mark Brown, Linux-Kernel, Linux-DT,
	Linux-ARM, Linux-ALSA, linux-clk


Hi Michael

> > +struct clk *devm_of_clk_get(struct device *dev,
> > +                           struct device_node *np, int index)
> 
> Any reason not to use devm_clk_get? Why do we need this helper?

Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
And it can manage of_clk_provider.
But devm_clk_get() can't ?

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-07  9:54     ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-07  9:54 UTC (permalink / raw)
  To: linux-arm-kernel


Hi Michael

> > +struct clk *devm_of_clk_get(struct device *dev,
> > +                           struct device_node *np, int index)
> 
> Any reason not to use devm_clk_get? Why do we need this helper?

Because of_clk_get() can parse "clocks", "#clock-cells" on DT.
And it can manage of_clk_provider.
But devm_clk_get() can't ?

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

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
  2016-07-04  1:36 ` Kuninori Morimoto
  (?)
  (?)
@ 2016-07-07  0:43   ` Michael Turquette
  -1 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-07  0:43 UTC (permalink / raw)
  To: Kuninori Morimoto, Russell King, Rob Herring, Mark Brown
  Cc: Linux-Kernel, Linux-DT, Linux-ARM, Linux-ALSA, linux-clk

Quoting Kuninori Morimoto (2016-07-03 18:36:50)
> +struct clk *devm_of_clk_get(struct device *dev,
> +                           struct device_node *np, int index)

Any reason not to use devm_clk_get? Why do we need this helper?

Thanks,
Mike

> +{
> +       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	[flat|nested] 29+ messages in thread

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-07  0:43   ` Michael Turquette
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-07  0:43 UTC (permalink / raw)
  To: Kuninori Morimoto, Russell King, Rob Herring, Mark Brown
  Cc: Linux-DT, Linux-ALSA, Linux-Kernel, Linux-ARM, linux-clk

Quoting Kuninori Morimoto (2016-07-03 18:36:50)
> +struct clk *devm_of_clk_get(struct device *dev,
> +                           struct device_node *np, int index)

Any reason not to use devm_clk_get? Why do we need this helper?

Thanks,
Mike

> +{
> +       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	[flat|nested] 29+ messages in thread

* Re: [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-07  0:43   ` Michael Turquette
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-07  0:43 UTC (permalink / raw)
  To: Kuninori Morimoto, Russell King, Rob Herring, Mark Brown
  Cc: Linux-Kernel, Linux-DT, Linux-ARM, Linux-ALSA, linux-clk

Quoting Kuninori Morimoto (2016-07-03 18:36:50)
> +struct clk *devm_of_clk_get(struct device *dev,
> +                           struct device_node *np, int index)

Any reason not to use devm_clk_get? Why do we need this helper?

Thanks,
Mike

> +{
> +       struct clk **ptr, *clk;
> +
> +       ptr =3D devres_alloc(devm_of_clk_release, sizeof(*ptr), GFP_KERNE=
L);
> +       if (!ptr)
> +               return ERR_PTR(-ENOMEM);
> +
> +       clk =3D of_clk_get(np, index);
> +       if (!IS_ERR(clk)) {
> +               *ptr =3D 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_n=
ode *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
>=20

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

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-07  0:43   ` Michael Turquette
  0 siblings, 0 replies; 29+ messages in thread
From: Michael Turquette @ 2016-07-07  0:43 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Kuninori Morimoto (2016-07-03 18:36:50)
> +struct clk *devm_of_clk_get(struct device *dev,
> +                           struct device_node *np, int index)

Any reason not to use devm_clk_get? Why do we need this helper?

Thanks,
Mike

> +{
> +       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	[flat|nested] 29+ messages in thread

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-04  1:36 ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ 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] 29+ messages in thread

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-04  1:36 ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ 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] 29+ messages in thread

* [PATCH v2] clkdev: add devm_of_clk_get()
@ 2016-07-04  1:36 ` Kuninori Morimoto
  0 siblings, 0 replies; 29+ messages in thread
From: Kuninori Morimoto @ 2016-07-04  1:36 UTC (permalink / raw)
  To: linux-arm-kernel

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] 29+ messages in thread

end of thread, other threads:[~2016-11-28  9:22 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-28  6:56 [PATCH v2] clkdev: add devm_of_clk_get() Kuninori Morimoto
2016-11-28  6:56 ` Kuninori Morimoto
2016-11-28  6:56 ` Kuninori Morimoto
2016-11-28  9:14 ` Russell King - ARM Linux
2016-11-28  9:14   ` Russell King - ARM Linux
2016-11-28  9:21   ` Kuninori Morimoto
2016-11-28  9:21     ` Kuninori Morimoto
2016-11-28  9:21     ` Kuninori Morimoto
  -- strict thread matches above, loose matches on Subject: below --
2016-07-04  1:36 Kuninori Morimoto
2016-07-04  1:36 ` Kuninori Morimoto
2016-07-04  1:36 ` Kuninori Morimoto
2016-07-07  0:43 ` Michael Turquette
2016-07-07  0:43   ` Michael Turquette
2016-07-07  0:43   ` Michael Turquette
2016-07-07  0:43   ` Michael Turquette
2016-07-07  9:54   ` Kuninori Morimoto
2016-07-07  9:54     ` Kuninori Morimoto
2016-07-07  9:54     ` Kuninori Morimoto
2016-07-07 12:26     ` Russell King - ARM Linux
2016-07-07 12:26       ` Russell King - ARM Linux
2016-07-08  0:03       ` Kuninori Morimoto
2016-07-08  0:03         ` Kuninori Morimoto
2016-07-08  0:03         ` Kuninori Morimoto
2016-07-08  1:30         ` Michael Turquette
2016-07-08  1:30           ` Michael Turquette
2016-07-08  1:30           ` Michael Turquette
2016-07-08  3:18           ` Kuninori Morimoto
2016-07-08  3:18             ` Kuninori Morimoto
2016-07-08  3:18             ` Kuninori Morimoto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.