xref: /openbmc/linux/arch/s390/lib/delay.c (revision faffb083)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *    Precise Delay Loops for S390
4  *
5  *    Copyright IBM Corp. 1999, 2008
6  *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
7  */
8 
9 #include <linux/processor.h>
10 #include <linux/delay.h>
11 #include <asm/div64.h>
12 #include <asm/timex.h>
13 
14 void __delay(unsigned long loops)
15 {
16 	/*
17 	 * Loop 'loops' times. Callers must not assume a specific
18 	 * amount of time passes before this function returns.
19 	 */
20 	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
21 }
22 EXPORT_SYMBOL(__delay);
23 
24 static void delay_loop(unsigned long delta)
25 {
26 	unsigned long end;
27 
28 	end = get_tod_clock_monotonic() + delta;
29 	while (!tod_after(get_tod_clock_monotonic(), end))
30 		cpu_relax();
31 }
32 
33 void __udelay(unsigned long usecs)
34 {
35 	delay_loop(usecs << 12);
36 }
37 EXPORT_SYMBOL(__udelay);
38 
39 void __ndelay(unsigned long nsecs)
40 {
41 	nsecs <<= 9;
42 	do_div(nsecs, 125);
43 	delay_loop(nsecs);
44 }
45 EXPORT_SYMBOL(__ndelay);
46