delay.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OpenRISC Linux
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * Modifications for the OpenRISC architecture:
  10. * Copyright (C) 2010-2011 Jonas Bonn <[email protected]>
  11. *
  12. * Precise Delay Loops
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/export.h>
  16. #include <linux/init.h>
  17. #include <linux/timex.h>
  18. #include <asm/param.h>
  19. #include <asm/delay.h>
  20. #include <asm/timex.h>
  21. #include <asm/processor.h>
  22. int read_current_timer(unsigned long *timer_value)
  23. {
  24. *timer_value = get_cycles();
  25. return 0;
  26. }
  27. void __delay(unsigned long cycles)
  28. {
  29. cycles_t start = get_cycles();
  30. while ((get_cycles() - start) < cycles)
  31. cpu_relax();
  32. }
  33. EXPORT_SYMBOL(__delay);
  34. inline void __const_udelay(unsigned long xloops)
  35. {
  36. unsigned long long loops;
  37. loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
  38. __delay(loops >> 32);
  39. }
  40. EXPORT_SYMBOL(__const_udelay);
  41. void __udelay(unsigned long usecs)
  42. {
  43. __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  44. }
  45. EXPORT_SYMBOL(__udelay);
  46. void __ndelay(unsigned long nsecs)
  47. {
  48. __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  49. }
  50. EXPORT_SYMBOL(__ndelay);