delay.c 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <[email protected]>,
  7. */
  8. #include <linux/processor.h>
  9. #include <linux/delay.h>
  10. #include <asm/div64.h>
  11. #include <asm/timex.h>
  12. void __delay(unsigned long loops)
  13. {
  14. /*
  15. * Loop 'loops' times. Callers must not assume a specific
  16. * amount of time passes before this function returns.
  17. */
  18. asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
  19. }
  20. EXPORT_SYMBOL(__delay);
  21. static void delay_loop(unsigned long delta)
  22. {
  23. unsigned long end;
  24. end = get_tod_clock_monotonic() + delta;
  25. while (!tod_after(get_tod_clock_monotonic(), end))
  26. cpu_relax();
  27. }
  28. void __udelay(unsigned long usecs)
  29. {
  30. delay_loop(usecs << 12);
  31. }
  32. EXPORT_SYMBOL(__udelay);
  33. void __ndelay(unsigned long nsecs)
  34. {
  35. nsecs <<= 9;
  36. do_div(nsecs, 125);
  37. delay_loop(nsecs);
  38. }
  39. EXPORT_SYMBOL(__ndelay);