Merge tag 'hwmon-for-v6.13-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / arch / loongarch / lib / delay.c
blob831d4761f385a48dc59041baed79025b111d5c49
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4 */
5 #include <linux/delay.h>
6 #include <linux/export.h>
7 #include <linux/smp.h>
8 #include <linux/timex.h>
10 #include <asm/processor.h>
12 void __delay(unsigned long cycles)
14 u64 t0 = get_cycles();
16 while ((unsigned long)(get_cycles() - t0) < cycles)
17 cpu_relax();
19 EXPORT_SYMBOL(__delay);
22 * Division by multiplication: you don't have to worry about
23 * loss of precision.
25 * Use only for very small delays ( < 1 msec). Should probably use a
26 * lookup table, really, as the multiplications take much too long with
27 * short delays. This is a "reasonable" implementation, though (and the
28 * first constant multiplications gets optimized away if the delay is
29 * a constant)
32 void __udelay(unsigned long us)
34 __delay((us * 0x000010c7ull * HZ * lpj_fine) >> 32);
36 EXPORT_SYMBOL(__udelay);
38 void __ndelay(unsigned long ns)
40 __delay((ns * 0x00000005ull * HZ * lpj_fine) >> 32);
42 EXPORT_SYMBOL(__ndelay);