delay_no.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef _M68KNOMMU_DELAY_H
  2. #define _M68KNOMMU_DELAY_H
  3. /*
  4. * Copyright (C) 1994 Hamish Macdonald
  5. * Copyright (C) 2004 Greg Ungerer <gerg@snapgear.com>
  6. */
  7. #include <asm/param.h>
  8. static inline void __delay(unsigned long loops)
  9. {
  10. #if defined(CONFIG_COLDFIRE)
  11. /* The coldfire runs this loop at significantly different speeds
  12. * depending upon long word alignment or not. We'll pad it to
  13. * long word alignment which is the faster version.
  14. * The 0x4a8e is of course a 'tstl %fp' instruction. This is better
  15. * than using a NOP (0x4e71) instruction because it executes in one
  16. * cycle not three and doesn't allow for an arbitary delay waiting
  17. * for bus cycles to finish. Also fp/a6 isn't likely to cause a
  18. * stall waiting for the register to become valid if such is added
  19. * to the coldfire at some stage.
  20. */
  21. __asm__ __volatile__ ( ".balignw 4, 0x4a8e\n\t"
  22. "1: subql #1, %0\n\t"
  23. "jcc 1b"
  24. : "=d" (loops) : "0" (loops));
  25. #else
  26. __asm__ __volatile__ ( "1: subql #1, %0\n\t"
  27. "jcc 1b"
  28. : "=d" (loops) : "0" (loops));
  29. #endif
  30. }
  31. /*
  32. * Ideally we use a 32*32->64 multiply to calculate the number of
  33. * loop iterations, but the older standard 68k and ColdFire do not
  34. * have this instruction. So for them we have a clsoe approximation
  35. * loop using 32*32->32 multiplies only. This calculation based on
  36. * the ARM version of delay.
  37. *
  38. * We want to implement:
  39. *
  40. * loops = (usecs * 0x10c6 * HZ * loops_per_jiffy) / 2^32
  41. */
  42. #define HZSCALE (268435456 / (1000000/HZ))
  43. extern unsigned long loops_per_jiffy;
  44. static inline void _udelay(unsigned long usecs)
  45. {
  46. #if defined(CONFIG_M68328) || defined(CONFIG_M68EZ328) || \
  47. defined(CONFIG_M68VZ328) || defined(CONFIG_M68360) || \
  48. defined(CONFIG_COLDFIRE)
  49. __delay((((usecs * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6);
  50. #else
  51. unsigned long tmp;
  52. usecs *= 4295; /* 2**32 / 1000000 */
  53. __asm__ ("mulul %2,%0:%1"
  54. : "=d" (usecs), "=d" (tmp)
  55. : "d" (usecs), "1" (loops_per_jiffy*HZ));
  56. __delay(usecs);
  57. #endif
  58. }
  59. /*
  60. * Moved the udelay() function into library code, no longer inlined.
  61. * I had to change the algorithm because we are overflowing now on
  62. * the faster ColdFire parts. The code is a little bigger, so it makes
  63. * sense to library it.
  64. */
  65. extern void udelay(unsigned long usecs);
  66. #endif /* defined(_M68KNOMMU_DELAY_H) */