Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *    Precise Delay Loops for S390
0004  *
0005  *    Copyright IBM Corp. 1999, 2008
0006  *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
0007  */
0008 
0009 #include <linux/processor.h>
0010 #include <linux/delay.h>
0011 #include <asm/div64.h>
0012 #include <asm/timex.h>
0013 
0014 void __delay(unsigned long loops)
0015 {
0016         /*
0017          * To end the bloody studid and useless discussion about the
0018          * BogoMips number I took the liberty to define the __delay
0019          * function in a way that that resulting BogoMips number will
0020          * yield the megahertz number of the cpu. The important function
0021          * is udelay and that is done using the tod clock. -- martin.
0022          */
0023     asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
0024 }
0025 EXPORT_SYMBOL(__delay);
0026 
0027 static void delay_loop(unsigned long delta)
0028 {
0029     unsigned long end;
0030 
0031     end = get_tod_clock_monotonic() + delta;
0032     while (!tod_after(get_tod_clock_monotonic(), end))
0033         cpu_relax();
0034 }
0035 
0036 void __udelay(unsigned long usecs)
0037 {
0038     delay_loop(usecs << 12);
0039 }
0040 EXPORT_SYMBOL(__udelay);
0041 
0042 void __ndelay(unsigned long nsecs)
0043 {
0044     nsecs <<= 9;
0045     do_div(nsecs, 125);
0046     delay_loop(nsecs);
0047 }
0048 EXPORT_SYMBOL(__ndelay);