blob: f5c2eaa808a3a0ccf7c0fbf22e06a4204d3908df [file] [log] [blame]
Prafulla Wadaskar4efb77d2009-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 Roese2fbc18f2015-10-22 12:36:31 +02005 * Copyright (C) 2015 Stefan Roese <sr@denx.de>
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +02008 */
9
10#include <common.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 +020014DECLARE_GLOBAL_DATA_PTR;
Stefan Roese22700dc2014-10-22 12:13:08 +020015
Stefan Roese2fbc18f2015-10-22 12:36:31 +020016#define TIMER_LOAD_VAL 0xffffffff
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020017
Stefan Roese787ddb72015-09-03 12:47:07 +020018static int init_done __attribute__((section(".data"))) = 0;
Stefan Roeseade741b2015-07-15 15:36:52 +020019
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020020/*
Stefan Roese2fbc18f2015-10-22 12:36:31 +020021 * Timer initialization
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020022 */
23int timer_init(void)
24{
Stefan Roeseade741b2015-07-15 15:36:52 +020025 /* Only init the timer once */
26 if (init_done)
27 return 0;
28 init_done = 1;
29
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020030 /* load value into timer */
Stefan Roese2fbc18f2015-10-22 12:36:31 +020031 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10);
32 writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020033
Stefan Roese81e33f42015-12-21 13:56:33 +010034#if defined(CONFIG_ARCH_MVEBU)
Stefan Roese2fbc18f2015-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 Wadaskar4efb77d2009-06-20 11:01:53 +020038 /* enable timer in auto reload mode */
Stefan Roese2fbc18f2015-10-22 12:36:31 +020039 setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020040
41 return 0;
42}