8f968f1a5f48622a35ff07f9fa9e631707afacc3
[coreboot.git] / src / arch / ppc / lib / timer.c
1 /* $Id$ */
2 /* Copyright 2000  AG Electronics Ltd. */
3 /* This code is distributed without warranty under the GPL v2 (see COPYING) */
4
5 #include <timer.h>
6 #include <bsp.h>
7
8 unsigned get_hz(void)
9 {
10         return bsp_clock_speed();
11 }
12
13 unsigned ticks_since_boot(void)
14 {
15         extern unsigned long long _timebase(void);
16         return (unsigned) (_timebase());
17 }
18
19 void sleep_ticks(unsigned ticks)
20 {
21         unsigned then = ticks + ticks_since_boot();
22         while(ticks_since_boot() < then)
23                 ;
24 }
25
26 void udelay(int usecs)
27 {
28         unsigned ticksperusec = get_hz() / 1000000;
29
30         sleep_ticks(ticksperusec * usecs);
31 }