convert aruba to the new structure
[openwrt/svn-archive/archive.git] / target / linux / aruba-2.6 / files / arch / mips / aruba / time.c
1 /**************************************************************************
2 *
3 * BRIEF MODULE DESCRIPTION
4 * timer routines for IDT EB434 boards
5 *
6 * Copyright 2004 IDT Inc. (rischelp@idt.com)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 *
29 **************************************************************************
30 * May 2004 rkt, neb
31 *
32 * Initial Release
33 *
34 *
35 *
36 **************************************************************************
37 */
38
39 #include <linux/autoconf.h>
40 #include <linux/init.h>
41 #include <linux/kernel_stat.h>
42 #include <linux/sched.h>
43 #include <linux/spinlock.h>
44 #include <linux/mc146818rtc.h>
45 #include <linux/irq.h>
46 #include <linux/timex.h>
47
48 #include <linux/param.h>
49 #include <asm/mipsregs.h>
50 #include <asm/ptrace.h>
51 #include <asm/time.h>
52 #include <asm/hardirq.h>
53
54 #include <asm/mipsregs.h>
55 #include <asm/ptrace.h>
56 #include <asm/debug.h>
57 #include <asm/time.h>
58
59 #include <asm/idt-boards/rc32434/rc32434.h>
60
61 static unsigned long r4k_offset; /* Amount to incr compare reg each time */
62 static unsigned long r4k_cur; /* What counter should be at next timer irq */
63
64 extern unsigned int idt_cpu_freq;
65
66 static unsigned long __init cal_r4koff(void)
67 {
68 mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
69 return (mips_hpt_frequency / HZ);
70 }
71
72 void __init aruba_time_init(void)
73 {
74 unsigned int est_freq, flags;
75 local_irq_save(flags);
76
77 printk("calculating r4koff... ");
78 r4k_offset = cal_r4koff();
79 printk("%08lx(%d)\n", r4k_offset, (int)r4k_offset);
80
81 est_freq = 2 * r4k_offset * HZ;
82 est_freq += 5000; /* round */
83 est_freq -= est_freq % 10000;
84 printk("CPU frequency %d.%02d MHz\n", est_freq / 1000000,
85 (est_freq % 1000000) * 100 / 1000000);
86 local_irq_restore(flags);
87
88 }
89
90 void __init plat_timer_setup(struct irqaction *irq)
91 {
92 /* we are using the cpu counter for timer interrupts */
93 setup_irq(MIPS_CPU_TIMER_IRQ, irq);
94
95 /* to generate the first timer interrupt */
96 r4k_cur = (read_c0_count() + r4k_offset);
97 write_c0_compare(r4k_cur);
98
99 }
100
101 asmlinkage void aruba_timer_interrupt(struct pt_regs *regs)
102 {
103 int irq = MIPS_CPU_TIMER_IRQ;
104
105 irq_enter();
106 kstat_this_cpu.irqs[irq]++;
107
108 timer_interrupt(irq, NULL);
109 irq_exit();
110 }