3 Copyright 2004 Broadcom Corp. All Rights Reserved.
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.
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
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.
20 * Setup time for Broadcom 963xx MIPS boards
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>
33 #include <asm/mipsregs.h>
34 #include <asm/ptrace.h>
35 #include <asm/div64.h>
38 #include <bcm_map_part.h>
41 static unsigned long r4k_offset; /* Amount to increment compare reg each time */
42 static unsigned long r4k_cur; /* What counter should be at next timer irq */
44 /* *********************************************************************
46 * Calculate the BCM6348 CPU speed by reading the PLL strap register
47 * and applying the following formula:
48 * cpu_clk = (.25 * 64MHz freq) * (N1 + 1) * (N2 + 2) / (M1_CPU + 1)
53 ********************************************************************* */
55 static inline unsigned long __init calculateCpuSpeed(void)
57 UINT32 pllStrap = PERF->PllStrap;
58 int n1 = (pllStrap & PLL_N1_MASK) >> PLL_N1_SHFT;
59 int n2 = (pllStrap & PLL_N2_MASK) >> PLL_N2_SHFT;
60 int m1cpu = (pllStrap & PLL_M1_CPU_MASK) >> PLL_M1_CPU_SHFT;
62 return (16 * (n1 + 1) * (n2 + 2) / (m1cpu + 1)) * 1000000;
66 static inline unsigned long __init cal_r4koff(void)
68 mips_hpt_frequency = calculateCpuSpeed() / 2;
69 return (mips_hpt_frequency / HZ);
74 * There are a lot of conceptually broken versions of the MIPS timer interrupt
75 * handler floating around. This one is rather different, but the algorithm
76 * is provably more robust.
78 irqreturn_t brcm_timer_interrupt(struct pt_regs *regs)
80 int irq = MIPS_TIMER_INT;
83 kstat_this_cpu.irqs[irq]++;
85 timer_interrupt(irq, regs);
91 void __init brcm_time_init(void)
93 unsigned int est_freq, flags;
94 local_irq_save(flags);
96 printk("calculating r4koff... ");
97 r4k_offset = cal_r4koff();
98 printk("%08lx(%d)\n", r4k_offset, (int)r4k_offset);
100 est_freq = 2 * r4k_offset * HZ;
101 est_freq += 5000; /* round */
102 est_freq -= est_freq % 10000;
103 printk("CPU frequency %d.%02d MHz\n", est_freq / 1000000,
104 (est_freq % 1000000) * 100 / 1000000);
105 local_irq_restore(flags);
109 void __init plat_timer_setup(struct irqaction *irq)
111 r4k_cur = (read_c0_count() + r4k_offset);
112 write_c0_compare(r4k_cur);
113 set_c0_status(IE_IRQ5);