delay.h 935 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #ifndef __NDS32_DELAY_H__
  4. #define __NDS32_DELAY_H__
  5. #include <asm/param.h>
  6. /* There is no clocksource cycle counter in the CPU. */
  7. static inline void __delay(unsigned long loops)
  8. {
  9. __asm__ __volatile__(".align 2\n"
  10. "1:\n"
  11. "\taddi\t%0, %0, -1\n"
  12. "\tbgtz\t%0, 1b\n"
  13. :"=r"(loops)
  14. :"0"(loops));
  15. }
  16. static inline void __udelay(unsigned long usecs, unsigned long lpj)
  17. {
  18. usecs *= (unsigned long)(((0x8000000000000000ULL / (500000 / HZ)) +
  19. 0x80000000ULL) >> 32);
  20. usecs = (unsigned long)(((unsigned long long)usecs * lpj) >> 32);
  21. __delay(usecs);
  22. }
  23. #define udelay(usecs) __udelay((usecs), loops_per_jiffy)
  24. /* make sure "usecs *= ..." in udelay do not overflow. */
  25. #if HZ >= 1000
  26. #define MAX_UDELAY_MS 1
  27. #elif HZ <= 200
  28. #define MAX_UDELAY_MS 5
  29. #else
  30. #define MAX_UDELAY_MS (1000 / HZ)
  31. #endif
  32. #endif