3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/mipsregs.h>
11 static unsigned long timestamp
;
13 /* how many counter cycles in a jiffy */
14 #define CYCLES_PER_JIFFY \
15 (CONFIG_SYS_MIPS_TIMER_FREQ + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ
18 * timer without interrupts
23 /* Set up the timer for the first expiration. */
24 write_c0_compare(read_c0_count() + CYCLES_PER_JIFFY
);
29 ulong
get_timer(ulong base
)
32 unsigned int expirelo
= read_c0_compare();
34 /* Check to see if we have missed any timestamps. */
35 count
= read_c0_count();
36 while ((count
- expirelo
) < 0x7fffffff) {
37 expirelo
+= CYCLES_PER_JIFFY
;
40 write_c0_compare(expirelo
);
42 return timestamp
- base
;
45 void __udelay(unsigned long usec
)
49 tmo
= read_c0_count() + (usec
* (CONFIG_SYS_MIPS_TIMER_FREQ
/ 1000000));
50 while ((tmo
- read_c0_count()) < 0x7fffffff)
55 * This function is derived from PowerPC code (read timebase as long long).
56 * On MIPS it just returns the timer value.
58 unsigned long long get_ticks(void)
64 * This function is derived from PowerPC code (timebase clock frequency).
65 * On MIPS it returns the number of timer ticks per second.