xref: /openbmc/linux/arch/nios2/lib/delay.c (revision e3b9f1e8)
1 /* Copyright Altera Corporation (C) 2014. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License, version 2,
5  * as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
14  *
15  */
16 
17 #include <linux/module.h>
18 #include <asm/delay.h>
19 #include <asm/param.h>
20 #include <asm/processor.h>
21 #include <asm/timex.h>
22 
23 void __delay(unsigned long cycles)
24 {
25 	cycles_t start = get_cycles();
26 
27 	while ((get_cycles() - start) < cycles)
28 		cpu_relax();
29 }
30 EXPORT_SYMBOL(__delay);
31 
32 void __const_udelay(unsigned long xloops)
33 {
34 	u64 loops;
35 
36 	loops = (u64)xloops * loops_per_jiffy * HZ;
37 
38 	__delay(loops >> 32);
39 }
40 EXPORT_SYMBOL(__const_udelay);
41 
42 void __udelay(unsigned long usecs)
43 {
44 	__const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
45 }
46 EXPORT_SYMBOL(__udelay);
47 
48 void __ndelay(unsigned long nsecs)
49 {
50 	__const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
51 }
52 EXPORT_SYMBOL(__ndelay);
53