18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __ASM_GENERIC_DELAY_H 38c2ecf20Sopenharmony_ci#define __ASM_GENERIC_DELAY_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* Undefined functions to get compile-time errors */ 68c2ecf20Sopenharmony_ciextern void __bad_udelay(void); 78c2ecf20Sopenharmony_ciextern void __bad_ndelay(void); 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciextern void __udelay(unsigned long usecs); 108c2ecf20Sopenharmony_ciextern void __ndelay(unsigned long nsecs); 118c2ecf20Sopenharmony_ciextern void __const_udelay(unsigned long xloops); 128c2ecf20Sopenharmony_ciextern void __delay(unsigned long loops); 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* 158c2ecf20Sopenharmony_ci * The weird n/20000 thing suppresses a "comparison is always false due to 168c2ecf20Sopenharmony_ci * limited range of data type" warning with non-const 8-bit arguments. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* 0x10c7 is 2**32 / 1000000 (rounded up) */ 208c2ecf20Sopenharmony_ci#define udelay(n) \ 218c2ecf20Sopenharmony_ci ({ \ 228c2ecf20Sopenharmony_ci if (__builtin_constant_p(n)) { \ 238c2ecf20Sopenharmony_ci if ((n) / 20000 >= 1) \ 248c2ecf20Sopenharmony_ci __bad_udelay(); \ 258c2ecf20Sopenharmony_ci else \ 268c2ecf20Sopenharmony_ci __const_udelay((n) * 0x10c7ul); \ 278c2ecf20Sopenharmony_ci } else { \ 288c2ecf20Sopenharmony_ci __udelay(n); \ 298c2ecf20Sopenharmony_ci } \ 308c2ecf20Sopenharmony_ci }) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* 0x5 is 2**32 / 1000000000 (rounded up) */ 338c2ecf20Sopenharmony_ci#define ndelay(n) \ 348c2ecf20Sopenharmony_ci ({ \ 358c2ecf20Sopenharmony_ci if (__builtin_constant_p(n)) { \ 368c2ecf20Sopenharmony_ci if ((n) / 20000 >= 1) \ 378c2ecf20Sopenharmony_ci __bad_ndelay(); \ 388c2ecf20Sopenharmony_ci else \ 398c2ecf20Sopenharmony_ci __const_udelay((n) * 5ul); \ 408c2ecf20Sopenharmony_ci } else { \ 418c2ecf20Sopenharmony_ci __ndelay(n); \ 428c2ecf20Sopenharmony_ci } \ 438c2ecf20Sopenharmony_ci }) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#endif /* __ASM_GENERIC_DELAY_H */ 46