Tom Rini | 10e4779 | 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 | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 14 | #include <time.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 16 | |
Patrick Delaunay | 9858a60 | 2018-10-05 11:33:52 +0200 | [diff] [blame] | 17 | static ulong get_timer_masked (void) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 18 | { |
Patrick Delaunay | 9858a60 | 2018-10-05 11:33:52 +0200 | [diff] [blame] | 19 | return OSCR; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 20 | } |
21 | |||||
Patrick Delaunay | 9858a60 | 2018-10-05 11:33:52 +0200 | [diff] [blame] | 22 | ulong get_timer (ulong base) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 23 | { |
Patrick Delaunay | 9858a60 | 2018-10-05 11:33:52 +0200 | [diff] [blame] | 24 | return get_timer_masked (); |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 25 | } |
26 | |||||
Simon Glass | 0db4b94 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 27 | void __udelay(unsigned long usec) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 28 | { |
29 | ulong tmo; | ||||
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 30 | ulong endtime; |
31 | signed long diff; | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 32 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 33 | if (usec >= 1000) { |
34 | tmo = usec / 1000; | ||||
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 35 | tmo *= CONFIG_SYS_HZ; |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 36 | tmo /= 1000; |
37 | } else { | ||||
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 38 | tmo = usec * CONFIG_SYS_HZ; |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 39 | tmo /= (1000*1000); |
40 | } | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 41 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 42 | endtime = get_timer_masked () + tmo; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 43 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 44 | do { |
45 | ulong now = get_timer_masked (); | ||||
46 | diff = endtime - now; | ||||
47 | } while (diff >= 0); | ||||
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 48 | } |
wdenk | e28cf63 | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 49 | |
50 | /* | ||||
51 | * This function is derived from PowerPC code (read timebase as long long). | ||||
52 | * On ARM it just returns the timer value. | ||||
53 | */ | ||||
54 | unsigned long long get_ticks(void) | ||||
55 | { | ||||
56 | return get_timer(0); | ||||
57 | } | ||||
58 | |||||
59 | /* | ||||
60 | * This function is derived from PowerPC code (timebase clock frequency). | ||||
61 | * On ARM it returns the number of timer ticks per second. | ||||
62 | */ | ||||
Simon Glass | a9dc068 | 2019-12-28 10:44:59 -0700 | [diff] [blame] | 63 | ulong get_tbclk(void) |
wdenk | e28cf63 | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 64 | { |
Masahiro Yamada | 04cfea5 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 65 | return CONFIG_SYS_HZ; |
wdenk | e28cf63 | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 66 | } |