1 /*
2  *  linux/include/asm-arm/delay.h
3  *
4  *  Copyright (C) 1995-2003 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  *  Delay routines, using a pre-computed "loops_per_second" value.
11  */
12 #ifndef __ASM_ARM_DELAY_H
13 #define __ASM_ARM_DELAY_H
14 
15 /*
16  * Division by multiplication and shifts.
17  *
18  *  We want the number of loops to complete, where loops is:
19  *      (us * (HZ * loops_per_jiffy)) / 10^6
20  *  or
21  *      (ns * (HZ * loops_per_jiffy)) / 10^9
22  *
23  *  Since we don't want to do long division, we multiply both numerator
24  *  and denominator by (2^28 / 10^6):
25  *
26  *      (us * (2^28 / 10^6) * HZ * loops_per_jiffy) / 2^28
27  *
28  *  =>  (us * (2^28 * HZ / 10^6) * loops_per_jiffy) / 2^28
29  *
30  *  ~>  (((us * (2^28 * HZ / 10^6)) / 2^11) * (loops_per_jiffy / 2^12)) / 2^5
31  *         (for large loops_per_jiffy >> 2^12)
32  *
33  *  Note: maximum loops_per_jiffy = 67108863 (bogomips = 1342.18)
34  *        minimum loops_per_jiffy = 20000 (bogomips = 0.4)
35  *
36  * Note: we rely on HZ = 100.
37  */
38 #define UDELAY_FACTOR	26843
39 #define NDELAY_FACTOR	27
40 
41 #ifndef __ASSEMBLY__
42 
43 extern void __bad_udelay(void);	/* intentional errors */
44 extern void __bad_ndelay(void);	/* intentional errors */
45 
46 extern void __delay(unsigned long loops);
47 extern void __udelay(unsigned long usecs);
48 extern void __ndelay(unsigned long nsecs);
49 extern void __const_delay(unsigned long units);
50 
51 #define udelay(n) 							\
52 	(__builtin_constant_p(n) ?					\
53 		((n) > 20000 ? __bad_udelay()				\
54 			     : __const_delay((n) * UDELAY_FACTOR))	\
55 				 : __udelay(n))
56 
57 #define ndelay(n) 							\
58 	(__builtin_constant_p(n) ?					\
59 		((n) > 20000 ? __bad_ndelay()				\
60 			     : __const_delay((n) * NDELAY_FACTOR))	\
61 				 : __ndelay(n))
62 
63 #endif
64 
65 #endif /* defined(_ARM_DELAY_H) */
66 
67