/*
 *  File Name	    : linux/include/asm-arm/arch-mp200/timer.h
 *  Function	    : timer
 *  Release Version : Ver 1.02
 *  Release Date    : 2006/02/17
 *
 *  Copyright (C) NEC Electronics Corporation 2006
 *
 *
 *  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 Free Softwere Foundation; either version 2
 *  of 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 warrnty 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_ARM_ARCH_MP200_TIMER_H
#define __ASM_ARM_ARCH_MP200_TIMER_H

#ifdef CONFIG_MP201
#define TIMER_TG0		0
#define TIMER_TG1		1
#define TIMER_TG2		2
#define TIMER_TG3		3

#define TIMER_TI0		4
#define TIMER_TI1		5

#define TIMER_TW0		6
#define TIMER_TW1		7
#else
#define TIMER_TG0		0
#define TIMER_TG1		1
#define TIMER_TG2		2
#define TIMER_TG3		3
#define TIMER_TG4		4
#define TIMER_TG5		5

#define TIMER_TI0		6
#define TIMER_TI1		7
#define TIMER_TI2		8

#define TIMER_TW0		9
#define TIMER_TW1		10
#define TIMER_TW2		11
#endif				/* CONFIG_MP201 */

#if (defined(CONFIG_KFI) || defined(CONFIG_ILATENCY) || defined(CONFIG_DPM_STATS))
#define TIMER_TG_MIN		TIMER_TG1
#else
#define TIMER_TG_MIN		TIMER_TG0
#endif

#ifdef CONFIG_MP201
#define TIMER_TG_MAX_NUM	4
#else
#define TIMER_TG_MAX_NUM	6
#endif				/* CONFIG_MP201 */

#define TIMER_MAX_NUM		1

#define TIMER_MIN_USECS		62
#define TIMER_MAX_USECS		357913941
#define TIMER_MAX_COUNT		0xffffffff
#define TIMER_DEFAULT_TIME	TIMER_MAX_COUNT

#include <asm/arch/timex.h>

/* convert usec to count. */
#define USEC_TO_COUNT_32K(x)	((((unsigned long long int)(x) * CLOCK_TICK_RATE_32K) / 1000000) - 1)
#define USEC_TO_COUNT_12M(x)	((((unsigned long long int)(x) * CLOCK_TICK_RATE_12M) / 1000000) - 1)

/* convert count to usec. */
#define COUNT_TO_USEC_32K(x)	(((unsigned long long int)(x) * 1000000) / CLOCK_TICK_RATE_32K)
#define COUNT_TO_USEC_12M(x)	(((unsigned long long int)(x) * 1000000) / CLOCK_TICK_RATE_12M)

#include <linux/interrupt.h>

extern irqreturn_t(*timer_cb_t(int, void *, struct pt_regs *));

extern int mp200_timer_start(unsigned int timer);
extern int mp200_timer_stop(unsigned int timer);
extern int mp200_timer_set_period(unsigned int timer, unsigned int usecs);
extern int mp200_timer_get_period(unsigned int timer, unsigned int *usecs);
extern int mp200_timer_get_usecs(unsigned int timer, unsigned int *usecs);
extern int mp200_timer_get_counts(unsigned int timer, unsigned int *counts);
extern int mp200_timer_register_cb(unsigned int timer, char *devname,
				   irqreturn_t(*cb) (int, void *,
						     struct pt_regs *),
				   void *dev_id);
extern int mp200_timer_unregister_cb(unsigned int timer, void *dev_id);

extern int mp200_wdt_set_timeout(unsigned int timer, unsigned int usecs);
extern int mp200_wdt_ping(unsigned int timer);

#endif
