3 * Texas Instruments <www.ti.com>
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
13 * (C) Copyright 2002-2004
14 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
17 * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
19 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
21 * See file CREDITS for list of people who contributed to this
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License as
26 * published by the Free Software Foundation; either version 2 of
27 * the License, or (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
41 #include <arm926ejs.h>
43 typedef volatile struct {
45 u_int32_t emumgt_clksped;
59 davinci_timer *timer = (davinci_timer *)CFG_TIMERBASE;
61 #define TIMER_LOAD_VAL (CFG_HZ_CLOCK / CFG_HZ)
62 #define READ_TIMER timer->tim34
64 /* Timer runs with CFG_HZ_CLOCK, currently 27MHz. To avoid wrap
65 around of timestamp already after min ~159s, divide it, e.g. by 16.
66 timestamp will then wrap around all min ~42min */
67 #define DIV(x) ((x) >> 4)
69 static ulong timestamp;
74 /* We are using timer34 in unchained 32-bit mode, full speed */
79 timer->prd34 = TIMER_LOAD_VAL;
81 timer->tcr = 0x80 << 16;
87 void reset_timer(void)
92 ulong get_timer(ulong base)
94 return(get_timer_masked() - base);
97 void set_timer(ulong t)
102 void udelay(unsigned long usec)
107 void reset_timer_masked(void)
109 lastinc = DIV(READ_TIMER);
113 ulong get_timer_raw(void)
115 ulong now = DIV(READ_TIMER);
117 if (now >= lastinc) {
119 timestamp += now - lastinc;
122 timestamp += now + DIV(TIMER_LOAD_VAL) - lastinc;
128 ulong get_timer_masked(void)
130 return(get_timer_raw() / DIV(TIMER_LOAD_VAL));
133 void udelay_masked(unsigned long usec)
139 tmo = CFG_HZ_CLOCK / 1000;
143 endtime = get_timer_raw() + tmo;
146 ulong now = get_timer_raw();
147 diff = endtime - now;
152 * This function is derived from PowerPC code (read timebase as long long).
153 * On ARM it just returns the timer value.
155 unsigned long long get_ticks(void)
157 return(get_timer(0));
161 * This function is derived from PowerPC code (timebase clock frequency).
162 * On ARM it returns the number of timer ticks per second.
164 ulong get_tbclk(void)