delay.c 762 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * delay loops
  3. *
  4. * Copyright (C) 2015 Yoshinori Sato
  5. */
  6. #include <linux/module.h>
  7. #include <linux/delay.h>
  8. #include <asm/param.h>
  9. #include <asm/processor.h>
  10. #include <asm/timex.h>
  11. void __delay(unsigned long cycles)
  12. {
  13. __asm__ volatile ("1: dec.l #1,%0\n\t"
  14. "bne 1b":"=r"(cycles):"0"(cycles));
  15. }
  16. EXPORT_SYMBOL(__delay);
  17. void __const_udelay(unsigned long xloops)
  18. {
  19. u64 loops;
  20. loops = (u64)xloops * loops_per_jiffy * HZ;
  21. __delay(loops >> 32);
  22. }
  23. EXPORT_SYMBOL(__const_udelay);
  24. void __udelay(unsigned long usecs)
  25. {
  26. __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  27. }
  28. EXPORT_SYMBOL(__udelay);
  29. void __ndelay(unsigned long nsecs)
  30. {
  31. __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  32. }
  33. EXPORT_SYMBOL(__ndelay);