blob: f5c2eaa808a3a0ccf7c0fbf22e06a4204d3908df [file] [log] [blame]
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +02001/*
2 * Copyright (C) Marvell International Ltd. and its affiliates
3 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
4 *
Stefan Roese64174892015-10-22 12:36:31 +02005 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +02008 */
9
10#include <common.h>
Lei Wen298ae912011-10-18 20:11:42 +053011#include <asm/io.h>
Stefan Roesec2437842014-10-22 12:13:06 +020012#include <asm/arch/soc.h>
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020013
Heiko Schocher5504dab2011-01-20 22:56:39 +000014DECLARE_GLOBAL_DATA_PTR;
15
Stefan Roese64174892015-10-22 12:36:31 +020016#define TIMER_LOAD_VAL 0xffffffff
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020017
Stefan Roese64174892015-10-22 12:36:31 +020018static int init_done __attribute__((section(".data"))) = 0;
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020019
20/*
Stefan Roese64174892015-10-22 12:36:31 +020021 * Timer initialization
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020022 */
23int timer_init(void)
24{
Stefan Roesed04fe8b2015-07-15 15:36:52 +020025 /* Only init the timer once */
26 if (init_done)
27 return 0;
28 init_done = 1;
29
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020030 /* load value into timer */
Stefan Roese64174892015-10-22 12:36:31 +020031 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
32 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020033
Stefan Roeseeb083e52015-12-21 13:56:33 +010034#if defined(CONFIG_ARCH_MVEBU)
Stefan Roese64174892015-10-22 12:36:31 +020035 /* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */
36 setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11));
37#endif
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020038 /* enable timer in auto reload mode */
Stefan Roese64174892015-10-22 12:36:31 +020039 setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020040
41 return 0;
42}