delay.c 1.4 KB

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