/*
 * arch/arm/mach-cxd4115/timer.S
 *
 * TIMER initialize for CXD4115
 *
 * Copyright 2007,2008,2009 Sony Corporation
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 */

#include <linux/linkage.h>
#include <asm/assembler.h>
#include <asm/hardware.h>
#include <asm/arch/time.h>
#ifdef CONFIG_LOCAL_TIMER_TICK
# include <asm/hardware/arm_twd.h>
#else
# include <asm/arch/regs-timer.h>
#endif /* CONFIG_LOCAL_TIMER_TICK */

	.text				
ENTRY(timer_init)
	@ Preserve r0 and r1
#ifdef CONFIG_LOCAL_TIMER_TICK
	ldr	r2, =CXD4115_LOCALTIMER_BASE
	mov	r3, #0xffffffff
	str	r3, [r2, #TWD_WDOG_LOAD]
	ldr	r3, =((CXD4115_WDOG_DIV-1)<<TWD_PRESCALER_SHIFT)|TWD_AUTORELOAD|TWD_START
	str	r3, [r2, #TWD_WDOG_CONTROL]
#else /* CONFIG_LOCAL_TIMER_TICK */
	@ TIMER CLK and PCLK are enabled. (default)

	@ clear sched clock
	ldr	r2, =CXD4115_TIMER_BASE(TIMER_FOR_SCHED)
	mov	r3, #0
	str	r3, [r2, #CXD4105_TIMERCTL]
	mov	r3, #TMCLR|TMINTCLR
	str	r3, [r2, #CXD4105_TIMERCLR]

	@ start sched clock
	ldr	r3, =CXD4115_TMCK_SCHED_DIV|TMCS_FREERUN|TMST
	str	r3, [r2, #CXD4105_TIMERCTL]
#endif /* CONFIG_LOCAL_TIMER_TICK */
	
	mov	pc, lr
