1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7/* A9 MPCORE private timer */ 8#include <machine/timer.h> 9#include <arch/machine/timer.h> 10#include <drivers/timer/arm_priv.h> 11 12timer_t *const priv_timer = (timer_t *) ARM_MP_PRIV_TIMER_PPTR; 13 14#define TMR_CTRL_ENABLE BIT(0) 15#define TMR_CTRL_AUTORELOAD BIT(1) 16#define TMR_CTRL_IRQEN BIT(2) 17#define TMR_CTRL_PRESCALE 8 18 19#define TIMER_INTERVAL_MS (CONFIG_TIMER_TICK_MS) 20#define TIMER_COUNT_BITS 32 21 22#define PRESCALE ((TIMER_RELOAD) >> TIMER_COUNT_BITS) 23#define TMR_LOAD ((TIMER_RELOAD) / (PRESCALE + 1)) 24 25BOOT_CODE void initTimer(void) 26{ 27 /* reset */ 28 priv_timer->ctrl = 0; 29 priv_timer->ints = 0; 30 31 /* setup */ 32 priv_timer->load = TMR_LOAD; 33 priv_timer->ctrl |= ((PRESCALE) << (TMR_CTRL_PRESCALE)) 34 | TMR_CTRL_AUTORELOAD | TMR_CTRL_IRQEN; 35 36 /* Enable */ 37 priv_timer->ctrl |= TMR_CTRL_ENABLE; 38} 39