This source file includes following definitions.
- __delay
- udelay
- ndelay
1
2
3
4
5
6 #include <linux/delay.h>
7 #include <linux/param.h>
8 #include <linux/timex.h>
9 #include <linux/export.h>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #define MAX_UDELAY_US 2000
41 #define MAX_UDELAY_HZ 1000
42 #define UDELAY_MULT (2147UL * HZ + 483648UL * HZ / 1000000UL)
43 #define UDELAY_SHIFT 31
44
45 #if HZ > MAX_UDELAY_HZ
46 #error "HZ > MAX_UDELAY_HZ"
47 #endif
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 #define MAX_NDELAY_NS (1ULL << 42)
64 #define MAX_NDELAY_HZ MAX_UDELAY_HZ
65 #define NDELAY_MULT ((unsigned long long)(2199ULL * HZ + 23255550ULL * HZ / 1000000000ULL))
66 #define NDELAY_SHIFT 41
67
68 #if HZ > MAX_NDELAY_HZ
69 #error "HZ > MAX_NDELAY_HZ"
70 #endif
71
72 void __delay(unsigned long cycles)
73 {
74 u64 t0 = get_cycles();
75
76 while ((unsigned long)(get_cycles() - t0) < cycles)
77 cpu_relax();
78 }
79 EXPORT_SYMBOL(__delay);
80
81 void udelay(unsigned long usecs)
82 {
83 u64 ucycles = (u64)usecs * lpj_fine * UDELAY_MULT;
84 u64 n;
85
86 if (unlikely(usecs > MAX_UDELAY_US)) {
87 n = (u64)usecs * riscv_timebase;
88 do_div(n, 1000000);
89
90 __delay(n);
91 return;
92 }
93
94 __delay(ucycles >> UDELAY_SHIFT);
95 }
96 EXPORT_SYMBOL(udelay);
97
98 void ndelay(unsigned long nsecs)
99 {
100
101
102
103
104 unsigned long long ncycles = nsecs * lpj_fine * NDELAY_MULT;
105 __delay(ncycles >> NDELAY_SHIFT);
106 }
107 EXPORT_SYMBOL(ndelay);