strip the kernel version suffix from target directories, except for brcm-2.4 (the...
[openwrt/staging/florian.git] / target / linux / brcm63xx / files / arch / mips / bcm963xx / time.c
1 /*
2 <:copyright-gpl
3 Copyright 2004 Broadcom Corp. All Rights Reserved.
4
5 This program is free software; you can distribute it and/or modify it
6 under the terms of the GNU General Public License (Version 2) as
7 published by the Free Software Foundation.
8
9 This program is distributed in the hope it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 :>
18 */
19 /*
20 * Setup time for Broadcom 963xx MIPS boards
21 */
22
23 #include <linux/autoconf.h>
24 #include <linux/init.h>
25 #include <linux/kernel_stat.h>
26 #include <linux/sched.h>
27 #include <linux/spinlock.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/time.h>
31 #include <linux/timex.h>
32
33 #include <asm/mipsregs.h>
34 #include <asm/ptrace.h>
35 #include <asm/div64.h>
36 #include <asm/time.h>
37
38 #include <6348_map_part.h>
39 #include <6348_intr.h>
40 #include <bcm_map_part.h>
41 #include <bcm_intr.h>
42
43 static unsigned long r4k_offset; /* Amount to increment compare reg each time */
44 static unsigned long r4k_cur; /* What counter should be at next timer irq */
45
46 /* *********************************************************************
47 * calculateCpuSpeed()
48 * Calculate the BCM6348 CPU speed by reading the PLL strap register
49 * and applying the following formula:
50 * cpu_clk = (.25 * 64MHz freq) * (N1 + 1) * (N2 + 2) / (M1_CPU + 1)
51 * Input parameters:
52 * none
53 * Return value:
54 * none
55 ********************************************************************* */
56
57 static inline unsigned long __init calculateCpuSpeed(void)
58 {
59 u32 pllStrap = PERF->PllStrap;
60 int n1 = (pllStrap & PLL_N1_MASK) >> PLL_N1_SHFT;
61 int n2 = (pllStrap & PLL_N2_MASK) >> PLL_N2_SHFT;
62 int m1cpu = (pllStrap & PLL_M1_CPU_MASK) >> PLL_M1_CPU_SHFT;
63
64 return (16 * (n1 + 1) * (n2 + 2) / (m1cpu + 1)) * 1000000;
65 }
66
67
68 static inline unsigned long __init cal_r4koff(void)
69 {
70 mips_hpt_frequency = calculateCpuSpeed() / 2;
71 return (mips_hpt_frequency / HZ);
72 }
73
74
75 /*
76 * There are a lot of conceptually broken versions of the MIPS timer interrupt
77 * handler floating around. This one is rather different, but the algorithm
78 * is provably more robust.
79 */
80 irqreturn_t brcm_timer_interrupt(struct pt_regs *regs)
81 {
82 int irq = MIPS_TIMER_INT;
83
84 irq_enter();
85 kstat_this_cpu.irqs[irq]++;
86
87 timer_interrupt(irq, regs);
88 irq_exit();
89 return IRQ_HANDLED;
90 }
91
92
93 void __init brcm_time_init(void)
94 {
95 unsigned int est_freq, flags;
96 local_irq_save(flags);
97
98 printk("calculating r4koff... ");
99 r4k_offset = cal_r4koff();
100 printk("%08lx(%d)\n", r4k_offset, (int)r4k_offset);
101
102 est_freq = 2 * r4k_offset * HZ;
103 est_freq += 5000; /* round */
104 est_freq -= est_freq % 10000;
105 printk("CPU frequency %d.%02d MHz\n", est_freq / 1000000,
106 (est_freq % 1000000) * 100 / 1000000);
107 local_irq_restore(flags);
108 }
109
110
111 void __init plat_timer_setup(struct irqaction *irq)
112 {
113 r4k_cur = (read_c0_count() + r4k_offset);
114 write_c0_compare(r4k_cur);
115 set_c0_status(IE_IRQ5);
116 }