delay.c 499 B

12345678910111213141516171819202122232425
  1. #include <asm/timex.h>
  2. #include <asm/io.h>
  3. #include <variant/hardware.h>
  4. #define LOOPS 10
  5. void platform_calibrate_ccount(void)
  6. {
  7. u32 uninitialized_var(a);
  8. u32 uninitialized_var(u);
  9. u32 b;
  10. u32 tstamp = S6_REG_GREG1 + S6_GREG1_GLOBAL_TIMER;
  11. int i = LOOPS+1;
  12. do {
  13. u32 t = u;
  14. asm volatile(
  15. "1: l32i %0, %2, 0 ;"
  16. " beq %0, %1, 1b ;"
  17. : "=&a"(u) : "a"(t), "a"(tstamp));
  18. b = get_ccount();
  19. if (i == LOOPS)
  20. a = b;
  21. } while (--i >= 0);
  22. b -= a;
  23. ccount_freq = b * (100000UL / LOOPS);
  24. }