2 * Copyright (C) 1995-2004 Russell King
4 * Delay routines, using a pre-computed "loops_per_second" value.
6 #ifndef __ASM_ARM_DELAY_H
7 #define __ASM_ARM_DELAY_H
9 #include <asm/memory.h>
10 #include <asm/param.h> /* HZ */
13 * Loop (or tick) based delay:
15 * loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec
19 * jiffies_per_sec = HZ
20 * us_per_sec = 1000000
22 * Therefore the constant part is HZ / 1000000 which is a small
23 * fractional number. To make this usable with integer math, we
24 * scale up this constant by 2^31, perform the actual multiplication,
25 * and scale the result back down by 2^31 with a simple shift:
27 * loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 31
31 * UDELAY_MULT = 2^31 * HZ / 1000000
32 * = (2^31 / 1000000) * HZ
34 * = 2147 * HZ + 483648 * HZ / 1000000
36 * 31 is the biggest scale shift value that won't overflow 32 bits for
37 * delay_us * UDELAY_MULT assuming HZ <= 1000 and delay_us <= 2000.
39 #define MAX_UDELAY_MS 2
40 #define UDELAY_MULT UL(2147 * HZ + 483648 * HZ / 1000000)
41 #define UDELAY_SHIFT 31
46 unsigned long (*read_current_timer)(void);
50 extern struct arm_delay_ops {
51 void (*delay)(unsigned long);
52 void (*const_udelay)(unsigned long);
53 void (*udelay)(unsigned long);
54 unsigned long ticks_per_jiffy;
57 #define __delay(n) arm_delay_ops.delay(n)
60 * This function intentionally does not exist; if you see references to
61 * it, it means that you're calling udelay() with an out of range value.
63 * With currently imposed limits, this means that we support a max delay
64 * of 2000us. Further limits: HZ<=1000
66 extern void __bad_udelay(void);
69 * division by multiplication: you don't have to worry about
72 * Use only for very small delays ( < 2 msec). Should probably use a
73 * lookup table, really, as the multiplications take much too long with
74 * short delays. This is a "reasonable" implementation, though (and the
75 * first constant multiplications gets optimized away if the delay is
78 #define __udelay(n) arm_delay_ops.udelay(n)
79 #define __const_udelay(n) arm_delay_ops.const_udelay(n)
82 (__builtin_constant_p(n) ? \
83 ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
84 __const_udelay((n) * UDELAY_MULT)) : \
87 /* Loop-based definitions for assembly code. */
88 extern void __loop_delay(unsigned long loops);
89 extern void __loop_udelay(unsigned long usecs);
90 extern void __loop_const_udelay(unsigned long);
92 /* Delay-loop timer registration. */
93 #define ARCH_HAS_READ_CURRENT_TIMER
94 extern void register_current_timer_delay(const struct delay_timer *timer);
96 #endif /* __ASSEMBLY__ */
98 #endif /* defined(_ARM_DELAY_H) */