generic_timer.c 562 B

12345678910111213141516171819202122232425262728293031
  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. isb();
  26. asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
  27. return cntpct;
  28. }