delay.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright Altera Corporation (C) 2014. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License, version 2,
  5. * as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <asm/delay.h>
  18. #include <asm/param.h>
  19. #include <asm/processor.h>
  20. #include <asm/timex.h>
  21. void __delay(unsigned long cycles)
  22. {
  23. cycles_t start = get_cycles();
  24. while ((get_cycles() - start) < cycles)
  25. cpu_relax();
  26. }
  27. EXPORT_SYMBOL(__delay);
  28. void __const_udelay(unsigned long xloops)
  29. {
  30. u64 loops;
  31. loops = (u64)xloops * loops_per_jiffy * HZ;
  32. __delay(loops >> 32);
  33. }
  34. EXPORT_SYMBOL(__const_udelay);
  35. void __udelay(unsigned long usecs)
  36. {
  37. __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  38. }
  39. EXPORT_SYMBOL(__udelay);
  40. void __ndelay(unsigned long nsecs)
  41. {
  42. __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  43. }
  44. EXPORT_SYMBOL(__ndelay);