Full support for Ginger Console
[linux-ginger.git] / arch / h8300 / kernel / timer / timer16.c
blob042dbb53f3fb372707ab7a533a884e7ccb6b8dd3
1 /*
2 * linux/arch/h8300/kernel/timer/timer16.c
4 * Yoshinori Sato <ysato@users.sourcefoge.jp>
6 * 16bit Timer Handler
8 */
10 #include <linux/errno.h>
11 #include <linux/sched.h>
12 #include <linux/kernel.h>
13 #include <linux/param.h>
14 #include <linux/string.h>
15 #include <linux/mm.h>
16 #include <linux/interrupt.h>
17 #include <linux/init.h>
18 #include <linux/timex.h>
20 #include <asm/segment.h>
21 #include <asm/io.h>
22 #include <asm/irq.h>
23 #include <asm/regs306x.h>
25 /* 16bit timer */
26 #if CONFIG_H8300_TIMER16_CH == 0
27 #define _16BASE 0xffff78
28 #define _16IRQ 24
29 #elif CONFIG_H8300_TIMER16_CH == 1
30 #define _16BASE 0xffff80
31 #define _16IRQ 28
32 #elif CONFIG_H8300_TIMER16_CH == 2
33 #define _16BASE 0xffff88
34 #define _16IRQ 32
35 #else
36 #error Unknown timer channel.
37 #endif
39 #define TCR 0
40 #define TIOR 1
41 #define TCNT 2
42 #define GRA 4
43 #define GRB 6
45 #define H8300_TIMER_FREQ CONFIG_CPU_CLOCK*10000 /* Timer input freq. */
47 static irqreturn_t timer_interrupt(int irq, void *dev_id)
49 h8300_timer_tick();
50 ctrl_bclr(CONFIG_H8300_TIMER16_CH, TISRA);
51 return IRQ_HANDLED;
54 static struct irqaction timer16_irq = {
55 .name = "timer-16",
56 .handler = timer_interrupt,
57 .flags = IRQF_DISABLED | IRQF_TIMER,
60 static const int __initdata divide_rate[] = {1, 2, 4, 8};
62 void __init h8300_timer_setup(void)
64 unsigned int div;
65 unsigned int cnt;
67 calc_param(cnt, div, divide_rate, 0x10000);
69 setup_irq(_16IRQ, &timer16_irq);
71 /* initalize timer */
72 ctrl_outb(0, TSTR);
73 ctrl_outb(CCLR0 | div, _16BASE + TCR);
74 ctrl_outw(cnt, _16BASE + GRA);
75 ctrl_bset(4 + CONFIG_H8300_TIMER16_CH, TISRA);
76 ctrl_bset(CONFIG_H8300_TIMER16_CH, TSTR);