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 | 1a45966 | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | b54384e | 2009-05-15 23:47:02 +0200 | [diff] [blame] | 16 | int timer_init (void) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 17 | { |
Jean-Christophe PLAGNIOL-VILLARD | b54384e | 2009-05-15 23:47:02 +0200 | [diff] [blame] | 18 | return 0; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 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 | |
Ingo van Lil | 3eb90ba | 2009-11-24 14:09:21 +0100 | [diff] [blame] | 26 | void __udelay (unsigned long usec) |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 27 | { |
| 28 | udelay_masked (usec); |
| 29 | } |
| 30 | |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 31 | ulong get_timer_masked (void) |
| 32 | { |
| 33 | return OSCR; |
| 34 | } |
| 35 | |
| 36 | void udelay_masked (unsigned long usec) |
| 37 | { |
| 38 | ulong tmo; |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 39 | ulong endtime; |
| 40 | signed long diff; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 41 | |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 42 | if (usec >= 1000) { |
| 43 | tmo = usec / 1000; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | tmo *= CONFIG_SYS_HZ; |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 45 | tmo /= 1000; |
| 46 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | tmo = usec * CONFIG_SYS_HZ; |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 48 | tmo /= (1000*1000); |
| 49 | } |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 50 | |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 51 | endtime = get_timer_masked () + tmo; |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 52 | |
wdenk | 101e8df | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 53 | do { |
| 54 | ulong now = get_timer_masked (); |
| 55 | diff = endtime - now; |
| 56 | } while (diff >= 0); |
wdenk | 1580924 | 2002-09-08 20:56:32 +0000 | [diff] [blame] | 57 | } |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * This function is derived from PowerPC code (read timebase as long long). |
| 61 | * On ARM it just returns the timer value. |
| 62 | */ |
| 63 | unsigned long long get_ticks(void) |
| 64 | { |
| 65 | return get_timer(0); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * This function is derived from PowerPC code (timebase clock frequency). |
| 70 | * On ARM it returns the number of timer ticks per second. |
| 71 | */ |
| 72 | ulong get_tbclk (void) |
| 73 | { |
| 74 | ulong tbclk; |
| 75 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 76 | tbclk = CONFIG_SYS_HZ; |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 77 | return tbclk; |
| 78 | } |