blob: 43b3ed15d07448b9460b0b264deeac7b5f0a86db [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +02002/*
3 * Copyright (C) Marvell International Ltd. and its affiliates
4 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
5 *
Stefan Roese64174892015-10-22 12:36:31 +02006 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +02007 */
8
9#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060013#include <linux/bitops.h>
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020014
Stefan Roese64174892015-10-22 12:36:31 +020015#define TIMER_LOAD_VAL 0xffffffff
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020016
Stefan Roese64174892015-10-22 12:36:31 +020017static int init_done __attribute__((section(".data"))) = 0;
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020018
19/*
Stefan Roese64174892015-10-22 12:36:31 +020020 * Timer initialization
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020021 */
22int timer_init(void)
23{
Stefan Roesed04fe8b2015-07-15 15:36:52 +020024 /* Only init the timer once */
25 if (init_done)
26 return 0;
27 init_done = 1;
28
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020029 /* load value into timer */
Stefan Roese64174892015-10-22 12:36:31 +020030 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
31 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020032
Stefan Roeseeb083e52015-12-21 13:56:33 +010033#if defined(CONFIG_ARCH_MVEBU)
Stefan Roese64174892015-10-22 12:36:31 +020034 /* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */
35 setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11));
36#endif
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020037 /* enable timer in auto reload mode */
Stefan Roese64174892015-10-22 12:36:31 +020038 setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020039
40 return 0;
41}