f2cbee5dca7bf2b9921aa7bf973e416a03ff27ff
[oweals/u-boot.git] / arch / arm / cpu / sa1100 / timer.c
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 #include <time.h>
15
16 static ulong get_timer_masked (void)
17 {
18         return OSCR;
19 }
20
21 ulong get_timer (ulong base)
22 {
23         return get_timer_masked ();
24 }
25
26 void __udelay(unsigned long usec)
27 {
28         ulong tmo;
29         ulong endtime;
30         signed long diff;
31
32         if (usec >= 1000) {
33                 tmo = usec / 1000;
34                 tmo *= CONFIG_SYS_HZ;
35                 tmo /= 1000;
36         } else {
37                 tmo = usec * CONFIG_SYS_HZ;
38                 tmo /= (1000*1000);
39         }
40
41         endtime = get_timer_masked () + tmo;
42
43         do {
44                 ulong now = get_timer_masked ();
45                 diff = endtime - now;
46         } while (diff >= 0);
47 }
48
49 /*
50  * This function is derived from PowerPC code (read timebase as long long).
51  * On ARM it just returns the timer value.
52  */
53 unsigned long long get_ticks(void)
54 {
55         return get_timer(0);
56 }
57
58 /*
59  * This function is derived from PowerPC code (timebase clock frequency).
60  * On ARM it returns the number of timer ticks per second.
61  */
62 ulong get_tbclk(void)
63 {
64         return CONFIG_SYS_HZ;
65 }