delay.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 by Waldorf Electronics
  7. * Copyright (C) 1995 - 2000, 01, 03 by Ralf Baechle
  8. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  9. * Copyright (C) 2007, 2014 Maciej W. Rozycki
  10. */
  11. #include <linux/module.h>
  12. #include <linux/param.h>
  13. #include <linux/smp.h>
  14. #include <linux/stringify.h>
  15. #include <asm/asm.h>
  16. #include <asm/compiler.h>
  17. #include <asm/war.h>
  18. #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
  19. #define GCC_DADDI_IMM_ASM() "I"
  20. #else
  21. #define GCC_DADDI_IMM_ASM() "r"
  22. #endif
  23. void __delay(unsigned long loops)
  24. {
  25. __asm__ __volatile__ (
  26. " .set noreorder \n"
  27. " .align 3 \n"
  28. "1: bnez %0, 1b \n"
  29. " " __stringify(LONG_SUBU) " %0, %1 \n"
  30. " .set reorder \n"
  31. : "=r" (loops)
  32. : GCC_DADDI_IMM_ASM() (1), "0" (loops));
  33. }
  34. EXPORT_SYMBOL(__delay);
  35. /*
  36. * Division by multiplication: you don't have to worry about
  37. * loss of precision.
  38. *
  39. * Use only for very small delays ( < 1 msec). Should probably use a
  40. * lookup table, really, as the multiplications take much too long with
  41. * short delays. This is a "reasonable" implementation, though (and the
  42. * first constant multiplications gets optimized away if the delay is
  43. * a constant)
  44. */
  45. void __udelay(unsigned long us)
  46. {
  47. unsigned int lpj = raw_current_cpu_data.udelay_val;
  48. __delay((us * 0x000010c7ull * HZ * lpj) >> 32);
  49. }
  50. EXPORT_SYMBOL(__udelay);
  51. void __ndelay(unsigned long ns)
  52. {
  53. unsigned int lpj = raw_current_cpu_data.udelay_val;
  54. __delay((ns * 0x00000005ull * HZ * lpj) >> 32);
  55. }
  56. EXPORT_SYMBOL(__ndelay);