imx-common: timer: clean up code
Subsystems (2)
PATCH 1/1 imx-common: timer: clean up code
We can reuse common functions in lib/time.c, but not reimplement functions in imx-common/time.c.
Only keep timer_init ,get_tbclk and implement timer_read_counter in imx-common/time.c.
Signed-off-by Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Fabio Estevam <[email protected]>
--- arch/arm/imx-common/timer.c | 75 ++------------------------------------------- 1 file changed, 2 insertions(+), 73 deletions(-)
arch/arm/imx-common/timer.c +2 -73
@@ -66,25 +66,6 @@ static inline ulong gpt_get_clk(void)return MXC_CLK32 ;#endif } -static inline unsigned long long tick_to_time (unsigned long long tick) -{ -ulong gpt_clk =gpt_get_clk (); - - tick *=CONFIG_SYS_HZ ; -do_div (tick, gpt_clk); - -return tick; -} - -static inline unsigned long long us_to_tick (unsigned long long usec) -{ -ulong gpt_clk =gpt_get_clk (); - - usec = usec * gpt_clk +999999 ; -do_div (usec,1000000 ); - -return usec; -}int timer_init (void ) {
@@ -130,44 +111,9 @@ int timer_init(void)return 0 ; } -unsigned long long get_ticks (void ) +unsigned long timer_read_counter (void ) { -ulong now =__raw_readl (&cur_gpt->counter);/* current tick value */ - -/* increment tbu if tbl has rolled over */ -if (now < gd->arch.tbl) - gd->arch.tbu++; - gd->arch.tbl = now; -return (((unsigned long long )gd->arch.tbu) <<32 ) | gd->arch.tbl; -} - -ulong get_timer_masked (void ) -{ -/* -* get_ticks() returns a long long (64 bit), it wraps in -* 2^64 / GPT_CLK = 2^64 / 2^15 = 2^49 ~ 5 * 10^14 (s) ~ -* 5 * 10^9 days... and get_ticks() * CONFIG_SYS_HZ wraps in -* 5 * 10^6 days - long enough. -*/ -return tick_to_time (get_ticks ()); -} - -ulong get_timer (ulong base) -{ -return get_timer_masked () - base; -} - -/* delay x useconds AND preserve advance timstamp value */ -void __udelay (unsigned long usec) -{ -unsigned long long tmp; -ulong tmo; - - tmo =us_to_tick (usec); - tmp =get_ticks () + tmo;/* get current timestamp */ - -while (get_ticks () < tmp)/* loop till event */ -/*NOP*/ ; +return __raw_readl (&cur_gpt->counter);/* current tick value */ }/*
@@ -178,20 +124,3 @@ ulong get_tbclk(void) {return gpt_get_clk (); } - -/* -* This function is intended for SHORT delays only. -* It will overflow at around 10 seconds @ 400MHz, -* or 20 seconds @ 200MHz. -*/ -unsigned long usec2ticks (unsigned long usec) -{ -ulong ticks; - -if (usec <1000 ) - ticks = ((usec * (get_tbclk ()/1000 )) +500 ) /1000 ; -else - ticks = ((usec /10 ) * (get_tbclk () /100000 )); - -return ticks; -}
Signature · 1 line
1.8.4