cleanup
[linux-2.4.21-pre4.git] / include / asm-mips / delay.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994 by Waldorf Electronics
7  * Copyright (C) 1995 - 1998, 2001 by Ralf Baechle
8  */
9 #ifndef _ASM_DELAY_H
10 #define _ASM_DELAY_H
11
12 #include <linux/config.h>
13 #include <linux/param.h>
14
15 extern unsigned long loops_per_jiffy;
16
17 extern __inline__ void
18 __delay(unsigned long loops)
19 {
20         __asm__ __volatile__ (
21                 ".set\tnoreorder\n"
22                 "1:\tbnez\t%0,1b\n\t"
23                 "subu\t%0,1\n\t"
24                 ".set\treorder"
25                 :"=r" (loops)
26                 :"0" (loops));
27 }
28
29 /*
30  * division by multiplication: you don't have to worry about
31  * loss of precision.
32  *
33  * Use only for very small delays ( < 1 msec).  Should probably use a
34  * lookup table, really, as the multiplications take much too long with
35  * short delays.  This is a "reasonable" implementation, though (and the
36  * first constant multiplications gets optimized away if the delay is
37  * a constant)
38  */
39 extern __inline__ void __udelay(unsigned long usecs, unsigned long lpj)
40 {
41         unsigned long lo;
42
43 #if (HZ == 100)
44         usecs *= 0x00068db8;            /* 2**32 / (1000000 / HZ) */
45 #elif (HZ == 128)
46         usecs *= 0x0008637b;            /* 2**32 / (1000000 / HZ) */
47 #endif
48         __asm__("multu\t%2,%3"
49                 :"=h" (usecs), "=l" (lo)
50                 :"r" (usecs),"r" (lpj));
51         __delay(usecs);
52 }
53
54 #ifdef CONFIG_SMP
55 #define __udelay_val cpu_data[smp_processor_id()].udelay_val
56 #else
57 #define __udelay_val loops_per_jiffy
58 #endif
59
60 #define udelay(usecs) __udelay((usecs),__udelay_val)
61
62 #endif /* _ASM_DELAY_H */