delay.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
  3. * Mostly copied from arch/x86/lib/delay.c
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/delay.h>
  12. #include <asm/param.h>
  13. void __delay(unsigned long loops)
  14. {
  15. asm volatile(
  16. "test %0,%0\n"
  17. "jz 3f\n"
  18. "jmp 1f\n"
  19. ".align 16\n"
  20. "1: jmp 2f\n"
  21. ".align 16\n"
  22. "2: dec %0\n"
  23. " jnz 2b\n"
  24. "3: dec %0\n"
  25. : /* we don't need output */
  26. : "a" (loops)
  27. );
  28. }
  29. EXPORT_SYMBOL(__delay);
  30. inline void __const_udelay(unsigned long xloops)
  31. {
  32. int d0;
  33. xloops *= 4;
  34. asm("mull %%edx"
  35. : "=d" (xloops), "=&a" (d0)
  36. : "1" (xloops), "0"
  37. (loops_per_jiffy * (HZ/4)));
  38. __delay(++xloops);
  39. }
  40. EXPORT_SYMBOL(__const_udelay);
  41. void __udelay(unsigned long usecs)
  42. {
  43. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  44. }
  45. EXPORT_SYMBOL(__udelay);
  46. void __ndelay(unsigned long nsecs)
  47. {
  48. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  49. }
  50. EXPORT_SYMBOL(__ndelay);