blob: 08608854a79e679170895130b11431763fe2db3f [file] [log] [blame]
developer86ada3c2020-07-03 09:19:06 +08001/*
2 * Copyright (c) 2020, MediaTek Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
developer57d8b882020-07-06 18:01:42 +08008#include <lib/mmio.h>
developer86ada3c2020-07-03 09:19:06 +08009#include <mt_timer.h>
10#include <platform_def.h>
11
12
13uint64_t normal_time_base;
14uint64_t atf_time_base;
15
16void sched_clock_init(uint64_t normal_base, uint64_t atf_base)
17{
18 normal_time_base += normal_base;
19 atf_time_base = atf_base;
20}
21
22uint64_t sched_clock(void)
23{
24 uint64_t cval;
25 uint64_t rel_base;
26
27 rel_base = read_cntpct_el0() - atf_time_base;
28 cval = ((rel_base * 1000U) / SYS_COUNTER_FREQ_IN_MHZ)
29 - normal_time_base;
30 return cval;
31}
developer57d8b882020-07-06 18:01:42 +080032
33void mt_systimer_init(void)
34{
35 /* Enable access in NS mode */
36 mmio_write_32(CNTWACR_REG, CNT_WRITE_ACCESS_CTL_MASK);
37 mmio_write_32(CNTRACR_REG, CNT_READ_ACCESS_CTL_MASK);
38}