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
65 * Timer runs with CFG_HZ_CLOCK, currently 27MHz. To avoid wrap
66 * around of timestamp already after min ~159s, divide it, e.g. by 16.
67 * timestamp will then wrap around all min ~42min
69 #define DIV(x) ((x) >> 4)
71 static ulong timestamp;
76 /* We are using timer34 in unchained 32-bit mode, full speed */
81 timer->prd34 = TIMER_LOAD_VAL;
83 timer->tcr = 0x80 << 16;
89 void reset_timer(void)
94 ulong get_timer(ulong base)
96 return(get_timer_masked() - base);
99 void set_timer(ulong t)
104 void udelay(unsigned long usec)
109 void reset_timer_masked(void)
111 lastinc = DIV(READ_TIMER);
115 ulong get_timer_raw(void)
117 ulong now = DIV(READ_TIMER);
119 if (now >= lastinc) {
121 timestamp += now - lastinc;
124 timestamp += now + DIV(TIMER_LOAD_VAL) - lastinc;
130 ulong get_timer_masked(void)
132 return(get_timer_raw() / DIV(TIMER_LOAD_VAL));
135 void udelay_masked(unsigned long usec)
141 tmo = CFG_HZ_CLOCK / 1000;
145 endtime = get_timer_raw() + tmo;
148 ulong now = get_timer_raw();
149 diff = endtime - now;
154 * This function is derived from PowerPC code (read timebase as long long).
155 * On ARM it just returns the timer value.
157 unsigned long long get_ticks(void)
159 return(get_timer(0));
163 * This function is derived from PowerPC code (timebase clock frequency).
164 * On ARM it returns the number of timer ticks per second.
166 ulong get_tbclk(void)