delay.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 1995-2004 Russell King
  3. *
  4. * Delay routines, using a pre-computed "loops_per_second" value.
  5. */
  6. #ifndef __ASM_ARM_DELAY_H
  7. #define __ASM_ARM_DELAY_H
  8. #include <asm/memory.h>
  9. #include <asm/param.h> /* HZ */
  10. /*
  11. * Loop (or tick) based delay:
  12. *
  13. * loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec
  14. *
  15. * where:
  16. *
  17. * jiffies_per_sec = HZ
  18. * us_per_sec = 1000000
  19. *
  20. * Therefore the constant part is HZ / 1000000 which is a small
  21. * fractional number. To make this usable with integer math, we
  22. * scale up this constant by 2^31, perform the actual multiplication,
  23. * and scale the result back down by 2^31 with a simple shift:
  24. *
  25. * loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 31
  26. *
  27. * where:
  28. *
  29. * UDELAY_MULT = 2^31 * HZ / 1000000
  30. * = (2^31 / 1000000) * HZ
  31. * = 2147.483648 * HZ
  32. * = 2147 * HZ + 483648 * HZ / 1000000
  33. *
  34. * 31 is the biggest scale shift value that won't overflow 32 bits for
  35. * delay_us * UDELAY_MULT assuming HZ <= 1000 and delay_us <= 2000.
  36. */
  37. #define MAX_UDELAY_MS 2
  38. #define UDELAY_MULT UL(2147 * HZ + 483648 * HZ / 1000000)
  39. #define UDELAY_SHIFT 31
  40. #ifndef __ASSEMBLY__
  41. struct delay_timer {
  42. unsigned long (*read_current_timer)(void);
  43. unsigned long freq;
  44. };
  45. extern struct arm_delay_ops {
  46. void (*delay)(unsigned long);
  47. void (*const_udelay)(unsigned long);
  48. void (*udelay)(unsigned long);
  49. unsigned long ticks_per_jiffy;
  50. } arm_delay_ops;
  51. #define __delay(n) arm_delay_ops.delay(n)
  52. /*
  53. * This function intentionally does not exist; if you see references to
  54. * it, it means that you're calling udelay() with an out of range value.
  55. *
  56. * With currently imposed limits, this means that we support a max delay
  57. * of 2000us. Further limits: HZ<=1000
  58. */
  59. extern void __bad_udelay(void);
  60. /*
  61. * division by multiplication: you don't have to worry about
  62. * loss of precision.
  63. *
  64. * Use only for very small delays ( < 2 msec). Should probably use a
  65. * lookup table, really, as the multiplications take much too long with
  66. * short delays. This is a "reasonable" implementation, though (and the
  67. * first constant multiplications gets optimized away if the delay is
  68. * a constant)
  69. */
  70. #define __udelay(n) arm_delay_ops.udelay(n)
  71. #define __const_udelay(n) arm_delay_ops.const_udelay(n)
  72. #define udelay(n) \
  73. (__builtin_constant_p(n) ? \
  74. ((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
  75. __const_udelay((n) * UDELAY_MULT)) : \
  76. __udelay(n))
  77. /* Loop-based definitions for assembly code. */
  78. extern void __loop_delay(unsigned long loops);
  79. extern void __loop_udelay(unsigned long usecs);
  80. extern void __loop_const_udelay(unsigned long);
  81. /* Delay-loop timer registration. */
  82. #define ARCH_HAS_READ_CURRENT_TIMER
  83. extern void register_current_timer_delay(const struct delay_timer *timer);
  84. #endif /* __ASSEMBLY__ */
  85. #endif /* defined(_ARM_DELAY_H) */