]> git.sur5r.net Git - u-boot/blobdiff - cpu/arm925t/interrupts.c
Fix e-mail address of Gary Jennejohn.
[u-boot] / cpu / arm925t / interrupts.c
index 3ef455447cf81138cc772f3f6e0ad0fb47fd8bd5..179992debedbd2b1d00f9de83724fbeadfefb7af 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * (C) Copyright 2009
+ * 2N Telekomunikace, <www.2n.cz>
+ *
  * (C) Copyright 2003
  * Texas Instruments, <www.ti.com>
  *
@@ -11,7 +14,7 @@
  * Alex Zuepke <azu@sysgo.de>
  *
  * (C) Copyright 2002
- * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
+ * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
 #include <common.h>
 #include <arm925t.h>
 #include <configs/omap1510.h>
+#include <asm/io.h>
 
-#define TIMER_LOAD_VAL 0xffffffff
-
-/* macro to read the 32 bit timer */
-#define READ_TIMER (*(volatile ulong *)(CONFIG_SYS_TIMERBASE+8))
+#define TIMER_LOAD_VAL 0xffffffff
+#define TIMER_CLOCK    (CONFIG_SYS_CLK_FREQ / (2 << CONFIG_SYS_PTV))
 
-static ulong timestamp;
-static ulong lastdec;
+static uint32_t timestamp;
+static uint32_t lastdec;
 
 /* nothing really to do with interrupts, just starts up a counter. */
 int interrupt_init (void)
 {
-       int32_t val;
-
        /* Start the decrementer ticking down from 0xffffffff */
-       *((int32_t *) (CONFIG_SYS_TIMERBASE + LOAD_TIM)) = TIMER_LOAD_VAL;
-       val = MPUTIM_ST | MPUTIM_AR | MPUTIM_CLOCK_ENABLE | (CONFIG_SYS_PVT << MPUTIM_PTV_BIT);
-       *((int32_t *) (CONFIG_SYS_TIMERBASE + CNTL_TIMER)) = val;
+       __raw_writel(TIMER_LOAD_VAL, CONFIG_SYS_TIMERBASE + LOAD_TIM);
+       __raw_writel(MPUTIM_ST | MPUTIM_AR | MPUTIM_CLOCK_ENABLE |
+               (CONFIG_SYS_PTV << MPUTIM_PTV_BIT),
+               CONFIG_SYS_TIMERBASE + CNTL_TIMER);
 
        /* init the timestamp and lastdec value */
        reset_timer_masked();
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -82,85 +83,41 @@ void set_timer (ulong t)
 /* delay x useconds AND preserve advance timestamp value */
 void udelay (unsigned long usec)
 {
-       ulong tmo, tmp;
-
-       if(usec >= 1000){               /* if "big" number, spread normalization to seconds */
-               tmo = usec / 1000;      /* start to normalize for usec to ticks per sec */
-               tmo *= CONFIG_SYS_HZ;           /* find number of "ticks" to wait to achieve target */
-               tmo /= 1000;            /* finish normalize. */
-       }else{                          /* else small number, don't kill it prior to HZ multiply */
-               tmo = usec * CONFIG_SYS_HZ;
-               tmo /= (1000*1000);
+       int32_t tmo = usec * (TIMER_CLOCK / 1000) / 1000;
+       uint32_t now, last = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
+
+       while (tmo > 0) {
+               now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
+               if (last < now) /* count down timer underflow */
+                       tmo -= TIMER_LOAD_VAL - now + last;
+               else
+                       tmo -= last - now;
+               last = now;
        }
-
-       tmp = get_timer (0);            /* get current timestamp */
-       if( (tmo + tmp + 1) < tmp )     /* if setting this fordward will roll time stamp */
-               reset_timer_masked ();  /* reset "advancing" timestamp to 0, set lastdec value */
-       else
-               tmo += tmp;             /* else, set advancing stamp wake up time */
-
-       while (get_timer_masked () < tmo) /* loop till event */
-               /*NOP*/;
 }
 
 void reset_timer_masked (void)
 {
        /* reset time */
-       lastdec = READ_TIMER;  /* capure current decrementer value time */
+       lastdec = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
+                       (TIMER_CLOCK / CONFIG_SYS_HZ);
        timestamp = 0;         /* start "advancing" time stamp from 0 */
 }
 
 ulong get_timer_masked (void)
 {
-       ulong now = READ_TIMER;         /* current tick value */
-
-       if (lastdec >= now) {           /* normal mode (non roll) */
-               /* normal mode */
-               timestamp += lastdec - now; /* move stamp fordward with absoulte diff ticks */
-       } else {                        /* we have overflow of the count down timer */
-               /* nts = ts + ld + (TLV - now)
-                * ts=old stamp, ld=time that passed before passing through -1
-                * (TLV-now) amount of time after passing though -1
-                * nts = new "advancing time stamp"...it could also roll and cause problems.
-                */
-               timestamp += lastdec + TIMER_LOAD_VAL - now;
-       }
+       uint32_t now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
+                       (TIMER_CLOCK / CONFIG_SYS_HZ);
+       if (lastdec < now)      /* count down timer underflow */
+               timestamp += TIMER_LOAD_VAL / (TIMER_CLOCK / CONFIG_SYS_HZ) -
+                               now + lastdec;
+       else
+               timestamp += lastdec - now;
        lastdec = now;
 
        return timestamp;
 }
 
-/* waits specified delay value and resets timestamp */
-void udelay_masked (unsigned long usec)
-{
-#ifdef CONFIG_INNOVATOROMAP1510
-       #define LOOPS_PER_MSEC 60 /* tuned on omap1510 */
-       volatile int i, time_remaining = LOOPS_PER_MSEC*usec;
-    for (i=time_remaining; i>0; i--) { }
-#else
-
-       ulong tmo;
-       ulong endtime;
-       signed long diff;
-
-       if (usec >= 1000) {             /* if "big" number, spread normalization to seconds */
-               tmo = usec / 1000;      /* start to normalize for usec to ticks per sec */
-               tmo *= CONFIG_SYS_HZ;           /* find number of "ticks" to wait to achieve target */
-               tmo /= 1000;            /* finish normalize. */
-       } else {                        /* else small number, don't kill it prior to HZ multiply */
-               tmo = usec * CONFIG_SYS_HZ;
-               tmo /= (1000*1000);
-       }
-
-       endtime = get_timer_masked () + tmo;
-
-       do {
-               ulong now = get_timer_masked ();
-               diff = endtime - now;
-       } while (diff >= 0);
-#endif
-}
-
 /*
  * This function is derived from PowerPC code (read timebase as long long).
  * On ARM it just returns the timer value.
@@ -176,8 +133,5 @@ unsigned long long get_ticks(void)
  */
 ulong get_tbclk (void)
 {
-       ulong tbclk;
-
-       tbclk = CONFIG_SYS_HZ;
-       return tbclk;
+       return CONFIG_SYS_HZ;
 }