mips: Use 'CFG_MIPS_CLOCK' to compute the MIPS tick timebase
PATCH 1/1 mips: Use 'CFG_MIPS_CLOCK' to compute the MIPS tick timebase
All existing MIPS boards define CFG_HZ to be the number of ticks per second for the timebase. However, CFG_HZ should be a constant 1000 for all boards.
This patch set CFG_HZ to be defined as 1000 for all MIPS boards, and uses the new configuration value 'CFG_MIPS_CLOCK' to calculate the timebase.
Per-board patches to board config files are included.
Signed-off-by Jason McMullan <[email protected]>
--- include/configs/dbau1x00.h | 3 ++- include/configs/gth2.h | 3 ++- include/configs/incaip.h | 3 ++- include/configs/pb1x00.h | 3 ++- include/configs/purple.h | 3 ++- include/configs/qemu-mips.h | 3 ++- include/configs/tb0229.h | 3 ++- lib_mips/time.c | 17 +++++++++++++++-- 8 files changed, 29 insertions(+), 9 deletions(-)
include/configs/dbau1x00.h +2 -1
@@ -148,7 +148,8 @@#error "Invalid CPU frequency - must be multiple of 12!"#endif -#define CFG_HZ (CFG_MHZ * 1000000)/* FIXME causes overflow in net.c */ +#define CFG_MIPS_CLOCK (CFG_MHZ * 1000000) +#define CFG_HZ 1000#define CFG_SDRAM_BASE 0x80000000/* Cached addr */
include/configs/gth2.h +2 -1
@@ -117,8 +117,9 @@#define CFG_BOOTPARAMS_LEN 128*1024#define CFG_MHZ 500 +#define CFG_MIPS_CLOCK (CFG_MHZ * 1000000) -#define CFG_HZ (CFG_MHZ * 1000000)/* FIXME causes overflow in net.c */ +#define CFG_HZ 1000#define CFG_SDRAM_BASE 0x80000000/* Cached addr */
include/configs/incaip.h +2 -1
@@ -118,7 +118,8 @@#define CFG_BOOTPARAMS_LEN 128*1024 -#define CFG_HZ (incaip_get_cpuclk() / 2) +#define CFG_MIPS_CLOCK (incaip_get_cpuclk() / 2) +#define CFG_HZ 1000#define CFG_SDRAM_BASE 0x80000000
include/configs/pb1x00.h +2 -1
@@ -81,7 +81,8 @@#define CFG_BOOTPARAMS_LEN 128*1024 -#define CFG_HZ 396000000/* FIXME causes overflow in net.c */ +#define CFG_MIPS_CLOCK 396000000 +#define CFG_HZ 1000#define CFG_SDRAM_BASE 0x80000000/* Cached addr */
include/configs/purple.h +2 -1
@@ -114,7 +114,8 @@#define CFG_PROMPT "PURPLE # "/* Monitor Command Prompt */ #define CFG_CBSIZE 256/* Console I/O Buffer Size */ #define CFG_PBSIZE (CFG_CBSIZE+sizeof(CFG_PROMPT)+16)/* Print Buffer Size */ -#define CFG_HZ (CPU_CLOCK_RATE/2) +#define CFG_MIPS_CLOCK (CPU_CLOCK_RATE/2) +#define CFG_HZ 1000#define CFG_MAXARGS 16/* max number of command args*/ #define CFG_LOAD_ADDR 0x80500000/* default load address */
include/configs/qemu-mips.h +2 -1
@@ -119,8 +119,9 @@#define CFG_BOOTPARAMS_LEN 128*1024#define CFG_MHZ 132 +#define CFG_MIPS_CLOCK (132 * 1000000) -#define CFG_HZ (CFG_MHZ * 1000000) +#define CFG_HZ 1000#define CFG_SDRAM_BASE 0x80000000/* Cached addr */
include/configs/tb0229.h +2 -1
@@ -122,7 +122,8 @@#define CFG_BOOTPARAMS_LEN 128*1024 -#define CFG_HZ (CPU_TCLOCK_RATE/4) +#define CFG_MIPS_CLOCK (CPU_TCLOCK_RATE/4) +#define CFG_HZ 1000#define CFG_SDRAM_BASE 0x80000000
lib_mips/time.c +15 -2
@@ -23,24 +23,37 @@#include <common.h> +/* CFG_MIPS_CLOCK is the number of ticks per second of the MIPS cpu timer. +* For MIPS processors, this is often the same as the CPU speed in HZ, +* however many embedded processors have a /2 or /4 divider. Please see +* your CPU reference manual for details. +*/ +#ifndef CFG_MIPS_CLOCK +#error CFG_MIPS_CLOCK must be set in the board configuration file +#endif +/* Input is in CFG_HZ ticks */ static inline void mips_compare_set (u32 v) { + v *= (CFG_MIPS_CLOCK /CFG_HZ ); asmvolatile ("mtc0 %0, $11" : :"r" (v)); } +/* Input is in CFG_HZ ticks */ static inline void mips_count_set (u32 v) { + v *= (CFG_MIPS_CLOCK /CFG_HZ ); asmvolatile ("mtc0 %0, $9" : :"r" (v)); } +/* Returns CFG_HZ ticks */ static inline u32 mips_count_get (void ) {u32 count; asmvolatile ("mfc0 %0, $9" :"=r" (count) :); -return count; +return count / (CFG_MIPS_CLOCK /CFG_HZ ); }/*
@@ -75,7 +88,7 @@ void udelay (unsigned long usec)ulong tmo;ulong start =get_timer (0 ); - tmo = usec * (CFG_HZ /1000000 ); + tmo = usec *CFG_HZ /1000 ;while ((ulong)((mips_count_get () - start)) < tmo)/*NOP*/ ; }
Signature · 1 line
1.5.4.3