delay.h 917 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * delay.h - delay functions
  3. *
  4. * Copyright (c) 2004-2007 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef __ASM_DELAY_H__
  9. #define __ASM_DELAY_H__
  10. #include <mach/anomaly.h>
  11. static inline void __delay(unsigned long loops)
  12. {
  13. __asm__ __volatile__ (
  14. "LSETUP(1f, 1f) LC0 = %0;"
  15. "1: NOP;"
  16. :
  17. : "a" (loops)
  18. : "LT0", "LB0", "LC0"
  19. );
  20. }
  21. #include <linux/param.h> /* needed for HZ */
  22. /*
  23. * close approximation borrowed from m68knommu to avoid 64-bit math
  24. */
  25. #define HZSCALE (268435456 / (1000000/HZ))
  26. static inline unsigned long __to_delay(unsigned long scale)
  27. {
  28. extern unsigned long loops_per_jiffy;
  29. return (((scale * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6;
  30. }
  31. static inline void udelay(unsigned long usecs)
  32. {
  33. __delay(__to_delay(usecs));
  34. }
  35. static inline void ndelay(unsigned long nsecs)
  36. {
  37. __delay(__to_delay(1) * nsecs / 1000);
  38. }
  39. #define ndelay ndelay
  40. #endif