mips: Support to set CFG_HZ to 1000, consistent with other architectures
PATCH 1/1 mips: Support to set CFG_HZ to 1000, consistent with other architectures
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.
The MIPS time code now has a software maintained 64-bit counter, however get_timer() must be called every few seconds for this counter to be fully reliable.
Per-board patches to board config files are included.
--- 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 | 38 ++++++++++++++++++++++++++++++++++++-- 8 files changed, 50 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 +36 -2
@@ -23,23 +23,57 @@#include <common.h> +/* CFG_MIPS_CLOCK is the number of ticks per second of the MIPS C0 Clock timer. +* +* For most implementations, this is the same as the CPU speed in HZ +* divided by 2. Some embedded MIPS implementations may use a /4 +* or /1 divider, so see your CPU reference manual for specific details. +*/ +#ifndef CFG_MIPS_CLOCK +#error CFG_MIPS_CLOCK must be set in the board configuration file +#endif -static inline void mips_compare_set (u32 v) +static struct { +uint32_t lo; +uint32_t hi; +} mips_ticks;/* Last number of ticks seen */ + +/* Input is in CFG_HZ ticks */ +static inline void mips_compare_set (uint64_t 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 ); + mips_ticks.lo = v; + mips_ticks.hi =0 ; asmvolatile ("mtc0 %0, $9" : :"r" (v)); } +/* Returns CFG_HZ ticks +* +* NOTE: This must be called at least once every +* few seconds to be reliable. +*/ static inline u32 mips_count_get (void ) {u32 count; asmvolatile ("mfc0 %0, $9" :"=r" (count) :); + +/* Handle 32-bit timer overflow */ +if (count < mips_ticks.lo) { + mips_ticks.hi++; + } + mips_ticks.lo = count; + count =(mips_ticks.lo / (CFG_MIPS_CLOCK /CFG_HZ )) + + (mips_ticks.hi * (0x100000000ULL / (CFG_MIPS_CLOCK /CFG_HZ ))); +return count; }
@@ -75,7 +109,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
McMullan
PATCH 1/1 mips: Support to set CFG_HZ to 1000, consistent with other architectures
Quoted 2 lines · Jason McMullan
All existing MIPS boards define
CFG_HZto be the number of ticks per second for the timebase. However,CFG_HZshould be a constant 1000 for all boards.
ARGH!
Resending patch, as I left some code from a uint64_t attempt.
Please review the [resend] version.
(I'll get this right one of thse days)
Jason McMullan
MTS SW
System Firmware
NetApp
724.741.5011 Fax 724.741.5166 Direct 412.656.3519 Mobile
jason.mcmullan at netapp.com
www.netapp.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.denx.de/pipermail/u-boot/attachments/20080520/295e870a/attachment.pgp