All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
@ 2021-07-07 13:12 ` Codrin Ciubotariu
  0 siblings, 0 replies; 10+ messages in thread
From: Codrin Ciubotariu @ 2021-07-07 13:12 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, claudiu.beznea, Codrin Ciubotariu

On clk_generated_determine_rate(), the requested rate could be outside
of clk's range. Limit the rate to the clock's range to not return an
error.

Fixes: df70aeef6083 ("clk: at91: add generated clock driver")
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 drivers/clk/at91/clk-generated.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c
index b4fc8d71daf2..b656d25a9767 100644
--- a/drivers/clk/at91/clk-generated.c
+++ b/drivers/clk/at91/clk-generated.c
@@ -128,6 +128,12 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
 	int i;
 	u32 div;
 
+	/* do not look for a rate that is outside of our range */
+	if (gck->range.max && req->rate > gck->range.max)
+		req->rate = gck->range.max;
+	if (gck->range.min && req->rate < gck->range.min)
+		req->rate = gck->range.min;
+
 	for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
 		if (gck->chg_pid == i)
 			continue;
-- 
2.30.2


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

* [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
@ 2021-07-07 13:12 ` Codrin Ciubotariu
  0 siblings, 0 replies; 10+ messages in thread
From: Codrin Ciubotariu @ 2021-07-07 13:12 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel, linux-kernel
  Cc: alexandre.belloni, sboyd, mturquette, ludovic.desroches,
	Codrin Ciubotariu, claudiu.beznea

On clk_generated_determine_rate(), the requested rate could be outside
of clk's range. Limit the rate to the clock's range to not return an
error.

Fixes: df70aeef6083 ("clk: at91: add generated clock driver")
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 drivers/clk/at91/clk-generated.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c
index b4fc8d71daf2..b656d25a9767 100644
--- a/drivers/clk/at91/clk-generated.c
+++ b/drivers/clk/at91/clk-generated.c
@@ -128,6 +128,12 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
 	int i;
 	u32 div;
 
+	/* do not look for a rate that is outside of our range */
+	if (gck->range.max && req->rate > gck->range.max)
+		req->rate = gck->range.max;
+	if (gck->range.min && req->rate < gck->range.min)
+		req->rate = gck->range.min;
+
 	for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
 		if (gck->chg_pid == i)
 			continue;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
  2021-07-07 13:12 ` Codrin Ciubotariu
@ 2021-07-09  9:21   ` Nicolas Ferre
  -1 siblings, 0 replies; 10+ messages in thread
From: Nicolas Ferre @ 2021-07-09  9:21 UTC (permalink / raw)
  To: Codrin Ciubotariu, linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, alexandre.belloni, ludovic.desroches, claudiu.beznea

On 07/07/2021 at 15:12, Codrin Ciubotariu wrote:
> On clk_generated_determine_rate(), the requested rate could be outside
> of clk's range. Limit the rate to the clock's range to not return an
> error.

Isn't it saner for the user to return an error code instead of 
automatically restrain the dynamics requested without notice?

Can you elaborate the use case where returning an error is not convenient?

Regards,
   Nicolas

> Fixes: df70aeef6083 ("clk: at91: add generated clock driver")
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
> ---
>   drivers/clk/at91/clk-generated.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c
> index b4fc8d71daf2..b656d25a9767 100644
> --- a/drivers/clk/at91/clk-generated.c
> +++ b/drivers/clk/at91/clk-generated.c
> @@ -128,6 +128,12 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
>   	int i;
>   	u32 div;
>   
> +	/* do not look for a rate that is outside of our range */
> +	if (gck->range.max && req->rate > gck->range.max)
> +		req->rate = gck->range.max;
> +	if (gck->range.min && req->rate < gck->range.min)
> +		req->rate = gck->range.min;
> +
>   	for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
>   		if (gck->chg_pid == i)
>   			continue;
> 


-- 
Nicolas Ferre

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
@ 2021-07-09  9:21   ` Nicolas Ferre
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Ferre @ 2021-07-09  9:21 UTC (permalink / raw)
  To: Codrin Ciubotariu, linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, alexandre.belloni, ludovic.desroches, claudiu.beznea

On 07/07/2021 at 15:12, Codrin Ciubotariu wrote:
> On clk_generated_determine_rate(), the requested rate could be outside
> of clk's range. Limit the rate to the clock's range to not return an
> error.

Isn't it saner for the user to return an error code instead of 
automatically restrain the dynamics requested without notice?

Can you elaborate the use case where returning an error is not convenient?

Regards,
   Nicolas

> Fixes: df70aeef6083 ("clk: at91: add generated clock driver")
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
> ---
>   drivers/clk/at91/clk-generated.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c
> index b4fc8d71daf2..b656d25a9767 100644
> --- a/drivers/clk/at91/clk-generated.c
> +++ b/drivers/clk/at91/clk-generated.c
> @@ -128,6 +128,12 @@ static int clk_generated_determine_rate(struct clk_hw *hw,
>   	int i;
>   	u32 div;
>   
> +	/* do not look for a rate that is outside of our range */
> +	if (gck->range.max && req->rate > gck->range.max)
> +		req->rate = gck->range.max;
> +	if (gck->range.min && req->rate < gck->range.min)
> +		req->rate = gck->range.min;
> +
>   	for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
>   		if (gck->chg_pid == i)
>   			continue;
> 


-- 
Nicolas Ferre

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
  2021-07-09  9:21   ` Nicolas Ferre
