arch_timer.c 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012-2014
  4. * Texas Instruments Incorporated, <www.ti.com>
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <div64.h>
  9. #include <bootstage.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. #ifndef CONFIG_SYS_HZ_CLOCK
  12. static inline u32 read_cntfrq(void)
  13. {
  14. u32 frq;
  15. asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq));
  16. return frq;
  17. }
  18. #endif
  19. int timer_init(void)
  20. {
  21. gd->arch.tbl = 0;
  22. gd->arch.tbu = 0;
  23. #ifdef CONFIG_SYS_HZ_CLOCK
  24. gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
  25. #else
  26. gd->arch.timer_rate_hz = read_cntfrq();
  27. #endif
  28. return 0;
  29. }
  30. unsigned long long get_ticks(void)
  31. {
  32. ulong nowl, nowu;
  33. asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu));
  34. gd->arch.tbl = nowl;
  35. gd->arch.tbu = nowu;
  36. return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl;
  37. }
  38. ulong timer_get_boot_us(void)
  39. {
  40. return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
  41. }
  42. ulong get_tbclk(void)
  43. {
  44. return gd->arch.timer_rate_hz;
  45. }