[PATCH] clk: k210: Fix error calculation on 32bit

Michal Suchánek msuchanek at suse.de
Sun Oct 16 09:51:42 CEST 2022


On Thu, Oct 13, 2022 at 10:34:29PM +0200, Michal Suchanek wrote:
> k210 is 64bit but the driver and tests are also built in sandbox, and
> that can be built 32bit.
> 
> BIT(32) does not work on 32bit, shift before subtraction to fit into
> 32bit integer with BIT values.


Also see
https://patchwork.ozlabs.org/project/uboot/patch/20221016071035.461454-1-heinrich.schuchardt@canonical.com/
> 
> Signed-off-by: Michal Suchanek <msuchanek at suse.de>
> ---
> 
>  drivers/clk/clk_k210.c | 2 +-
>  test/dm/k210_pll.c     | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c
> index 1961efaa5e..e85f8ae14a 100644
> --- a/drivers/clk/clk_k210.c
> +++ b/drivers/clk/clk_k210.c
> @@ -846,7 +846,7 @@ again:
>  
>  		error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od);
>  		/* The lower 16 bits are spurious */
> -		error = abs((error - BIT(32))) >> 16;
> +		error = abs((error >> 16) - BIT(32 - 16));
>  
>  		if (error < best_error) {
>  			best->r = r;
> diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c
> index a0cc84c396..622b1c9bef 100644
> --- a/test/dm/k210_pll.c
> +++ b/test/dm/k210_pll.c
> @@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in,
>  				error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio,
>  							      r * od);
>  				/* The lower 16 bits are spurious */
> -				error = abs((error - BIT(32))) >> 16;
> +				error = abs((error >> 16) - BIT(32 - 16));
>  				if (error < best_error) {
>  					best->r = r;
>  					best->f = f;
> -- 
> 2.37.3
> 


More information about the U-Boot mailing list