mt_timer.c 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <lib/mmio.h>
  9. #include <lib/mtk_init/mtk_init.h>
  10. #include <mt_timer.h>
  11. #include <platform_def.h>
  12. uint64_t normal_time_base;
  13. uint64_t atf_time_base;
  14. void sched_clock_init(uint64_t normal_base, uint64_t atf_base)
  15. {
  16. normal_time_base += normal_base;
  17. atf_time_base = atf_base;
  18. }
  19. uint64_t sched_clock(void)
  20. {
  21. uint64_t cval;
  22. uint64_t rel_base;
  23. rel_base = read_cntpct_el0() - atf_time_base;
  24. cval = ((rel_base * 1000U) / SYS_COUNTER_FREQ_IN_MHZ)
  25. - normal_time_base;
  26. return cval;
  27. }
  28. int mt_systimer_init(void)
  29. {
  30. INFO("[%s] systimer initialization\n", __func__);
  31. /* Enable access in NS mode */
  32. mmio_write_32(CNTWACR_REG, CNT_WRITE_ACCESS_CTL_MASK);
  33. mmio_write_32(CNTRACR_REG, CNT_READ_ACCESS_CTL_MASK);
  34. return 0;
  35. }
  36. MTK_PLAT_SETUP_0_INIT(mt_systimer_init);