delay.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * include/asm-xtensa/delay.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. *
  10. */
  11. #ifndef _XTENSA_DELAY_H
  12. #define _XTENSA_DELAY_H
  13. #include <asm/timex.h>
  14. #include <asm/param.h>
  15. extern unsigned long loops_per_jiffy;
  16. static inline void __delay(unsigned long loops)
  17. {
  18. if (__builtin_constant_p(loops) && loops < 2)
  19. __asm__ __volatile__ ("nop");
  20. else if (loops >= 2)
  21. /* 2 cycles per loop. */
  22. __asm__ __volatile__ ("1: addi %0, %0, -2; bgeui %0, 2, 1b"
  23. : "+r" (loops));
  24. }
  25. /* Undefined function to get compile-time error */
  26. void __bad_udelay(void);
  27. void __bad_ndelay(void);
  28. #define __MAX_UDELAY 30000
  29. #define __MAX_NDELAY 30000
  30. static inline void __udelay(unsigned long usecs)
  31. {
  32. unsigned long start = get_ccount();
  33. unsigned long cycles = (usecs * (ccount_freq >> 15)) >> 5;
  34. /* Note: all variables are unsigned (can wrap around)! */
  35. while (((unsigned long)get_ccount()) - start < cycles)
  36. cpu_relax();
  37. }
  38. static inline void udelay(unsigned long usec)
  39. {
  40. if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY)
  41. __bad_udelay();
  42. else
  43. __udelay(usec);
  44. }
  45. static inline void __ndelay(unsigned long nsec)
  46. {
  47. /*
  48. * Inner shift makes sure multiplication doesn't overflow
  49. * for legitimate nsec values
  50. */
  51. unsigned long cycles = (nsec * (ccount_freq >> 15)) >> 15;
  52. __delay(cycles);
  53. }
  54. #define ndelay(n) ndelay(n)
  55. static inline void ndelay(unsigned long nsec)
  56. {
  57. if (__builtin_constant_p(nsec) && nsec >= __MAX_NDELAY)
  58. __bad_ndelay();
  59. else
  60. __ndelay(nsec);
  61. }
  62. #endif