summaryrefslogtreecommitdiff
path: root/arch/arm/mach-mvebu/timer.c
blob: aef2df2f7a07390169c4b56f78081ded9f9ac4ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (C) Marvell International Ltd. and its affiliates
 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
 *
 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <asm/io.h>
#include <asm/arch/soc.h>

DECLARE_GLOBAL_DATA_PTR;

#define TIMER_LOAD_VAL			0xffffffff

static int init_done __attribute__((section(".data"))) = 0;

/*
 * Timer initialization
 */
int timer_init(void)
{
	/* Only init the timer once */
	if (init_done)
		return 0;
	init_done = 1;

	/* load value into timer */
	writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
	writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);

#if defined(CONFIG_ARMADA_XP)
	/* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */
	setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11));
#endif
	/* enable timer in auto reload mode */
	setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);

	return 0;
}