2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 #if CONFIG_SYS_HZ != 1000
14 #warning "CONFIG_SYS_HZ must be 1000 and should not be defined by platforms"
17 #ifndef CONFIG_WD_PERIOD
18 # define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default*/
21 DECLARE_GLOBAL_DATA_PTR;
23 #ifdef CONFIG_SYS_TIMER_RATE
24 ulong notrace get_tbclk(void)
26 return CONFIG_SYS_TIMER_RATE;
30 #ifdef CONFIG_SYS_TIMER_COUNTER
31 unsigned long notrace timer_read_counter(void)
33 #ifdef CONFIG_SYS_TIMER_COUNTS_DOWN
34 return ~readl(CONFIG_SYS_TIMER_COUNTER);
36 return readl(CONFIG_SYS_TIMER_COUNTER);
40 extern unsigned long __weak timer_read_counter(void);
43 unsigned long long __weak notrace get_ticks(void)
45 unsigned long now = timer_read_counter();
47 /* increment tbu if tbl has rolled over */
48 if (now < gd->timebase_l)
51 return ((unsigned long long)gd->timebase_h << 32) | gd->timebase_l;
54 static unsigned long long notrace tick_to_time(uint64_t tick)
56 unsigned int div = get_tbclk();
58 tick *= CONFIG_SYS_HZ;
63 int __weak timer_init(void)
68 ulong __weak get_timer(ulong base)
70 return tick_to_time(get_ticks()) - base;
73 unsigned long __weak notrace timer_get_us(void)
75 return tick_to_time(get_ticks() * 1000);
77 static unsigned long long usec_to_tick(unsigned long usec)
81 do_div(tick, 1000000);
85 void __weak __udelay(unsigned long usec)
87 unsigned long long tmp;
90 tmo = usec_to_tick(usec);
91 tmp = get_ticks() + tmo; /* get current timestamp */
93 while (get_ticks() < tmp) /* loop till event */
97 /* ------------------------------------------------------------------------- */
99 void udelay(unsigned long usec)
105 kv = usec > CONFIG_WD_PERIOD ? CONFIG_WD_PERIOD : usec;
111 void mdelay(unsigned long msec)