1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
5 #include <linux/delay.h>
6 #include <linux/export.h>
8 #include <linux/timex.h>
10 #include <asm/compiler.h>
11 #include <asm/processor.h>
13 void __delay(unsigned long cycles)
15 u64 t0 = get_cycles();
17 while ((unsigned long)(get_cycles() - t0) < cycles)
20 EXPORT_SYMBOL(__delay);
23 * Division by multiplication: you don't have to worry about
26 * Use only for very small delays ( < 1 msec). Should probably use a
27 * lookup table, really, as the multiplications take much too long with
28 * short delays. This is a "reasonable" implementation, though (and the
29 * first constant multiplications gets optimized away if the delay is
33 void __udelay(unsigned long us)
35 __delay((us * 0x000010c7ull * HZ * lpj_fine) >> 32);
37 EXPORT_SYMBOL(__udelay);
39 void __ndelay(unsigned long ns)
41 __delay((ns * 0x00000005ull * HZ * lpj_fine) >> 32);
43 EXPORT_SYMBOL(__ndelay);