03ca5321a73ffc833bbbd7ecbb941afc12cd8fa7
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
7 #include <arch_helpers.h>
11 #include <delay_timer.h>
12 #include <generic_delay_timer.h>
15 /* Ticks elapsed in one second by a signal of 1 MHz */
16 #define MHZ_TICKS_PER_SEC 1000000
18 static timer_ops_t ops
;
20 static uint32_t get_timer_value(void)
23 * Generic delay timer implementation expects the timer to be a down
24 * counter. We apply bitwise NOT operator to the tick values returned
25 * by read_cntpct_el0() to simulate the down counter. The value is
26 * clipped from 64 to 32 bits.
28 return (uint32_t)(~read_cntpct_el0());
31 void generic_delay_timer_init_args(uint32_t mult
, uint32_t div
)
33 ops
.get_timer_value
= get_timer_value
;
39 VERBOSE("Generic delay timer configured with mult=%u and div=%u\n",
43 void generic_delay_timer_init(void)
46 unsigned int mult
= MHZ_TICKS_PER_SEC
;
48 /* Value in ticks per second (Hz) */
49 unsigned int div
= plat_get_syscnt_freq2();
51 /* Reduce multiplier and divider by dividing them repeatedly by 10 */
52 while (((mult
% 10U) == 0U) && ((div
% 10U) == 0U)) {
57 generic_delay_timer_init_args(mult
, div
);