]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
at91sam9/at91cap: fix CONFIG_SYS_HZ to 1000
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Thu, 16 Apr 2009 19:30:48 +0000 (21:30 +0200)
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Thu, 16 Apr 2009 19:30:48 +0000 (21:30 +0200)
The timer has been rewrote with a precision at ~0,18%

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Tested-by: Sergey Lapin <slapin@ossfans.org>
Tested-by: Eric BENARD <ebenard@free.fr>
cpu/arm926ejs/at91/timer.c
include/configs/afeb9260.h
include/configs/at91cap9adk.h
include/configs/at91sam9260ek.h
include/configs/at91sam9261ek.h
include/configs/at91sam9263ek.h
include/configs/at91sam9rlek.h
include/configs/pm9263.h

index fec545b6652737a88d89cc96b81fe24989982ef6..c84cb5e96f73ebb03054551388c3752efdad7bb2 100644 (file)
@@ -27,7 +27,9 @@
 #include <asm/arch/at91_pit.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_rstc.h>
+#include <asm/arch/clk.h>
 #include <asm/arch/io.h>
+#include <div64.h>
 
 /*
  * We're using the AT91CAP9/SAM9 PITC in 32 bit mode, by
 #define TIMER_LOAD_VAL 0xfffff
 #define READ_RESET_TIMER at91_sys_read(AT91_PIT_PIVR)
 #define READ_TIMER at91_sys_read(AT91_PIT_PIIR)
-#define TIMER_FREQ (AT91C_MASTER_CLOCK << 4)
-#define TICKS_TO_USEC(ticks) ((ticks) / 6)
 
-ulong get_timer_masked(void);
-ulong resettime;
+static ulong timestamp;
+static ulong lastinc;
+static ulong timer_freq;
+
+static inline unsigned long long tick_to_time(unsigned long long tick)
+{
+       tick *= CONFIG_SYS_HZ;
+       do_div(tick, timer_freq);
+
+       return tick;
+}
+
+static inline unsigned long long usec_to_tick(unsigned long long usec)
+{
+       usec *= timer_freq;
+       do_div(usec, 1000000);
+
+       return usec;
+}
 
 /* nothing really to do with interrupts, just starts up a counter. */
 int timer_init(void)
@@ -56,41 +73,49 @@ int timer_init(void)
 
        reset_timer_masked();
 
+       timer_freq = get_mck_clk_rate() >> 4;
+
        return 0;
 }
 
 /*
  * timer without interrupts
  */
-
-static inline ulong get_timer_raw(void)
+unsigned long long get_ticks(void)
 {
        ulong now = READ_TIMER;
 
-       if (now >= resettime)
-               return now - resettime;
-       else
-               return 0xFFFFFFFFUL - (resettime - now) ;
+       if (now >= lastinc)     /* normal mode (non roll) */
+               /* move stamp forward with absolut diff ticks */
+               timestamp += (now - lastinc);
+       else                    /* we have rollover of incrementer */
+               timestamp += (0xFFFFFFFF - lastinc) + now;
+       lastinc = now;
+       return timestamp;
 }
 
 void reset_timer_masked(void)
 {
-       resettime = READ_TIMER;
+       /* reset time */
+       lastinc = READ_TIMER; /* capture current incrementer value time */
+       timestamp = 0; /* start "advancing" time stamp from 0 */
 }
 
 ulong get_timer_masked(void)
 {
-       return TICKS_TO_USEC(get_timer_raw());
-
+       return tick_to_time(get_ticks());
 }
 
-void udelay_masked(unsigned long usec)
+void udelay(unsigned long usec)
 {
-       ulong tmp;
+       unsigned long long tmp;
+       ulong tmo;
 
-       tmp = get_timer(0);
-       while (get_timer(tmp) < usec)   /* our timer works in usecs */
-               ; /* NOP */
+       tmo = usec_to_tick(usec);
+       tmp = get_ticks() + tmo;        /* get current timestamp */
+
+       while (get_ticks() < tmp)       /* loop till event */
+                /*NOP*/;
 }
 
 void reset_timer(void)
