1/*
2 * include/asm-v850/v850e_timer_d.c -- `Timer D' component often used
3 *	with V850E CPUs
4 *
5 *  Copyright (C) 2001,02,03  NEC Electronics Corporation
6 *  Copyright (C) 2001,02,03  Miles Bader <miles@gnu.org>
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License.  See the file COPYING in the main directory of this
10 * archive for more details.
11 *
12 * Written by Miles Bader <miles@gnu.org>
13 */
14
15#include <linux/kernel.h>
16
17#include <asm/v850e_utils.h>
18#include <asm/v850e_timer_d.h>
19
20/* Start interval timer TIMER (0-3).  The timer will issue the
21   corresponding INTCMD interrupt RATE times per second.
22   This function does not enable the interrupt.  */
23void v850e_timer_d_configure (unsigned timer, unsigned rate)
24{
25	unsigned divlog2, count;
26
27	/* Calculate params for timer.  */
28	if (! calc_counter_params (
29		    V850E_TIMER_D_BASE_FREQ, rate,
30		    V850E_TIMER_D_TMCD_CS_MIN, V850E_TIMER_D_TMCD_CS_MAX, 16,
31		    &divlog2, &count))
32		printk (KERN_WARNING
33			"Cannot find interval timer %d setting suitable"
34			" for rate of %dHz.\n"
35			"Using rate of %dHz instead.\n",
36			timer, rate,
37			(V850E_TIMER_D_BASE_FREQ >> divlog2) >> 16);
38
39	/* Do the actual hardware timer initialization:  */
40
41	/* Enable timer.  */
42	V850E_TIMER_D_TMCD(timer) = V850E_TIMER_D_TMCD_CAE;
43	/* Set clock divider.  */
44	V850E_TIMER_D_TMCD(timer)
45		= V850E_TIMER_D_TMCD_CAE
46		| V850E_TIMER_D_TMCD_CS(divlog2);
47	/* Set timer compare register.  */
48	V850E_TIMER_D_CMD(timer) = count;
49	/* Start counting.  */
50	V850E_TIMER_D_TMCD(timer)
51		= V850E_TIMER_D_TMCD_CAE
52		| V850E_TIMER_D_TMCD_CS(divlog2)
53		| V850E_TIMER_D_TMCD_CE;
54}
55