delay.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * include/asm-microblaze/delay.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2008 Michal Simek
  9. * Copyright (C) 2007 John Williams
  10. * Copyright (C) 2006 Atmark Techno, Inc.
  11. */
  12. #ifndef _ASM_MICROBLAZE_DELAY_H
  13. #define _ASM_MICROBLAZE_DELAY_H
  14. #include <linux/param.h>
  15. static inline void __delay(unsigned long loops)
  16. {
  17. asm volatile ("# __delay \n\t" \
  18. "1: addi %0, %0, -1\t\n" \
  19. "bneid %0, 1b \t\n" \
  20. "nop \t\n"
  21. : "=r" (loops)
  22. : "0" (loops));
  23. }
  24. /*
  25. * Note that 19 * 226 == 4294 ==~ 2^32 / 10^6, so
  26. * loops = (4294 * usecs * loops_per_jiffy * HZ) / 2^32.
  27. *
  28. * The mul instruction gives us loops = (a * b) / 2^32.
  29. * We choose a = usecs * 19 * HZ and b = loops_per_jiffy * 226
  30. * because this lets us support a wide range of HZ and
  31. * loops_per_jiffy values without either a or b overflowing 2^32.
  32. * Thus we need usecs * HZ <= (2^32 - 1) / 19 = 226050910 and
  33. * loops_per_jiffy <= (2^32 - 1) / 226 = 19004280
  34. * (which corresponds to ~3800 bogomips at HZ = 100).
  35. * -- paulus
  36. */
  37. #define __MAX_UDELAY (226050910UL/HZ) /* maximum udelay argument */
  38. #define __MAX_NDELAY (4294967295UL/HZ) /* maximum ndelay argument */
  39. extern unsigned long loops_per_jiffy;
  40. static inline void __udelay(unsigned int x)
  41. {
  42. unsigned long long tmp =
  43. (unsigned long long)x * (unsigned long long)loops_per_jiffy \
  44. * 226LL;
  45. unsigned loops = tmp >> 32;
  46. /*
  47. __asm__("mulxuu %0,%1,%2" : "=r" (loops) :
  48. "r" (x), "r" (loops_per_jiffy * 226));
  49. */
  50. __delay(loops);
  51. }
  52. extern void __bad_udelay(void); /* deliberately undefined */
  53. extern void __bad_ndelay(void); /* deliberately undefined */
  54. #define udelay(n) \
  55. ({ \
  56. if (__builtin_constant_p(n)) { \
  57. if ((n) / __MAX_UDELAY >= 1) \
  58. __bad_udelay(); \
  59. else \
  60. __udelay((n) * (19 * HZ)); \
  61. } else { \
  62. __udelay((n) * (19 * HZ)); \
  63. } \
  64. })
  65. #define ndelay(n) \
  66. ({ \
  67. if (__builtin_constant_p(n)) { \
  68. if ((n) / __MAX_NDELAY >= 1) \
  69. __bad_ndelay(); \
  70. else \
  71. __udelay((n) * HZ); \
  72. } else { \
  73. __udelay((n) * HZ); \
  74. } \
  75. })
  76. #define muldiv(a, b, c) (((a)*(b))/(c))
  77. #endif /* _ASM_MICROBLAZE_DELAY_H */