Merge tag 'for-linus-5.18-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / arch / s390 / lib / delay.c
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          * To end the bloody studid and useless discussion about the
18          * BogoMips number I took the liberty to define the __delay
19          * function in a way that that resulting BogoMips number will
20          * yield the megahertz number of the cpu. The important function
21          * is udelay and that is done using the tod clock. -- martin.
22          */
23         asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
24 }
25 EXPORT_SYMBOL(__delay);
26
27 static void delay_loop(unsigned long delta)
28 {
29         unsigned long end;
30
31         end = get_tod_clock_monotonic() + delta;
32         while (!tod_after(get_tod_clock_monotonic(), end))
33                 cpu_relax();
34 }
35
36 void __udelay(unsigned long usecs)
37 {
38         delay_loop(usecs << 12);
39 }
40 EXPORT_SYMBOL(__udelay);
41
42 void __ndelay(unsigned long nsecs)
43 {
44         nsecs <<= 9;
45         do_div(nsecs, 125);
46         delay_loop(nsecs);
47 }
48 EXPORT_SYMBOL(__ndelay);