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/processor.h>
12 void __delay(unsigned long cycles
)
14 u64 t0
= get_cycles();
16 while ((unsigned long)(get_cycles() - t0
) < cycles
)
19 EXPORT_SYMBOL(__delay
);
22 * Division by multiplication: you don't have to worry about
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
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
);