blob: 12514e4dbc955458d3c076d826f022b4f67c1087 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk15809242002-09-08 20:56:32 +00002/*
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>
wdenk15809242002-09-08 20:56:32 +000010 */
11
12#include <common.h>
13#include <SA-1100.h>
14
wdenk15809242002-09-08 20:56:32 +000015ulong get_timer (ulong base)
16{
17 return get_timer_masked ();
18}
19
Ingo van Lil3eb90ba2009-11-24 14:09:21 +010020void __udelay (unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000021{
22 udelay_masked (usec);
23}
24
wdenk15809242002-09-08 20:56:32 +000025ulong get_timer_masked (void)
26{
27 return OSCR;
28}
29
30void udelay_masked (unsigned long usec)
31{
32 ulong tmo;
wdenk101e8df2005-04-04 12:08:28 +000033 ulong endtime;
34 signed long diff;
wdenk15809242002-09-08 20:56:32 +000035
wdenk101e8df2005-04-04 12:08:28 +000036 if (usec >= 1000) {
37 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038 tmo *= CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000039 tmo /= 1000;
40 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 tmo = usec * CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000042 tmo /= (1000*1000);
43 }
wdenk15809242002-09-08 20:56:32 +000044
wdenk101e8df2005-04-04 12:08:28 +000045 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000046
wdenk101e8df2005-04-04 12:08:28 +000047 do {
48 ulong now = get_timer_masked ();
49 diff = endtime - now;
50 } while (diff >= 0);
wdenk15809242002-09-08 20:56:32 +000051}
wdenkaaf224a2004-03-14 15:20:55 +000052
53/*
54 * This function is derived from PowerPC code (read timebase as long long).
55 * On ARM it just returns the timer value.
56 */
57unsigned long long get_ticks(void)
58{
59 return get_timer(0);
60}
61
62/*
63 * This function is derived from PowerPC code (timebase clock frequency).
64 * On ARM it returns the number of timer ticks per second.
65 */
66ulong get_tbclk (void)
67{
Masahiro Yamada63a75782016-09-06 22:17:38 +090068 return CONFIG_SYS_HZ;
wdenkaaf224a2004-03-14 15:20:55 +000069}