blob: a5cdaf5a66c4593f2b967031445cb9a9babec669 [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>
Simon Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
wdenk15809242002-09-08 20:56:32 +000016
Patrick Delaunay6180ea72018-10-05 11:33:52 +020017static ulong get_timer_masked (void)
18{
19 return OSCR;
20}
21
wdenk15809242002-09-08 20:56:32 +000022ulong get_timer (ulong base)
23{
24 return get_timer_masked ();
25}
26
Simon Glass07e11142020-05-10 11:40:10 -060027void __udelay(unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000028{
29 ulong tmo;
wdenk101e8df2005-04-04 12:08:28 +000030 ulong endtime;
31 signed long diff;
wdenk15809242002-09-08 20:56:32 +000032
wdenk101e8df2005-04-04 12:08:28 +000033 if (usec >= 1000) {
34 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020035 tmo *= CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000036 tmo /= 1000;
37 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038 tmo = usec * CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000039 tmo /= (1000*1000);
40 }
wdenk15809242002-09-08 20:56:32 +000041
wdenk101e8df2005-04-04 12:08:28 +000042 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000043
wdenk101e8df2005-04-04 12:08:28 +000044 do {
45 ulong now = get_timer_masked ();
46 diff = endtime - now;
47 } while (diff >= 0);
wdenk15809242002-09-08 20:56:32 +000048}
wdenkaaf224a2004-03-14 15:20:55 +000049
50/*
51 * This function is derived from PowerPC code (read timebase as long long).
52 * On ARM it just returns the timer value.
53 */
54unsigned long long get_ticks(void)
55{
56 return get_timer(0);
57}
58
59/*
60 * This function is derived from PowerPC code (timebase clock frequency).
61 * On ARM it returns the number of timer ticks per second.
62 */
Simon Glass049f8d62019-12-28 10:44:59 -070063ulong get_tbclk(void)
wdenkaaf224a2004-03-14 15:20:55 +000064{
Masahiro Yamada63a75782016-09-06 22:17:38 +090065 return CONFIG_SYS_HZ;
wdenkaaf224a2004-03-14 15:20:55 +000066}