ARM iMX28: incorrect frac/div calculation
Subsystems (3)
PATCH 1/1 ARM iMX28: incorrect frac/div calculation
The frac and div values in _CLK_SET_RATE are calculated incorrectly for some clock rates ie. CPU clk of 454.73MHz, 392.72MHz, 261.81Mhz, etc.
Now the frac and div values which result in the closest actual clock rate to that requested is selected. Also there are no limitations on what frac values can be used, as long as they fall in the valid (18 < frac < 35) range.
Tested on custom iMX28 board.
--- arch/arm/mach-mxs/clock-mx28.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +2 -6
@@ -354,19 +354,15 @@ static int name##_set_rate(struct clk *clk, unsigned long rate) \ } \for (d =1 ; d <= div_max; d++) { \ f = parent_rate *18 / d / rate; \ -if ((parent_rate *18 / d) % rate) \ - f++; \if (f <18 || f >35 ) \continue ; \ \ calc_rate = parent_rate *18 / f / d; \ -if (calc_rate > rate) \ -continue ; \ \ -if (rate - calc_rate < diff) { \ +if (abs (rate - calc_rate) < diff) { \ frac = f; \ div = d; \ - diff = rate - calc_rate; \ + diff =abs (rate - calc_rate); \ } \ \if (diff ==0 ) \
Signature · 1 line
1.7.5.4
PATCH 1/1 ARM iMX28: incorrect frac/div calculation
Quoted 6 lines · Matt Burtch
The frac and div values in
_CLK_SET_RATEare calculated incorrectly for some clock rates ie. CPU clk of 454.73MHz, 392.72MHz, 261.81Mhz, etc.Now the frac and div values which result in the closest actual clock rate to that requested is selected.
My understanding on clk_set_rate is we need to set the clk to a rate closest to the requested one but never exceeding it. Does your change ensure that?
Regards,
Shawn
Quoted 40 lines
Also there are no limitations
on what frac values can be used, as long as they fall in the valid (18 < frac < 35) range.Tested on custom iMX28 board.
Signed-off-by Matt Burtch <[email protected]>--- arch/arm/mach-mxs/clock-mx28.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)arch/arm/mach-mxs/clock-mx28.c +2
-6@@ -354,19 +354,15 @@ static int name##_set_rate(struct clk *clk, unsigned long rate) \ } \for (d =1 ; d <= div_max; d++) { \ f = parent_rate *18 / d / rate; \ -if ((parent_rate *18 / d) % rate) \ - f++; \if (f <18 || f >35 ) \continue ; \ \ calc_rate = parent_rate *18 / f / d; \ -if (calc_rate > rate) \ -continue ; \ \ -if (rate - calc_rate < diff) { \ +if (abs (rate - calc_rate) < diff) { \ frac = f; \ div = d; \ - diff = rate - calc_rate; \ + diff =abs (rate - calc_rate); \ } \ \if (diff ==0 ) \Signature · 1 line
1.7.5.4
PATCH 1/1 ARM iMX28: incorrect frac/div calculation
In reply to Matt BurtchHi,
Quoted 25 lines · Matt Burtch
The frac and div values in
_CLK_SET_RATEare calculated incorrectly for some clock rates ie. CPU clk of 454.73MHz, 392.72MHz, 261.81Mhz, etc.Now the frac and div values which result in the closest actual clock rate to that requested is selected. Also there are no limitations on what frac values can be used, as long as they fall in the valid (18 < frac < 35) range.
Tested on custom iMX28 board.
Signed-off-by Matt Burtch <[email protected]>--- arch/arm/mach-mxs/clock-mx28.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)arch/arm/mach-mxs/clock-mx28.c +0
-1@@ -354,19 +354,15 @@ static int name##_set_rate(struct clk *clk, unsigned long rate) \ } \for (d =1 ; d <= div_max; d++) { \ f = parent_rate *18 / d / rate; \ -if ((parent_rate *18 / d) % rate) \
arch/arm/mach-mxs/clock-mx28.c static int name##_set_rate(struct clk *clk, unsigned long rate) \ · line 362
Quoted 10 lines
arch/arm/mach-mxs/clock-mx28.c +1
-4- f++; \if (f <18 || f >35 ) \continue ; \ \ calc_rate = parent_rate *18 / f / d; \ -if (calc_rate > rate) \ -continue ; \ \ -if (rate - calc_rate < diff) { \ +if (abs (rate - calc_rate) < diff) { \
Shouldn't this actually be '<=' (also in the original code)?
Lothar Wa?mann
Signature · 9 lines
___________________________________________________________ Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10 Gesch?ftsf?hrer: Matthias Kaussen Handelsregistereintrag: Amtsgericht Aachen, HRB 4996 www.karo-electronics.de | [email protected] ___________________________________________________________
PATCH 1/1 ARM iMX28: incorrect frac/div calculation
In reply to Shawn GuoQuoted 5 lines · Shawn Guo
Quoted 4 lines · Matt Burtch
The frac and div values in
_CLK_SET_RATEare calculated incorrectly for some clock rates ie. CPU clk of 454.73MHz, 392.72MHz, 261.81Mhz, etc.
Quoted 8 lines
Quoted 2 lines
Now the frac and div values which result in the closest actual clock rate to that requested is selected.
My understanding on
clk_set_rateis we need to set the clk to a rate closest to the requested one but never exceeding it. Does your change ensure that?Regards,
Shawn
It currently doesn't check that the resultant clock is lower than the requested. I can certainly make that change and resubmit. I wasn't aware of this requirement.
So with the patch as it stands, if you request a CPU clock of 391Mhz, it'll give you 392.71MHz. Would it be correct for the clock to be set at 375.65MHz (the next closest valid clock rate without going over)?
Thanks,
Matt
Quoted 40 lines
Quoted 40 lines
Also there are no limitations
on what frac values can be used, as long as they fall in the valid (18< frac< 35) range.Tested on custom iMX28 board.
Signed-off-by Matt Burtch<[email protected]>--- arch/arm/mach-mxs/clock-mx28.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)arch/arm/mach-mxs/clock-mx28.c +2
-6@@ -354,19 +354,15 @@ static int name##_set_rate(struct clk *clk, unsigned long rate) \ } \for (d =1 ; d<= div_max; d++) { \ f = parent_rate *18 / d / rate; \ -if ((parent_rate *18 / d) % rate) \ - f++; \if (f<18 || f>35 ) \continue ; \ \ calc_rate = parent_rate *18 / f / d; \ -if (calc_rate> rate) \ -continue ; \ \ -if (rate - calc_rate< diff) { \ +if (abs (rate - calc_rate)< diff) { \ frac = f; \ div = d; \ - diff = rate - calc_rate; \ + diff =abs (rate - calc_rate); \ } \ \if (diff ==0 ) \Signature · 1 line
1.7.5.4
PATCH 1/1 ARM iMX28: incorrect frac/div calculation
In reply to Lothar WaßmannQuoted 31 lines · Lothar Wa?mann
Hi,
Quoted 28 lines · Matt Burtch
The frac and div values in
_CLK_SET_RATEare calculated incorrectly for some clock rates ie. CPU clk of 454.73MHz, 392.72MHz, 261.81Mhz, etc.Now the frac and div values which result in the closest actual clock rate to that requested is selected. Also there are no limitations on what frac values can be used, as long as they fall in the valid (18< frac< 35) range.
Tested on custom iMX28 board.
Signed-off-by Matt Burtch<[email protected]>--- arch/arm/mach-mxs/clock-mx28.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)arch/arm/mach-mxs/clock-mx28.c +0
-2@@ -354,19 +354,15 @@ static int name##_set_rate(struct clk *clk, unsigned long rate) \ } \for (d =1 ; d<= div_max; d++) { \ f = parent_rate *18 / d / rate; \ -if ((parent_rate *18 / d) % rate) \ - f++; \if (f<18 || f>35 ) \continue ; \
Quoted 8 lines
arch/arm/mach-mxs/clock-mx28.c static int name##_set_rate(struct clk *clk, unsigned long rate) \
Quoted 7 lines
arch/arm/mach-mxs/clock-mx28.c +1
-3\ calc_rate = parent_rate *18 / f / d; \ -if (calc_rate> rate) \ -continue ; \ \ -if (rate - calc_rate< diff) { \ +if (abs (rate - calc_rate)< diff) { \Shouldn't this actually be '<=' (also in the original code)?
Hi Lothar,
It shouldn't make a difference. If it was '<=' it would result in a different frac and higher div value but the difference between the requested rate and actual would be the same.
Thanks,
Matt Burtch
Quoted 1 line
Lothar Wa?mann