udelay.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * arch/sh/lib64/udelay.c
  3. *
  4. * Delay routines, using a pre-computed "loops_per_jiffy" value.
  5. *
  6. * Copyright (C) 2000, 2001 Paolo Alberelli
  7. * Copyright (C) 2003, 2004 Paul Mundt
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/sched.h>
  14. #include <asm/param.h>
  15. /*
  16. * Use only for very small delays (< 1 msec).
  17. *
  18. * The active part of our cycle counter is only 32-bits wide, and
  19. * we're treating the difference between two marks as signed. On
  20. * a 1GHz box, that's about 2 seconds.
  21. */
  22. void __delay(unsigned long loops)
  23. {
  24. long long dummy;
  25. __asm__ __volatile__("gettr tr0, %1\n\t"
  26. "pta $+4, tr0\n\t"
  27. "addi %0, -1, %0\n\t"
  28. "bne %0, r63, tr0\n\t"
  29. "ptabs %1, tr0\n\t":"=r"(loops),
  30. "=r"(dummy)
  31. :"0"(loops));
  32. }
  33. void __const_udelay(unsigned long xloops)
  34. {
  35. __delay(xloops * (HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy));
  36. }
  37. void __udelay(unsigned long usecs)
  38. {
  39. __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
  40. }
  41. void __ndelay(unsigned long nsecs)
  42. {
  43. __const_udelay(nsecs * 0x00000005);
  44. }