1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2008 Michal Simek
4 * Copyright (C) 2007 John Williams
5 * Copyright (C) 2006 Atmark Techno, Inc.
8 #ifndef _ASM_MICROBLAZE_DELAY_H
9 #define _ASM_MICROBLAZE_DELAY_H
11 #include <linux/param.h>
13 static inline void __delay(unsigned long loops
)
15 asm volatile ("# __delay \n\t" \
16 "1: addi %0, %0, -1\t\n" \
24 * Note that 19 * 226 == 4294 ==~ 2^32 / 10^6, so
25 * loops = (4294 * usecs * loops_per_jiffy * HZ) / 2^32.
27 * The mul instruction gives us loops = (a * b) / 2^32.
28 * We choose a = usecs * 19 * HZ and b = loops_per_jiffy * 226
29 * because this lets us support a wide range of HZ and
30 * loops_per_jiffy values without either a or b overflowing 2^32.
31 * Thus we need usecs * HZ <= (2^32 - 1) / 19 = 226050910 and
32 * loops_per_jiffy <= (2^32 - 1) / 226 = 19004280
33 * (which corresponds to ~3800 bogomips at HZ = 100).
36 #define __MAX_UDELAY (226050910UL/HZ) /* maximum udelay argument */
37 #define __MAX_NDELAY (4294967295UL/HZ) /* maximum ndelay argument */
39 extern unsigned long loops_per_jiffy
;
41 static inline void __udelay(unsigned int x
)
44 unsigned long long tmp
=
45 (unsigned long long)x
* (unsigned long long)loops_per_jiffy \
47 unsigned loops
= tmp
>> 32;
50 __asm__("mulxuu %0,%1,%2" : "=r" (loops) :
51 "r" (x), "r" (loops_per_jiffy * 226));
56 extern void __bad_udelay(void); /* deliberately undefined */
57 extern void __bad_ndelay(void); /* deliberately undefined */
61 if (__builtin_constant_p(n)) { \
62 if ((n) / __MAX_UDELAY >= 1) \
65 __udelay((n) * (19 * HZ)); \
67 __udelay((n) * (19 * HZ)); \
73 if (__builtin_constant_p(n)) { \
74 if ((n) / __MAX_NDELAY >= 1) \
83 #define muldiv(a, b, c) (((a)*(b))/(c))
85 #endif /* _ASM_MICROBLAZE_DELAY_H */