LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] clk-si544: Properly round requested frequency to nearest match
@ 2018-05-31 14:03 Mike Looijmans
  2018-05-31 15:34 ` Stephen Boyd
  2018-06-02  6:25 ` Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: Mike Looijmans @ 2018-05-31 14:03 UTC (permalink / raw)
  To: linux-clk; +Cc: linux-kernel, mturquette, sboyd, Mike Looijmans

The si544 driver had a rounding problem that using the result of clk_round_rate
may set the clock to yet another rate, for example:
clk_round_rate(195000000) = 194999999
clk_round_rate(194999999) = 194999998

Clients would expect that after clk_set_rate(clk, freq2=clk_round_rate(clk, freq)) the
chip will be running at exactly freq2.

The problem was in the calculation of the feedback divider, it was always rounded
down instead of to the nearest possible VCO value.

After this change, the following holds true for any supported frequency:
actual_freq = clk_round_rate(clk, freq);
clk_set_rate(clk, actual_freq);
clk_round_rate(clk, actual_freq) == actual_freq && clk_get_rate(clk) == actual_freq

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---
 drivers/clk/clk-si544.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/clk/clk-si544.c b/drivers/clk/clk-si544.c
index d437722..e972ffb 100644
--- a/drivers/clk/clk-si544.c
+++ b/drivers/clk/clk-si544.c
@@ -207,6 +207,7 @@ static int si544_calc_muldiv(struct clk_si544_muldiv *settings,
 
 	/* And the fractional bits using the remainder */
 	vco = (u64)tmp << 32;
+	vco += FXO / 2; /* Round to nearest multiple */
 	do_div(vco, FXO);
 	settings->fb_div_frac = vco;
 
-- 
1.9.1

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

* Re: [PATCH] clk-si544: Properly round requested frequency to nearest match
  2018-05-31 14:03 [PATCH] clk-si544: Properly round requested frequency to nearest match Mike Looijmans
@ 2018-05-31 15:34 ` Stephen Boyd
  2018-06-01  5:05   ` Mike Looijmans
  2018-06-02  6:25 ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2018-05-31 15:34 UTC (permalink / raw)
  To: Mike Looijmans, linux-clk; +Cc: linux-kernel, mturquette, Mike Looijmans

Quoting Mike Looijmans (2018-05-31 07:03:55)
> The si544 driver had a rounding problem that using the result of clk_round_rate
> may set the clock to yet another rate, for example:
> clk_round_rate(195000000) = 194999999
> clk_round_rate(194999999) = 194999998
> 
> Clients would expect that after clk_set_rate(clk, freq2=clk_round_rate(clk, freq)) the
> chip will be running at exactly freq2.
> 
> The problem was in the calculation of the feedback divider, it was always rounded
> down instead of to the nearest possible VCO value.
> 
> After this change, the following holds true for any supported frequency:
> actual_freq = clk_round_rate(clk, freq);
> clk_set_rate(clk, actual_freq);
> clk_round_rate(clk, actual_freq) == actual_freq && clk_get_rate(clk) == actual_freq
> 
> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>

Any fixes tag? I can slap 

Fixes: 953cc3e81170 ("clk: Add driver for the si544 clock generator chip")

on to the patch here.

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

* Re: [PATCH] clk-si544: Properly round requested frequency to nearest match
  2018-05-31 15:34 ` Stephen Boyd
@ 2018-06-01  5:05   ` Mike Looijmans
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Looijmans @ 2018-06-01  5:05 UTC (permalink / raw)
  To: Stephen Boyd, linux-clk; +Cc: linux-kernel, mturquette

On 31-05-18 17:34, Stephen Boyd wrote:
> Quoting Mike Looijmans (2018-05-31 07:03:55)
>> The si544 driver had a rounding problem that using the result of clk_round_rate
>> may set the clock to yet another rate, for example:
>> clk_round_rate(195000000) = 194999999
>> clk_round_rate(194999999) = 194999998
>>
>> Clients would expect that after clk_set_rate(clk, freq2=clk_round_rate(clk, freq)) the
>> chip will be running at exactly freq2.
>>
>> The problem was in the calculation of the feedback divider, it was always rounded
>> down instead of to the nearest possible VCO value.
>>
>> After this change, the following holds true for any supported frequency:
>> actual_freq = clk_round_rate(clk, freq);
>> clk_set_rate(clk, actual_freq);
>> clk_round_rate(clk, actual_freq) == actual_freq && clk_get_rate(clk) == actual_freq
>>
>> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
> 
> Any fixes tag? I can slap
> 
> Fixes: 953cc3e81170 ("clk: Add driver for the si544 clock generator chip")
> 
> on to the patch here.
> 

I think that would be good, yes. Slap it on.


Kind regards,

Mike Looijmans
System Expert

TOPIC Products
Materiaalweg 4, NL-5681 RJ Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
E-mail: mike.looijmans@topicproducts.com
Website: www.topicproducts.com

Please consider the environment before printing this e-mail

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

* Re: [PATCH] clk-si544: Properly round requested frequency to nearest match
  2018-05-31 14:03 [PATCH] clk-si544: Properly round requested frequency to nearest match Mike Looijmans
  2018-05-31 15:34 ` Stephen Boyd
@ 2018-06-02  6:25 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2018-06-02  6:25 UTC (permalink / raw)
  To: Mike Looijmans, linux-clk; +Cc: linux-kernel, mturquette, Mike Looijmans

Quoting Mike Looijmans (2018-05-31 07:03:55)
> The si544 driver had a rounding problem that using the result of clk_round_rate
> may set the clock to yet another rate, for example:
> clk_round_rate(195000000) = 194999999
> clk_round_rate(194999999) = 194999998
> 
> Clients would expect that after clk_set_rate(clk, freq2=clk_round_rate(clk, freq)) the
> chip will be running at exactly freq2.
> 
> The problem was in the calculation of the feedback divider, it was always rounded
> down instead of to the nearest possible VCO value.
> 
> After this change, the following holds true for any supported frequency:
> actual_freq = clk_round_rate(clk, freq);
> clk_set_rate(clk, actual_freq);
> clk_round_rate(clk, actual_freq) == actual_freq && clk_get_rate(clk) == actual_freq
> 
> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
> ---

Applied to clk-next

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

end of thread, other threads:[~2018-06-02  6:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-31 14:03 [PATCH] clk-si544: Properly round requested frequency to nearest match Mike Looijmans
2018-05-31 15:34 ` Stephen Boyd
2018-06-01  5:05   ` Mike Looijmans
2018-06-02  6:25 ` Stephen Boyd

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).