blob: 0f79054ce7cd0e93b597c1ae2bb862707fe2b8b4 [file] [log] [blame]
Arnd Bergmannaafe4db2009-05-13 22:56:33 +00001#ifndef __ASM_GENERIC_DELAY_H
2#define __ASM_GENERIC_DELAY_H
3
Jonas Bonn30ab2b02011-07-02 10:29:24 +02004/* Undefined functions to get compile-time errors */
5extern void __bad_udelay(void);
6extern void __bad_ndelay(void);
7
Arnd Bergmannaafe4db2009-05-13 22:56:33 +00008extern void __udelay(unsigned long usecs);
Jonas Bonn30ab2b02011-07-02 10:29:24 +02009extern void __ndelay(unsigned long nsecs);
10extern void __const_udelay(unsigned long xloops);
Arnd Bergmannaafe4db2009-05-13 22:56:33 +000011extern void __delay(unsigned long loops);
12
Andrew Mortona87e5532011-07-18 15:28:20 +020013/*
14 * The weird n/20000 thing suppresses a "comparison is always false due to
15 * limited range of data type" warning with non-const 8-bit arguments.
16 */
17
Jonas Bonn30ab2b02011-07-02 10:29:24 +020018/* 0x10c7 is 2**32 / 1000000 (rounded up) */
Andrew Mortona87e5532011-07-18 15:28:20 +020019#define udelay(n) \
20 ({ \
21 if (__builtin_constant_p(n)) { \
22 if ((n) / 20000 >= 1) \
23 __bad_udelay(); \
24 else \
25 __const_udelay((n) * 0x10c7ul); \
26 } else { \
27 __udelay(n); \
28 } \
29 })
Jonas Bonn30ab2b02011-07-02 10:29:24 +020030
31/* 0x5 is 2**32 / 1000000000 (rounded up) */
Andrew Mortona87e5532011-07-18 15:28:20 +020032#define ndelay(n) \
33 ({ \
34 if (__builtin_constant_p(n)) { \
35 if ((n) / 20000 >= 1) \
36 __bad_ndelay(); \
37 else \
38 __const_udelay((n) * 5ul); \
39 } else { \
40 __ndelay(n); \
41 } \
42 })
Arnd Bergmannaafe4db2009-05-13 22:56:33 +000043
44#endif /* __ASM_GENERIC_DELAY_H */