generic_timer.c 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * (C) Copyright 2013
  3. * David Feng <fenghua@phytium.com.cn>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <asm/system.h>
  10. /*
  11. * Generic timer implementation of get_tbclk()
  12. */
  13. unsigned long get_tbclk(void)
  14. {
  15. unsigned long cntfrq;
  16. asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
  17. return cntfrq;
  18. }
  19. /*
  20. * Generic timer implementation of timer_read_counter()
  21. */
  22. unsigned long timer_read_counter(void)
  23. {
  24. unsigned long cntpct;
  25. #ifdef CONFIG_SYS_FSL_ERRATUM_A008585
  26. /* This erratum number needs to be confirmed to match ARM document */
  27. unsigned long temp;
  28. #endif
  29. isb();
  30. asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
  31. #ifdef CONFIG_SYS_FSL_ERRATUM_A008585
  32. asm volatile("mrs %0, cntpct_el0" : "=r" (temp));
  33. while (temp != cntpct) {
  34. asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
  35. asm volatile("mrs %0, cntpct_el0" : "=r" (temp));
  36. }
  37. #endif
  38. return cntpct;
  39. }