diff mbox series

[v2,03/11] clk: fixed-factor: Introduce *clk_hw_register_fixed_factor_parent_hw()

Message ID 20220601220747.1145095-4-marijn.suijten@somainline.org (mailing list archive)
State Changes Requested, archived
Headers show
Series drm/msm/dsi_phy: Replace parent names with clk_hw pointers | expand

Commit Message

Marijn Suijten June 1, 2022, 10:07 p.m. UTC
Add the devres and non-devres variant of
clk_hw_register_fixed_factor_parent_hw() for registering a fixed factor
clock with clk_hw parent pointer instead of parent name.

Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
---
 drivers/clk/clk-fixed-factor.c | 57 ++++++++++++++++++++++++++++------
 include/linux/clk-provider.h   |  8 +++++
 2 files changed, 55 insertions(+), 10 deletions(-)

Comments

Dmitry Baryshkov June 2, 2022, 10:20 a.m. UTC | #1
On Thu, 2 Jun 2022 at 01:07, Marijn Suijten
<marijn.suijten@somainline.org> wrote:
>
> Add the devres and non-devres variant of
> clk_hw_register_fixed_factor_parent_hw() for registering a fixed factor
> clock with clk_hw parent pointer instead of parent name.
>
> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>

Two minor comments below. It's up to Stephen to check if they are
correct or not.

> ---
>  drivers/clk/clk-fixed-factor.c | 57 ++++++++++++++++++++++++++++------
>  include/linux/clk-provider.h   |  8 +++++
>  2 files changed, 55 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
> index 54942d758ee6..fabb98d0cdb2 100644
> --- a/drivers/clk/clk-fixed-factor.c
> +++ b/drivers/clk/clk-fixed-factor.c
> @@ -78,7 +78,8 @@ static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *
>
>  static struct clk_hw *
>  __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
> -               const char *name, const char *parent_name, int index,
> +               const char *name, const char *parent_name,
> +               const struct clk_hw *parent_hw, int index,
>                 unsigned long flags, unsigned int mult, unsigned int div,
>                 bool devm)
>  {
> @@ -108,7 +109,9 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
>         init.name = name;
>         init.ops = &clk_fixed_factor_ops;
>         init.flags = flags;
> -       if (parent_name)
> +       if (parent_hw)
> +               init.parent_hws = &parent_hw;
> +       else if (parent_name)
>                 init.parent_names = &parent_name;

If you change the order of if clauses, you won't have to introduce
unnecessary changes.

>         else
>                 init.parent_data = &pdata;
> @@ -148,17 +151,50 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
>                 const char *name, unsigned int index, unsigned long flags,
>                 unsigned int mult, unsigned int div)
>  {
> -       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, index,
> -                                             flags, mult, div, true);
> +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL,
> +                                             index, flags, mult, div, true);

Here (and several times later) you are inserting an argument and then
moving arguments to the next line. My slight preference would be to
just insert the arg (and maybe break the line if it gets too long) w/o
touching the next lines.

