[U-Boot] [PATCH 2/7] mx25: Clean up clock calculations

Benoît Thébaudeau benoit.thebaudeau at advansee.com
Thu Sep 27 22:27:14 CEST 2012


Avoid possible overflow in clock calculations, and do not waste calls to lldiv()
to divide simple ulongs.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau at advansee.com>
Cc: Stefano Babic <sbabic at denx.de>
---
 .../arch/arm/cpu/arm926ejs/mx25/generic.c          |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git u-boot-imx-e1eb75b.orig/arch/arm/cpu/arm926ejs/mx25/generic.c u-boot-imx-e1eb75b/arch/arm/cpu/arm926ejs/mx25/generic.c
index 2283a89..5503522 100644
--- u-boot-imx-e1eb75b.orig/arch/arm/cpu/arm926ejs/mx25/generic.c
+++ u-boot-imx-e1eb75b/arch/arm/cpu/arm926ejs/mx25/generic.c
@@ -80,12 +80,12 @@ ulong imx_get_armclk(void)
 	ulong div;
 
 	if (cctl & CCM_CCTL_ARM_SRC)
-		fref = lldiv((fref * 3), 4);
+		fref = lldiv((u64) fref * 3, 4);
 
 	div = ((cctl >> CCM_CCTL_ARM_DIV_SHIFT)
 	       & CCM_CCTL_ARM_DIV_MASK) + 1;
 
-	return lldiv(fref, div);
+	return fref / div;
 }
 
 ulong imx_get_ahbclk(void)
@@ -98,7 +98,7 @@ ulong imx_get_ahbclk(void)
 	div = ((cctl >> CCM_CCTL_AHB_DIV_SHIFT)
 	       & CCM_CCTL_AHB_DIV_MASK) + 1;
 
-	return lldiv(fref, div);
+	return fref / div;
 }
 
 ulong imx_get_perclk(int clk)
@@ -110,7 +110,7 @@ ulong imx_get_perclk(int clk)
 	div = readl(&ccm->pcdr[CCM_PERCLK_REG(clk)]);
 	div = ((div >> CCM_PERCLK_SHIFT(clk)) & CCM_PERCLK_MASK) + 1;
 
-	return lldiv(fref, div);
+	return fref / div;
 }
 
 unsigned int mxc_get_clock(enum mxc_clock clk)


More information about the U-Boot mailing list