delay.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Precise Delay Loops for SuperH
  4. *
  5. * Copyright (C) 1999 Niibe Yutaka & Kaz Kojima
  6. */
  7. #include <linux/sched.h>
  8. #include <linux/delay.h>
  9. void __delay(unsigned long loops)
  10. {
  11. __asm__ __volatile__(
  12. /*
  13. * ST40-300 appears to have an issue with this code,
  14. * normally taking two cycles each loop, as with all
  15. * other SH variants. If however the branch and the
  16. * delay slot straddle an 8 byte boundary, this increases
  17. * to 3 cycles.
  18. * This align directive ensures this doesn't occur.
  19. */
  20. ".balign 8\n\t"
  21. "tst %0, %0\n\t"
  22. "1:\t"
  23. "bf/s 1b\n\t"
  24. " dt %0"
  25. : "=r" (loops)
  26. : "0" (loops)
  27. : "t");
  28. }
  29. inline void __const_udelay(unsigned long xloops)
  30. {
  31. xloops *= 4;
  32. __asm__("dmulu.l %0, %2\n\t"
  33. "sts mach, %0"
  34. : "=r" (xloops)
  35. : "0" (xloops),
  36. "r" (cpu_data[raw_smp_processor_id()].loops_per_jiffy * (HZ/4))
  37. : "macl", "mach");
  38. __delay(++xloops);
  39. }
  40. void __udelay(unsigned long usecs)
  41. {
  42. __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
  43. }
  44. void __ndelay(unsigned long nsecs)
  45. {
  46. __const_udelay(nsecs * 0x00000005);
  47. }