2 * bcu.c, Bus Control Unit routines for the NEC VR4100 series.
4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com, or source@mvista.com>
6 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
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. <yyuasa@mvista.com> or <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported.
26 * - Added support for NEC VR4111 and VR4121.
28 * Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
29 * - Added support for NEC VR4133.
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/smp.h>
34 #include <linux/types.h>
39 #define CLKSPEEDREG_TYPE1 (void __iomem *)KSEG1ADDR(0x0b000014)
40 #define CLKSPEEDREG_TYPE2 (void __iomem *)KSEG1ADDR(0x0f000014)
41 #define CLKSP(x) ((x) & 0x001f)
42 #define CLKSP_VR4133(x) ((x) & 0x0007)
48 #define DIVT(x) (((x) & 0xf000) >> 12)
49 #define DIVVT(x) (((x) & 0x0f00) >> 8)
51 #define TDIVMODE(x) (2 << (((x) & 0x1000) >> 12))
52 #define VTDIVMODE(x) (((x) & 0x0700) >> 8)
54 static unsigned long vr41xx_vtclock;
55 static unsigned long vr41xx_tclock;
57 unsigned long vr41xx_get_vtclock_frequency(void)
59 return vr41xx_vtclock;
62 EXPORT_SYMBOL_GPL(vr41xx_get_vtclock_frequency);
64 unsigned long vr41xx_get_tclock_frequency(void)
69 EXPORT_SYMBOL_GPL(vr41xx_get_tclock_frequency);
71 static inline uint16_t read_clkspeed(void)
73 switch (current_cpu_type()) {
75 case CPU_VR4121: return readw(CLKSPEEDREG_TYPE1);
78 case CPU_VR4133: return readw(CLKSPEEDREG_TYPE2);
80 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
87 static inline unsigned long calculate_pclock(uint16_t clkspeed)
89 unsigned long pclock = 0;
91 switch (current_cpu_type()) {
94 pclock = 18432000 * 64;
95 pclock /= CLKSP(clkspeed);
98 pclock = 18432000 * 98;
99 pclock /= CLKSP(clkspeed);
102 pclock = 18432000 * 108;
103 pclock /= CLKSP(clkspeed);
106 switch (CLKSP_VR4133(clkspeed)) {
123 printk(KERN_INFO "Unknown PClock speed for NEC VR4133\n");
128 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
132 printk(KERN_INFO "PClock: %ldHz\n", pclock);
137 static inline unsigned long calculate_vtclock(uint16_t clkspeed, unsigned long pclock)
139 unsigned long vtclock = 0;
141 switch (current_cpu_type()) {
143 /* The NEC VR4111 doesn't have the VTClock. */
147 /* DIVVT == 9 Divide by 1.5 . VTClock = (PClock * 6) / 9 */
148 if (DIVVT(clkspeed) == 9)
149 vtclock = pclock * 6;
150 /* DIVVT == 10 Divide by 2.5 . VTClock = (PClock * 4) / 10 */
151 else if (DIVVT(clkspeed) == 10)
152 vtclock = pclock * 4;
153 vtclock /= DIVVT(clkspeed);
154 printk(KERN_INFO "VTClock: %ldHz\n", vtclock);
157 if(VTDIVMODE(clkspeed) == 7)
158 vtclock = pclock / 1;
159 else if(VTDIVMODE(clkspeed) == 1)
160 vtclock = pclock / 2;
162 vtclock = pclock / VTDIVMODE(clkspeed);
163 printk(KERN_INFO "VTClock: %ldHz\n", vtclock);
167 vtclock = pclock / VTDIVMODE(clkspeed);
168 printk(KERN_INFO "VTClock: %ldHz\n", vtclock);
171 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
178 static inline unsigned long calculate_tclock(uint16_t clkspeed, unsigned long pclock,
179 unsigned long vtclock)
181 unsigned long tclock = 0;
183 switch (current_cpu_type()) {
185 if (!(clkspeed & DIV2B))
187 else if (!(clkspeed & DIV3B))
189 else if (!(clkspeed & DIV4B))
193 tclock = pclock / DIVT(clkspeed);
198 tclock = vtclock / TDIVMODE(clkspeed);
201 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
205 printk(KERN_INFO "TClock: %ldHz\n", tclock);
210 void vr41xx_calculate_clock_frequency(void)
212 unsigned long pclock;
215 clkspeed = read_clkspeed();
217 pclock = calculate_pclock(clkspeed);
218 vr41xx_vtclock = calculate_vtclock(clkspeed, pclock);
219 vr41xx_tclock = calculate_tclock(clkspeed, pclock, vr41xx_vtclock);
222 EXPORT_SYMBOL_GPL(vr41xx_calculate_clock_frequency);