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