[RFC,2/3] clk: add managed version of clk_bulk_get
diff mbox

Message ID 1491969809-20154-3-git-send-email-aisheng.dong@nxp.com
State Changes Requested
Headers show

Commit Message

Aisheng Dong April 12, 2017, 4:03 a.m. UTC
This patch introduces the managed version of clk_bulk_get.

Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: Sascha Hauer <kernel@pengutronix.de>
Cc: Anson Huang <anson.huang@nxp.com>
Cc: Robin Gong <yibin.gong@nxp.com>
Cc: Bai Ping <ping.bai@nxp.com>
Cc: Leonard Crestez <leonard.crestez@nxp.com>
Cc: Octavian Purdila <octavian.purdila@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
 drivers/clk/clk-devres.c | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/clk.h      | 22 +++++++++++++++++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

Comments

Dong Aisheng April 13, 2017, 2:37 p.m. UTC | #1
On Wed, Apr 12, 2017 at 12:03:28PM +0800, Dong Aisheng wrote:
> This patch introduces the managed version of clk_bulk_get.
> 
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Cc: Sascha Hauer <kernel@pengutronix.de>
> Cc: Anson Huang <anson.huang@nxp.com>
> Cc: Robin Gong <yibin.gong@nxp.com>
> Cc: Bai Ping <ping.bai@nxp.com>
> Cc: Leonard Crestez <leonard.crestez@nxp.com>
> Cc: Octavian Purdila <octavian.purdila@nxp.com>
> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> ---
>  drivers/clk/clk-devres.c | 36 ++++++++++++++++++++++++++++++++++++
>  include/linux/clk.h      | 22 +++++++++++++++++++++-
>  2 files changed, 57 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
> index 3a218c3..c7fb31d 100644
> --- a/drivers/clk/clk-devres.c
> +++ b/drivers/clk/clk-devres.c
> @@ -34,6 +34,42 @@ struct clk *devm_clk_get(struct device *dev, const char *id)
>  }
>  EXPORT_SYMBOL(devm_clk_get);
>  
> +struct clk_bulk_devres {
> +	struct clk_bulk_data *clks;
> +	int num_clks;
> +};
> +
> +static void devm_clk_bulk_release(struct device *dev, void *res)
> +{
> +	struct clk_bulk_devres *devres = res;
> +
> +	clk_bulk_put(devres->num_clks, devres->clks);
> +}
> +
> +int devm_clk_bulk_get(struct device *dev, int num_clks,
> +		      struct clk_bulk_data *clks)
> +{
> +	struct clk_bulk_devres *devres;
> +	int ret;
> +
> +	devres = devres_alloc(devm_clk_bulk_release,
> +			      sizeof(*devres), GFP_KERNEL);
> +	if (!devres)
> +		return -ENOMEM;
> +
> +	ret = clk_bulk_get(dev, num_clks, clks);


Another catch by 0day robot.

   drivers/built-in.o: In function `devm_clk_bulk_get':
>> (.text+0x1930e): undefined reference to `clk_bulk_get'
   drivers/built-in.o: In function `devm_clk_bulk_release':
>> clk-devres.c:(.text+0x19370): undefined reference to `clk_bulk_put'

clk_bulk_get is defined in clkdev.c which depends on CONFIG_CLKDEV_LOOKUP.
However, some platforms like m68k may not select CLKDEV_LOOKUP but
select HAVE_CLK. Thus compiling devm_clk_bulk_get may cause a undefined
reference to 'clk_bulk_get'.

Since clk_bulk_get is built upon the platform specific clk_get api,
clk_bulk_get can also be used by that platform accordingly.

Then we probably could move clk_bulk_get into clk-devres.c as well which
is controlled by common CONFIG_HAVE_CLK to benifit all platforms.

Regards
Dong Aisheng
--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stephen Boyd April 22, 2017, 2:55 a.m. UTC | #2
On 04/12, Dong Aisheng wrote:
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index 1d05b66..3fc6010 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -278,11 +278,25 @@ struct clk *clk_get(struct device *dev, const char *id);
>   *
>   * clk_bulk_get should not be called from within interrupt context.
>   */
> -

Should be in previous patch?

>  int __must_check clk_bulk_get(struct device *dev, int num_clks,
>  			      struct clk_bulk_data *clks);
>  
>  /**
> + * devm_clk_bulk_get - managed get multiple clk consumers
> + * @dev: device for clock "consumer"
> + * @num_clks: the number of clk_bulk_data
> + * @clks: the clk_bulk_data table of consumer
> + *
> + * Return 0 on success, an errno on failure.
> + *
> + * This helper function allows drivers to get several regulator

s/regulator/clk/

> + * consumers in one operation with management, the clks will
> + * automatically be freed when the device is unbound.
> + */
> +int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,

Thanks for the __must_check. We need to add more __must_check to
clk APIs.

> +				   struct clk_bulk_data *clks);
> +
> +/**
Stephen Boyd April 22, 2017, 2:58 a.m. UTC | #3
On 04/13, Dong Aisheng wrote:
> On Wed, Apr 12, 2017 at 12:03:28PM +0800, Dong Aisheng wrote:
> 
>    drivers/built-in.o: In function `devm_clk_bulk_get':
> >> (.text+0x1930e): undefined reference to `clk_bulk_get'
>    drivers/built-in.o: In function `devm_clk_bulk_release':
> >> clk-devres.c:(.text+0x19370): undefined reference to `clk_bulk_put'
> 
> clk_bulk_get is defined in clkdev.c which depends on CONFIG_CLKDEV_LOOKUP.
> However, some platforms like m68k may not select CLKDEV_LOOKUP but
> select HAVE_CLK. Thus compiling devm_clk_bulk_get may cause a undefined
> reference to 'clk_bulk_get'.
> 
> Since clk_bulk_get is built upon the platform specific clk_get api,
> clk_bulk_get can also be used by that platform accordingly.
> 
> Then we probably could move clk_bulk_get into clk-devres.c as well which
> is controlled by common CONFIG_HAVE_CLK to benifit all platforms.

clk-devres is for devm* things. I'd just make another file for
now, clk-bulk.c or something like that. When everyone moves to
common clk, we can fold it into clk.c, or not because clk.c is
rather large right now.
Dong Aisheng May 8, 2017, 11:37 a.m. UTC | #4
On Fri, Apr 21, 2017 at 07:55:47PM -0700, Stephen Boyd wrote:
> On 04/12, Dong Aisheng wrote:
> > diff --git a/include/linux/clk.h b/include/linux/clk.h
> > index 1d05b66..3fc6010 100644
> > --- a/include/linux/clk.h
> > +++ b/include/linux/clk.h
> > @@ -278,11 +278,25 @@ struct clk *clk_get(struct device *dev, const char *id);
> >   *
> >   * clk_bulk_get should not be called from within interrupt context.
> >   */
> > -
> 
> Should be in previous patch?
> 

