2 * linux/include/asm-arm/delay.h
4 * Copyright (C) 1995-2003 Russell King
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.
10 * Delay routines, using a pre-computed "loops_per_second" value.
12 #ifndef __ASM_ARM_DELAY_H
13 #define __ASM_ARM_DELAY_H
16 * Division by multiplication and shifts.
18 * We want the number of loops to complete, where loops is:
19 * (us * (HZ * loops_per_jiffy)) / 10^6
21 * (ns * (HZ * loops_per_jiffy)) / 10^9
23 * Since we don't want to do long division, we multiply both numerator
24 * and denominator by (2^28 / 10^6):
26 * (us * (2^28 / 10^6) * HZ * loops_per_jiffy) / 2^28
28 * => (us * (2^28 * HZ / 10^6) * loops_per_jiffy) / 2^28
30 * ~> (((us * (2^28 * HZ / 10^6)) / 2^11) * (loops_per_jiffy / 2^12)) / 2^5
31 * (for large loops_per_jiffy >> 2^12)
33 * Note: maximum loops_per_jiffy = 67108863 (bogomips = 1342.18)
34 * minimum loops_per_jiffy = 20000 (bogomips = 0.4)
36 * Note: we rely on HZ = 100.
38 #define UDELAY_FACTOR 26843
39 #define NDELAY_FACTOR 27
43 extern void __bad_udelay(void); /* intentional errors */
44 extern void __bad_ndelay(void); /* intentional errors */
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);
52 (__builtin_constant_p(n) ? \
53 ((n) > 20000 ? __bad_udelay() \
54 : __const_delay((n) * UDELAY_FACTOR)) \
58 (__builtin_constant_p(n) ? \
59 ((n) > 20000 ? __bad_ndelay() \
60 : __const_delay((n) * NDELAY_FACTOR)) \
65 #endif /* defined(_ARM_DELAY_H) */