2 * Precise Delay Loops for S390
4 * Copyright IBM Corp. 1999, 2008
5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
6 * Heiko Carstens <heiko.carstens@de.ibm.com>,
9 #include <linux/sched.h>
10 #include <linux/delay.h>
11 #include <linux/timex.h>
12 #include <linux/module.h>
13 #include <linux/irqflags.h>
14 #include <linux/interrupt.h>
15 #include <asm/vtimer.h>
16 #include <asm/div64.h>
18 void __delay(unsigned long loops
)
21 * To end the bloody studid and useless discussion about the
22 * BogoMips number I took the liberty to define the __delay
23 * function in a way that that resulting BogoMips number will
24 * yield the megahertz number of the cpu. The important function
25 * is udelay and that is done using the tod clock. -- martin.
27 asm volatile("0: brct %0,0b" : : "d" ((loops
/2) + 1));
30 static void __udelay_disabled(unsigned long long usecs
)
32 unsigned long cr0
, cr6
, new;
35 end
= get_tod_clock() + (usecs
<< 12);
36 clock_saved
= local_tick_disable();
37 __ctl_store(cr0
, 0, 0);
38 __ctl_store(cr6
, 6, 6);
39 new = (cr0
& 0xffff00e0) | 0x00000800;
40 __ctl_load(new , 0, 0);
42 __ctl_load(new, 6, 6);
45 set_clock_comparator(end
);
48 } while (get_tod_clock() < end
);
50 __ctl_load(cr0
, 0, 0);
51 __ctl_load(cr6
, 6, 6);
52 local_tick_enable(clock_saved
);
55 static void __udelay_enabled(unsigned long long usecs
)
59 end
= get_tod_clock() + (usecs
<< 12);
62 if (end
< S390_lowcore
.clock_comparator
) {
63 clock_saved
= local_tick_disable();
64 set_clock_comparator(end
);
69 local_tick_enable(clock_saved
);
70 } while (get_tod_clock() < end
);
74 * Waits for 'usecs' microseconds using the TOD clock comparator.
76 void __udelay(unsigned long long usecs
)
81 local_irq_save(flags
);
83 __udelay_disabled(usecs
);
87 if (raw_irqs_disabled_flags(flags
))
88 __udelay_disabled(usecs
);
90 __udelay_enabled(usecs
);
93 if (raw_irqs_disabled_flags(flags
)) {
95 __udelay_disabled(usecs
);
99 __udelay_enabled(usecs
);
101 local_irq_restore(flags
);
104 EXPORT_SYMBOL(__udelay
);
107 * Simple udelay variant. To be used on startup and reboot
108 * when the interrupt handler isn't working.
110 void udelay_simple(unsigned long long usecs
)
114 end
= get_tod_clock() + (usecs
<< 12);
115 while (get_tod_clock() < end
)
119 void __ndelay(unsigned long long nsecs
)
125 end
= get_tod_clock() + nsecs
;
126 if (nsecs
& ~0xfffUL
)
127 __udelay(nsecs
>> 12);
128 while (get_tod_clock() < end
)
131 EXPORT_SYMBOL(__ndelay
);