Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 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> | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 10 | */ |
11 | |||||
12 | #include <common.h> | ||||
13 | #include <SA-1100.h> | ||||
Simon Glass | 1045315 | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 14 | #include <time.h> |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 15 | |
Patrick Delaunay | 6180ea7 | 2018-10-05 11:33:52 +0200 | [diff] [blame] | 16 | static ulong get_timer_masked (void) |
17 | { | ||||
18 | return OSCR; | ||||
19 | } | ||||
20 | |||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 21 | ulong get_timer (ulong base) |
22 | { | ||||
23 | return get_timer_masked (); | ||||
24 | } | ||||
25 | |||||
Patrick Delaunay | aa33fe8 | 2018-10-05 11:33:51 +0200 | [diff] [blame] | 26 | void __udelay (unsigned long usec) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 27 | { |
28 | ulong tmo; | ||||
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 29 | ulong endtime; |
30 | signed long diff; | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 31 | |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 32 | if (usec >= 1000) { |
33 | tmo = usec / 1000; | ||||
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | tmo *= CONFIG_SYS_HZ; |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 35 | tmo /= 1000; |
36 | } else { | ||||
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 37 | tmo = usec * CONFIG_SYS_HZ; |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 38 | tmo /= (1000*1000); |
39 | } | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 40 | |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 41 | endtime = get_timer_masked () + tmo; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 42 | |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 43 | do { |
44 | ulong now = get_timer_masked (); | ||||
45 | diff = endtime - now; | ||||
46 | } while (diff >= 0); | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 47 | } |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 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 | */ | ||||
Simon Glass | 049f8d6 | 2019-12-28 10:44:59 -0700 | [diff] [blame^] | 62 | ulong get_tbclk(void) |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 63 | { |
Masahiro Yamada | 63a7578 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 64 | return CONFIG_SYS_HZ; |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 65 | } |