From: Kim, HeungJun Date: Mon, 25 May 2009 08:40:42 +0000 (+0900) Subject: [S5PC100] working udeay() X-Git-Tag: s5pc110_universal_support~277 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f872c730642fd022bc1de1e689a35e2d73dd5019;p=kernel%2Fu-boot.git [S5PC100] working udeay() --- diff --git a/cpu/arm_cortexa8/s5pc100/interrupts.c b/cpu/arm_cortexa8/s5pc100/interrupts.c index 1f93f10..a0175cc 100644 --- a/cpu/arm_cortexa8/s5pc100/interrupts.c +++ b/cpu/arm_cortexa8/s5pc100/interrupts.c @@ -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() 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 } diff --git a/include/s5pc1xx.h b/include/s5pc1xx.h index 23cab1e..b0c621e 100644 --- a/include/s5pc1xx.h +++ b/include/s5pc1xx.h @@ -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__*/