]> git.sur5r.net Git - u-boot/blobdiff - arch/arm/cpu/arm1136/omap24xx/timer.c
Merge git://git.denx.de/u-boot
[u-boot] / arch / arm / cpu / arm1136 / omap24xx / timer.c
index 68fe1b22066a6f42782fff15e1152b5165bb3fff..e929ae45bbf7023248608d3cf055692da423fc7f 100644 (file)
@@ -39,8 +39,7 @@
 /* macro to read the 32 bit timer */
 #define READ_TIMER (*((volatile ulong *)(CONFIG_SYS_TIMERBASE+TCRR)))
 
-static ulong timestamp;
-static ulong lastinc;
+DECLARE_GLOBAL_DATA_PTR;
 
 int timer_init (void)
 {
@@ -51,28 +50,20 @@ int timer_init (void)
        val = (CONFIG_SYS_PTV << 2) | BIT5 | BIT1 | BIT0;               /* mask to enable timer*/
        *((int32_t *) (CONFIG_SYS_TIMERBASE + TCLR)) = val;     /* start timer */
 
-       reset_timer_masked(); /* init the timestamp and lastinc value */
+       /* reset time */
+       gd->lastinc = READ_TIMER;       /* capture current incrementer value */
+       gd->tbl = 0;                    /* start "advancing" time stamp */
 
        return(0);
 }
 /*
  * timer without interrupts
  */
-void reset_timer (void)
-{
-       reset_timer_masked ();
-}
-
 ulong get_timer (ulong base)
 {
        return get_timer_masked () - base;
 }
 
-void set_timer (ulong t)
-{
-       timestamp = t;
-}
-
 /* delay x useconds AND preserve advance timestamp value */
 void __udelay (unsigned long usec)
 {
@@ -88,31 +79,27 @@ void __udelay (unsigned long usec)
        }
 
        tmp = get_timer (0);            /* get current timestamp */
-       if ( (tmo + tmp + 1) < tmp )    /* if setting this forward will roll time stamp */
-               reset_timer_masked ();  /* reset "advancing" timestamp to 0, set lastinc value */
-       else
+       if ((tmo + tmp + 1) < tmp) {    /* if setting this forward will roll */
+                                       /* time stamp, then reset time */
+               gd->lastinc = READ_TIMER;       /* capture incrementer value */
+               gd->tbl = 0;                    /* start time stamp */
+       } 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 */
-       lastinc = READ_TIMER;           /* capture current incrementer value time */
-       timestamp = 0;                  /* start "advancing" time stamp from 0 */
-}
-
 ulong get_timer_masked (void)
 {
        ulong now = READ_TIMER;         /* current tick value */
 
-       if (now >= lastinc)             /* normal mode (non roll) */
-               timestamp += (now - lastinc); /* move stamp fordward with absoulte diff ticks */
+       if (now >= gd->lastinc)         /* normal mode (non roll) */
+               gd->tbl += (now - gd->lastinc); /* move stamp fordward with absoulte diff ticks */
        else                            /* we have rollover of incrementer */
-               timestamp += (0xFFFFFFFF - lastinc) + now;
-       lastinc = now;
-       return timestamp;
+               gd->tbl += (0xFFFFFFFF - gd->lastinc) + now;
+       gd->lastinc = now;
+       return gd->tbl;
 }
 
 /* waits specified delay value and resets timestamp */