3 * arch/mips/vr41xx/common/bcu.c
5 * BRIEF MODULE DESCRIPTION
6 * Bus Control Unit routines for the NEC VR4100 series.
9 * yyuasa@mvista.com or source@mvista.com
11 * Copyright 2002 MontaVista Software Inc.
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
35 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com>
36 * - Added support for NEC VR4111 and VR4121.
38 * Paul Mundt <lethal@chaoticdreams.org>
39 * - Calculate mips_counter_frequency properly on VR4131.
41 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com>
42 * - New creation, NEC VR4122 and VR4131 are supported.
44 #include <linux/init.h>
45 #include <linux/types.h>
47 #include <asm/addrspace.h>
51 #include <asm/vr41xx/vr41xx.h>
53 #define VR4111_CLKSPEEDREG KSEG1ADDR(0x0b000014)
54 #define VR4122_CLKSPEEDREG KSEG1ADDR(0x0f000014)
55 #define VR4131_CLKSPEEDREG VR4122_CLKSPEEDREG
56 #define CLKSP(x) ((x) & 0x001f)
62 #define DIVT(x) (((x) & 0xf000) >> 12)
63 #define DIVVT(x) (((x) & 0x0f00) >> 8)
65 #define TDIVMODE(x) (2 << (((x) & 0x1000) >> 12))
66 #define VTDIVMODE(x) (((x) & 0x0700) >> 8)
68 unsigned long vr41xx_vtclock
= 0;
70 static inline u16
read_clkspeed(void)
72 switch (current_cpu_data
.cputype
) {
74 case CPU_VR4121
: return readw(VR4111_CLKSPEEDREG
);
75 case CPU_VR4122
: return readw(VR4122_CLKSPEEDREG
);
76 case CPU_VR4131
: return readw(VR4131_CLKSPEEDREG
);
78 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
85 static inline unsigned long calculate_pclock(u16 clkspeed
)
87 unsigned long pclock
= 0;
89 switch (current_cpu_data
.cputype
) {
92 pclock
= 18432000 * 64;
95 pclock
= 18432000 * 98;
98 pclock
= 18432000 * 108;
101 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
105 pclock
/= CLKSP(clkspeed
);
106 printk(KERN_INFO
"PClock: %ldHz\n", pclock
);
111 static inline unsigned long calculate_vtclock(u16 clkspeed
, unsigned long pclock
)
113 switch (current_cpu_data
.cputype
) {
115 /* The NEC VR4111 doesn't have the VTClock. */
118 vr41xx_vtclock
= pclock
;
119 /* DIVVT == 9 Divide by 1.5 . VTClock = (PClock * 6) / 9 */
120 if (DIVVT(clkspeed
) == 9)
121 vr41xx_vtclock
= pclock
* 6;
122 /* DIVVT == 10 Divide by 2.5 . VTClock = (PClock * 4) / 10 */
123 else if (DIVVT(clkspeed
) == 10)
124 vr41xx_vtclock
= pclock
* 4;
125 vr41xx_vtclock
/= DIVVT(clkspeed
);
126 printk(KERN_INFO
"VTClock: %ldHz\n", vr41xx_vtclock
);
129 if(VTDIVMODE(clkspeed
) == 7)
130 vr41xx_vtclock
= pclock
/ 1;
131 else if(VTDIVMODE(clkspeed
) == 1)
132 vr41xx_vtclock
= pclock
/ 2;
134 vr41xx_vtclock
= pclock
/ VTDIVMODE(clkspeed
);
135 printk(KERN_INFO
"VTClock: %ldHz\n", vr41xx_vtclock
);
138 vr41xx_vtclock
= pclock
/ VTDIVMODE(clkspeed
);
139 printk(KERN_INFO
"VTClock: %ldHz\n", vr41xx_vtclock
);
142 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
146 return vr41xx_vtclock
;
149 static inline unsigned long calculate_tclock(u16 clkspeed
, unsigned long pclock
,
150 unsigned long vtclock
)
152 unsigned long tclock
= 0;
154 switch (current_cpu_data
.cputype
) {
156 if (!(clkspeed
& DIV2B
))
158 else if (!(clkspeed
& DIV3B
))
160 else if (!(clkspeed
& DIV4B
))
164 tclock
= pclock
/ DIVT(clkspeed
);
168 tclock
= vtclock
/ TDIVMODE(clkspeed
);
171 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
175 printk(KERN_INFO
"TClock: %ldHz\n", tclock
);
180 static inline unsigned long calculate_mips_counter_frequency(unsigned long tclock
)
183 * VR4131 Revision 2.0 and 2.1 use a value of (tclock / 2).
185 if ((current_cpu_data
.processor_id
== PRID_VR4131_REV2_0
) ||
186 (current_cpu_data
.processor_id
== PRID_VR4131_REV2_1
))
194 void __init
vr41xx_bcu_init(void)
196 unsigned long pclock
, vtclock
, tclock
;
199 clkspeed
= read_clkspeed();
201 pclock
= calculate_pclock(clkspeed
);
202 vtclock
= calculate_vtclock(clkspeed
, pclock
);
203 tclock
= calculate_tclock(clkspeed
, pclock
, vtclock
);
205 mips_counter_frequency
= calculate_mips_counter_frequency(tclock
);