cmd: clk: Don't truncate "clk dump" clock rates to u32
PATCH 1/1 cmd: clk: Don't truncate "clk dump" clock rates to u32
show_clks() prints information about the clock tree such as the rates of various clocks. While doing this it gets the rate via clk_get_rate() and stores it in an unsigned 32 bit integer variable. This limits the clock rate to 4294967295 (or around 4.2GHz). If a clock rate exceeds this then "clk dump" will print a rate which has wrapped around the unsigned 32 bit integer.
This was observed in the clock tree of an SoC ADI is currently bringing up (the ADSP-SC846):
=> clk dump ... cgu1_vco 505032704 cgu1_pllclk 2400000000 cclk2_1 1600000000 dclk1_1 960000000 ...
In the above the VCO clock should have a rate of 4.8GHz via:
VCO = SYS_CLKIN * MSEL * 2 = 25MHz * 96 * 2 = 4,800,000,000 Hz. However, 4,800,000,000 truncated to 32 bits is 505032704, which is the value reported above.
To fix this issue change the type of "rate" to ulong to match the return value of clk_get_rate() also change the format specifier to %lu to accommodate the type change.
--- cmd/clk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/clk.c +2 -2
@@ -15,7 +15,7 @@ static void show_clks(struct udevice *dev, int depth, int last_flag)int i, is_last;struct udevice *child;struct clk *clkp, *parent; -u32 rate; +ulong rate; clkp =dev_get_clk_ptr (dev);if (clkp) {
@@ -25,7 +25,7 @@ static void show_clks(struct udevice *dev, int depth, int last_flag) depth++; rate =clk_get_rate (clkp); -printf (" %-12u %8d " , rate, clkp->enable_count); +printf (" %-12lu %8d " , rate, clkp->enable_count);for (i = depth; i >=0 ; i--) { is_last = (last_flag >> i) &1 ;
Signature · 1 line
2.43.0
Quoted 23 lines · Qasim Ijaz
show_clks()prints information about the clock tree such as the rates of various clocks. While doing this it gets the rate viaclk_get_rate()and stores it in an unsigned 32 bit integer variable. This limits the clock rate to 4294967295 (or around 4.2GHz). If a clock rate exceeds this then "clk dump" will print a rate which has wrapped around the unsigned 32 bit integer.This was observed in the clock tree of an SoC ADI is currently bringing up (the ADSP-SC846):
=> clk dump ... cgu1_vco 505032704 cgu1_pllclk 2400000000 cclk2_1 1600000000 dclk1_1 960000000 ...In the above the VCO clock should have a rate of 4.8GHz via:
VCO =SYS_CLKIN* MSEL * 2 = 25MHz * 96 * 2 = 4,800,000,000 Hz. However, 4,800,000,000 truncated to 32 bits is 505032704, which is the value reported above.
Quoted 7 lines
To fix this issue change the type of "rate" to ulong to match the return value of
clk_get_rate()also change the format specifier to %lu to accommodate the type change.Fixes aeeb2e6d9c67 ("clk: support clk tree dump")Signed-off-by Qasim Ijaz <[email protected]>---
Quoted 27 lines
cmd/clk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/clk.c +2
-2@@ -15,7 +15,7 @@ static void show_clks(struct udevice *dev, int depth, int last_flag)int i, is_last;struct udevice *child;struct clk *clkp, *parent; -u32 rate; +ulong rate; clkp =dev_get_clk_ptr (dev);if (clkp) {@@ -25,7 +25,7 @@ static void show_clks(struct udevice *dev, int depth, int last_flag) depth++; rate =clk_get_rate (clkp); -printf (" %-12u %8d " , rate, clkp->enable_count); +printf (" %-12lu %8d " , rate, clkp->enable_count);for (i = depth; i >=0 ; i--) { is_last = (last_flag >> i) &1 ;Signature · 1 line
2.43.0
Quoted 8 lines · Qasim Ijaz
show_clks()prints information about the clock tree such as the rates of various clocks. While doing this it gets the rate viaclk_get_rate()and stores it in an unsigned 32 bit integer variable. This limits the clock rate to 4294967295 (or around 4.2GHz). If a clock rate exceeds this then "clk dump" will print a rate which has wrapped around the unsigned 32 bit integer.[...]
Applied to u-boot/main, thanks!
[1/1] cmd: clk: Don't truncate "clk dump" clock rates to u32
commit: d452a0d4c19bc19fa476128c412cd24fe4bf41ba
Signature · 1 line
Tom