clk: at91: clk-generated: Limit the requested rate to our range
Subsystems (2)
PATCH 1/1 clk: at91: clk-generated: Limit the requested rate to our range
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.
--- drivers/clk/at91/clk-generated.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/clk/at91/clk-generated.c +6 -0
@@ -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 ;
Signature · 1 line
2.30.2
Nicolas Ferre
maintainerQuoted 3 lines · 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.
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
Quoted 24 lines
Fixes df70aeef6083 ("clk: at91: add generated clock driver")Signed-off-by Codrin Ciubotariu <[email protected]>--- drivers/clk/at91/clk-generated.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/clk/at91/clk-generated.c +6
-0@@ -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 ;
Signature · 1 line
Nicolas Ferre
Quoted 9 lines · Nicolas Ferre
Quoted 3 lines · 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.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
Quoted 18 lines · On 09/07/2021 at 11:59, Codrin Ciubotariu - M19940 wrote:
Quoted 9 lines · Nicolas Ferre
Quoted 3 lines · 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.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 whatdetermine_rate()should accomplish. The user has no clk API to get clock's range, so there is no way to callclk_round_rate()only for values within our range.
Quoted 6 lines
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:
Regards,
Nicolas
Signature · 1 line
Nicolas Ferre
Quoting Codrin Ciubotariu (2021-07-07 06:12:13)
Quoted 7 lines
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 <[email protected]>---
Applied to clk-next