more changes on original files
[linux-2.4.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 #include <asm/compiler.h>
16
17 extern unsigned long loops_per_jiffy;
18
19 static __inline__ void __delay(unsigned long loops)
20 {
21         __asm__ __volatile__ (
22                 ".set\tnoreorder\n"
23                 "1:\tbnez\t%0,1b\n\t"
24                 "subu\t%0,1\n\t"
25                 ".set\treorder"
26                 :"=r" (loops)
27                 :"0" (loops));
28 }
29
30 /*
31  * Division by multiplication: you don't have to worry about
32  * loss of precision.
33  *
34  * Use only for very small delays ( < 1 msec).  Should probably use a
35  * lookup table, really, as the multiplications take much too long with
36  * short delays.  This is a "reasonable" implementation, though (and the
37  * first constant multiplications gets optimized away if the delay is
38  * a constant)
39  */
40 static __inline__ void __udelay(unsigned long usecs, unsigned long lpj)
41 {
42         unsigned long lo;
43
44         /*
45          * Excessive precission?  Probably ...
46          */
47         usecs *= (unsigned long) (((0x8000000000000000ULL / (500000 / HZ)) +
48                                    0x80000000ULL) >> 32);
49         __asm__("multu\t%2,%3"
50                 : "=h" (usecs), "=l" (lo)
51                 : "r" (usecs), "r" (lpj)
52                 : GCC_REG_ACCUM);
53         __delay(usecs);
54 }
55
56 static __inline__ void __ndelay(unsigned long nsecs, unsigned long lpj)
57 {
58         unsigned long lo;
59
60         /*
61          * Excessive precission?  Probably ...
62          */
63         nsecs *= (unsigned long) (((0x8000000000000000ULL / (500000000 / HZ)) +
64                                    0x80000000ULL) >> 32);
65         __asm__("multu\t%2,%3"
66                 : "=h" (nsecs), "=l" (lo)
67                 : "r" (nsecs), "r" (lpj)
68                 : GCC_REG_ACCUM);
69         __delay(nsecs);
70 }
71
72 #ifdef CONFIG_SMP
73 #define __udelay_val cpu_data[smp_processor_id()].udelay_val
74 #else
75 #define __udelay_val loops_per_jiffy
76 #endif
77
78 #define udelay(usecs) __udelay((usecs),__udelay_val)
79 #define ndelay(nsecs) __ndelay((nsecs),__udelay_val)
80
81 #endif /* _ASM_DELAY_H */