blob: a5cdaf5a66c4593f2b967031445cb9a9babec669 [file] [log] [blame]
Tom Rini10e47792018-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 Glass495a5dc2019-11-14 12:57:30 -070014#include <time.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
wdenk15809242002-09-08 20:56:32 +000016
Patrick Delaunay9858a602018-10-05 11:33:52 +020017static ulong get_timer_masked (void)
wdenk15809242002-09-08 20:56:32 +000018{
Patrick Delaunay9858a602018-10-05 11:33:52 +020019 return OSCR;
wdenk15809242002-09-08 20:56:32 +000020}
21
Patrick Delaunay9858a602018-10-05 11:33:52 +020022ulong get_timer (ulong base)
wdenk15809242002-09-08 20:56:32 +000023{
Patrick Delaunay9858a602018-10-05 11:33:52 +020024 return get_timer_masked ();
wdenk15809242002-09-08 20:56:32 +000025}
26
Simon Glass0db4b942020-05-10 11:40:10 -060027void __udelay(unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000028{
29 ulong tmo;
wdenk7af1f9d2005-04-04 12:08:28 +000030 ulong endtime;
31 signed long diff;
wdenk15809242002-09-08 20:56:32 +000032
wdenk7af1f9d2005-04-04 12:08:28 +000033 if (usec >= 1000) {
34 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020035 tmo *= CONFIG_SYS_HZ;
wdenk7af1f9d2005-04-04 12:08:28 +000036 tmo /= 1000;
37 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020038 tmo = usec * CONFIG_SYS_HZ;
wdenk7af1f9d2005-04-04 12:08:28 +000039 tmo /= (1000*1000);
40 }
wdenk15809242002-09-08 20:56:32 +000041
wdenk7af1f9d2005-04-04 12:08:28 +000042 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000043
wdenk7af1f9d2005-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}
wdenke28cf632004-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 Glassa9dc0682019-12-28 10:44:59 -070063ulong get_tbclk(void)
wdenke28cf632004-03-14 15:20:55 +000064{
Masahiro Yamada04cfea52016-09-06 22:17:38 +090065 return CONFIG_SYS_HZ;
wdenke28cf632004-03-14 15:20:55 +000066}