Yes, will fix.

> >  int __must_check clk_bulk_get(struct device *dev, int num_clks,
> >  			      struct clk_bulk_data *clks);
> >  
> >  /**
> > + * devm_clk_bulk_get - managed get multiple clk consumers
> > + * @dev: device for clock "consumer"
> > + * @num_clks: the number of clk_bulk_data
> > + * @clks: the clk_bulk_data table of consumer
> > + *
> > + * Return 0 on success, an errno on failure.
> > + *
> > + * This helper function allows drivers to get several regulator
> 
> s/regulator/clk/
> 

ditto

> > + * consumers in one operation with management, the clks will
> > + * automatically be freed when the device is unbound.
> > + */
> > +int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
> 
> Thanks for the __must_check. We need to add more __must_check to
> clk APIs.
> 

Yes, just easy to do it from the beginning. :-)

Regards
Dong Aisheng

> > +				   struct clk_bulk_data *clks);
> > +
> > +/**
> 
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
> --
> To unsubscribe from this list: send the line "unsubscribe linux-clk" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dong Aisheng May 8, 2017, 11:41 a.m. UTC | #5
On Fri, Apr 21, 2017 at 07:58:37PM -0700, Stephen Boyd wrote:
> On 04/13, Dong Aisheng wrote:
> > On Wed, Apr 12, 2017 at 12:03:28PM +0800, Dong Aisheng wrote:
> > 
> >    drivers/built-in.o: In function `devm_clk_bulk_get':
> > >> (.text+0x1930e): undefined reference to `clk_bulk_get'
> >    drivers/built-in.o: In function `devm_clk_bulk_release':
> > >> clk-devres.c:(.text+0x19370): undefined reference to `clk_bulk_put'
> > 
> > clk_bulk_get is defined in clkdev.c which depends on CONFIG_CLKDEV_LOOKUP.
> > However, some platforms like m68k may not select CLKDEV_LOOKUP but
> > select HAVE_CLK. Thus compiling devm_clk_bulk_get may cause a undefined
> > reference to 'clk_bulk_get'.
> > 
> > Since clk_bulk_get is built upon the platform specific clk_get api,
> > clk_bulk_get can also be used by that platform accordingly.
> > 
> > Then we probably could move clk_bulk_get into clk-devres.c as well which
> > is controlled by common CONFIG_HAVE_CLK to benifit all platforms.
> 
> clk-devres is for devm* things. I'd just make another file for
> now, clk-bulk.c or something like that. When everyone moves to
> common clk, we can fold it into clk.c, or not because clk.c is
> rather large right now.
> 

Thanks for the suggestion.
Much agree with you that getting a new file to handle them is better.
Will do them in clk-bulk.c first.

Regards
Dong Aisheng

> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
index 3a218c3..c7fb31d 100644
--- a/drivers/clk/clk-devres.c
+++ b/drivers/clk/clk-devres.c
@@ -34,6 +34,42 @@  struct clk *devm_clk_get(struct device *dev, const char *id)
 }
 EXPORT_SYMBOL(devm_clk_get);
 
+struct clk_bulk_devres {
+	struct clk_bulk_data *clks;
+	int num_clks;
+};
+
+static void devm_clk_bulk_release(struct device *dev, void *res)
+{
+	struct clk_bulk_devres *devres = res;
+
+	clk_bulk_put(devres->num_clks, devres->clks);
+}
+
+int devm_clk_bulk_get(struct device *dev, int num_clks,
+		      struct clk_bulk_data *clks)
+{
+	struct clk_bulk_devres *devres;
+	int ret;
+
+	devres = devres_alloc(devm_clk_bulk_release,
+			      sizeof(*devres), GFP_KERNEL);
+	if (!devres)
+		return -ENOMEM;
+
+	ret = clk_bulk_get(dev, num_clks, clks);
+	if (!ret) {
+		devres->clks = clks;
+		devres->num_clks = num_clks;
+		devres_add(dev, devres);
+	} else {
+		devres_free(devres);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(devm_clk_bulk_get);
+
 static int devm_clk_match(struct device *dev, void *res, void *data)
 {
 	struct clk **c = res;
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 1d05b66..3fc6010 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -278,11 +278,25 @@  struct clk *clk_get(struct device *dev, const char *id);
  *
  * clk_bulk_get should not be called from within interrupt context.
  */
-
 int __must_check clk_bulk_get(struct device *dev, int num_clks,
 			      struct clk_bulk_data *clks);
 
 /**
+ * devm_clk_bulk_get - managed get multiple clk consumers
+ * @dev: device for clock "consumer"
+ * @num_clks: the number of clk_bulk_data
+ * @clks: the clk_bulk_data table of consumer
+ *
+ * Return 0 on success, an errno on failure.
+ *
+ * This helper function allows drivers to get several regulator
+ * consumers in one operation with management, the clks will
+ * automatically be freed when the device is unbound.
+ */
+int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
+				   struct clk_bulk_data *clks);
+
+/**
  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
  * @dev: device for clock "consumer"
  * @id: clock consumer ID
@@ -554,6 +568,12 @@  static inline struct clk *devm_clk_get(struct device *dev, const char *id)
 	return NULL;
 }
 
+static inline int devm_clk_bulk_get(struct device *dev, int num_clks,
+				    struct clk_bulk_data *clks)
+{
+	return NULL;
+}
+
 static inline struct clk *devm_get_clk_from_child(struct device *dev,
 				struct device_node *np, const char *con_id)
 {