blob: c6b1b2c177512b68b2ec9e2e1f3c951284712bc0 [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>
wdenk15809242002-09-08 20:56:32 +000015
Patrick Delaunay9858a602018-10-05 11:33:52 +020016static ulong get_timer_masked (void)
wdenk15809242002-09-08 20:56:32 +000017{
Patrick Delaunay9858a602018-10-05 11:33:52 +020018 return OSCR;
wdenk15809242002-09-08 20:56:32 +000019}
20
Patrick Delaunay9858a602018-10-05 11:33:52 +020021ulong get_timer (ulong base)
wdenk15809242002-09-08 20:56:32 +000022{
Patrick Delaunay9858a602018-10-05 11:33:52 +020023 return get_timer_masked ();
wdenk15809242002-09-08 20:56:32 +000024}
25
Patrick Delaunay94a08592018-10-05 11:33:51 +020026void __udelay (unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000027{
28 ulong tmo;
wdenk7af1f9d2005-04-04 12:08:28 +000029 ulong endtime;
30 signed long diff;
wdenk15809242002-09-08 20:56:32 +000031
wdenk7af1f9d2005-04-04 12:08:28 +000032 if (usec >= 1000) {
33 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020034 tmo *= CONFIG_SYS_HZ;
wdenk7af1f9d2005-04-04 12:08:28 +000035 tmo /= 1000;
36 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037 tmo = usec * CONFIG_SYS_HZ;
wdenk7af1f9d2005-04-04 12:08:28 +000038 tmo /= (1000*1000);
39 }
wdenk15809242002-09-08 20:56:32 +000040
wdenk7af1f9d2005-04-04 12:08:28 +000041 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000042
wdenk7af1f9d2005-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}
wdenke28cf632004-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 Yamada04cfea52016-09-06 22:17:38 +090064 return CONFIG_SYS_HZ;
wdenke28cf632004-03-14 15:20:55 +000065}