[U-Boot-Users] [PATCH v2] 85xx: Round up frequency calculations to get reasonable output

Kumar Gala galak at kernel.crashing.org
Fri Apr 18 23:28:46 CEST 2008


eg. because of rounding error we can get 799Mhz instead of 800Mhz.

Signed-off-by: Dejan Minic <minic at freescale.com>
Signed-off-by: Srikanth Srinivasan <srikanth.srinivasan at freescale.com>
Signed-off-by: Kumar Gala <galak at kernel.crashing.org>
---

renamed integer_round to rounded_divide per Andy's request.

 cpu/mpc85xx/cpu.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/cpu/mpc85xx/cpu.c b/cpu/mpc85xx/cpu.c
index dcd8817..8efae26 100644
--- a/cpu/mpc85xx/cpu.c
+++ b/cpu/mpc85xx/cpu.c
@@ -65,6 +65,11 @@ struct cpu_type cpu_type_list [] = {
 	CPU_TYPE_ENTRY(8572_E),
 };

+static inline unsigned long rounded_divide (unsigned long val, unsigned long div)
+{
+	return ((val + (div/2)) / div);
+}
+
 int checkcpu (void)
 {
 	sys_info_t sysinfo;
@@ -116,22 +121,21 @@ int checkcpu (void)
 	get_sys_info(&sysinfo);

 	puts("Clock Configuration:\n");
-	printf("       CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
-	printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
-
+	printf("       CPU:%4lu MHz, ", rounded_divide(sysinfo.freqProcessor,1000000));
+	printf("CCB:%4lu MHz,\n", rounded_divide(sysinfo.freqSystemBus,1000000));
 	ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
 	switch (ddr_ratio) {
 	case 0x0:
 		printf("       DDR:%4lu MHz (%lu MT/s data rate), ",
-		sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000);
+		rounded_divide(sysinfo.freqDDRBus,2000000), rounded_divide(sysinfo.freqDDRBus,1000000));
 		break;
 	case 0x7:
 		printf("       DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ",
-		sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000);
+		rounded_divide(sysinfo.freqDDRBus, 2000000), rounded_divide(sysinfo.freqDDRBus, 1000000));
 		break;
 	default:
 		printf("       DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ",
-		sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000);
+		rounded_divide(sysinfo.freqDDRBus, 2000000), rounded_divide(sysinfo.freqDDRBus,1000000));
 		break;
 	}

@@ -154,7 +158,7 @@ int checkcpu (void)
 		 clkdiv *= 2;
 #endif
 		printf("LBC:%4lu MHz\n",
-		       sysinfo.freqSystemBus / 1000000 / clkdiv);
+		       rounded_divide(sysinfo.freqSystemBus, 1000000) / clkdiv);
 	} else {
 		printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
 	}
-- 
1.5.4.1





More information about the U-Boot mailing list