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 * - New creation, NEC VR4122 and VR4131 are supported.
37 * - Added support for NEC VR4111 and VR4121.
39 * Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
40 * - Added support for NEC VR4133.
42 #include <linux/init.h>
43 #include <linux/smp.h>
44 #include <linux/types.h>
49 #define CLKSPEEDREG_TYPE1 KSEG1ADDR(0x0b000014)
50 #define CLKSPEEDREG_TYPE2 KSEG1ADDR(0x0f000014)
51 #define CLKSP(x) ((x) & 0x001f)
52 #define CLKSP_VR4133(x) ((x) & 0x0007)
58 #define DIVT(x) (((x) & 0xf000) >> 12)
59 #define DIVVT(x) (((x) & 0x0f00) >> 8)
61 #define TDIVMODE(x) (2 << (((x) & 0x1000) >> 12))
62 #define VTDIVMODE(x) (((x) & 0x0700) >> 8)
64 static unsigned long vr41xx_vtclock;
65 static unsigned long vr41xx_tclock;
67 unsigned long vr41xx_get_vtclock_frequency(void)
69 return vr41xx_vtclock;
72 unsigned long vr41xx_get_tclock_frequency(void)
77 static inline uint16_t read_clkspeed(void)
79 switch (current_cpu_data.cputype) {
81 case CPU_VR4121: return readw(CLKSPEEDREG_TYPE1);
84 case CPU_VR4133: return readw(CLKSPEEDREG_TYPE2);
86 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
93 static inline unsigned long calculate_pclock(uint16_t clkspeed)
95 unsigned long pclock = 0;
97 switch (current_cpu_data.cputype) {
100 pclock = 18432000 * 64;
101 pclock /= CLKSP(clkspeed);
104 pclock = 18432000 * 98;
105 pclock /= CLKSP(clkspeed);
108 pclock = 18432000 * 108;
109 pclock /= CLKSP(clkspeed);
112 switch (CLKSP_VR4133(clkspeed)) {
129 printk(KERN_INFO "Unknown PClock speed for NEC VR4133\n");
134 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
138 printk(KERN_INFO "PClock: %ldHz\n", pclock);
143 static inline unsigned long calculate_vtclock(uint16_t clkspeed, unsigned long pclock)
145 unsigned long vtclock = 0;
147 switch (current_cpu_data.cputype) {
149 /* The NEC VR4111 doesn't have the VTClock. */
153 /* DIVVT == 9 Divide by 1.5 . VTClock = (PClock * 6) / 9 */
154 if (DIVVT(clkspeed) == 9)
155 vtclock = pclock * 6;
156 /* DIVVT == 10 Divide by 2.5 . VTClock = (PClock * 4) / 10 */
157 else if (DIVVT(clkspeed) == 10)
158 vtclock = pclock * 4;
159 vtclock /= DIVVT(clkspeed);
160 printk(KERN_INFO "VTClock: %ldHz\n", vtclock);
163 if(VTDIVMODE(clkspeed) == 7)
164 vtclock = pclock / 1;
165 else if(VTDIVMODE(clkspeed) == 1)
166 vtclock = pclock / 2;
168 vtclock = pclock / VTDIVMODE(clkspeed);
169 printk(KERN_INFO "VTClock: %ldHz\n", vtclock);
173 vtclock = pclock / VTDIVMODE(clkspeed);
174 printk(KERN_INFO "VTClock: %ldHz\n", vtclock);
177 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
184 static inline unsigned long calculate_tclock(uint16_t clkspeed, unsigned long pclock,
185 unsigned long vtclock)
187 unsigned long tclock = 0;
189 switch (current_cpu_data.cputype) {
191 if (!(clkspeed & DIV2B))
193 else if (!(clkspeed & DIV3B))
195 else if (!(clkspeed & DIV4B))
199 tclock = pclock / DIVT(clkspeed);
204 tclock = vtclock / TDIVMODE(clkspeed);
207 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
211 printk(KERN_INFO "TClock: %ldHz\n", tclock);
216 void __init vr41xx_bcu_init(void)
218 unsigned long pclock;
221 clkspeed = read_clkspeed();
223 pclock = calculate_pclock(clkspeed);
224 vr41xx_vtclock = calculate_vtclock(clkspeed, pclock);
225 vr41xx_tclock = calculate_tclock(clkspeed, pclock, vr41xx_vtclock);