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

eg. because of rounding error we can get 799Mhz instead of 800Mhz.
Introduced DIV_ROUND_UP and roundup taken from linux kernel.
Signed-off-by: Dejan Minic minic@freescale.com Signed-off-by: Srikanth Srinivasan srikanth.srinivasan@freescale.com Signed-off-by: Kumar Gala galak@kernel.crashing.org ---
Lets see if this version works for people. Introduced a generic DIV_ROUND_UP taken from the kernel.
cpu/mpc85xx/cpu.c | 13 ++++++------- include/common.h | 3 +++ 2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/cpu/mpc85xx/cpu.c b/cpu/mpc85xx/cpu.c index dcd8817..74b210c 100644 --- a/cpu/mpc85xx/cpu.c +++ b/cpu/mpc85xx/cpu.c @@ -116,22 +116,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, ", DIV_ROUND_UP(sysinfo.freqProcessor,1000000)); + printf("CCB:%4lu MHz,\n", DIV_ROUND_UP(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); + DIV_ROUND_UP(sysinfo.freqDDRBus,2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000)); break; case 0x7: printf(" DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ", - sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000); + DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus, 1000000)); break; default: printf(" DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ", - sysinfo.freqDDRBus / 2000000, sysinfo.freqDDRBus / 1000000); + DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000)); break; }
@@ -154,7 +153,7 @@ int checkcpu (void) clkdiv *= 2; #endif printf("LBC:%4lu MHz\n", - sysinfo.freqSystemBus / 1000000 / clkdiv); + DIV_ROUND_UP(sysinfo.freqSystemBus, 1000000) / clkdiv); } else { printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr); } diff --git a/include/common.h b/include/common.h index 8630780..348a0cb 100644 --- a/include/common.h +++ b/include/common.h @@ -670,6 +670,9 @@ void inline show_boot_progress (int val);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) + /* Multicore arch functions */ #ifdef CONFIG_MP int cpu_status(int nr);

On Mon, Apr 21, 2008 at 9:28 AM, Kumar Gala galak@kernel.crashing.org wrote:
eg. because of rounding error we can get 799Mhz instead of 800Mhz.
Introduced DIV_ROUND_UP and roundup taken from linux kernel.
Signed-off-by: Dejan Minic minic@freescale.com Signed-off-by: Srikanth Srinivasan srikanth.srinivasan@freescale.com Signed-off-by: Kumar Gala galak@kernel.crashing.org
Shouldn't this be two patches? One to add the macros, and then one to use them. Technically, I'd be overstepping my authority to apply the first patch. Though I'd be happy to apply it if Wolfgang ACKs it.
Andy

On Apr 21, 2008, at 12:17 PM, Andy Fleming wrote:
On Mon, Apr 21, 2008 at 9:28 AM, Kumar Gala galak@kernel.crashing.org wrote:
eg. because of rounding error we can get 799Mhz instead of 800Mhz.
Introduced DIV_ROUND_UP and roundup taken from linux kernel.
Signed-off-by: Dejan Minic minic@freescale.com Signed-off-by: Srikanth Srinivasan srikanth.srinivasan@freescale.com Signed-off-by: Kumar Gala galak@kernel.crashing.org
Shouldn't this be two patches? One to add the macros, and then one to use them. Technically, I'd be overstepping my authority to apply the first patch. Though I'd be happy to apply it if Wolfgang ACKs it.
I think its a bit silly to separate this into two patches. If you aren't comfortably applying it just ack the 85xx bits and ask Wolfgang to apply it.
- k

On Mon, Apr 21, 2008 at 9:28 AM, Kumar Gala galak@kernel.crashing.org wrote:
eg. because of rounding error we can get 799Mhz instead of 800Mhz.
Introduced DIV_ROUND_UP and roundup taken from linux kernel.
Signed-off-by: Dejan Minic minic@freescale.com Signed-off-by: Srikanth Srinivasan srikanth.srinivasan@freescale.com Signed-off-by: Kumar Gala galak@kernel.crashing.org
Acked-by: Andy Fleming afleming@freescale.com
Andy

On Apr 21, 2008, at 12:45 PM, Andy Fleming wrote:
On Mon, Apr 21, 2008 at 9:28 AM, Kumar Gala galak@kernel.crashing.org wrote:
eg. because of rounding error we can get 799Mhz instead of 800Mhz.
Introduced DIV_ROUND_UP and roundup taken from linux kernel.
Signed-off-by: Dejan Minic minic@freescale.com Signed-off-by: Srikanth Srinivasan srikanth.srinivasan@freescale.com Signed-off-by: Kumar Gala galak@kernel.crashing.org
Acked-by: Andy Fleming afleming@freescale.com
Andy
Wolfgang,
reminder to apply this if its ok.
- k

In message F107A121-2060-4FF7-8BF9-597180D1FD1F@kernel.crashing.org you wrote:
On Apr 21, 2008, at 12:45 PM, Andy Fleming wrote:
On Mon, Apr 21, 2008 at 9:28 AM, Kumar Gala galak@kernel.crashing.org wrote:
eg. because of rounding error we can get 799Mhz instead of 800Mhz.
Introduced DIV_ROUND_UP and roundup taken from linux kernel.
Signed-off-by: Dejan Minic minic@freescale.com Signed-off-by: Srikanth Srinivasan srikanth.srinivasan@freescale.com Signed-off-by: Kumar Gala galak@kernel.crashing.org
Acked-by: Andy Fleming afleming@freescale.com
Andy
Wolfgang,
reminder to apply this if its ok.
Will do as fast as I can.
Best regards,
Wolfgang Denk
participants (3)
-
Andy Fleming
-
Kumar Gala
-
Wolfgang Denk