linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate
@ 2018-09-21 22:01 ryang
  2018-09-24  8:08 ` Peter De Schrijver
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: ryang @ 2018-09-21 22:01 UTC (permalink / raw)
  To: Peter De Schrijver
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel, ryang

The current behavior is that clk_round_rate would return the same clock
rate passed to it for valid PLL configurations. This change will return
the exact rate the PLL will provide in accordance with clk API.

Signed-off-by: ryang <decatf@gmail.com>
---
 drivers/clk/tegra/clk-pll.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
index 17a058c3bbc1..36014a6ec42e 100644
--- a/drivers/clk/tegra/clk-pll.c
+++ b/drivers/clk/tegra/clk-pll.c
@@ -595,7 +595,12 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
 		return -EINVAL;
 	}
 
-	cfg->output_rate >>= p_div;
+	if (cfg->m == 0) {
+		cfg->output_rate = 0;
+	} else {
+		cfg->output_rate = cfg->n * DIV_ROUND_UP(parent_rate, cfg->m);
+		cfg->output_rate >>= p_div;
+	}
 
 	if (pll->params->pdiv_tohw) {
 		ret = _p_div_to_hw(hw, 1 << p_div);
-- 
2.17.1


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

* Re: [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate
  2018-09-21 22:01 [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate ryang
@ 2018-09-24  8:08 ` Peter De Schrijver
  2018-09-24 19:18   ` r yang
  2018-09-24 11:40 ` Thierry Reding
  2018-09-24 16:51 ` Dmitry Osipenko
  2 siblings, 1 reply; 6+ messages in thread
From: Peter De Schrijver @ 2018-09-24  8:08 UTC (permalink / raw)
  To: ryang
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

On Fri, Sep 21, 2018 at 06:01:49PM -0400, ryang wrote:
> The current behavior is that clk_round_rate would return the same clock
> rate passed to it for valid PLL configurations. This change will return
> the exact rate the PLL will provide in accordance with clk API.
> 
> Signed-off-by: ryang <decatf@gmail.com>
> ---
>  drivers/clk/tegra/clk-pll.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
> index 17a058c3bbc1..36014a6ec42e 100644
> --- a/drivers/clk/tegra/clk-pll.c
> +++ b/drivers/clk/tegra/clk-pll.c
> @@ -595,7 +595,12 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
>  		return -EINVAL;
>  	}
>  
> -	cfg->output_rate >>= p_div;
> +	if (cfg->m == 0) {
> +		cfg->output_rate = 0;

I think a WARN_ON() is appropriate here. the input divider should never be 0.

Peter.

> +	} else {
> +		cfg->output_rate = cfg->n * DIV_ROUND_UP(parent_rate, cfg->m);
> +		cfg->output_rate >>= p_div;
> +	}
>  
>  	if (pll->params->pdiv_tohw) {
>  		ret = _p_div_to_hw(hw, 1 << p_div);
> -- 
> 2.17.1
> 

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

* Re: [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate
  2018-09-21 22:01 [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate ryang
  2018-09-24  8:08 ` Peter De Schrijver
@ 2018-09-24 11:40 ` Thierry Reding
  2018-09-24 16:51 ` Dmitry Osipenko
  2 siblings, 0 replies; 6+ messages in thread
From: Thierry Reding @ 2018-09-24 11:40 UTC (permalink / raw)
  To: ryang
  Cc: Peter De Schrijver, Prashant Gaikwad, Michael Turquette,
	Stephen Boyd, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

On Fri, Sep 21, 2018 at 06:01:49PM -0400, ryang wrote:
> The current behavior is that clk_round_rate would return the same clock
> rate passed to it for valid PLL configurations. This change will return
> the exact rate the PLL will provide in accordance with clk API.
> 
> Signed-off-by: ryang <decatf@gmail.com>
> ---
>  drivers/clk/tegra/clk-pll.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

