All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: si5341: fix reported clk_rate when output divider is 2
@ 2021-12-03 14:12 Adam Wujek
  2022-01-13 21:23 ` Stephen Boyd
  2022-01-25  0:51 ` Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: Adam Wujek @ 2021-12-03 14:12 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd; +Cc: Adam Wujek, linux-clk, linux-kernel

SI5341_OUT_CFG_RDIV_FORCE2 shall be checked first to distinguish whether
a divider for a given output is set to 2 (SI5341_OUT_CFG_RDIV_FORCE2
is set) or the output is disabled (SI5341_OUT_CFG_RDIV_FORCE2 not set,
SI5341_OUT_R_REG is set 0).
Before the change, divider set to 2 (SI5341_OUT_R_REG set to 0) was
interpreted as output is disabled.

Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
 drivers/clk/clk-si5341.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
index b7641abe6747..15b1c90cafe5 100644
--- a/drivers/clk/clk-si5341.c
+++ b/drivers/clk/clk-si5341.c
@@ -798,6 +798,15 @@ static unsigned long si5341_output_clk_recalc_rate(struct clk_hw *hw,
 	u32 r_divider;
 	u8 r[3];

+	err = regmap_read(output->data->regmap,
+			SI5341_OUT_CONFIG(output), &val);
+	if (err < 0)
+		return err;
+
+	/* If SI5341_OUT_CFG_RDIV_FORCE2 is set, r_divider is 2 */
+	if (val & SI5341_OUT_CFG_RDIV_FORCE2)
+		return parent_rate / 2;
+
 	err = regmap_bulk_read(output->data->regmap,
 			SI5341_OUT_R_REG(output), r, 3);
 	if (err < 0)
@@ -814,13 +823,6 @@ static unsigned long si5341_output_clk_recalc_rate(struct clk_hw *hw,
 	r_divider += 1;
 	r_divider <<= 1;

-	err = regmap_read(output->data->regmap,
-			SI5341_OUT_CONFIG(output), &val);
-	if (err < 0)
-		return err;
-
-	if (val & SI5341_OUT_CFG_RDIV_FORCE2)
-		r_divider = 2;

 	return parent_rate / r_divider;
 }
--
2.25.1



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

* Re: [PATCH] clk: si5341: fix reported clk_rate when output divider is 2
  2021-12-03 14:12 [PATCH] clk: si5341: fix reported clk_rate when output divider is 2 Adam Wujek
@ 2022-01-13 21:23 ` Stephen Boyd
  2022-01-13 22:29   ` Robert Hancock
  2022-01-25  0:51 ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2022-01-13 21:23 UTC (permalink / raw)
  To: Adam Wujek, Michael Turquette, Robert Hancock
  Cc: Adam Wujek, linux-clk, linux-kernel

+Robert

Please review

Quoting Adam Wujek (2021-12-03 06:12:07)
> SI5341_OUT_CFG_RDIV_FORCE2 shall be checked first to distinguish whether
> a divider for a given output is set to 2 (SI5341_OUT_CFG_RDIV_FORCE2
> is set) or the output is disabled (SI5341_OUT_CFG_RDIV_FORCE2 not set,
> SI5341_OUT_R_REG is set 0).
> Before the change, divider set to 2 (SI5341_OUT_R_REG set to 0) was
> interpreted as output is disabled.
> 
> Signed-off-by: Adam Wujek <dev_public@wujek.eu>
> ---
>  drivers/clk/clk-si5341.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
> index b7641abe6747..15b1c90cafe5 100644
> --- a/drivers/clk/clk-si5341.c
> +++ b/drivers/clk/clk-si5341.c
> @@ -798,6 +798,15 @@ static unsigned long si5341_output_clk_recalc_rate(struct clk_hw *hw,
>         u32 r_divider;
>         u8 r[3];
> 
> +       err = regmap_read(output->data->regmap,
> +                       SI5341_OUT_CONFIG(output), &val);
> +       if (err < 0)
> +               return err;
> +
> +       /* If SI5341_OUT_CFG_RDIV_FORCE2 is set, r_divider is 2 */
> +       if (val & SI5341_OUT_CFG_RDIV_FORCE2)
> +               return parent_rate / 2;
> +
>         err = regmap_bulk_read(output->data->regmap,
>                         SI5341_OUT_R_REG(output), r, 3);
>         if (err < 0)
> @@ -814,13 +823,6 @@ static unsigned long si5341_output_clk_recalc_rate(struct clk_hw *hw,
>         r_divider += 1;
>         r_divider <<= 1;
> 
> -       err = regmap_read(output->data->regmap,
> -                       SI5341_OUT_CONFIG(output), &val);
> -       if (err < 0)
> -               return err;
> -
> -       if (val & SI5341_OUT_CFG_RDIV_FORCE2)
> -               r_divider = 2;
> 
>         return parent_rate / r_divider;
>  }

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

* Re: [PATCH] clk: si5341: fix reported clk_rate when output divider is 2
  2022-01-13 21:23 ` Stephen Boyd
@ 2022-01-13 22:29   ` Robert Hancock
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Hancock @ 2022-01-13 22:29 UTC (permalink / raw)
  To: sboyd, dev_public, mturquette; +Cc: linux-kernel, linux-clk

On Thu, 2022-01-13 at 13:23 -0800, Stephen Boyd wrote:
> +Robert
> 
> Please review
> 
> Quoting Adam Wujek (2021-12-03 06:12:07)
> > SI5341_OUT_CFG_RDIV_FORCE2 shall be checked first to distinguish whether
> > a divider for a given output is set to 2 (SI5341_OUT_CFG_RDIV_FORCE2
> > is set) or the output is disabled (SI5341_OUT_CFG_RDIV_FORCE2 not set,
> > SI5341_OUT_R_REG is set 0).
> > Before the change, divider set to 2 (SI5341_OUT_R_REG set to 0) was
> > interpreted as output is disabled.
> > 
> > Signed-off-by: Adam Wujek <dev_public@wujek.eu>
> > ---
> >  drivers/clk/clk-si5341.c | 16 +++++++++-------
> >  1 file changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
> > index b7641abe6747..15b1c90cafe5 100644
> > --- a/drivers/clk/clk-si5341.c
> > +++ b/drivers/clk/clk-si5341.c
> > @@ -798,6 +798,15 @@ static unsigned long
> > si5341_output_clk_recalc_rate(struct clk_hw *hw,
> >         u32 r_divider;
> >         u8 r[3];
> > 
> > +       err = regmap_read(output->data->regmap,
> > +                       SI5341_OUT_CONFIG(output), &val);
> > +       if (err < 0)
> > +               return err;
> > +
> > +       /* If SI5341_OUT_CFG_RDIV_FORCE2 is set, r_divider is 2 */
> > +       if (val & SI5341_OUT_CFG_RDIV_FORCE2)
> > +               return parent_rate / 2;
> > +
> >         err = regmap_bulk_read(output->data->regmap,
> >                         SI5341_OUT_R_REG(output), r, 3);
> >         if (err < 0)
> > @@ -814,13 +823,6 @@ static unsigned long
> > si5341_output_clk_recalc_rate(struct clk_hw *hw,
> >         r_divider += 1;
> >         r_divider <<= 1;
> > 
> > -       err = regmap_read(output->data->regmap,
> > -                       SI5341_OUT_CONFIG(output), &val);
> > -       if (err < 0)
> > -               return err;
> > -
> > -       if (val & SI5341_OUT_CFG_RDIV_FORCE2)
> > -               r_divider = 2;
> > 
> >         return parent_rate / r_divider;
> >  }

Looks reasonable to me. I guess this bug doesn't affect register settings that
were previously applied by this driver, as it always sets the RDIV to 1 when
setting the FORCE2 flag, but if the chip has power-up NVM configuration
generated by ClockBuilder etc. then this problem could show up.

Reviewed-by: Robert Hancock <robert.hancock@calian.com>

-- 
Robert Hancock
Senior Hardware Designer, Calian Advanced Technologies
www.calian.com

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

* Re: [PATCH] clk: si5341: fix reported clk_rate when output divider is 2
  2021-12-03 14:12 [PATCH] clk: si5341: fix reported clk_rate when output divider is 2 Adam Wujek
  2022-01-13 21:23 ` Stephen Boyd
@ 2022-01-25  0:51 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2022-01-25  0:51 UTC (permalink / raw)
  To: Adam Wujek, Michael Turquette; +Cc: Adam Wujek, linux-clk, linux-kernel

Quoting Adam Wujek (2021-12-03 06:12:07)
> SI5341_OUT_CFG_RDIV_FORCE2 shall be checked first to distinguish whether
> a divider for a given output is set to 2 (SI5341_OUT_CFG_RDIV_FORCE2
> is set) or the output is disabled (SI5341_OUT_CFG_RDIV_FORCE2 not set,
> SI5341_OUT_R_REG is set 0).
> Before the change, divider set to 2 (SI5341_OUT_R_REG set to 0) was
> interpreted as output is disabled.
> 
> Signed-off-by: Adam Wujek <dev_public@wujek.eu>
> ---

Applied to clk-next

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

end of thread, other threads:[~2022-01-25  3:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 14:12 [PATCH] clk: si5341: fix reported clk_rate when output divider is 2 Adam Wujek
2022-01-13 21:23 ` Stephen Boyd
2022-01-13 22:29   ` Robert Hancock
2022-01-25  0:51 ` Stephen Boyd

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.