1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * bcu.c, Bus Control Unit routines for the NEC VR4100 series.
5 * Copyright (C) 2002 MontaVista Software Inc.
6 * Author: Yoichi Yuasa <source@mvista.com>
7 * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
11 * MontaVista Software Inc. <source@mvista.com>
12 * - New creation, NEC VR4122 and VR4131 are supported.
13 * - Added support for NEC VR4111 and VR4121.
15 * Yoichi Yuasa <yuasa@linux-mips.org>
16 * - Added support for NEC VR4133.
18 #include <linux/export.h>
19 #include <linux/kernel.h>
20 #include <linux/smp.h>
21 #include <linux/types.h>
23 #include <asm/cpu-type.h>
27 #define CLKSPEEDREG_TYPE1 (void __iomem *)KSEG1ADDR(0x0b000014)
28 #define CLKSPEEDREG_TYPE2 (void __iomem *)KSEG1ADDR(0x0f000014)
29 #define CLKSP(x) ((x) & 0x001f)
30 #define CLKSP_VR4133(x) ((x) & 0x0007)
36 #define DIVT(x) (((x) & 0xf000) >> 12)
37 #define DIVVT(x) (((x) & 0x0f00) >> 8)
39 #define TDIVMODE(x) (2 << (((x) & 0x1000) >> 12))
40 #define VTDIVMODE(x) (((x) & 0x0700) >> 8)
42 static unsigned long vr41xx_vtclock
;
43 static unsigned long vr41xx_tclock
;
45 unsigned long vr41xx_get_vtclock_frequency(void)
47 return vr41xx_vtclock
;
50 EXPORT_SYMBOL_GPL(vr41xx_get_vtclock_frequency
);
52 unsigned long vr41xx_get_tclock_frequency(void)
57 EXPORT_SYMBOL_GPL(vr41xx_get_tclock_frequency
);
59 static inline uint16_t read_clkspeed(void)
61 switch (current_cpu_type()) {
63 case CPU_VR4121
: return readw(CLKSPEEDREG_TYPE1
);
66 case CPU_VR4133
: return readw(CLKSPEEDREG_TYPE2
);
68 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
75 static inline unsigned long calculate_pclock(uint16_t clkspeed
)
77 unsigned long pclock
= 0;
79 switch (current_cpu_type()) {
82 pclock
= 18432000 * 64;
83 pclock
/= CLKSP(clkspeed
);
86 pclock
= 18432000 * 98;
87 pclock
/= CLKSP(clkspeed
);
90 pclock
= 18432000 * 108;
91 pclock
/= CLKSP(clkspeed
);
94 switch (CLKSP_VR4133(clkspeed
)) {
111 printk(KERN_INFO
"Unknown PClock speed for NEC VR4133\n");
116 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
120 printk(KERN_INFO
"PClock: %ldHz\n", pclock
);
125 static inline unsigned long calculate_vtclock(uint16_t clkspeed
, unsigned long pclock
)
127 unsigned long vtclock
= 0;
129 switch (current_cpu_type()) {
131 /* The NEC VR4111 doesn't have the VTClock. */
135 /* DIVVT == 9 Divide by 1.5 . VTClock = (PClock * 6) / 9 */
136 if (DIVVT(clkspeed
) == 9)
137 vtclock
= pclock
* 6;
138 /* DIVVT == 10 Divide by 2.5 . VTClock = (PClock * 4) / 10 */
139 else if (DIVVT(clkspeed
) == 10)
140 vtclock
= pclock
* 4;
141 vtclock
/= DIVVT(clkspeed
);
142 printk(KERN_INFO
"VTClock: %ldHz\n", vtclock
);
145 if(VTDIVMODE(clkspeed
) == 7)
146 vtclock
= pclock
/ 1;
147 else if(VTDIVMODE(clkspeed
) == 1)
148 vtclock
= pclock
/ 2;
150 vtclock
= pclock
/ VTDIVMODE(clkspeed
);
151 printk(KERN_INFO
"VTClock: %ldHz\n", vtclock
);
155 vtclock
= pclock
/ VTDIVMODE(clkspeed
);
156 printk(KERN_INFO
"VTClock: %ldHz\n", vtclock
);
159 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
166 static inline unsigned long calculate_tclock(uint16_t clkspeed
, unsigned long pclock
,
167 unsigned long vtclock
)
169 unsigned long tclock
= 0;
171 switch (current_cpu_type()) {
173 if (!(clkspeed
& DIV2B
))
175 else if (!(clkspeed
& DIV3B
))
177 else if (!(clkspeed
& DIV4B
))
181 tclock
= pclock
/ DIVT(clkspeed
);
186 tclock
= vtclock
/ TDIVMODE(clkspeed
);
189 printk(KERN_INFO
"Unexpected CPU of NEC VR4100 series\n");
193 printk(KERN_INFO
"TClock: %ldHz\n", tclock
);
198 void vr41xx_calculate_clock_frequency(void)
200 unsigned long pclock
;
203 clkspeed
= read_clkspeed();
205 pclock
= calculate_pclock(clkspeed
);
206 vr41xx_vtclock
= calculate_vtclock(clkspeed
, pclock
);
207 vr41xx_tclock
= calculate_tclock(clkspeed
, pclock
, vr41xx_vtclock
);
210 EXPORT_SYMBOL_GPL(vr41xx_calculate_clock_frequency
);