delay_mm.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef _M68K_DELAY_H
  2. #define _M68K_DELAY_H
  3. #include <asm/param.h>
  4. /*
  5. * Copyright (C) 1994 Hamish Macdonald
  6. *
  7. * Delay routines, using a pre-computed "loops_per_jiffy" value.
  8. */
  9. static inline void __delay(unsigned long loops)
  10. {
  11. __asm__ __volatile__ ("1: subql #1,%0; jcc 1b"
  12. : "=d" (loops) : "0" (loops));
  13. }
  14. extern void __bad_udelay(void);
  15. /*
  16. * Use only for very small delays ( < 1 msec). Should probably use a
  17. * lookup table, really, as the multiplications take much too long with
  18. * short delays. This is a "reasonable" implementation, though (and the
  19. * first constant multiplications gets optimized away if the delay is
  20. * a constant)
  21. */
  22. static inline void __const_udelay(unsigned long xloops)
  23. {
  24. unsigned long tmp;
  25. __asm__ ("mulul %2,%0:%1"
  26. : "=d" (xloops), "=d" (tmp)
  27. : "d" (xloops), "1" (loops_per_jiffy));
  28. __delay(xloops * HZ);
  29. }
  30. static inline void __udelay(unsigned long usecs)
  31. {
  32. __const_udelay(usecs * 4295); /* 2**32 / 1000000 */
  33. }
  34. #define udelay(n) (__builtin_constant_p(n) ? \
  35. ((n) > 20000 ? __bad_udelay() : __const_udelay((n) * 4295)) : \
  36. __udelay(n))
  37. static inline unsigned long muldiv(unsigned long a, unsigned long b,
  38. unsigned long c)
  39. {
  40. unsigned long tmp;
  41. __asm__ ("mulul %2,%0:%1; divul %3,%0:%1"
  42. : "=d" (tmp), "=d" (a)
  43. : "d" (b), "d" (c), "1" (a));
  44. return a;
  45. }
  46. #endif /* defined(_M68K_DELAY_H) */