blob: f1e39c7f743947fbd34bad72a518d8ed5f5bd5ef [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/* Copyright Altera Corporation (C) 2014. All rights reserved.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00003 */
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);