>  }
>  EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index);
>
> +/**
> + * devm_clk_hw_register_fixed_factor_parent_hw - Register a fixed factor clock with
> + * pointer to parent clock
> + * @dev: device that is registering this clock
> + * @name: name of this clock
> + * @parent_hw: pointer to parent clk
> + * @flags: fixed factor flags
> + * @mult: multiplier
> + * @div: divider
> + *
> + * Return: Pointer to fixed factor clk_hw structure that was registered or
> + * an error pointer.
> + */
> +struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
> +               const char *name, const struct clk_hw *parent_hw,
> +               unsigned long flags, unsigned int mult, unsigned int div)
> +{
> +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw,
> +                                             -1, flags, mult, div, true);
> +}
> +EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw);
> +
> +struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
> +               const char *name, const struct clk_hw *parent_hw,
> +               unsigned long flags, unsigned int mult, unsigned int div)
> +{
> +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL,
> +                                             parent_hw, -1, flags, mult, div,
> +                                             false);
> +}
> +EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw);
> +
>  struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
>                 const char *name, const char *parent_name, unsigned long flags,
>                 unsigned int mult, unsigned int div)
>  {
> -       return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1,
> -                                             flags, mult, div, false);
> +       return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name,
> +                                             NULL, -1, flags, mult, div,
> +                                             false);
>  }
>  EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor);
>
> @@ -204,8 +240,9 @@ struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
>                 const char *name, const char *parent_name, unsigned long flags,
>                 unsigned int mult, unsigned int div)
>  {
> -       return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1,
> -                       flags, mult, div, true);
> +       return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name,
> +                                             NULL, -1, flags, mult, div,
> +                                             true);
>  }
>  EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor);
>
> @@ -240,8 +277,8 @@ static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node)
>         if (of_match_node(set_rate_parent_matches, node))
>                 flags |= CLK_SET_RATE_PARENT;
>
> -       hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, 0,
> -                                           flags, mult, div, false);
> +       hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL,
> +                                           0, flags, mult, div, false);
>         if (IS_ERR(hw)) {
>                 /*
>                  * Clear OF_POPULATED flag so that clock registration can be
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index 316c7e082934..94458cb669f0 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -1032,6 +1032,14 @@ struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
>  struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
>                 const char *name, unsigned int index, unsigned long flags,
>                 unsigned int mult, unsigned int div);
> +
> +struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
> +               const char *name, const struct clk_hw *parent_hw,
> +               unsigned long flags, unsigned int mult, unsigned int div);
> +
> +struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
> +               const char *name, const struct clk_hw *parent_hw,
> +               unsigned long flags, unsigned int mult, unsigned int div);
>  /**
>   * struct clk_fractional_divider - adjustable fractional divider clock
>   *
> --
> 2.36.1
>
Stephen Boyd June 9, 2022, 10:12 p.m. UTC | #2
Quoting Dmitry Baryshkov (2022-06-02 03:20:19)
> On Thu, 2 Jun 2022 at 01:07, Marijn Suijten
> <marijn.suijten@somainline.org> wrote:
> > diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
> > index 54942d758ee6..fabb98d0cdb2 100644
> > --- a/drivers/clk/clk-fixed-factor.c
> > +++ b/drivers/clk/clk-fixed-factor.c
> > @@ -78,7 +78,8 @@ static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *
> >
> >  static struct clk_hw *
> >  __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
> > -               const char *name, const char *parent_name, int index,
> > +               const char *name, const char *parent_name,
> > +               const struct clk_hw *parent_hw, int index,
> >                 unsigned long flags, unsigned int mult, unsigned int div,
> >                 bool devm)
> >  {
> > @@ -108,7 +109,9 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
> >         init.name = name;
> >         init.ops = &clk_fixed_factor_ops;
> >         init.flags = flags;
> > -       if (parent_name)
> > +       if (parent_hw)
> > +               init.parent_hws = &parent_hw;
> > +       else if (parent_name)
> >                 init.parent_names = &parent_name;
> 
> If you change the order of if clauses, you won't have to introduce
> unnecessary changes.

Indeed, please do that.

> 
> >         else
> >                 init.parent_data = &pdata;
> > @@ -148,17 +151,50 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
> >                 const char *name, unsigned int index, unsigned long flags,
> >                 unsigned int mult, unsigned int div)
> >  {
> > -       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, index,
> > -                                             flags, mult, div, true);
> > +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL,
> > +                                             index, flags, mult, div, true);
> 
> Here (and several times later) you are inserting an argument and then
> moving arguments to the next line. My slight preference would be to
> just insert the arg (and maybe break the line if it gets too long) w/o
> touching the next lines.

I'd just add the argument at the end because when it is added in the
middle it makes the diff more difficult to read.
Marijn Suijten June 10, 2022, 7:46 a.m. UTC | #3
On 2022-06-09 15:12:09, Stephen Boyd wrote:
> Quoting Dmitry Baryshkov (2022-06-02 03:20:19)
> > On Thu, 2 Jun 2022 at 01:07, Marijn Suijten
> > <marijn.suijten@somainline.org> wrote:
> > > diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
> > > index 54942d758ee6..fabb98d0cdb2 100644
> > > --- a/drivers/clk/clk-fixed-factor.c
> > > +++ b/drivers/clk/clk-fixed-factor.c
> > > @@ -78,7 +78,8 @@ static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *
> > >
> > >  static struct clk_hw *
> > >  __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
> > > -               const char *name, const char *parent_name, int index,
> > > +               const char *name, const char *parent_name,
> > > +               const struct clk_hw *parent_hw, int index,
> > >                 unsigned long flags, unsigned int mult, unsigned int div,
> > >                 bool devm)
> > >  {
> > > @@ -108,7 +109,9 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
> > >         init.name = name;
> > >         init.ops = &clk_fixed_factor_ops;
> > >         init.flags = flags;
> > > -       if (parent_name)
> > > +       if (parent_hw)
> > > +               init.parent_hws = &parent_hw;
> > > +       else if (parent_name)
> > >                 init.parent_names = &parent_name;
> > 
> > If you change the order of if clauses, you won't have to introduce
> > unnecessary changes.
> 
> Indeed, please do that.

The intent here was to prefer parent_hw over parent_name, but I later
reordered the function arguments again to have parent_name before
parent_hw; in-line with __clk_hw_register_divider.  Hence makes more
sense to swap these around indeed.

Besides, we don't expect more than one of these to be set anyway per
design of this private function, that is only called by well-defined
implementations below.

> > 
> > >         else
> > >                 init.parent_data = &pdata;
> > > @@ -148,17 +151,50 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
> > >                 const char *name, unsigned int index, unsigned long flags,
> > >                 unsigned int mult, unsigned int div)
> > >  {
> > > -       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, index,
> > > -                                             flags, mult, div, true);
> > > +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL,
> > > +                                             index, flags, mult, div, true);
> > 
> > Here (and several times later) you are inserting an argument and then
> > moving arguments to the next line. My slight preference would be to
> > just insert the arg (and maybe break the line if it gets too long) w/o
> > touching the next lines.

That'll definitely look odd, as we'll end up with index floating on a
single line, all on its own.

> I'd just add the argument at the end because when it is added in the
> middle it makes the diff more difficult to read.

How strong is this feeling, against keeping argument ordering consistent
with other implementations of similar __clk_hw_register_* functions?

- Marijn
Stephen Boyd June 10, 2022, 7:01 p.m. UTC | #4
Quoting Marijn Suijten (2022-06-10 00:46:32)
> On 2022-06-09 15:12:09, Stephen Boyd wrote:
> > Quoting Dmitry Baryshkov (2022-06-02 03:20:19)
> > > On Thu, 2 Jun 2022 at 01:07, Marijn Suijten
> > > <marijn.suijten@somainline.org> wrote:
> > > > diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
> > > > index 54942d758ee6..fabb98d0cdb2 100644
> > > > --- a/drivers/clk/clk-fixed-factor.c
> > > > +++ b/drivers/clk/clk-fixed-factor.c
> > > > @@ -148,17 +151,50 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
> > > >                 const char *name, unsigned int index, unsigned long flags,
> > > >                 unsigned int mult, unsigned int div)
> > > >  {
> > > > -       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, index,
> > > > -                                             flags, mult, div, true);
> > > > +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL,
> > > > +                                             index, flags, mult, div, true);
> > > 
> > > Here (and several times later) you are inserting an argument and then
> > > moving arguments to the next line. My slight preference would be to
> > > just insert the arg (and maybe break the line if it gets too long) w/o
> > > touching the next lines.
> 
> That'll definitely look odd, as we'll end up with index floating on a
> single line, all on its own.

Pretty sure Dmitry is suggesting to make the line longer, not put the
index on a line by itself. Ignore the 80-column limit.

> 
> > I'd just add the argument at the end because when it is added in the
> > middle it makes the diff more difficult to read.
> 
> How strong is this feeling, against keeping argument ordering consistent
> with other implementations of similar __clk_hw_register_* functions?
> 

Not super strong. Just try to minimize the diff to make the reviewer's
job easier. In this case it would be inserting NULL before 'index' and
not modifying the next line so the diff is one line instead of two.
Marijn Suijten June 27, 2022, 10:36 p.m. UTC | #5
On 2022-06-10 12:01:10, Stephen Boyd wrote:
> Quoting Marijn Suijten (2022-06-10 00:46:32)
> > On 2022-06-09 15:12:09, Stephen Boyd wrote:
> > > Quoting Dmitry Baryshkov (2022-06-02 03:20:19)
> > > > On Thu, 2 Jun 2022 at 01:07, Marijn Suijten
> > > > <marijn.suijten@somainline.org> wrote:
> > > > > diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
> > > > > index 54942d758ee6..fabb98d0cdb2 100644
> > > > > --- a/drivers/clk/clk-fixed-factor.c
> > > > > +++ b/drivers/clk/clk-fixed-factor.c
> > > > > @@ -148,17 +151,50 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
> > > > >                 const char *name, unsigned int index, unsigned long flags,
> > > > >                 unsigned int mult, unsigned int div)
> > > > >  {
> > > > > -       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, index,
> > > > > -                                             flags, mult, div, true);
> > > > > +       return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL,
> > > > > +                                             index, flags, mult, div, true);
> > > > 
> > > > Here (and several times later) you are inserting an argument and then
> > > > moving arguments to the next line. My slight preference would be to
> > > > just insert the arg (and maybe break the line if it gets too long) w/o
> > > > touching the next lines.
> > 
> > That'll definitely look odd, as we'll end up with index floating on a
> > single line, all on its own.
> 
> Pretty sure Dmitry is suggesting to make the line longer, not put the
> index on a line by itself. Ignore the 80-column limit.

There's a "(and maybe break the line if it gets too long)" in there, but
it's ugly especially for short (ie. "0,") arguments.  I'm following your
request to ignore 80-columns as a limit.

Will resend this after being able to physically build-test it tomorrow,
thanks!

- Marijn
diff mbox series

Patch

diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 54942d758ee6..fabb98d0cdb2 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -78,7 +78,8 @@  static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *
 
 static struct clk_hw *
 __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
-		const char *name, const char *parent_name, int index,
+		const char *name, const char *parent_name,
+		const struct clk_hw *parent_hw, int index,
 		unsigned long flags, unsigned int mult, unsigned int div,
 		bool devm)
 {
@@ -108,7 +109,9 @@  __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
 	init.name = name;
 	init.ops = &clk_fixed_factor_ops;
 	init.flags = flags;
-	if (parent_name)
+	if (parent_hw)
+		init.parent_hws = &parent_hw;
+	else if (parent_name)
 		init.parent_names = &parent_name;
 	else
 		init.parent_data = &pdata;
@@ -148,17 +151,50 @@  struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
 		const char *name, unsigned int index, unsigned long flags,
 		unsigned int mult, unsigned int div)
 {
-	return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, index,
-					      flags, mult, div, true);
+	return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL,
+					      index, flags, mult, div, true);
 }
 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index);
 
+/**
+ * devm_clk_hw_register_fixed_factor_parent_hw - Register a fixed factor clock with
+ * pointer to parent clock
+ * @dev: device that is registering this clock
+ * @name: name of this clock
+ * @parent_hw: pointer to parent clk
+ * @flags: fixed factor flags
+ * @mult: multiplier
+ * @div: divider
+ *
+ * Return: Pointer to fixed factor clk_hw structure that was registered or
+ * an error pointer.
+ */
+struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
+		const char *name, const struct clk_hw *parent_hw,
+		unsigned long flags, unsigned int mult, unsigned int div)
+{
+	return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw,
+					      -1, flags, mult, div, true);
+}
+EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw);
+
+struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
+		const char *name, const struct clk_hw *parent_hw,
+		unsigned long flags, unsigned int mult, unsigned int div)
+{
+	return __clk_hw_register_fixed_factor(dev, NULL, name, NULL,
+					      parent_hw, -1, flags, mult, div,
+					      false);
+}
+EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw);
+
 struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
 		const char *name, const char *parent_name, unsigned long flags,
 		unsigned int mult, unsigned int div)
 {
-	return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1,
-					      flags, mult, div, false);
+	return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name,
+					      NULL, -1, flags, mult, div,
+					      false);
 }
 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor);
 
