blob: 11e4572532b34183706618a5e2090b286e7271c2 [file] [log] [blame]
developer86ada3c2020-07-03 09:19:06 +08001/*
developerfe14b9f2022-09-05 11:18:04 +08002 * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved.
developer86ada3c2020-07-03 09:19:06 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
developerc193d632022-07-08 13:16:17 +08008#include <common/debug.h>
developer57d8b882020-07-06 18:01:42 +08009#include <lib/mmio.h>
developerc193d632022-07-08 13:16:17 +080010#include <lib/mtk_init/mtk_init.h>
developer86ada3c2020-07-03 09:19:06 +080011#include <mt_timer.h>
12#include <platform_def.h>
13
developer86ada3c2020-07-03 09:19:06 +080014uint64_t normal_time_base;
15uint64_t atf_time_base;
16
17void sched_clock_init(uint64_t normal_base, uint64_t atf_base)
18{
19 normal_time_base += normal_base;
20 atf_time_base = atf_base;
21}
22
23uint64_t sched_clock(void)
24{
25 uint64_t cval;
26 uint64_t rel_base;
27
28 rel_base = read_cntpct_el0() - atf_time_base;
29 cval = ((rel_base * 1000U) / SYS_COUNTER_FREQ_IN_MHZ)
30 - normal_time_base;
31 return cval;
32}
developer57d8b882020-07-06 18:01:42 +080033
developerc193d632022-07-08 13:16:17 +080034int mt_systimer_init(void)
developer57d8b882020-07-06 18:01:42 +080035{
developerc193d632022-07-08 13:16:17 +080036 INFO("[%s] systimer initialization\n", __func__);
37
developer57d8b882020-07-06 18:01:42 +080038 /* Enable access in NS mode */
39 mmio_write_32(CNTWACR_REG, CNT_WRITE_ACCESS_CTL_MASK);
40 mmio_write_32(CNTRACR_REG, CNT_READ_ACCESS_CTL_MASK);
developerc193d632022-07-08 13:16:17 +080041
42 return 0;
developer57d8b882020-07-06 18:01:42 +080043}
developerc193d632022-07-08 13:16:17 +080044MTK_PLAT_SETUP_0_INIT(mt_systimer_init);