]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cpu/arm926ejs/davinci/timer.c
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, <garyj@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 {
57 davinci_timer
*timer
= (davinci_timer
*)CONFIG_SYS_TIMERBASE
;
59 #define TIMER_LOAD_VAL (CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ)
60 #define TIM_CLK_DIV 16
62 static ulong timestamp
;
67 /* We are using timer34 in unchained 32-bit mode, full speed */
70 timer
->tgcr
= 0x06 | ((TIM_CLK_DIV
- 1) << 8);
72 timer
->prd34
= TIMER_LOAD_VAL
;
80 void reset_timer(void)
89 static ulong
get_timer_raw(void)
91 ulong now
= timer
->tim34
;
95 timestamp
+= now
- lastinc
;
98 timestamp
+= now
+ TIMER_LOAD_VAL
- lastinc
;
104 ulong
get_timer(ulong base
)
106 return((get_timer_raw() / (TIMER_LOAD_VAL
/ TIM_CLK_DIV
)) - base
);
109 void set_timer(ulong t
)
114 void udelay(unsigned long usec
)
120 tmo
= CONFIG_SYS_HZ_CLOCK
/ 1000;
122 tmo
/= (1000 * TIM_CLK_DIV
);
124 endtime
= get_timer_raw() + tmo
;
127 ulong now
= get_timer_raw();
128 diff
= endtime
- now
;
133 * This function is derived from PowerPC code (read timebase as long long).
134 * On ARM it just returns the timer value.
136 unsigned long long get_ticks(void)
138 return(get_timer(0));
142 * This function is derived from PowerPC code (timebase clock frequency).
143 * On ARM it returns the number of timer ticks per second.
145 ulong
get_tbclk(void)
147 return CONFIG_SYS_HZ
;