1 // SPDX-License-Identifier: GPL-2.0
3 * Precise Delay Loops for S390
5 * Copyright IBM Corp. 1999, 2008
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 * Heiko Carstens <heiko.carstens@de.ibm.com>,
10 #include <linux/sched.h>
11 #include <linux/delay.h>
12 #include <linux/timex.h>
13 #include <linux/export.h>
14 #include <linux/irqflags.h>
15 #include <linux/interrupt.h>
16 #include <linux/jump_label.h>
17 #include <linux/irq.h>
18 #include <asm/vtimer.h>
19 #include <asm/div64.h>
22 static DEFINE_STATIC_KEY_FALSE(udelay_ready);
24 void __init udelay_enable(void)
26 static_branch_enable(&udelay_ready);
29 void __delay(unsigned long loops)
32 * To end the bloody studid and useless discussion about the
33 * BogoMips number I took the liberty to define the __delay
34 * function in a way that that resulting BogoMips number will
35 * yield the megahertz number of the cpu. The important function
36 * is udelay and that is done using the tod clock. -- martin.
38 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
40 EXPORT_SYMBOL(__delay);
42 static void delay_loop(unsigned long delta, bool simple)
46 if (static_branch_likely(&udelay_ready) && !simple) {
47 end = get_tod_clock_monotonic() + delta;
48 while (!tod_after(get_tod_clock_monotonic(), end))
51 end = get_tod_clock() + delta;
52 while (!tod_after(get_tod_clock(), end))
57 void __udelay(unsigned long usecs)
59 delay_loop(usecs << 12, 0);
61 EXPORT_SYMBOL(__udelay);
64 * Simple udelay variant. To be used on startup and reboot
65 * when the interrupt handler isn't working.
67 void udelay_simple(unsigned long usecs)
69 delay_loop(usecs << 12, 1);
72 void __ndelay(unsigned long nsecs)
78 EXPORT_SYMBOL(__ndelay);