1// SPDX-License-Identifier: GPL-2.0-only
2/* Copyright Altera Corporation (C) 2014. All rights reserved.
3 */
4
5#include <linux/module.h>
6#include <asm/delay.h>
7#include <asm/param.h>
8#include <asm/processor.h>
9#include <asm/timex.h>
10
11void __delay(unsigned long cycles)
12{
13 cycles_t start = get_cycles();
14
15 while ((get_cycles() - start) < cycles)
16 cpu_relax();
17}
18EXPORT_SYMBOL(__delay);
19
20void __const_udelay(unsigned long xloops)
21{
22 u64 loops;
23
24 loops = (u64)xloops * loops_per_jiffy * HZ;
25
26 __delay(loops >> 32);
27}
28EXPORT_SYMBOL(__const_udelay);
29
30void __udelay(unsigned long usecs)
31{
32 __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
33}
34EXPORT_SYMBOL(__udelay);
35
36void __ndelay(unsigned long nsecs)
37{
38 __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
39}
40EXPORT_SYMBOL(__ndelay);
41

source code of linux/arch/nios2/lib/delay.c