blob: 43b3ed15d07448b9460b0b264deeac7b5f0a86db [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar4efb77d2009-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 Roese2fbc18f2015-10-22 12:36:31 +02006 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +02007 */
8
9#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Lei Wena7efd712011-10-18 20:11:42 +053011#include <asm/io.h>
Stefan Roese3dc23f72014-10-22 12:13:06 +020012#include <asm/arch/soc.h>
Simon Glasscd93d622020-05-10 11:40:13 -060013#include <linux/bitops.h>
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020014
Stefan Roese2fbc18f2015-10-22 12:36:31 +020015#define TIMER_LOAD_VAL 0xffffffff
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020016
Stefan Roese787ddb72015-09-03 12:47:07 +020017static int init_done __attribute__((section(".data"))) = 0;
Stefan Roeseade741b2015-07-15 15:36:52 +020018
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020019/*
Stefan Roese2fbc18f2015-10-22 12:36:31 +020020 * Timer initialization
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020021 */
22int timer_init(void)
23{
Stefan Roeseade741b2015-07-15 15:36:52 +020024 /* Only init the timer once */
25 if (init_done)
26 return 0;
27 init_done = 1;
28
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020029 /* load value into timer */
Stefan Roese2fbc18f2015-10-22 12:36:31 +020030 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
31 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020032
Stefan Roese81e33f42015-12-21 13:56:33 +010033#if defined(CONFIG_ARCH_MVEBU)
Stefan Roese2fbc18f2015-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 Wadaskar4efb77d2009-06-20 11:01:53 +020037 /* enable timer in auto reload mode */
Stefan Roese2fbc18f2015-10-22 12:36:31 +020038 setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020039
40 return 0;
41}