1 /* 2 * Copyright (c) 2020, MediaTek Inc. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch_helpers.h> 8 #include <lib/mmio.h> 9 #include <mt_timer.h> 10 #include <platform_def.h> 11 12 13 uint64_t normal_time_base; 14 uint64_t atf_time_base; 15 sched_clock_init(uint64_t normal_base,uint64_t atf_base)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 sched_clock(void)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 } 32 mt_systimer_init(void)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 } 39