[S5PC100] working udeay()
authorKim, HeungJun <riverful.kim@samsung.com>
Mon, 25 May 2009 08:40:42 +0000 (17:40 +0900)
committerKim, HeungJun <root@riverbuntu.(none)>
Mon, 25 May 2009 08:40:42 +0000 (17:40 +0900)
cpu/arm_cortexa8/s5pc100/interrupts.c
include/configs/s5pc100_tt.h
include/s5pc1xx.h

index 1f93f10..a0175cc 100644 (file)
@@ -45,8 +45,6 @@
 
 static ulong timer_load_val;
 
-#define PRESCALER      167
-
 static s5pc1xx_timers *s5pc1xx_get_base_timers(void)
 {
        return (s5pc1xx_timers *)S5P_TIMER_BASE;
@@ -109,24 +107,9 @@ int interrupt_init(void)
  */
 unsigned long long get_ticks(void)
 {
-       ulong now = read_timer();
-
-       if (lastdec >= now) {
-               /* normal mode */
-               timestamp += lastdec - now;
-       } else {
-               /* we have an overflow ... */
-               timestamp += lastdec + timer_load_val - now;
-       }
-       lastdec = now;
-
-       return timestamp;
+       return get_timer(0);
 }
 
-/*
- * This function is derived from PowerPC code (timebase clock frequency).
- * On ARM it returns the number of timer ticks per second.
- */
 ulong get_tbclk(void)
 {
        /* We overrun in 100s */
@@ -147,9 +130,19 @@ void reset_timer(void)
 
 ulong get_timer_masked(void)
 {
-       unsigned long long res = get_ticks();
-       do_div (res, (timer_load_val / (100 * CONFIG_SYS_HZ)));
-       return res;
+       ulong now = read_timer();
+
+       if (lastdec >= now) {
+               /* normal mode */
+               timestamp += lastdec - now;
+       }
+       else {
+               /* we have an overflow ... */
+               timestamp += lastdec + timer_load_val - now;
+       }
+       lastdec = now;
+
+       return timestamp;
 }
 
 ulong get_timer(ulong base)
@@ -159,17 +152,30 @@ ulong get_timer(ulong base)
 
 void set_timer(ulong t)
 {
-       timestamp = t * (timer_load_val / (100 * CONFIG_SYS_HZ));
+       timestamp = t;
 }
 
 void udelay(unsigned long usec)
 {
-       unsigned long long tmp;
-       ulong tmo;
+       ulong tmo, tmp;
 
-       tmo = (usec + 9) / 10;
-       tmp = get_ticks() + tmo;        /* get current timestamp */
+       if (usec >= 1000) {             /* if "big" number, spread normalization to seconds */
+               tmo = usec / 1000;      /* start to normalize for usec to ticks per sec */
+               tmo *= CFG_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 * CFG_HZ;
+               tmo /= (1000 * 1000);
+       }
+
+       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_ticks() < tmp)/* loop till event */
+       while (get_timer_masked()<tmo)  /* loop till event */
                 /*NOP*/;
 }
+
index 1639ee8..2cb3dbe 100644 (file)
 #define CONFIG_SYS_PTV                 2       /* Divisor: 2^(PTV+1) => 8 */
 
 #define CONFIG_SYS_HZ                  1000
+#define CFG_HZ                                 2085900         /* at PCLK 66.75MHz */
 
 /* valid baudrates */
 #define CONFIG_SYS_BAUDRATE_TABLE      { 9600, 19200, 38400, 57600, 115200 }
index 23cab1e..b0c621e 100644 (file)
@@ -1665,6 +1665,8 @@ enum s5pc1xx_uarts_nr {
        S5PC1XX_UART3,
 };
 
+ulong get_PCLK(void);
+
 #include "s5pc1x0.h"
 
 static inline s5pc1xx_uart *s5pc1xx_get_base_uart(enum s5pc1xx_uarts_nr nr)
@@ -1674,6 +1676,7 @@ static inline s5pc1xx_uart *s5pc1xx_get_base_uart(enum s5pc1xx_uarts_nr nr)
 #endif
 
 
+
 #endif /*__S5PC100_H__*/