2 * bcu.c, Bus Control Unit routines for the NEC VR4100 series.
4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * MontaVista Software Inc. <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported.
26 * - Added support for NEC VR4111 and VR4121.
28 * Yoichi Yuasa <yuasa@linux-mips.org>
29 * - Added support for NEC VR4133.
31 #include <linux/export.h>
32 #include <linux/kernel.h>
33 #include <linux/smp.h>
34 #include <linux/types.h>
36 #include <asm/cpu-type.h>
40 #define CLKSPEEDREG_TYPE1 (void __iomem *)KSEG1ADDR(0x0b000014)
41 #define CLKSPEEDREG_TYPE2 (void __iomem *)KSEG1ADDR(0x0f000014)
42 #define CLKSP(x) ((x) & 0x001f)
43 #define CLKSP_VR4133(x) ((x) & 0x0007)
49 #define DIVT(x) (((x) & 0xf000) >> 12)
50 #define DIVVT(x) (((x) & 0x0f00) >> 8)
52 #define TDIVMODE(x) (2 << (((x) & 0x1000) >> 12))
53 #define VTDIVMODE(x) (((x) & 0x0700) >> 8)
55 static unsigned long vr41xx_vtclock
;
56 static unsigned long vr41xx_tclock
;
58 unsigned long vr41xx_get_vtclock_frequency(void)
60 return vr41xx_vtclock
;
63 EXPORT_SYMBOL_GPL(vr41xx_get_vtclock_frequency
);
65 unsigned long vr41xx_get_tclock_frequency(void)
70 EXPORT_SYMBOL_GPL(vr41xx_get_tclock_frequency
);
72 static inline uint16_t read_clkspeed(void)
74 switch (current_cpu_type()) {
76 case CPU_VR4121
: return readw(CLKSPEEDREG_TYPE1
);
79 case CPU_VR4133
: return readw(CLKSPEEDREG_TYPE2
);
81 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
88 static inline unsigned long calculate_pclock(uint16_t clkspeed
)
90 unsigned long pclock
= 0;
92 switch (current_cpu_type()) {
95 pclock
= 18432000 * 64;
96 pclock
/= CLKSP(clkspeed
);
99 pclock
= 18432000 * 98;
100 pclock
/= CLKSP(clkspeed
);
103 pclock
= 18432000 * 108;
104 pclock
/= CLKSP(clkspeed
);
107 switch (CLKSP_VR4133(clkspeed
)) {
124 printk(KERN_INFO
"Unknown PClock speed for NEC VR4133\n");
129 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
133 printk(KERN_INFO
"PClock: %ldHz\n", pclock
);
138 static inline unsigned long calculate_vtclock(uint16_t clkspeed
, unsigned long pclock
)
140 unsigned long vtclock
= 0;
142 switch (current_cpu_type()) {
144 /* The NEC VR4111 doesn't have the VTClock. */
148 /* DIVVT == 9 Divide by 1.5 . VTClock = (PClock * 6) / 9 */
149 if (DIVVT(clkspeed
) == 9)
150 vtclock
= pclock
* 6;
151 /* DIVVT == 10 Divide by 2.5 . VTClock = (PClock * 4) / 10 */
152 else if (DIVVT(clkspeed
) == 10)
153 vtclock
= pclock
* 4;
154 vtclock
/= DIVVT(clkspeed
);
155 printk(KERN_INFO
"VTClock: %ldHz\n", vtclock
);
158 if(VTDIVMODE(clkspeed
) == 7)
159 vtclock
= pclock
/ 1;
160 else if(VTDIVMODE(clkspeed
) == 1)
161 vtclock
= pclock
/ 2;
163 vtclock
= pclock
/ VTDIVMODE(clkspeed
);
164 printk(KERN_INFO
"VTClock: %ldHz\n", vtclock
);
168 vtclock
= pclock
/ VTDIVMODE(clkspeed
);
169 printk(KERN_INFO
"VTClock: %ldHz\n", vtclock
);
172 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
179 static inline unsigned long calculate_tclock(uint16_t clkspeed
, unsigned long pclock
,
180 unsigned long vtclock
)
182 unsigned long tclock
= 0;
184 switch (current_cpu_type()) {
186 if (!(clkspeed
& DIV2B
))
188 else if (!(clkspeed
& DIV3B
))
190 else if (!(clkspeed
& DIV4B
))
194 tclock
= pclock
/ DIVT(clkspeed
);
199 tclock
= vtclock
/ TDIVMODE(clkspeed
);
202 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
206 printk(KERN_INFO
"TClock: %ldHz\n", tclock
);
211 void vr41xx_calculate_clock_frequency(void)
213 unsigned long pclock
;
216 clkspeed
= read_clkspeed();
218 pclock
= calculate_pclock(clkspeed
);
219 vr41xx_vtclock
= calculate_vtclock(clkspeed
, pclock
);
220 vr41xx_tclock
= calculate_tclock(clkspeed
, pclock
, vr41xx_vtclock
);
223 EXPORT_SYMBOL_GPL(vr41xx_calculate_clock_frequency
);