delay.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/module.h>
  19. #include <linux/init.h>
  20. #include <asm/delay.h>
  21. #include <asm/timex.h>
  22. #include <asm/processor.h>
  23. int read_current_timer(unsigned long *timer_value)
  24. {
  25. *timer_value = mfspr(SPR_TTCR);
  26. return 0;
  27. }
  28. void __delay(unsigned long cycles)
  29. {
  30. cycles_t start = get_cycles();
  31. while ((get_cycles() - start) < cycles)
  32. cpu_relax();
  33. }
  34. EXPORT_SYMBOL(__delay);
  35. inline void __const_udelay(unsigned long xloops)
  36. {
  37. unsigned long long loops;
  38. loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
  39. __delay(loops >> 32);
  40. }
  41. EXPORT_SYMBOL(__const_udelay);
  42. void __udelay(unsigned long usecs)
  43. {
  44. __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  45. }
  46. EXPORT_SYMBOL(__udelay);
  47. void __ndelay(unsigned long nsecs)
  48. {
  49. __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  50. }
  51. EXPORT_SYMBOL(__ndelay);