blob: c6b1b2c177512b68b2ec9e2e1f3c951284712bc0 [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>
Simon Glass10453152019-11-14 12:57:30 -070014#include <time.h>
wdenk15809242002-09-08 20:56:32 +000015
Patrick Delaunay6180ea72018-10-05 11:33:52 +020016static ulong get_timer_masked (void)
17{
18 return OSCR;
19}
20
wdenk15809242002-09-08 20:56:32 +000021ulong get_timer (ulong base)
22{
23 return get_timer_masked ();
24}
25
Patrick Delaunayaa33fe82018-10-05 11:33:51 +020026void __udelay (unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000027{
28 ulong tmo;
wdenk101e8df2005-04-04 12:08:28 +000029 ulong endtime;
30 signed long diff;
wdenk15809242002-09-08 20:56:32 +000031
wdenk101e8df2005-04-04 12:08:28 +000032 if (usec >= 1000) {
33 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034 tmo *= CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000035 tmo /= 1000;
36 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020037 tmo = usec * CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000038 tmo /= (1000*1000);
39 }
wdenk15809242002-09-08 20:56:32 +000040
wdenk101e8df2005-04-04 12:08:28 +000041 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000042
wdenk101e8df2005-04-04 12:08:28 +000043 do {
44 ulong now = get_timer_masked ();
45 diff = endtime - now;
46 } while (diff >= 0);
wdenk15809242002-09-08 20:56:32 +000047}
wdenkaaf224a2004-03-14 15:20:55 +000048
49/*
50 * This function is derived from PowerPC code (read timebase as long long).
51 * On ARM it just returns the timer value.
52 */
53unsigned long long get_ticks(void)
54{
55 return get_timer(0);
56}
57
58/*
59 * This function is derived from PowerPC code (timebase clock frequency).
60 * On ARM it returns the number of timer ticks per second.
61 */
62ulong get_tbclk (void)
63{
Masahiro Yamada63a75782016-09-06 22:17:38 +090064 return CONFIG_SYS_HZ;
wdenkaaf224a2004-03-14 15:20:55 +000065}