delay.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _M68K_DELAY_H
  2. #define _M68K_DELAY_H
  3. #include <asm/param.h>
  4. /*
  5. * Copyright (C) 1994 Hamish Macdonald
  6. * Copyright (C) 2004 Greg Ungerer <gerg@uclinux.com>
  7. *
  8. * Delay routines, using a pre-computed "loops_per_jiffy" value.
  9. */
  10. #if defined(CONFIG_COLDFIRE)
  11. /*
  12. * The ColdFire runs the delay loop at significantly different speeds
  13. * depending upon long word alignment or not. We'll pad it to
  14. * long word alignment which is the faster version.
  15. * The 0x4a8e is of course a 'tstl %fp' instruction. This is better
  16. * than using a NOP (0x4e71) instruction because it executes in one
  17. * cycle not three and doesn't allow for an arbitrary delay waiting
  18. * for bus cycles to finish. Also fp/a6 isn't likely to cause a
  19. * stall waiting for the register to become valid if such is added
  20. * to the coldfire at some stage.
  21. */
  22. #define DELAY_ALIGN ".balignw 4, 0x4a8e\n\t"
  23. #else
  24. /*
  25. * No instruction alignment required for other m68k types.
  26. */
  27. #define DELAY_ALIGN
  28. #endif
  29. static inline void __delay(unsigned long loops)
  30. {
  31. __asm__ __volatile__ (
  32. DELAY_ALIGN
  33. "1: subql #1,%0\n\t"
  34. "jcc 1b"
  35. : "=d" (loops)
  36. : "0" (loops));
  37. }
  38. extern void __bad_udelay(void);
  39. #ifdef CONFIG_CPU_HAS_NO_MULDIV64
  40. /*
  41. * The simpler m68k and ColdFire processors do not have a 32*32->64
  42. * multiply instruction. So we need to handle them a little differently.
  43. * We use a bit of shifting and a single 32*32->32 multiply to get close.
  44. * This is a macro so that the const version can factor out the first
  45. * multiply and shift.
  46. */
  47. #define HZSCALE (268435456 / (1000000 / HZ))
  48. #define __const_udelay(u) \
  49. __delay(((((u) * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6)
  50. #else
  51. static inline void __xdelay(unsigned long xloops)
  52. {
  53. unsigned long tmp;
  54. __asm__ ("mulul %2,%0:%1"
  55. : "=d" (xloops), "=d" (tmp)
  56. : "d" (xloops), "1" (loops_per_jiffy));
  57. __delay(xloops * HZ);
  58. }
  59. /*
  60. * The definition of __const_udelay is specifically made a macro so that
  61. * the const factor (4295 = 2**32 / 1000000) can be optimized out when
  62. * the delay is a const.
  63. */
  64. #define __const_udelay(n) (__xdelay((n) * 4295))
  65. #endif
  66. static inline void __udelay(unsigned long usecs)
  67. {
  68. __const_udelay(usecs);
  69. }
  70. /*
  71. * Use only for very small delays ( < 1 msec). Should probably use a
  72. * lookup table, really, as the multiplications take much too long with
  73. * short delays. This is a "reasonable" implementation, though (and the
  74. * first constant multiplications gets optimized away if the delay is
  75. * a constant)
  76. */
  77. #define udelay(n) (__builtin_constant_p(n) ? \
  78. ((n) > 20000 ? __bad_udelay() : __const_udelay(n)) : __udelay(n))
  79. /*
  80. * nanosecond delay:
  81. *
  82. * ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6) is the number of loops
  83. * per microsecond
  84. *
  85. * 1000 / ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6) is the number of
  86. * nanoseconds per loop
  87. *
  88. * So n / ( 1000 / ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6) ) would
  89. * be the number of loops for n nanoseconds
  90. */
  91. /*
  92. * The simpler m68k and ColdFire processors do not have a 32*32->64
  93. * multiply instruction. So we need to handle them a little differently.
  94. * We use a bit of shifting and a single 32*32->32 multiply to get close.
  95. * This is a macro so that the const version can factor out the first
  96. * multiply and shift.
  97. */
  98. #define HZSCALE (268435456 / (1000000 / HZ))
  99. #define ndelay(n) __delay(DIV_ROUND_UP((n) * ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6), 1000));
  100. #endif /* defined(_M68K_DELAY_H) */