blob: 0a0006b426323d4162ea73900137cad3541051c2 [file] [log] [blame]
wdenk15809242002-09-08 20:56:32 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
9 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk15809242002-09-08 20:56:32 +000011 */
12
13#include <common.h>
14#include <SA-1100.h>
15
wdenk15809242002-09-08 20:56:32 +000016ulong get_timer (ulong base)
17{
18 return get_timer_masked ();
19}
20
Ingo van Lilf0f778a2009-11-24 14:09:21 +010021void __udelay (unsigned long usec)
wdenk15809242002-09-08 20:56:32 +000022{
23 udelay_masked (usec);
24}
25
wdenk15809242002-09-08 20:56:32 +000026ulong get_timer_masked (void)
27{
28 return OSCR;
29}
30
31void udelay_masked (unsigned long usec)
32{
33 ulong tmo;
wdenk7af1f9d2005-04-04 12:08:28 +000034 ulong endtime;
35 signed long diff;
wdenk15809242002-09-08 20:56:32 +000036
wdenk7af1f9d2005-04-04 12:08:28 +000037 if (usec >= 1000) {
38 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020039 tmo *= CONFIG_SYS_HZ;
wdenk7af1f9d2005-04-04 12:08:28 +000040 tmo /= 1000;
41 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 tmo = usec * CONFIG_SYS_HZ;
wdenk7af1f9d2005-04-04 12:08:28 +000043 tmo /= (1000*1000);
44 }
wdenk15809242002-09-08 20:56:32 +000045
wdenk7af1f9d2005-04-04 12:08:28 +000046 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000047
wdenk7af1f9d2005-04-04 12:08:28 +000048 do {
49 ulong now = get_timer_masked ();
50 diff = endtime - now;
51 } while (diff >= 0);
wdenk15809242002-09-08 20:56:32 +000052}
wdenke28cf632004-03-14 15:20:55 +000053
54/*
55 * This function is derived from PowerPC code (read timebase as long long).
56 * On ARM it just returns the timer value.
57 */
58unsigned long long get_ticks(void)
59{
60 return get_timer(0);
61}
62
63/*
64 * This function is derived from PowerPC code (timebase clock frequency).
65 * On ARM it returns the number of timer ticks per second.
66 */
67ulong get_tbclk (void)
68{
69 ulong tbclk;
70
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071 tbclk = CONFIG_SYS_HZ;
wdenke28cf632004-03-14 15:20:55 +000072 return tbclk;
73}