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 | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 8 | #include <lib/mmio.h> |
developer | 86ada3c | 2020-07-03 09:19:06 +0800 | [diff] [blame] | 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 | |
| 16 | void 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 | |
| 22 | uint64_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 | } |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 32 | |
| 33 | void 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 | } |