@@ -204,8 +240,9 @@  struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
 		const char *name, const char *parent_name, unsigned long flags,
 		unsigned int mult, unsigned int div)
 {
-	return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1,
-			flags, mult, div, true);
+	return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name,
+					      NULL, -1, flags, mult, div,
+					      true);
 }
 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor);
 
@@ -240,8 +277,8 @@  static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node)
 	if (of_match_node(set_rate_parent_matches, node))
 		flags |= CLK_SET_RATE_PARENT;
 
-	hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, 0,
-					    flags, mult, div, false);
+	hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL,
+					    0, flags, mult, div, false);
 	if (IS_ERR(hw)) {
 		/*
 		 * Clear OF_POPULATED flag so that clock registration can be
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 316c7e082934..94458cb669f0 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -1032,6 +1032,14 @@  struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
 struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
 		const char *name, unsigned int index, unsigned long flags,
 		unsigned int mult, unsigned int div);
+
+struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
+		const char *name, const struct clk_hw *parent_hw,
+		unsigned long flags, unsigned int mult, unsigned int div);
+
+struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
+		const char *name, const struct clk_hw *parent_hw,
+		unsigned long flags, unsigned int mult, unsigned int div);
 /**
  * struct clk_fractional_divider - adjustable fractional divider clock
  *