delay.c 1.3 KB

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