]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/arm/include/asm/delay.h
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / arch / arm / include / asm / delay.h
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 1995-2004 Russell King
3 *
4 * Delay routines, using a pre-computed "loops_per_second" value.
5 */
6#ifndef __ASM_ARM_DELAY_H
7#define __ASM_ARM_DELAY_H
8
d0a533b1 9#include <asm/memory.h>
6d4518d7
PT
10#include <asm/param.h> /* HZ */
11
207b1150
NP
12/*
13 * Loop (or tick) based delay:
14 *
15 * loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec
16 *
17 * where:
18 *
19 * jiffies_per_sec = HZ
20 * us_per_sec = 1000000
21 *
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:
26 *
27 * loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 31
28 *
29 * where:
30 *
31 * UDELAY_MULT = 2^31 * HZ / 1000000
32 * = (2^31 / 1000000) * HZ
33 * = 2147.483648 * HZ
34 * = 2147 * HZ + 483648 * HZ / 1000000
35 *
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.
38 */
d0a533b1 39#define MAX_UDELAY_MS 2
fb833b1f 40#define UDELAY_MULT UL(2147 * HZ + 483648 * HZ / 1000000)
215e362d 41#define UDELAY_SHIFT 31
d0a533b1
WD
42
43#ifndef __ASSEMBLY__
44
56942fec
JA
45struct delay_timer {
46 unsigned long (*read_current_timer)(void);
47 unsigned long freq;
48};
49
d0a533b1
WD
50extern struct arm_delay_ops {
51 void (*delay)(unsigned long);
52 void (*const_udelay)(unsigned long);
53 void (*udelay)(unsigned long);
6f3d90e5 54 unsigned long ticks_per_jiffy;
d0a533b1
WD
55} arm_delay_ops;
56
57#define __delay(n) arm_delay_ops.delay(n)
1da177e4
LT
58
59/*
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.
62 *
63 * With currently imposed limits, this means that we support a max delay
215e362d 64 * of 2000us. Further limits: HZ<=1000
1da177e4
LT
65 */
66extern void __bad_udelay(void);
67
68/*
69 * division by multiplication: you don't have to worry about
70 * loss of precision.
71 *
d0a533b1 72 * Use only for very small delays ( < 2 msec). Should probably use a
1da177e4
LT
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
76 * a constant)
77 */
d0a533b1
WD
78#define __udelay(n) arm_delay_ops.udelay(n)
79#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1da177e4 80
6d4518d7
PT
81#define udelay(n) \
82 (__builtin_constant_p(n) ? \
83 ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
d0a533b1 84 __const_udelay((n) * UDELAY_MULT)) : \
1da177e4
LT
85 __udelay(n))
86
d0a533b1
WD
87/* Loop-based definitions for assembly code. */
88extern void __loop_delay(unsigned long loops);
89extern void __loop_udelay(unsigned long usecs);
90extern void __loop_const_udelay(unsigned long);
91
56942fec
JA
92/* Delay-loop timer registration. */
93#define ARCH_HAS_READ_CURRENT_TIMER
94extern void register_current_timer_delay(const struct delay_timer *timer);
95
d0a533b1
WD
96#endif /* __ASSEMBLY__ */
97
1da177e4
LT
98#endif /* defined(_ARM_DELAY_H) */
99