blob: 90e2128b22ee3ca95d3cc0b169dd9bc7fdd04492 [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 Denk1a459662013-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 Lil3eb90ba2009-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;
wdenk101e8df2005-04-04 12:08:28 +000034 ulong endtime;
35 signed long diff;
wdenk15809242002-09-08 20:56:32 +000036
wdenk101e8df2005-04-04 12:08:28 +000037 if (usec >= 1000) {
38 tmo = usec / 1000;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 tmo *= CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000040 tmo /= 1000;
41 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042 tmo = usec * CONFIG_SYS_HZ;
wdenk101e8df2005-04-04 12:08:28 +000043 tmo /= (1000*1000);
44 }
wdenk15809242002-09-08 20:56:32 +000045
wdenk101e8df2005-04-04 12:08:28 +000046 endtime = get_timer_masked () + tmo;
wdenk15809242002-09-08 20:56:32 +000047
wdenk101e8df2005-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}
wdenkaaf224a2004-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{
Masahiro Yamada63a75782016-09-06 22:17:38 +090069 return CONFIG_SYS_HZ;
wdenkaaf224a2004-03-14 15:20:55 +000070}