blob: 50b78cb07b0bee5cf2b2c07924a465f58a1c693e [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>
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020013
Stefan Roese2fbc18f2015-10-22 12:36:31 +020014#define TIMER_LOAD_VAL 0xffffffff
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020015
Stefan Roese787ddb72015-09-03 12:47:07 +020016static int init_done __attribute__((section(".data"))) = 0;
Stefan Roeseade741b2015-07-15 15:36:52 +020017
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020018/*
Stefan Roese2fbc18f2015-10-22 12:36:31 +020019 * Timer initialization
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020020 */
21int timer_init(void)
22{
Stefan Roeseade741b2015-07-15 15:36:52 +020023 /* Only init the timer once */
24 if (init_done)
25 return 0;
26 init_done = 1;
27
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020028 /* load value into timer */
Stefan Roese2fbc18f2015-10-22 12:36:31 +020029 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
30 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020031
Stefan Roese81e33f42015-12-21 13:56:33 +010032#if defined(CONFIG_ARCH_MVEBU)
Stefan Roese2fbc18f2015-10-22 12:36:31 +020033 /* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */
34 setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11));
35#endif
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020036 /* enable timer in auto reload mode */
Stefan Roese2fbc18f2015-10-22 12:36:31 +020037 setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020038
39 return 0;
40}