delay.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Precise Delay Loops for Meta
  3. *
  4. * Copyright (C) 1993 Linus Torvalds
  5. * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  6. * Copyright (C) 2007,2009 Imagination Technologies Ltd.
  7. *
  8. */
  9. #include <linux/export.h>
  10. #include <linux/sched.h>
  11. #include <linux/delay.h>
  12. #include <asm/core_reg.h>
  13. #include <asm/processor.h>
  14. /*
  15. * TXTACTCYC is only 24 bits, so on chips with fast clocks it will wrap
  16. * many times per-second. If it does wrap __delay will return prematurely,
  17. * but this is only likely with large delay values.
  18. *
  19. * We also can't implement read_current_timer() with TXTACTCYC due to
  20. * this wrapping behaviour.
  21. */
  22. #define rdtimer(t) t = __core_reg_get(TXTACTCYC)
  23. void __delay(unsigned long loops)
  24. {
  25. unsigned long bclock, now;
  26. rdtimer(bclock);
  27. do {
  28. asm("NOP");
  29. rdtimer(now);
  30. } while ((now-bclock) < loops);
  31. }
  32. EXPORT_SYMBOL(__delay);
  33. inline void __const_udelay(unsigned long xloops)
  34. {
  35. u64 loops = (u64)xloops * (u64)loops_per_jiffy * HZ;
  36. __delay(loops >> 32);
  37. }
  38. EXPORT_SYMBOL(__const_udelay);
  39. void __udelay(unsigned long usecs)
  40. {
  41. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  42. }
  43. EXPORT_SYMBOL(__udelay);
  44. void __ndelay(unsigned long nsecs)
  45. {
  46. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  47. }
  48. EXPORT_SYMBOL(__ndelay);