udelay.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * arch/sh64/lib/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. extern unsigned long loops_per_jiffy;
  16. /*
  17. * Use only for very small delays (< 1 msec).
  18. *
  19. * The active part of our cycle counter is only 32-bits wide, and
  20. * we're treating the difference between two marks as signed. On
  21. * a 1GHz box, that's about 2 seconds.
  22. */
  23. void __delay(int loops)
  24. {
  25. long long dummy;
  26. __asm__ __volatile__("gettr tr0, %1\n\t"
  27. "pta $+4, tr0\n\t"
  28. "addi %0, -1, %0\n\t"
  29. "bne %0, r63, tr0\n\t"
  30. "ptabs %1, tr0\n\t":"=r"(loops),
  31. "=r"(dummy)
  32. :"0"(loops));
  33. }
  34. void __udelay(unsigned long long usecs, unsigned long lpj)
  35. {
  36. usecs *= (((unsigned long long) HZ << 32) / 1000000) * lpj;
  37. __delay((long long) usecs >> 32);
  38. }
  39. void __ndelay(unsigned long long nsecs, unsigned long lpj)
  40. {
  41. nsecs *= (((unsigned long long) HZ << 32) / 1000000000) * lpj;
  42. __delay((long long) nsecs >> 32);
  43. }
  44. void udelay(unsigned long usecs)
  45. {
  46. __udelay(usecs, loops_per_jiffy);
  47. }
  48. void ndelay(unsigned long nsecs)
  49. {
  50. __ndelay(nsecs, loops_per_jiffy);
  51. }