mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] clk: fix clk_round_rate() behaviour
@ 2022-05-16  7:00 Denis Orlov
  2022-05-16  9:07 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Orlov @ 2022-05-16  7:00 UTC (permalink / raw)
  To: barebox; +Cc: Denis Orlov

Right now this function returns the current rate of the clock in the
case when the round_rate() is not given in the clock's ops. This breaks
clk_set_rate(), which calls clk_round_rate() to check if the resulting
frequency would be the same as the one that is already set.
Make it so that clk_round_rate() returns the frequency that was given as
argument in this case.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 drivers/clk/clk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 52e309e877..7492717d3c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -139,16 +139,16 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
 	if (IS_ERR(clk))
 		return 0;
 
+	if (!clk->ops->round_rate)
+		return rate;
+
 	parent = clk_get_parent(clk);
 	if (parent)
 		parent_rate = clk_get_rate(parent);
 
 	hw = clk_to_clk_hw(clk);
 
-	if (clk->ops->round_rate)
-		return clk->ops->round_rate(hw, rate, &parent_rate);
-
-	return clk_get_rate(clk);
+	return clk->ops->round_rate(hw, rate, &parent_rate);
 }
 
 long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH] clk: fix clk_round_rate() behaviour
  2022-05-16  7:00 [PATCH] clk: fix clk_round_rate() behaviour Denis Orlov
@ 2022-05-16  9:07 ` Sascha Hauer
  2022-05-19  8:12   ` Денис Орлов
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2022-05-16  9:07 UTC (permalink / raw)
  To: Denis Orlov; +Cc: barebox

Hi Denis,

On Mon, May 16, 2022 at 10:00:49AM +0300, Denis Orlov wrote:
> Right now this function returns the current rate of the clock in the
> case when the round_rate() is not given in the clock's ops. This breaks
> clk_set_rate(), which calls clk_round_rate() to check if the resulting
> frequency would be the same as the one that is already set.
> Make it so that clk_round_rate() returns the frequency that was given as
> argument in this case.
> 
> Signed-off-by: Denis Orlov <denorl2009@gmail.com>
> ---
>  drivers/clk/clk.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 52e309e877..7492717d3c 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -139,16 +139,16 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
>  	if (IS_ERR(clk))
>  		return 0;
>  
> +	if (!clk->ops->round_rate)
> +		return rate;
> +
>  	parent = clk_get_parent(clk);
>  	if (parent)
>  		parent_rate = clk_get_rate(parent);
>  
>  	hw = clk_to_clk_hw(clk);
>  
> -	if (clk->ops->round_rate)
> -		return clk->ops->round_rate(hw, rate, &parent_rate);
> -
> -	return clk_get_rate(clk);
> +	return clk->ops->round_rate(hw, rate, &parent_rate);
>  }

I smell problems with this patch. Which clocks do you have that do not
have a round_rate hook but still allow to set its rate?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH] clk: fix clk_round_rate() behaviour
  2022-05-16  9:07 ` Sascha Hauer
@ 2022-05-19  8:12   ` Денис Орлов
  0 siblings, 0 replies; 3+ messages in thread
From: Денис Орлов @ 2022-05-19  8:12 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi,

On Mon, 16 May 2022 at 12:07, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> I smell problems with this patch. Which clocks do you have that do not
> have a round_rate hook but still allow to set its rate?

Well, the reason for making this patch was actually the lack of any
output from the clk_set_rate command if there was no set_rate (together
with round_rate) hook set for a given clock. In this case set_rate()
would check round_rate() to be equal to the current rate and leave
without returning an error. But I would like to actually receive some
response about the fact that this clock does not support setting its
rate.
However, I agree with you that this solution may lead to problems.
Maybe instead we should explicitly check in a command whether the given
clock has an appropriate hook set and output some message if this is not
the case. What do you think?

Regards,
Denis

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2022-05-19  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  7:00 [PATCH] clk: fix clk_round_rate() behaviour Denis Orlov
2022-05-16  9:07 ` Sascha Hauer
2022-05-19  8:12   ` Денис Орлов

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox