xref: /openbmc/u-boot/arch/arm/cpu/sa1100/timer.c (revision c00d0012)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2002
4  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
5  * Marius Groeger <mgroeger@sysgo.de>
6  *
7  * (C) Copyright 2002
8  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9  * Alex Zuepke <azu@sysgo.de>
10  */
11 
12 #include <common.h>
13 #include <SA-1100.h>
14 
15 static ulong get_timer_masked (void)
16 {
17 	return OSCR;
18 }
19 
20 ulong get_timer (ulong base)
21 {
22 	return get_timer_masked ();
23 }
24 
25 void __udelay (unsigned long usec)
26 {
27 	ulong tmo;
28 	ulong endtime;
29 	signed long diff;
30 
31 	if (usec >= 1000) {
32 		tmo = usec / 1000;
33 		tmo *= CONFIG_SYS_HZ;
34 		tmo /= 1000;
35 	} else {
36 		tmo = usec * CONFIG_SYS_HZ;
37 		tmo /= (1000*1000);
38 	}
39 
40 	endtime = get_timer_masked () + tmo;
41 
42 	do {
43 		ulong now = get_timer_masked ();
44 		diff = endtime - now;
45 	} while (diff >= 0);
46 }
47 
48 /*
49  * This function is derived from PowerPC code (read timebase as long long).
50  * On ARM it just returns the timer value.
51  */
52 unsigned long long get_ticks(void)
53 {
54 	return get_timer(0);
55 }
56 
57 /*
58  * This function is derived from PowerPC code (timebase clock frequency).
59  * On ARM it returns the number of timer ticks per second.
60  */
61 ulong get_tbclk (void)
62 {
63 	return CONFIG_SYS_HZ;
64 }
65