xref: /openbmc/u-boot/arch/arm/mach-mvebu/timer.c (revision 57efeb04)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) Marvell International Ltd. and its affiliates
4  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
5  *
6  * Copyright (C) 2015 Stefan Roese <sr@denx.de>
7  */
8 
9 #include <common.h>
10 #include <asm/io.h>
11 #include <asm/arch/soc.h>
12 
13 #define TIMER_LOAD_VAL			0xffffffff
14 
15 static int init_done __attribute__((section(".data"))) = 0;
16 
17 /*
18  * Timer initialization
19  */
20 int timer_init(void)
21 {
22 	/* Only init the timer once */
23 	if (init_done)
24 		return 0;
25 	init_done = 1;
26 
27 	/* load value into timer */
28 	writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
29 	writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
30 
31 #if defined(CONFIG_ARCH_MVEBU)
32 	/* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */
33 	setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11));
34 #endif
35 	/* enable timer in auto reload mode */
36 	setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
37 
38 	return 0;
39 }
40