13320a6caf8d76a80749564aea7d1497912f20c5
[openwrt/svn-archive/archive.git] / target / linux / rb532 / files / arch / mips / rb500 / time.c
1 /*
2 ****************************************************************************
3 * Carsten Langgaard, carstenl@mips.com
4 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
5 *
6 ***************************************************************************
7 *
8 * This program is free software; you can distribute it and/or modify it
9 * under the terms of the GNU General Public License (Version 2) as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
20 *
21 ****************************************************************************
22 *
23 * Setting up the clock on the MIPS boards.
24 *
25 ****************************************************************************
26 * P. Sadik Oct 10, 2003
27 *
28 * Started change log.
29 * mips_counter_frequency is now calculated at run time, based on idt_cpu_freq.
30 * Code cleanup
31 ****************************************************************************
32 */
33
34 #include <linux/autoconf.h>
35 #include <linux/init.h>
36 #include <linux/kernel_stat.h>
37 #include <linux/sched.h>
38 #include <linux/spinlock.h>
39 #include <linux/mc146818rtc.h>
40 #include <linux/irq.h>
41 #include <linux/timex.h>
42
43 #include <asm/irq_cpu.h>
44 #include <asm/mipsregs.h>
45 #include <asm/ptrace.h>
46 #include <asm/debug.h>
47 #include <asm/rc32434/rc32434.h>
48
49 static unsigned long r4k_offset; /* Amount to incr compare reg each time */
50 static unsigned long r4k_cur; /* What counter should be at next timer irq */
51 extern unsigned int mips_hpt_frequency;
52 extern unsigned int idt_cpu_freq;
53
54 /*
55 * Figure out the r4k offset, the amount to increment the compare
56 * register for each time tick. There is no RTC available.
57 *
58 * The RC32434 counts at half the CPU *core* speed.
59 */
60 static unsigned long __init cal_r4koff(void)
61 {
62 mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
63 return (mips_hpt_frequency / HZ);
64 }
65
66
67 void __init rc32434_time_init(void)
68 {
69 unsigned int est_freq, flags;
70
71 local_irq_save(flags);
72
73 printk("calculating r4koff... ");
74 r4k_offset = cal_r4koff();
75 printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
76
77 est_freq = 2*r4k_offset*HZ;
78 est_freq += 5000; /* round */
79 est_freq -= est_freq%10000;
80 printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
81 (est_freq%1000000)*100/1000000);
82 local_irq_restore(flags);
83 }
84
85 void __init plat_timer_setup(struct irqaction *irq)
86 {
87 /* we are using the cpu counter for timer interrupts */
88 setup_irq(MIPS_CPU_TIMER_IRQ, irq);
89
90 /* to generate the first timer interrupt */
91 r4k_cur = (read_c0_count() + r4k_offset);
92 write_c0_compare(r4k_cur);
93 }
94