delay.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * OpenRISC Linux
  3. *
  4. * Linux architectural port borrowing liberally from similar works of
  5. * others. All original copyrights apply as per the original source
  6. * declaration.
  7. *
  8. * Modifications for the OpenRISC architecture:
  9. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * version 2 as published by the Free Software Foundation
  14. *
  15. * Precise Delay Loops
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/export.h>
  19. #include <linux/init.h>
  20. #include <asm/param.h>
  21. #include <asm/delay.h>
  22. #include <asm/timex.h>
  23. #include <asm/processor.h>
  24. int read_current_timer(unsigned long *timer_value)
  25. {
  26. *timer_value = get_cycles();
  27. return 0;
  28. }
  29. void __delay(unsigned long cycles)
  30. {
  31. cycles_t start = get_cycles();
  32. while ((get_cycles() - start) < cycles)
  33. cpu_relax();
  34. }
  35. EXPORT_SYMBOL(__delay);
  36. inline void __const_udelay(unsigned long xloops)
  37. {
  38. unsigned long long loops;
  39. loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
  40. __delay(loops >> 32);
  41. }
  42. EXPORT_SYMBOL(__const_udelay);
  43. void __udelay(unsigned long usecs)
  44. {
  45. __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  46. }
  47. EXPORT_SYMBOL(__udelay);
  48. void __ndelay(unsigned long nsecs)
  49. {
  50. __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  51. }
  52. EXPORT_SYMBOL(__ndelay);