1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (C) Marvell International Ltd. and its affiliates 3*4882a593Smuzhiyun * Written-by: Prafulla Wadaskar <prafulla@marvell.com> 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2015 Stefan Roese <sr@denx.de> 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #include <common.h> 11*4882a593Smuzhiyun #include <asm/io.h> 12*4882a593Smuzhiyun #include <asm/arch/soc.h> 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR; 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun #define TIMER_LOAD_VAL 0xffffffff 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun static int init_done __attribute__((section(".data"))) = 0; 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun /* 21*4882a593Smuzhiyun * Timer initialization 22*4882a593Smuzhiyun */ timer_init(void)23*4882a593Smuzhiyunint timer_init(void) 24*4882a593Smuzhiyun { 25*4882a593Smuzhiyun /* Only init the timer once */ 26*4882a593Smuzhiyun if (init_done) 27*4882a593Smuzhiyun return 0; 28*4882a593Smuzhiyun init_done = 1; 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /* load value into timer */ 31*4882a593Smuzhiyun writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x10); 32*4882a593Smuzhiyun writel(TIMER_LOAD_VAL, MVEBU_TIMER_BASE + 0x14); 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun #if defined(CONFIG_ARCH_MVEBU) 35*4882a593Smuzhiyun /* On Armada XP / 38x ..., the 25MHz clock source needs to be enabled */ 36*4882a593Smuzhiyun setbits_le32(MVEBU_TIMER_BASE + 0x00, BIT(11)); 37*4882a593Smuzhiyun #endif 38*4882a593Smuzhiyun /* enable timer in auto reload mode */ 39*4882a593Smuzhiyun setbits_le32(MVEBU_TIMER_BASE + 0x00, 0x3); 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun return 0; 42*4882a593Smuzhiyun } 43