2 * cmu.c, Clock Mask Unit routines for the NEC VR4100 series.
4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
6 * Copuright (C) 2003-2005 Yoichi Yuasa <yuasa@hh.iij4u.or.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 <yuasa@hh.iij4u.or.jp>
29 * - Added support for NEC VR4133.
31 #include <linux/init.h>
32 #include <linux/ioport.h>
33 #include <linux/module.h>
34 #include <linux/smp.h>
35 #include <linux/spinlock.h>
36 #include <linux/types.h>
40 #include <asm/vr41xx/vr41xx.h>
42 #define CMU_TYPE1_BASE 0x0b000060UL
43 #define CMU_TYPE1_SIZE 0x4
45 #define CMU_TYPE2_BASE 0x0f000060UL
46 #define CMU_TYPE2_SIZE 0x4
48 #define CMU_TYPE3_BASE 0x0f000060UL
49 #define CMU_TYPE3_SIZE 0x8
57 #define MSKDSIU 0x0820
59 #define MSKPCIU 0x0080
60 #define MSKSSIU 0x0100
61 #define MSKSHSP 0x0200
62 #define MSKFFIR 0x0400
63 #define MSKSCSI 0x1000
64 #define MSKPPCIU 0x2000
65 #define CMUCLKMSK2 0x4
67 #define MSKMAC0 0x0002
68 #define MSKMAC1 0x0004
70 static void __iomem
*cmu_base
;
71 static uint16_t cmuclkmsk
, cmuclkmsk2
;
72 static spinlock_t cmu_lock
;
74 #define cmu_read(offset) readw(cmu_base + (offset))
75 #define cmu_write(offset, value) writew((value), cmu_base + (offset))
77 void vr41xx_supply_clock(vr41xx_clock_t clock
)
79 spin_lock_irq(&cmu_lock
);
86 cmuclkmsk
|= MSKSIU
| MSKSSIU
;
95 cmuclkmsk
|= MSKFIR
| MSKFFIR
;
98 if (current_cpu_data
.cputype
== CPU_VR4111
||
99 current_cpu_data
.cputype
== CPU_VR4121
)
100 cmuclkmsk
|= MSKDSIU
;
102 cmuclkmsk
|= MSKSIU
| MSKDSIU
;
105 cmuclkmsk
|= MSKCSI
| MSKSCSI
;
108 cmuclkmsk
|= MSKPCIU
;
111 cmuclkmsk
|= MSKSHSP
;
114 cmuclkmsk
|= MSKPPCIU
;
117 cmuclkmsk2
|= MSKCEU
;
120 cmuclkmsk2
|= MSKMAC0
;
123 cmuclkmsk2
|= MSKMAC1
;
129 if (clock
== CEU_CLOCK
|| clock
== ETHER0_CLOCK
||
130 clock
== ETHER1_CLOCK
)
131 cmu_write(CMUCLKMSK2
, cmuclkmsk2
);
133 cmu_write(CMUCLKMSK
, cmuclkmsk
);
135 spin_unlock_irq(&cmu_lock
);
138 EXPORT_SYMBOL_GPL(vr41xx_supply_clock
);
140 void vr41xx_mask_clock(vr41xx_clock_t clock
)
142 spin_lock_irq(&cmu_lock
);
146 cmuclkmsk
&= ~MSKPIU
;
149 if (current_cpu_data
.cputype
== CPU_VR4111
||
150 current_cpu_data
.cputype
== CPU_VR4121
) {
151 cmuclkmsk
&= ~(MSKSIU
| MSKSSIU
);
153 if (cmuclkmsk
& MSKDSIU
)
154 cmuclkmsk
&= ~MSKSSIU
;
156 cmuclkmsk
&= ~(MSKSIU
| MSKSSIU
);
160 cmuclkmsk
&= ~MSKAIU
;
163 cmuclkmsk
&= ~MSKKIU
;
166 cmuclkmsk
&= ~(MSKFIR
| MSKFFIR
);
169 if (current_cpu_data
.cputype
== CPU_VR4111
||
170 current_cpu_data
.cputype
== CPU_VR4121
) {
171 cmuclkmsk
&= ~MSKDSIU
;
173 if (cmuclkmsk
& MSKSSIU
)
174 cmuclkmsk
&= ~MSKDSIU
;
176 cmuclkmsk
&= ~(MSKSIU
| MSKDSIU
);
180 cmuclkmsk
&= ~(MSKCSI
| MSKSCSI
);
183 cmuclkmsk
&= ~MSKPCIU
;
186 cmuclkmsk
&= ~MSKSHSP
;
189 cmuclkmsk
&= ~MSKPPCIU
;
192 cmuclkmsk2
&= ~MSKCEU
;
195 cmuclkmsk2
&= ~MSKMAC0
;
198 cmuclkmsk2
&= ~MSKMAC1
;
204 if (clock
== CEU_CLOCK
|| clock
== ETHER0_CLOCK
||
205 clock
== ETHER1_CLOCK
)
206 cmu_write(CMUCLKMSK2
, cmuclkmsk2
);
208 cmu_write(CMUCLKMSK
, cmuclkmsk
);
210 spin_unlock_irq(&cmu_lock
);
213 EXPORT_SYMBOL_GPL(vr41xx_mask_clock
);
215 static int __init
vr41xx_cmu_init(void)
217 unsigned long start
, size
;
219 switch (current_cpu_data
.cputype
) {
222 start
= CMU_TYPE1_BASE
;
223 size
= CMU_TYPE1_SIZE
;
227 start
= CMU_TYPE2_BASE
;
228 size
= CMU_TYPE2_SIZE
;
231 start
= CMU_TYPE3_BASE
;
232 size
= CMU_TYPE3_SIZE
;
235 panic("Unexpected CPU of NEC VR4100 series");
239 if (request_mem_region(start
, size
, "CMU") == NULL
)
242 cmu_base
= ioremap(start
, size
);
243 if (cmu_base
== NULL
) {
244 release_mem_region(start
, size
);
248 cmuclkmsk
= cmu_read(CMUCLKMSK
);
249 if (current_cpu_data
.cputype
== CPU_VR4133
)
250 cmuclkmsk2
= cmu_read(CMUCLKMSK2
);
252 spin_lock_init(&cmu_lock
);
257 core_initcall(vr41xx_cmu_init
);