Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / arch / unicore32 / include / asm / delay.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * linux/arch/unicore32/include/asm/delay.h
4  *
5  * Code specific to PKUnity SoC and UniCore ISA
6  *
7  * Copyright (C) 2001-2010 GUAN Xue-tao
8  *
9  * Delay routines, using a pre-computed "loops_per_second" value.
10  */
11 #ifndef __UNICORE_DELAY_H__
12 #define __UNICORE_DELAY_H__
13
14 #include <asm/param.h>  /* HZ */
15
16 extern void __delay(int loops);
17
18 /*
19  * This function intentionally does not exist; if you see references to
20  * it, it means that you're calling udelay() with an out of range value.
21  *
22  * With currently imposed limits, this means that we support a max delay
23  * of 2000us. Further limits: HZ<=1000 and bogomips<=3355
24  */
25 extern void __bad_udelay(void);
26
27 /*
28  * division by multiplication: you don't have to worry about
29  * loss of precision.
30  *
31  * Use only for very small delays ( < 1 msec).  Should probably use a
32  * lookup table, really, as the multiplications take much too long with
33  * short delays.  This is a "reasonable" implementation, though (and the
34  * first constant multiplications gets optimized away if the delay is
35  * a constant)
36  */
37 extern void __udelay(unsigned long usecs);
38 extern void __const_udelay(unsigned long);
39
40 #define MAX_UDELAY_MS 2
41
42 #define udelay(n)                                                       \
43         (__builtin_constant_p(n) ?                                      \
44           ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() :              \
45                         __const_udelay((n) * ((2199023U*HZ)>>11))) :    \
46           __udelay(n))
47
48 #endif /* __UNICORE_DELAY_H__ */
49