With Peter's comment addressed:

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate
  2018-09-21 22:01 [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate ryang
  2018-09-24  8:08 ` Peter De Schrijver
  2018-09-24 11:40 ` Thierry Reding
@ 2018-09-24 16:51 ` Dmitry Osipenko
  2 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2018-09-24 16:51 UTC (permalink / raw)
  To: ryang, Peter De Schrijver
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

On 9/22/18 1:01 AM, ryang wrote:
> The current behavior is that clk_round_rate would return the same clock
> rate passed to it for valid PLL configurations. This change will return
> the exact rate the PLL will provide in accordance with clk API.
> 
> Signed-off-by: ryang <decatf@gmail.com>

A minor comment.. [0] require a real name, it's not even obvious whether
you're "Ryan G" or "R Yang".

[0]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

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

* Re: [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate
  2018-09-24  8:08 ` Peter De Schrijver
@ 2018-09-24 19:18   ` r yang
  2018-09-25  8:44     ` Peter De Schrijver
  0 siblings, 1 reply; 6+ messages in thread
From: r yang @ 2018-09-24 19:18 UTC (permalink / raw)
  To: Peter De Schrijver
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

On Mon, Sep 24, 2018 at 11:08:03AM +0300, Peter De Schrijver wrote:
> On Fri, Sep 21, 2018 at 06:01:49PM -0400, ryang wrote:
> > The current behavior is that clk_round_rate would return the same clock
> > rate passed to it for valid PLL configurations. This change will return
> > the exact rate the PLL will provide in accordance with clk API.
> > 
> > Signed-off-by: ryang <decatf@gmail.com>
> > ---
> >  drivers/clk/tegra/clk-pll.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
> > index 17a058c3bbc1..36014a6ec42e 100644
> > --- a/drivers/clk/tegra/clk-pll.c
> > +++ b/drivers/clk/tegra/clk-pll.c
> > @@ -595,7 +595,12 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
> >  		return -EINVAL;
> >  	}
> >  
> > -	cfg->output_rate >>= p_div;
> > +	if (cfg->m == 0) {
> > +		cfg->output_rate = 0;
> 
> I think a WARN_ON() is appropriate here. the input divider should never be 0.
> 
> Peter.
> 

Should it return -EINVAL (or some error) too? _calc_rate is also in the
clk_set_rate code path. I think we want to avoid programming the
register to 0 input divider all together?

> > +	} else {
> > +		cfg->output_rate = cfg->n * DIV_ROUND_UP(parent_rate, cfg->m);
> > +		cfg->output_rate >>= p_div;
> > +	}
> >  
> >  	if (pll->params->pdiv_tohw) {
> >  		ret = _p_div_to_hw(hw, 1 << p_div);
> > -- 
> > 2.17.1
> > 

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

* Re: [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate
  2018-09-24 19:18   ` r yang
@ 2018-09-25  8:44     ` Peter De Schrijver
  0 siblings, 0 replies; 6+ messages in thread
From: Peter De Schrijver @ 2018-09-25  8:44 UTC (permalink / raw)
  To: r yang
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

On Mon, Sep 24, 2018 at 03:18:04PM -0400, r yang wrote:
> On Mon, Sep 24, 2018 at 11:08:03AM +0300, Peter De Schrijver wrote:
> > On Fri, Sep 21, 2018 at 06:01:49PM -0400, ryang wrote:
> > > The current behavior is that clk_round_rate would return the same clock
> > > rate passed to it for valid PLL configurations. This change will return
> > > the exact rate the PLL will provide in accordance with clk API.
> > > 
> > > Signed-off-by: ryang <decatf@gmail.com>
> > > ---
> > >  drivers/clk/tegra/clk-pll.c | 7 ++++++-
> > >  1 file changed, 6 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
> > > index 17a058c3bbc1..36014a6ec42e 100644
> > > --- a/drivers/clk/tegra/clk-pll.c
> > > +++ b/drivers/clk/tegra/clk-pll.c
> > > @@ -595,7 +595,12 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
> > >  		return -EINVAL;
> > >  	}
> > >  
> > > -	cfg->output_rate >>= p_div;
> > > +	if (cfg->m == 0) {
> > > +		cfg->output_rate = 0;
> > 
> > I think a WARN_ON() is appropriate here. the input divider should never be 0.
> > 
> > Peter.
> > 
> 
> Should it return -EINVAL (or some error) too? _calc_rate is also in the
> clk_set_rate code path. I think we want to avoid programming the
> register to 0 input divider all together?
> 

Yes. writing 0 to the input divider is usually not allowed. In some cases it's
equivalent to writing 1, but better not count on that.

Peter.

> > > +	} else {
> > > +		cfg->output_rate = cfg->n * DIV_ROUND_UP(parent_rate, cfg->m);
> > > +		cfg->output_rate >>= p_div;
> > > +	}
> > >  
> > >  	if (pll->params->pdiv_tohw) {
> > >  		ret = _p_div_to_hw(hw, 1 << p_div);
> > > -- 
> > > 2.17.1
> > > 

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

end of thread, other threads:[~2018-09-25  8:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-21 22:01 [PATCH] clk: tegra: Return the exact clock rate from clk_round_rate ryang
2018-09-24  8:08 ` Peter De Schrijver
2018-09-24 19:18   ` r yang
2018-09-25  8:44     ` Peter De Schrijver
2018-09-24 11:40 ` Thierry Reding
2018-09-24 16:51 ` Dmitry Osipenko

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