[U-Boot-Users] [PATCH] 85xx: Round up frequency calculations to get reasonable output
Kumar Gala
galak at kernel.crashing.org
Fri Apr 18 18:57:15 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>
---
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..6972bb1 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 integer_round (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, ", integer_round(sysinfo.freqProcessor,1000000));
+ printf("CCB:%4lu MHz,\n", integer_round(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);
+ integer_round(sysinfo.freqDDRBus,2000000), integer_round(sysinfo.freqDDRBus,1000000));
break;
case 0x7:
printf(" DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ",
- sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000);
+ integer_round(sysinfo.freqDDRBus, 2000000), integer_round(sysinfo.freqDDRBus, 1000000));
break;
default:
printf(" DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ",
- sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000);
+ integer_round(sysinfo.freqDDRBus, 2000000), integer_round(sysinfo.freqDDRBus,1000000));
break;
}
@@ -154,7 +158,7 @@ int checkcpu (void)
clkdiv *= 2;
#endif
printf("LBC:%4lu MHz\n",
- sysinfo.freqSystemBus / 1000000 / clkdiv);
+ integer_round(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