@ 2021-07-09  9:59     ` Codrin.Ciubotariu
  -1 siblings, 0 replies; 10+ messages in thread
From: Codrin.Ciubotariu @ 2021-07-09  9:59 UTC (permalink / raw)
  To: Nicolas.Ferre, linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, alexandre.belloni, Ludovic.Desroches, Claudiu.Beznea

On 09.07.2021 12:21, Nicolas Ferre wrote:
> On 07/07/2021 at 15:12, Codrin Ciubotariu wrote:
>> On clk_generated_determine_rate(), the requested rate could be outside
>> of clk's range. Limit the rate to the clock's range to not return an
>> error.
> 
> Isn't it saner for the user to return an error code instead of 
> automatically restrain the dynamics requested without notice?
> 
> Can you elaborate the use case where returning an error is not convenient?

The way I see it, if the user requests a rate that is out of clock's 
range, the driver's determine_rate() should return min/max, not an 
error. That is actually the closest rate supported by the clock, which 
is what determine_rate() should accomplish. The user has no clk API to 
get clock's range, so there is no way to call clk_round_rate() only for 
values within our range.

The use cause is with sam9x60's I2S driver, which has to try different 
rates to get the closest one to what it needs. There is no 'perfect' 
rate, because there is no AUDIO PLL and we have to try different values 
for our internal dividers to find the closest one.

https://elixir.bootlin.com/linux/latest/source/sound/soc/atmel/mchp-i2s-mcc.c#L416

Best regards,
Codrin

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
@ 2021-07-09  9:59     ` Codrin.Ciubotariu
  0 siblings, 0 replies; 10+ messages in thread
From: Codrin.Ciubotariu @ 2021-07-09  9:59 UTC (permalink / raw)
  To: Nicolas.Ferre, linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, alexandre.belloni, Ludovic.Desroches, Claudiu.Beznea

On 09.07.2021 12:21, Nicolas Ferre wrote:
> On 07/07/2021 at 15:12, Codrin Ciubotariu wrote:
>> On clk_generated_determine_rate(), the requested rate could be outside
>> of clk's range. Limit the rate to the clock's range to not return an
>> error.
> 
> Isn't it saner for the user to return an error code instead of 
> automatically restrain the dynamics requested without notice?
> 
> Can you elaborate the use case where returning an error is not convenient?

The way I see it, if the user requests a rate that is out of clock's 
range, the driver's determine_rate() should return min/max, not an 
error. That is actually the closest rate supported by the clock, which 
is what determine_rate() should accomplish. The user has no clk API to 
get clock's range, so there is no way to call clk_round_rate() only for 
values within our range.

The use cause is with sam9x60's I2S driver, which has to try different 
rates to get the closest one to what it needs. There is no 'perfect' 
rate, because there is no AUDIO PLL and we have to try different values 
for our internal dividers to find the closest one.

https://elixir.bootlin.com/linux/latest/source/sound/soc/atmel/mchp-i2s-mcc.c#L416

Best regards,
Codrin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
  2021-07-09  9:59     ` Codrin.Ciubotariu
@ 2021-07-16 19:17       ` Nicolas Ferre
  -1 siblings, 0 replies; 10+ messages in thread
From: Nicolas Ferre @ 2021-07-16 19:17 UTC (permalink / raw)
  To: Codrin Ciubotariu - M19940, linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, alexandre.belloni, Ludovic Desroches - M43218,
	Claudiu Beznea - M18063

On 09/07/2021 at 11:59, Codrin Ciubotariu - M19940 wrote:
> On 09.07.2021 12:21, Nicolas Ferre wrote:
>> On 07/07/2021 at 15:12, Codrin Ciubotariu wrote:
>>> On clk_generated_determine_rate(), the requested rate could be outside
>>> of clk's range. Limit the rate to the clock's range to not return an
>>> error.
>>
>> Isn't it saner for the user to return an error code instead of
>> automatically restrain the dynamics requested without notice?
>>
>> Can you elaborate the use case where returning an error is not convenient?
> 
> The way I see it, if the user requests a rate that is out of clock's
> range, the driver's determine_rate() should return min/max, not an
> error. That is actually the closest rate supported by the clock, which
> is what determine_rate() should accomplish. The user has no clk API to
> get clock's range, so there is no way to call clk_round_rate() only for
> values within our range.
> 
> The use cause is with sam9x60's I2S driver, which has to try different
> rates to get the closest one to what it needs. There is no 'perfect'
> rate, because there is no AUDIO PLL and we have to try different values
> for our internal dividers to find the closest one.
> 
> https://elixir.bootlin.com/linux/latest/source/sound/soc/atmel/mchp-i2s-mcc.c#L416

