delay.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifdef __KERNEL__
  2. #ifndef _PPC_DELAY_H
  3. #define _PPC_DELAY_H
  4. #include <asm/param.h>
  5. /*
  6. * Copyright 1996, Paul Mackerras.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. extern unsigned long loops_per_jiffy;
  14. extern void __delay(unsigned int loops);
  15. /*
  16. * Note that 19 * 226 == 4294 ==~ 2^32 / 10^6, so
  17. * loops = (4294 * usecs * loops_per_jiffy * HZ) / 2^32.
  18. *
  19. * The mulhwu instruction gives us loops = (a * b) / 2^32.
  20. * We choose a = usecs * 19 * HZ and b = loops_per_jiffy * 226
  21. * because this lets us support a wide range of HZ and
  22. * loops_per_jiffy values without either a or b overflowing 2^32.
  23. * Thus we need usecs * HZ <= (2^32 - 1) / 19 = 226050910 and
  24. * loops_per_jiffy <= (2^32 - 1) / 226 = 19004280
  25. * (which corresponds to ~3800 bogomips at HZ = 100).
  26. * -- paulus
  27. */
  28. #define __MAX_UDELAY (226050910UL/HZ) /* maximum udelay argument */
  29. #define __MAX_NDELAY (4294967295UL/HZ) /* maximum ndelay argument */
  30. extern __inline__ void __udelay(unsigned int x)
  31. {
  32. unsigned int loops;
  33. __asm__("mulhwu %0,%1,%2" : "=r" (loops) :
  34. "r" (x), "r" (loops_per_jiffy * 226));
  35. __delay(loops);
  36. }
  37. extern __inline__ void __ndelay(unsigned int x)
  38. {
  39. unsigned int loops;
  40. __asm__("mulhwu %0,%1,%2" : "=r" (loops) :
  41. "r" (x), "r" (loops_per_jiffy * 5));
  42. __delay(loops);
  43. }
  44. extern void __bad_udelay(void); /* deliberately undefined */
  45. extern void __bad_ndelay(void); /* deliberately undefined */
  46. #define udelay(n) (__builtin_constant_p(n)? \
  47. ((n) > __MAX_UDELAY? __bad_udelay(): __udelay((n) * (19 * HZ))) : \
  48. __udelay((n) * (19 * HZ)))
  49. #define ndelay(n) (__builtin_constant_p(n)? \
  50. ((n) > __MAX_NDELAY? __bad_ndelay(): __ndelay((n) * HZ)) : \
  51. __ndelay((n) * HZ))
  52. #endif /* defined(_PPC_DELAY_H) */
  53. #endif /* __KERNEL__ */