@@ -100,26 +125,7 @@ void reset_timer(void)
 
 ulong get_timer(ulong base)
 {
-       ulong now = get_timer_masked();
-
-       if (now >= base)
-               return now - base;
-       else
-               return TICKS_TO_USEC(0xFFFFFFFFUL) - (base - now) ;
-}
-
-void udelay(unsigned long usec)
-{
-       udelay_masked(usec);
-}
-
-/*
- * This function is derived from PowerPC code (read timebase as long long).
- * On ARM it just returns the timer value.
- */
-unsigned long long get_ticks(void)
-{
-       return get_timer(0);
+       return get_timer_masked () - base;
 }
 
 /*
index d637a9455b8c8e4a401206bcbefbf0f238b8094d..c5134a2140cc0faa7e6c66b77e1933c0a149d87c 100644 (file)
@@ -28,7 +28,7 @@
 
 /* ARM asynchronous clock */
 #define AT91_MAIN_CLOCK                18429952        /* from 18.432 MHz crystal */
-#define CONFIG_SYS_HZ          1000000         /* 1us resolution */
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_AT91SAM9260     1       /* It's an Atmel AT91SAM9260 SoC*/
 #define CONFIG_AFEB9260                1       /* on an AFEB9260 Board */
index c61af08be2688b3444179e2ac0d293bc75162f30..b2e6d7d02c9fa78ea45ebf08913dfd465b6c2cac 100644 (file)
@@ -30,7 +30,7 @@
 /* ARM asynchronous clock */
 #define AT91_CPU_NAME          "AT91CAP9"
 #define AT91_MAIN_CLOCK                12000000        /* 12 MHz crystal */
-#define CONFIG_SYS_HZ          1000000         /* 1us resolution */
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_ARM926EJS       1       /* This is an ARM926EJS Core    */
 #define CONFIG_AT91CAP9                1       /* It's an Atmel AT91CAP9 SoC   */
index b6e2edf3135dc5ed872482d41ee4d3dc06ecbca1..e46c9d6ae6509b320616a51b0686d17d1cfc88f8 100644 (file)
@@ -29,7 +29,7 @@
 
 /* ARM asynchronous clock */
 #define AT91_MAIN_CLOCK                18432000        /* 18.432 MHz crystal */
-#define CONFIG_SYS_HZ          1000000         /* 1us resolution */
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_ARM926EJS       1       /* This is an ARM926EJS Core    */
 
index 7ec171cfbb3327becc00054041e02bc4f6631542..fdaa71cfcc354da25b1a72b00a077e4ac37d2ad4 100644 (file)
@@ -30,7 +30,7 @@
 /* ARM asynchronous clock */
 #define AT91_CPU_NAME          "AT91SAM9261"
 #define AT91_MAIN_CLOCK                18432000        /* 18.432 MHz crystal */
-#define CONFIG_SYS_HZ          1000000         /* 1us resolution */
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_ARM926EJS       1       /* This is an ARM926EJS Core    */
 #define CONFIG_AT91SAM9261     1       /* It's an Atmel AT91SAM9261 SoC*/
index 34c7521f3fd70dc5623cfcf077f744ae92d22ef4..d03ecee3f61c265f6468103473d70bc627abbf4e 100644 (file)
@@ -30,7 +30,7 @@
 /* ARM asynchronous clock */
 #define AT91_CPU_NAME          "AT91SAM9263"
 #define AT91_MAIN_CLOCK                16367660        /* 16.367 MHz crystal */
-#define CONFIG_SYS_HZ          1000000         /* 1us resolution */
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_ARM926EJS       1       /* This is an ARM926EJS Core    */
 #define CONFIG_AT91SAM9263     1       /* It's an Atmel AT91SAM9263 SoC*/
index 2ccf9587a6987039d1d3f03c632ee021a2d79d01..846d1658e07f76af460c6be3cbc2e5c897217aae 100644 (file)
@@ -30,7 +30,7 @@
 /* ARM asynchronous clock */
 #define AT91_CPU_NAME          "AT91SAM9RL"
 #define AT91_MAIN_CLOCK                12000000        /* 12 MHz crystal */
-#define CONFIG_SYS_HZ          1000000         /* 1us resolution */
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_ARM926EJS       1       /* This is an ARM926EJS Core    */
 #define CONFIG_AT91SAM9RL      1       /* It's an Atmel AT91SAM9RL SoC*/
index 9ae737f40111820e12d75596abb88d52d33ced0b..0db17b3545a316222f32aed6fff7ecb78c27008e 100644 (file)
@@ -38,7 +38,7 @@
 #define MAIN_PLL_DIV           2       /* 2 or 4 */
 #define AT91_MAIN_CLOCK        18432000
 
-#define CONFIG_SYS_HZ          1000000
+#define CONFIG_SYS_HZ          1000
 
 #define CONFIG_ARM926EJS       1       /* This is an ARM926EJS Core    */
 #define CONFIG_AT91SAM9263     1       /* It's an Atmel AT91SAM9263 SoC*/