1 /*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 #include <arch_helpers.h>
7 #include <mcucfg.h>
8 #include <mmio.h>
9 #include <mt8173_def.h>
10 #include <mt_cpuxgpt.h>
11
write_cpuxgpt(unsigned int reg_index,unsigned int value)12 static void write_cpuxgpt(unsigned int reg_index, unsigned int value)
13 {
14 mmio_write_32((uintptr_t)&mt8173_mcucfg->xgpt_idx, reg_index);
15 mmio_write_32((uintptr_t)&mt8173_mcucfg->xgpt_ctl, value);
16 }
17
cpuxgpt_set_init_cnt(unsigned int countH,unsigned int countL)18 static void cpuxgpt_set_init_cnt(unsigned int countH, unsigned int countL)
19 {
20 write_cpuxgpt(INDEX_CNT_H_INIT, countH);
21 /* update count when countL programmed */
22 write_cpuxgpt(INDEX_CNT_L_INIT, countL);
23 }
24
generic_timer_backup(void)25 void generic_timer_backup(void)
26 {
27 uint64_t cval;
28
29 cval = read_cntpct_el0();
30 cpuxgpt_set_init_cnt((uint32_t)(cval >> 32),
31 (uint32_t)(cval & 0xffffffff));
32 }
33