wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 8 | * Alex Zuepke <azu@sysgo.de> |
| 9 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <SA-1100.h> |
| 15 | |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 16 | ulong get_timer (ulong base) |
| 17 | { |
| 18 | return get_timer_masked (); |
| 19 | } |
| 20 | |
Ingo van Lil | f0f778a | 2009-11-24 14:09:21 +0100 | [diff] [blame] | 21 | void __udelay (unsigned long usec) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 22 | { |
| 23 | udelay_masked (usec); |
| 24 | } |
| 25 | |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 26 | ulong get_timer_masked (void) |
| 27 | { |
| 28 | return OSCR; |
| 29 | } |
| 30 | |
| 31 | void udelay_masked (unsigned long usec) |
| 32 | { |
| 33 | ulong tmo; |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 34 | ulong endtime; |
| 35 | signed long diff; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 36 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 37 | if (usec >= 1000) { |
| 38 | tmo = usec / 1000; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | tmo *= CONFIG_SYS_HZ; |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 40 | tmo /= 1000; |
| 41 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | tmo = usec * CONFIG_SYS_HZ; |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 43 | tmo /= (1000*1000); |
| 44 | } |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 45 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 46 | endtime = get_timer_masked () + tmo; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 47 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 48 | do { |
| 49 | ulong now = get_timer_masked (); |
| 50 | diff = endtime - now; |
| 51 | } while (diff >= 0); |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 52 | } |
wdenk | e28cf63 | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * This function is derived from PowerPC code (read timebase as long long). |
| 56 | * On ARM it just returns the timer value. |
| 57 | */ |
| 58 | unsigned long long get_ticks(void) |
| 59 | { |
| 60 | return get_timer(0); |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * This function is derived from PowerPC code (timebase clock frequency). |
| 65 | * On ARM it returns the number of timer ticks per second. |
| 66 | */ |
| 67 | ulong get_tbclk (void) |
| 68 | { |
| 69 | ulong tbclk; |
| 70 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | tbclk = CONFIG_SYS_HZ; |
wdenk | e28cf63 | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 72 | return tbclk; |
| 73 | } |