delay.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/types.h>
  15. #include <asm/processor.h>
  16. #include <asm/sysreg.h>
  17. int read_current_timer(unsigned long *timer_value)
  18. {
  19. *timer_value = sysreg_read(COUNT);
  20. return 0;
  21. }
  22. void __delay(unsigned long loops)
  23. {
  24. unsigned bclock, now;
  25. bclock = sysreg_read(COUNT);
  26. do {
  27. now = sysreg_read(COUNT);
  28. } while ((now - bclock) < loops);
  29. }
  30. inline void __const_udelay(unsigned long xloops)
  31. {
  32. unsigned long long loops;
  33. asm("mulu.d %0, %1, %2"
  34. : "=r"(loops)
  35. : "r"(current_cpu_data.loops_per_jiffy * HZ), "r"(xloops));
  36. __delay(loops >> 32);
  37. }
  38. void __udelay(unsigned long usecs)
  39. {
  40. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  41. }
  42. void __ndelay(unsigned long nsecs)
  43. {
  44. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  45. }