^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __ASM_GENERIC_DELAY_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __ASM_GENERIC_DELAY_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /* Undefined functions to get compile-time errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) extern void __bad_udelay(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) extern void __bad_ndelay(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) extern void __udelay(unsigned long usecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) extern void __ndelay(unsigned long nsecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) extern void __const_udelay(unsigned long xloops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) extern void __delay(unsigned long loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * The weird n/20000 thing suppresses a "comparison is always false due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * limited range of data type" warning with non-const 8-bit arguments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* 0x10c7 is 2**32 / 1000000 (rounded up) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define udelay(n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) if (__builtin_constant_p(n)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if ((n) / 20000 >= 1) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) __bad_udelay(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) else \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) __const_udelay((n) * 0x10c7ul); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) } else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) __udelay(n); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* 0x5 is 2**32 / 1000000000 (rounded up) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define ndelay(n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (__builtin_constant_p(n)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if ((n) / 20000 >= 1) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) __bad_ndelay(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) else \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __const_udelay((n) * 5ul); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) } else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __ndelay(n); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif /* __ASM_GENERIC_DELAY_H */