1 From 7d6656dc127b54e53e507e8f264bb7e14e620cad Mon Sep 17 00:00:00 2001
2 From: Axel Gembe <ago@bastart.eu.org>
3 Date: Sat, 17 May 2008 15:02:39 +0200
4 Subject: [PATCH] bcm963xx: add new timer code
6 This basically selects the new generic MIPS timer code for BCM963xx and
7 simplifies the timer setup code.
9 Signed-off-by: Axel Gembe <ago@bastart.eu.org>
11 arch/mips/Kconfig | 2 +
12 arch/mips/bcm963xx/time.c | 64 ++++++++++++++++++++------------------------
13 2 files changed, 31 insertions(+), 35 deletions(-)
15 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
16 index 1b1c4bf..3f8be3f 100644
17 --- a/arch/mips/Kconfig
18 +++ b/arch/mips/Kconfig
19 @@ -67,6 +67,8 @@ config BCM963XX
21 select DMA_NONCOHERENT
26 This is a fmaily of boards based on the Broadcom MIPS32
28 diff --git a/arch/mips/bcm963xx/time.c b/arch/mips/bcm963xx/time.c
29 index 8a5007e..9fae8fd 100644
30 --- a/arch/mips/bcm963xx/time.c
31 +++ b/arch/mips/bcm963xx/time.c
35 Copyright 2004 Broadcom Corp. All Rights Reserved.
36 + Copyright (C) 2008 Axel Gembe <ago@bastart.eu.org>
38 This program is free software; you can distribute it and/or modify it
39 under the terms of the GNU General Public License (Version 2) as
41 #include <bcm_map_part.h>
44 -static unsigned long r4k_offset; /* Amount to increment compare reg each time */
45 -static unsigned long r4k_cur; /* What counter should be at next timer irq */
47 -/* *********************************************************************
48 - * calculateCpuSpeed()
49 - * Calculate the BCM6348 CPU speed by reading the PLL strap register
50 - * and applying the following formula:
51 - * cpu_clk = (.25 * 64MHz freq) * (N1 + 1) * (N2 + 2) / (M1_CPU + 1)
56 - ********************************************************************* */
59 + * calculateCpuSpeed()
61 + * Calculate the BCM6348 CPU speed by reading the PLL strap register and applying
62 + * the following formula:
64 + * cpu_clk = (.25 * 64MHz freq) * (N1 + 1) * (N2 + 2) / (M1_CPU + 1)
66 static inline unsigned long __init calculateCpuSpeed(void)
68 - u32 pllStrap = PERF->PllStrap;
69 - int n1 = (pllStrap & PLL_N1_MASK) >> PLL_N1_SHFT;
70 - int n2 = (pllStrap & PLL_N2_MASK) >> PLL_N2_SHFT;
71 - int m1cpu = (pllStrap & PLL_M1_CPU_MASK) >> PLL_M1_CPU_SHFT;
75 + pllStrap = PERF->PllStrap;
76 + n1 = (pllStrap & PLL_N1_MASK) >> PLL_N1_SHFT;
77 + n2 = (pllStrap & PLL_N2_MASK) >> PLL_N2_SHFT;
78 + m1cpu = (pllStrap & PLL_M1_CPU_MASK) >> PLL_M1_CPU_SHFT;
80 return (16 * (n1 + 1) * (n2 + 2) / (m1cpu + 1)) * 1000000;
84 -static inline unsigned long __init cal_r4koff(void)
86 - mips_hpt_frequency = calculateCpuSpeed() / 2;
87 - return (mips_hpt_frequency / HZ);
90 void __init plat_time_init(void)
92 - unsigned int est_freq, flags;
93 - local_irq_save(flags);
94 + unsigned long cpu_clock;
96 + cpu_clock = calculateCpuSpeed();
98 + printk("CPU frequency %lu.%02lu MHz\n", cpu_clock / 1000000,
99 + (cpu_clock % 1000000) * 100 / 1000000);
101 - printk("calculating r4koff... ");
102 - r4k_offset = cal_r4koff();
103 - printk("%08lx(%d)\n", r4k_offset, (int)r4k_offset);
104 + mips_hpt_frequency = cpu_clock / 2;
106 - est_freq = 2 * r4k_offset * HZ;
107 - est_freq += 5000; /* round */
108 - est_freq -= est_freq % 10000;
109 - printk("CPU frequency %d.%02d MHz\n", est_freq / 1000000,
110 - (est_freq % 1000000) * 100 / 1000000);
111 - local_irq_restore(flags);
113 + * Use deterministic values for initial counter interrupt
114 + * so that calibrate delay avoids encountering a counter wrap.
117 + write_c0_compare(0xffff);