developer | 86ada3c | 2020-07-03 09:19:06 +0800 | [diff] [blame] | 1 | /* |
developer | fe14b9f | 2022-09-05 11:18:04 +0800 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved. |
developer | 86ada3c | 2020-07-03 09:19:06 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
developer | c193d63 | 2022-07-08 13:16:17 +0800 | [diff] [blame^] | 8 | #include <common/debug.h> |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 9 | #include <lib/mmio.h> |
developer | c193d63 | 2022-07-08 13:16:17 +0800 | [diff] [blame^] | 10 | #include <lib/mtk_init/mtk_init.h> |
developer | 86ada3c | 2020-07-03 09:19:06 +0800 | [diff] [blame] | 11 | #include <mt_timer.h> |
| 12 | #include <platform_def.h> |
| 13 | |
developer | 86ada3c | 2020-07-03 09:19:06 +0800 | [diff] [blame] | 14 | uint64_t normal_time_base; |
| 15 | uint64_t atf_time_base; |
| 16 | |
| 17 | void 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 | |
| 23 | uint64_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 | } |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 33 | |
developer | c193d63 | 2022-07-08 13:16:17 +0800 | [diff] [blame^] | 34 | int mt_systimer_init(void) |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 35 | { |
developer | c193d63 | 2022-07-08 13:16:17 +0800 | [diff] [blame^] | 36 | INFO("[%s] systimer initialization\n", __func__); |
| 37 | |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 38 | /* 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); |
developer | c193d63 | 2022-07-08 13:16:17 +0800 | [diff] [blame^] | 41 | |
| 42 | return 0; |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 43 | } |
developer | c193d63 | 2022-07-08 13:16:17 +0800 | [diff] [blame^] | 44 | MTK_PLAT_SETUP_0_INIT(mt_systimer_init); |