Initial commit
[savezelda.git] / loader / time.c
1 // Copyright 2008-2009  Segher Boessenkool  <segher@kernel.crashing.org>
2 // This code is licensed to you under the terms of the GNU GPL, version 2;
3 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
4
5 #include "loader.h"
6
7 // Timebase frequency is bus frequency / 4.  Ignore roundoff, this
8 // doesn't have to be very accurate.
9 #define TICKS_PER_USEC (243/4)
10
11 static u32 mftb(void)
12 {
13         u32 x;
14
15         asm volatile("mftb %0" : "=r"(x));
16
17         return x;
18 }
19
20 static void __delay(u32 ticks)
21 {
22         u32 start = mftb();
23
24         while (mftb() - start < ticks)
25                 ;
26 }
27
28 void udelay(u32 us)
29 {
30         __delay(TICKS_PER_USEC * us);
31 }