delay.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Precise Delay Loops for avr32
  3. *
  4. * Copyright (C) 1993 Linus Torvalds
  5. * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  6. * Copyright (C) 2005-2006 Atmel Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/module.h>
  14. #include <linux/param.h>
  15. #include <linux/types.h>
  16. #include <asm/processor.h>
  17. #include <asm/sysreg.h>
  18. int read_current_timer(unsigned long *timer_value)
  19. {
  20. *timer_value = sysreg_read(COUNT);
  21. return 0;
  22. }
  23. void __delay(unsigned long loops)
  24. {
  25. unsigned bclock, now;
  26. bclock = sysreg_read(COUNT);
  27. do {
  28. now = sysreg_read(COUNT);
  29. } while ((now - bclock) < loops);
  30. }
  31. inline void __const_udelay(unsigned long xloops)
  32. {
  33. unsigned long long loops;
  34. asm("mulu.d %0, %1, %2"
  35. : "=r"(loops)
  36. : "r"(current_cpu_data.loops_per_jiffy * HZ), "r"(xloops));
  37. __delay(loops >> 32);
  38. }
  39. void __udelay(unsigned long usecs)
  40. {
  41. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  42. }
  43. void __ndelay(unsigned long nsecs)
  44. {
  45. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  46. }