/*
 * include/asm-arm/arch-cxd4105/time.h
 *
 * OS timer definitions
 *
 * Copyright 2005,2006,2007 Sony Corporation
 *
 * This code is based on include/asm-arm/arch-integrator/time.h.
 */
/*
 *  linux/include/asm-arm/arch-integrator/time.h
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __ASM_ARCH_TIME_H__
#define __ASM_ARCH_TIME_H__

#include <asm/system.h>
#include <asm/arch/timex.h>
#include <asm/arch/regs-timer.h>

#ifdef CONFIG_CXD4105_UART3
# define TM_OFF 4
#else
# define TM_OFF 0
#endif
#define TIMER_FOR_TICK  (TM_OFF+0)
#define TIMER_FOR_SCHED (TM_OFF+1)
#define TIMER_FOR_APP   (TM_OFF+2)
#define TIMER_FOR_ETC   (TM_OFF+3)

/*
 * How long is the timer interval?
 */

#define TIMER_RELOAD	(CLOCK_TICK_RATE/HZ)
#define TICKS2USECS(x)	(((x) * 100)/(CLOCK_TICK_RATE/10000))
#ifndef __ASSEMBLY__
/* ticks to ns */
static inline unsigned long long ticks2ns(unsigned long long v)
{
#if defined(CONFIG_ARCH_CXD4108)
	v *= 500;  	/* v / 2.0MHz * 1000 = v * 500 */
#else /* CONFIG_ARCH_CXD4105 */
	v *= 3125;
	v >>= 2;   	/* v / 1.28MHz * 1000 = v * 3125 / 4 */
#endif
	return v;
}

extern unsigned long long read_sched_clock(void);

static inline unsigned long read_freerun(void)
{
	return readl(TIMER_VA_BASE(TIMER_FOR_SCHED)+CXD4105_TIMERREAD);
}

#define FREERUN_TICK_RATE CLOCK_TICK_RATE

extern unsigned long (*gettimeoffset)(void);
extern void cxd4105_timer_early_init(void);
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_ARCH_TIME_H__ */