Sure, makes sense:

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>

Regards,
   Nicolas

-- 
Nicolas Ferre

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
@ 2021-07-16 19:17       ` Nicolas Ferre
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Ferre @ 2021-07-16 19:17 UTC (permalink / raw)
  To: Codrin Ciubotariu - M19940, linux-clk, linux-arm-kernel, linux-kernel
  Cc: mturquette, sboyd, alexandre.belloni, Ludovic Desroches - M43218,
	Claudiu Beznea - M18063

On 09/07/2021 at 11:59, Codrin Ciubotariu - M19940 wrote:
> On 09.07.2021 12:21, Nicolas Ferre wrote:
>> On 07/07/2021 at 15:12, Codrin Ciubotariu wrote:
>>> On clk_generated_determine_rate(), the requested rate could be outside
>>> of clk's range. Limit the rate to the clock's range to not return an
>>> error.
>>
>> Isn't it saner for the user to return an error code instead of
>> automatically restrain the dynamics requested without notice?
>>
>> Can you elaborate the use case where returning an error is not convenient?
> 
> The way I see it, if the user requests a rate that is out of clock's
> range, the driver's determine_rate() should return min/max, not an
> error. That is actually the closest rate supported by the clock, which
> is what determine_rate() should accomplish. The user has no clk API to
> get clock's range, so there is no way to call clk_round_rate() only for
> values within our range.
> 
> The use cause is with sam9x60's I2S driver, which has to try different
> rates to get the closest one to what it needs. There is no 'perfect'
> rate, because there is no AUDIO PLL and we have to try different values
> for our internal dividers to find the closest one.
> 
> https://elixir.bootlin.com/linux/latest/source/sound/soc/atmel/mchp-i2s-mcc.c#L416

Sure, makes sense:

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>

Regards,
   Nicolas

-- 
Nicolas Ferre

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
  2021-07-07 13:12 ` Codrin Ciubotariu
@ 2021-08-29  5:28   ` Stephen Boyd
  -1 siblings, 0 replies; 10+ messages in thread
From: Stephen Boyd @ 2021-08-29  5:28 UTC (permalink / raw)
  To: Codrin Ciubotariu, linux-arm-kernel, linux-clk, linux-kernel
  Cc: mturquette, nicolas.ferre, alexandre.belloni, ludovic.desroches,
	claudiu.beznea, Codrin Ciubotariu

Quoting Codrin Ciubotariu (2021-07-07 06:12:13)
> On clk_generated_determine_rate(), the requested rate could be outside
> of clk's range. Limit the rate to the clock's range to not return an
> error.
> 
> Fixes: df70aeef6083 ("clk: at91: add generated clock driver")
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
> ---

Applied to clk-next

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

* Re: [PATCH] clk: at91: clk-generated: Limit the requested rate to our range
@ 2021-08-29  5:28   ` Stephen Boyd
  0 siblings, 0 replies; 10+ messages in thread
From: Stephen Boyd @ 2021-08-29  5:28 UTC (permalink / raw)
  To: Codrin Ciubotariu, linux-arm-kernel, linux-clk, linux-kernel
  Cc: alexandre.belloni, mturquette, ludovic.desroches,
	Codrin Ciubotariu, claudiu.beznea

Quoting Codrin Ciubotariu (2021-07-07 06:12:13)
> On clk_generated_determine_rate(), the requested rate could be outside
> of clk's range. Limit the rate to the clock's range to not return an
> error.
> 
> Fixes: df70aeef6083 ("clk: at91: add generated clock driver")
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
> ---

Applied to clk-next

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-08-29  5:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 13:12 [PATCH] clk: at91: clk-generated: Limit the requested rate to our range Codrin Ciubotariu
2021-07-07 13:12 ` Codrin Ciubotariu
2021-07-09  9:21 ` Nicolas Ferre
2021-07-09  9:21   ` Nicolas Ferre
2021-07-09  9:59   ` Codrin.Ciubotariu
2021-07-09  9:59     ` Codrin.Ciubotariu
2021-07-16 19:17     ` Nicolas Ferre
2021-07-16 19:17       ` Nicolas Ferre
2021-08-29  5:28 ` Stephen Boyd
2021-08-29  5:28   ` 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.