• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   *		 Heiko Carstens <heiko.carstens@de.ibm.com>,
8   */
9  
10  #include <linux/processor.h>
11  #include <linux/delay.h>
12  #include <asm/div64.h>
13  #include <asm/timex.h>
14  
__delay(unsigned long loops)15  void __delay(unsigned long loops)
16  {
17          /*
18           * To end the bloody studid and useless discussion about the
19           * BogoMips number I took the liberty to define the __delay
20           * function in a way that that resulting BogoMips number will
21           * yield the megahertz number of the cpu. The important function
22           * is udelay and that is done using the tod clock. -- martin.
23           */
24  	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
25  }
26  EXPORT_SYMBOL(__delay);
27  
delay_loop(unsigned long delta)28  static void delay_loop(unsigned long delta)
29  {
30  	unsigned long end;
31  
32  	end = get_tod_clock_monotonic() + delta;
33  	while (!tod_after(get_tod_clock_monotonic(), end))
34  		cpu_relax();
35  }
36  
__udelay(unsigned long usecs)37  void __udelay(unsigned long usecs)
38  {
39  	delay_loop(usecs << 12);
40  }
41  EXPORT_SYMBOL(__udelay);
42  
__ndelay(unsigned long nsecs)43  void __ndelay(unsigned long nsecs)
44  {
45  	nsecs <<= 9;
46  	do_div(nsecs, 125);
47  	delay_loop(nsecs);
48  }
49  EXPORT_SYMBOL(__ndelay);
50