1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 1995-2004 Russell King
5 * Delay routines, using a pre-computed "loops_per_second" value.
7 #ifndef __ASM_ARM_DELAY_H
8 #define __ASM_ARM_DELAY_H
10 #include <asm/memory.h>
11 #include <asm/param.h> /* HZ */
14 * Loop (or tick) based delay:
16 * loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec
20 * jiffies_per_sec = HZ
21 * us_per_sec = 1000000
23 * Therefore the constant part is HZ / 1000000 which is a small
24 * fractional number. To make this usable with integer math, we
25 * scale up this constant by 2^31, perform the actual multiplication,
26 * and scale the result back down by 2^31 with a simple shift:
28 * loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 31
32 * UDELAY_MULT = 2^31 * HZ / 1000000
33 * = (2^31 / 1000000) * HZ
35 * = 2147 * HZ + 483648 * HZ / 1000000
37 * 31 is the biggest scale shift value that won't overflow 32 bits for
38 * delay_us * UDELAY_MULT assuming HZ <= 1000 and delay_us <= 2000.
40 #define MAX_UDELAY_MS 2
41 #define UDELAY_MULT UL(2147 * HZ + 483648 * HZ / 1000000)
42 #define UDELAY_SHIFT 31
47 unsigned long (*read_current_timer
)(void);
51 extern struct arm_delay_ops
{
52 void (*delay
)(unsigned long);
53 void (*const_udelay
)(unsigned long);
54 void (*udelay
)(unsigned long);
55 unsigned long ticks_per_jiffy
;
58 #define __delay(n) arm_delay_ops.delay(n)
61 * This function intentionally does not exist; if you see references to
62 * it, it means that you're calling udelay() with an out of range value.
64 * With currently imposed limits, this means that we support a max delay
65 * of 2000us. Further limits: HZ<=1000
67 extern void __bad_udelay(void);
70 * division by multiplication: you don't have to worry about
73 * Use only for very small delays ( < 2 msec). Should probably use a
74 * lookup table, really, as the multiplications take much too long with
75 * short delays. This is a "reasonable" implementation, though (and the
76 * first constant multiplications gets optimized away if the delay is
79 #define __udelay(n) arm_delay_ops.udelay(n)
80 #define __const_udelay(n) arm_delay_ops.const_udelay(n)
83 (__builtin_constant_p(n) ? \
84 ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
85 __const_udelay((n) * UDELAY_MULT)) : \
88 /* Loop-based definitions for assembly code. */
89 extern void __loop_delay(unsigned long loops
);
90 extern void __loop_udelay(unsigned long usecs
);
91 extern void __loop_const_udelay(unsigned long);
93 /* Delay-loop timer registration. */
94 #define ARCH_HAS_READ_CURRENT_TIMER
95 extern void register_current_timer_delay(const struct delay_timer
*timer
);
97 #endif /* __ASSEMBLY__ */
99 #endif /* defined(_ARM_DELAY_H) */