delay.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. extern inline void __delay(unsigned long loops)
  15. {
  16. asm volatile ("# __delay \n\t" \
  17. "1: addi %0, %0, -1\t\n" \
  18. "bneid %0, 1b \t\n" \
  19. "nop \t\n"
  20. : "=r" (loops)
  21. : "0" (loops));
  22. }
  23. /*
  24. * Note that 19 * 226 == 4294 ==~ 2^32 / 10^6, so
  25. * loops = (4294 * usecs * loops_per_jiffy * HZ) / 2^32.
  26. *
  27. * The mul instruction gives us loops = (a * b) / 2^32.
  28. * We choose a = usecs * 19 * HZ and b = loops_per_jiffy * 226
  29. * because this lets us support a wide range of HZ and
  30. * loops_per_jiffy values without either a or b overflowing 2^32.
  31. * Thus we need usecs * HZ <= (2^32 - 1) / 19 = 226050910 and
  32. * loops_per_jiffy <= (2^32 - 1) / 226 = 19004280
  33. * (which corresponds to ~3800 bogomips at HZ = 100).
  34. * -- paulus
  35. */
  36. #define __MAX_UDELAY (226050910UL/HZ) /* maximum udelay argument */
  37. #define __MAX_NDELAY (4294967295UL/HZ) /* maximum ndelay argument */
  38. extern unsigned long loops_per_jiffy;
  39. extern inline void __udelay(unsigned int x)
  40. {
  41. unsigned long long tmp =
  42. (unsigned long long)x * (unsigned long long)loops_per_jiffy \
  43. * 226LL;
  44. unsigned loops = tmp >> 32;
  45. /*
  46. __asm__("mulxuu %0,%1,%2" : "=r" (loops) :
  47. "r" (x), "r" (loops_per_jiffy * 226));
  48. */
  49. __delay(loops);
  50. }
  51. extern void __bad_udelay(void); /* deliberately undefined */
  52. extern void __bad_ndelay(void); /* deliberately undefined */
  53. #define udelay(n) (__builtin_constant_p(n) ? \
  54. ((n) > __MAX_UDELAY ? __bad_udelay() : __udelay((n) * (19 * HZ))) : \
  55. __udelay((n) * (19 * HZ)))
  56. #define ndelay(n) (__builtin_constant_p(n) ? \
  57. ((n) > __MAX_NDELAY ? __bad_ndelay() : __udelay((n) * HZ)) : \
  58. __udelay((n) * HZ))
  59. #define muldiv(a, b, c) (((a)*(b))/(c))
  60. #endif /* _ASM_MICROBLAZE_DELAY_H */