delay.c 814 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright Altera Corporation (C) 2014. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <asm/delay.h>
  6. #include <asm/param.h>
  7. #include <asm/processor.h>
  8. #include <asm/timex.h>
  9. void __delay(unsigned long cycles)
  10. {
  11. cycles_t start = get_cycles();
  12. while ((get_cycles() - start) < cycles)
  13. cpu_relax();
  14. }
  15. EXPORT_SYMBOL(__delay);
  16. void __const_udelay(unsigned long xloops)
  17. {
  18. u64 loops;
  19. loops = (u64)xloops * loops_per_jiffy * HZ;
  20. __delay(loops >> 32);
  21. }
  22. EXPORT_SYMBOL(__const_udelay);
  23. void __udelay(unsigned long usecs)
  24. {
  25. __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  26. }
  27. EXPORT_SYMBOL(__udelay);
  28. void __ndelay(unsigned long nsecs)
  29. {
  30. __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  31. }
  32. EXPORT_SYMBOL(__ndelay);