blob: 4b981e46e7d95ef37866f30be577e68f74df60e0 [file] [log] [blame]
wdenk15809242002-09-08 20:56:32 +00001/*
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 Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk15809242002-09-08 20:56:32 +000011 */
12
13#include <common.h>
14#include <SA-1100.h>
15
Jean-Christophe PLAGNIOL-VILLARDb54384e2009-05-15 23:47:02 +020016int timer_init (void)
wdenk15809242002-09-08 20:56:32 +000017{
Jean-Christophe PLAGNIOL-VILLARDb54384e2009-05-15 23:47:02 +020018 return 0;
wdenk15809242002-09-08 20:56:32 +000019}
20
wdenk15809242002-09-08 20:56:32 +000021ulong get_timer (ulong base)
22{
23 return get_timer_masked ();
24}
25
Ingo van Lil3eb90ba2009-11-24 14:09:21 +010026void __udelay (unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000027{
28 udelay_masked (usec);
29}
30
wdenk15809242002-09-08 20:56:32 +000031ulong get_timer_masked (void)
32{
33 return OSCR;
34}
35
36void udelay_masked (unsigned long usec)
37{
38 ulong tmo;
wdenk101e8df2005-04-04 12:08:28 +000039 ulong endtime;
40 signed long diff;
wdenk15809242002-09-08 20:56:32 +000041
wdenk101e8df2005-04-04 12:08:28 +000042 if (usec >= 1000) {
43 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020044 tmo *= CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000045 tmo /= 1000;
46 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020047 tmo = usec * CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000048 tmo /= (1000*1000);
49 }
wdenk15809242002-09-08 20:56:32 +000050
wdenk101e8df2005-04-04 12:08:28 +000051 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000052
wdenk101e8df2005-04-04 12:08:28 +000053 do {
54 ulong now = get_timer_masked ();
55 diff = endtime - now;
56 } while (diff >= 0);
wdenk15809242002-09-08 20:56:32 +000057}
wdenkaaf224a2004-03-14 15:20:55 +000058
59/*
60 * This function is derived from PowerPC code (read timebase as long long).
61 * On ARM it just returns the timer value.
62 */
63unsigned 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 */
72ulong get_tbclk (void)
73{
74 ulong tbclk;
75
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076 tbclk = CONFIG_SYS_HZ;
wdenkaaf224a2004-03-14 15:20:55 +000077 return tbclk;
78}