]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/armltd/integrator/timer.c
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
7 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
10 * Texas Instruments, <www.ti.com>
11 * Kshitij Gupta <Kshitij@ti.com>
15 * Philippe Robin, <philippe.robin@arm.com>
17 * See file CREDITS for list of people who contributed to this
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of
23 * the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
39 #ifdef CONFIG_ARCH_CINTEGRATOR
40 #define DIV_CLOCK_INIT 1
41 #define TIMER_LOAD_VAL 0xFFFFFFFFL
43 #define DIV_CLOCK_INIT 256
44 #define TIMER_LOAD_VAL 0x0000FFFFL
46 /* The Integrator/CP timer1 is clocked at 1MHz
47 * can be divided by 16 or 256
48 * and can be set up as a 32-bit timer
50 /* U-Boot expects a 32 bit timer, running at CONFIG_SYS_HZ */
51 /* Keep total timer count to avoid losing decrements < div_timer */
52 static unsigned long long total_count
= 0;
53 static unsigned long long lastdec
; /* Timer reading at last call */
54 /* Divisor applied to timer clock */
55 static unsigned long long div_clock
= DIV_CLOCK_INIT
;
56 static unsigned long long div_timer
= 1; /* Divisor to convert timer reading
57 * change to U-Boot ticks
59 /* CONFIG_SYS_HZ = CONFIG_SYS_HZ_CLOCK/(div_clock * div_timer) */
60 static ulong timestamp
; /* U-Boot ticks since startup */
62 #define READ_TIMER (*(volatile ulong *)(CONFIG_SYS_TIMERBASE+4))
64 /* all function return values in U-Boot ticks i.e. (1/CONFIG_SYS_HZ) sec
65 * - unless otherwise stated
68 /* starts up a counter
69 * - the Integrator/CP timer can be set up to issue an interrupt */
72 /* Load timer with initial value */
73 *(volatile ulong
*)(CONFIG_SYS_TIMERBASE
+ 0) = TIMER_LOAD_VAL
;
74 #ifdef CONFIG_ARCH_CINTEGRATOR
80 * divider 1 00 == less rounding error
84 *(volatile ulong
*)(CONFIG_SYS_TIMERBASE
+ 8) = 0x000000C2;
93 *(volatile ulong
*)(CONFIG_SYS_TIMERBASE
+ 8) = 0x00000088;
96 /* init the timestamp */
100 div_timer
= CONFIG_SYS_HZ_CLOCK
;
101 do_div(div_timer
, CONFIG_SYS_HZ
);
102 do_div(div_timer
, div_clock
);
108 * timer without interrupts
110 void reset_timer (void)
112 reset_timer_masked ();
115 ulong
get_timer (ulong base_ticks
)
117 return get_timer_masked () - base_ticks
;
120 /* delay usec useconds */
121 void __udelay (unsigned long usec
)
125 /* Convert to U-Boot ticks */
126 tmo
= usec
* CONFIG_SYS_HZ
;
129 tmp
= get_timer_masked(); /* get current timestamp */
130 tmo
+= tmp
; /* form target timestamp */
132 while (get_timer_masked () < tmo
) {/* loop till event */
137 void reset_timer_masked (void)
139 /* capure current decrementer value */
140 lastdec
= READ_TIMER
;
141 /* start "advancing" time stamp from 0 */
145 /* converts the timer reading to U-Boot ticks */
146 /* the timestamp is the number of ticks since reset */
147 ulong
get_timer_masked (void)
149 /* get current count */
150 unsigned long long now
= READ_TIMER
;
153 /* Must have wrapped */
154 total_count
+= lastdec
+ TIMER_LOAD_VAL
+ 1 - now
;
156 total_count
+= lastdec
- now
;
162 do_div(now
, div_timer
);
168 /* waits specified delay value and resets timestamp */
169 void udelay_masked (unsigned long usec
)
175 * This function is derived from PowerPC code (read timebase as long long).
176 * On ARM it just returns the timer value.
178 unsigned long long get_ticks(void)
184 * Return the timebase clock frequency
185 * i.e. how often the timer decrements
187 ulong
get_tbclk (void)
189 unsigned long long tmp
= CONFIG_SYS_HZ_CLOCK
;
191 do_div(tmp
, div_clock
);