vrip.c revision 1.15 1 1.15 takemura /* $NetBSD: vrip.c,v 1.15 2002/01/27 14:18:12 takemura Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.14 takemura * Copyright (c) 1999, 2002
5 1.1 takemura * Shin Takemura and PocketBSD Project. All rights reserved.
6 1.1 takemura *
7 1.1 takemura * Redistribution and use in source and binary forms, with or without
8 1.1 takemura * modification, are permitted provided that the following conditions
9 1.1 takemura * are met:
10 1.1 takemura * 1. Redistributions of source code must retain the above copyright
11 1.1 takemura * notice, this list of conditions and the following disclaimer.
12 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 takemura * notice, this list of conditions and the following disclaimer in the
14 1.1 takemura * documentation and/or other materials provided with the distribution.
15 1.14 takemura * 3. Neither the name of the project nor the names of its contributors
16 1.1 takemura * may be used to endorse or promote products derived from this software
17 1.1 takemura * without specific prior written permission.
18 1.1 takemura *
19 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 takemura * SUCH DAMAGE.
30 1.1 takemura *
31 1.1 takemura */
32 1.7 sato #include "opt_vr41xx.h"
33 1.7 sato #include "opt_tx39xx.h"
34 1.7 sato
35 1.1 takemura #include <sys/param.h>
36 1.1 takemura #include <sys/systm.h>
37 1.1 takemura #include <sys/device.h>
38 1.1 takemura #include <sys/reboot.h>
39 1.1 takemura
40 1.1 takemura #include <machine/cpu.h>
41 1.1 takemura #include <machine/bus.h>
42 1.1 takemura #include <machine/autoconf.h>
43 1.8 sato #include <machine/platid.h>
44 1.8 sato #include <machine/platid_mask.h>
45 1.14 takemura #include <machine/bitdisp.h>
46 1.1 takemura
47 1.1 takemura #include <hpcmips/vr/vr.h>
48 1.9 sato #include <hpcmips/vr/vrcpudef.h>
49 1.15 takemura #include <hpcmips/vr/vripunit.h>
50 1.15 takemura #include <hpcmips/vr/vripif.h>
51 1.1 takemura #include <hpcmips/vr/vripreg.h>
52 1.1 takemura #include <hpcmips/vr/vripvar.h>
53 1.1 takemura #include <hpcmips/vr/icureg.h>
54 1.15 takemura #include <hpcmips/vr/cmureg.h>
55 1.1 takemura #include "locators.h"
56 1.1 takemura
57 1.3 takemura #define VRIPDEBUG
58 1.3 takemura #ifdef VRIPDEBUG
59 1.6 sato #ifndef VRIPDEBUG_CONF
60 1.6 sato #define VRIPDEBUG_CONF 0
61 1.6 sato #endif /* VRIPDEBUG_CONF */
62 1.6 sato int vrip_debug = VRIPDEBUG_CONF;
63 1.6 sato #define DPRINTF(arg) if (vrip_debug) printf arg;
64 1.6 sato #define DBITDISP32(reg) if (vrip_debug) bitdisp32(reg);
65 1.15 takemura #define DDUMP_LEVEL2MASK(sc,arg) if (vrip_debug) __vrip_dump_level2mask(sc,arg)
66 1.3 takemura #else
67 1.6 sato #define DPRINTF(arg)
68 1.6 sato #define DBITDISP32(arg)
69 1.6 sato #define DDUMP_LEVEL2MASK(sc,arg)
70 1.3 takemura #endif
71 1.3 takemura
72 1.15 takemura #define MAX_LEVEL1 32
73 1.15 takemura #define VALID_UNIT(sc, unit) (0 <= (unit) && (unit) < (sc)->sc_nunits)
74 1.15 takemura
75 1.14 takemura struct vrip_softc {
76 1.14 takemura struct device sc_dv;
77 1.14 takemura bus_space_tag_t sc_iot;
78 1.14 takemura bus_space_handle_t sc_ioh;
79 1.14 takemura hpcio_chip_t sc_gpio_chips[VRIP_NIOCHIPS];
80 1.14 takemura vrcmu_chipset_tag_t sc_cc;
81 1.14 takemura int sc_pri; /* attaching device priority */
82 1.14 takemura u_int32_t sc_intrmask;
83 1.15 takemura struct vrip_chipset_tag sc_chipset;
84 1.15 takemura const struct vrip_unit *sc_units;
85 1.15 takemura int sc_nunits;
86 1.15 takemura struct intrhand {
87 1.15 takemura int (*ih_fun)(void *);
88 1.15 takemura void *ih_arg;
89 1.15 takemura const struct vrip_unit *ih_unit;
90 1.15 takemura } sc_intrhands[MAX_LEVEL1];
91 1.14 takemura };
92 1.14 takemura
93 1.12 uch int vripmatch(struct device *, struct cfdata *, void *);
94 1.12 uch void vripattach(struct device *, struct device *, void *);
95 1.12 uch int vrip_print(void *, const char *);
96 1.12 uch int vrip_search(struct device *, struct cfdata *, void *);
97 1.12 uch int vrip_intr(void *, u_int32_t, u_int32_t);
98 1.1 takemura
99 1.15 takemura int __vrip_power(vrip_chipset_tag_t, int, int);
100 1.15 takemura vrip_intr_handle_t __vrip_intr_establish(vrip_chipset_tag_t, int, int,
101 1.15 takemura int, int(*)(void*), void*);
102 1.15 takemura void __vrip_intr_disestablish(vrip_chipset_tag_t, vrip_intr_handle_t);
103 1.15 takemura void __vrip_intr_setmask1(vrip_chipset_tag_t, vrip_intr_handle_t, int);
104 1.15 takemura void __vrip_intr_setmask2(vrip_chipset_tag_t, vrip_intr_handle_t,
105 1.15 takemura u_int32_t, int);
106 1.15 takemura void __vrip_intr_getstatus2(vrip_chipset_tag_t, vrip_intr_handle_t,
107 1.15 takemura u_int32_t*);
108 1.15 takemura void __vrip_register_cmu(vrip_chipset_tag_t, vrcmu_chipset_tag_t);
109 1.15 takemura void __vrip_register_gpio(vrip_chipset_tag_t, hpcio_chip_t);
110 1.15 takemura void __vrip_dump_level2mask(vrip_chipset_tag_t, void *);
111 1.1 takemura
112 1.1 takemura struct cfattach vrip_ca = {
113 1.1 takemura sizeof(struct vrip_softc), vripmatch, vripattach
114 1.1 takemura };
115 1.1 takemura
116 1.15 takemura struct vrip_softc *the_vrip_sc = NULL;
117 1.1 takemura
118 1.15 takemura static const struct vrip_chipset_tag vrip_chipset_methods = {
119 1.15 takemura .vc_power = __vrip_power,
120 1.15 takemura .vc_intr_establish = __vrip_intr_establish,
121 1.15 takemura .vc_intr_disestablish = __vrip_intr_disestablish,
122 1.15 takemura .vc_intr_setmask1 = __vrip_intr_setmask1,
123 1.15 takemura .vc_intr_setmask2 = __vrip_intr_setmask2,
124 1.15 takemura .vc_intr_getstatus2 = __vrip_intr_getstatus2,
125 1.15 takemura .vc_register_cmu = __vrip_register_cmu,
126 1.15 takemura .vc_register_gpio = __vrip_register_gpio,
127 1.15 takemura };
128 1.2 takemura
129 1.15 takemura static const struct vrip_unit vrip_units[] = {
130 1.15 takemura [VRIP_UNIT_PMU] = { "pmu",
131 1.15 takemura { VRIP_INTR_POWER, VRIP_INTR_BAT, }, },
132 1.15 takemura [VRIP_UNIT_RTC] = { "rtc",
133 1.15 takemura { VRIP_INTR_RTCL1, }, },
134 1.15 takemura [VRIP_UNIT_PIU] = { "piu",
135 1.15 takemura { VRIP_INTR_PIU, },
136 1.15 takemura CMUMASK_PIU,
137 1.15 takemura ICUPIUINT_REG_W, MPIUINT_REG_W },
138 1.15 takemura [VRIP_UNIT_KIU] = { "kiu",
139 1.15 takemura { VRIP_INTR_KIU, },
140 1.15 takemura CMUMASK_KIU,
141 1.15 takemura KIUINT_REG_W, MKIUINT_REG_W },
142 1.15 takemura [VRIP_UNIT_SIU] = { "siu",
143 1.15 takemura { VRIP_INTR_SIU, }, },
144 1.15 takemura [VRIP_UNIT_GIU] = { "giu",
145 1.15 takemura { VRIP_INTR_GIU, },
146 1.15 takemura 0,
147 1.15 takemura GIUINT_L_REG_W,MGIUINT_L_REG_W,
148 1.12 uch GIUINT_H_REG_W, MGIUINT_H_REG_W },
149 1.15 takemura [VRIP_UNIT_LED] = { "led",
150 1.15 takemura { VRIP_INTR_LED, }, },
151 1.15 takemura [VRIP_UNIT_AIU] = { "aiu",
152 1.15 takemura { VRIP_INTR_AIU, },
153 1.15 takemura CMUMASK_AIU,
154 1.15 takemura AIUINT_REG_W, MAIUINT_REG_W },
155 1.15 takemura [VRIP_UNIT_FIR] = { "fir",
156 1.15 takemura { VRIP_INTR_FIR, },
157 1.15 takemura CMUMASK_FIR,
158 1.15 takemura FIRINT_REG_W, MFIRINT_REG_W },
159 1.15 takemura [VRIP_UNIT_DSIU]= { "dsiu",
160 1.15 takemura { VRIP_INTR_DSIU, },
161 1.15 takemura CMUMASK_DSIU,
162 1.15 takemura DSIUINT_REG_W, MDSIUINT_REG_W },
163 1.15 takemura [VRIP_UNIT_PCIU]= { "pciu",
164 1.15 takemura { VRIP_INTR_PCI, },
165 1.15 takemura CMUMASK_PCIU,
166 1.15 takemura PCIINT_REG_W, MPCIINT_REG_W },
167 1.15 takemura [VRIP_UNIT_SCU] = { "scu",
168 1.15 takemura { VRIP_INTR_SCU, },
169 1.15 takemura 0,
170 1.15 takemura SCUINT_REG_W, MSCUINT_REG_W },
171 1.15 takemura [VRIP_UNIT_CSI] = { "csi",
172 1.15 takemura { VRIP_INTR_CSI, },
173 1.15 takemura CMUMASK_CSI,
174 1.15 takemura CSIINT_REG_W, MCSIINT_REG_W },
175 1.15 takemura [VRIP_UNIT_BCU] = { "bcu",
176 1.15 takemura { VRIP_INTR_BCU, },
177 1.15 takemura 0,
178 1.15 takemura BCUINT_REG_W, MBCUINT_REG_W }
179 1.1 takemura };
180 1.9 sato
181 1.1 takemura int
182 1.12 uch vripmatch(struct device *parent, struct cfdata *match, void *aux)
183 1.1 takemura {
184 1.1 takemura struct mainbus_attach_args *ma = aux;
185 1.7 sato
186 1.7 sato #ifdef TX39XX
187 1.7 sato if (!platid_match(&platid, &platid_mask_CPU_MIPS_VR_41XX))
188 1.13 uch return (0);
189 1.13 uch #endif /* TX39XX */
190 1.1 takemura if (strcmp(ma->ma_name, match->cf_driver->cd_name))
191 1.12 uch return (0);
192 1.12 uch
193 1.12 uch return (1);
194 1.1 takemura }
195 1.1 takemura
196 1.1 takemura void
197 1.12 uch vripattach(struct device *parent, struct device *self, void *aux)
198 1.1 takemura {
199 1.15 takemura struct vrip_softc *sc = (struct vrip_softc*)self;
200 1.15 takemura
201 1.15 takemura printf("\n");
202 1.15 takemura
203 1.15 takemura sc->sc_units = vrip_units;
204 1.15 takemura sc->sc_nunits = sizeof(vrip_units)/sizeof(struct vrip_unit);
205 1.15 takemura
206 1.15 takemura vripattach_common(parent, self, aux);
207 1.15 takemura }
208 1.15 takemura
209 1.15 takemura void
210 1.15 takemura vripattach_common(struct device *parent, struct device *self, void *aux)
211 1.15 takemura {
212 1.1 takemura struct mainbus_attach_args *ma = aux;
213 1.1 takemura struct vrip_softc *sc = (struct vrip_softc*)self;
214 1.1 takemura
215 1.15 takemura sc->sc_chipset = vrip_chipset_methods; /* structure assignment */
216 1.15 takemura sc->sc_chipset.vc_sc = sc;
217 1.15 takemura
218 1.1 takemura /*
219 1.1 takemura * Map ICU (Interrupt Control Unit) register space.
220 1.1 takemura */
221 1.1 takemura sc->sc_iot = ma->ma_iot;
222 1.12 uch if (bus_space_map(sc->sc_iot, VRIP_ICU_ADDR,
223 1.12 uch 0x20 /*XXX lower area only*/,
224 1.12 uch 0, /* no flags */
225 1.12 uch &sc->sc_ioh)) {
226 1.1 takemura printf("vripattach: can't map ICU register.\n");
227 1.1 takemura return;
228 1.1 takemura }
229 1.1 takemura
230 1.1 takemura /*
231 1.1 takemura * Disable all Level 1 interrupts.
232 1.1 takemura */
233 1.2 takemura sc->sc_intrmask = 0;
234 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, MSYSINT1_REG_W, 0x0000);
235 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, MSYSINT2_REG_W, 0x0000);
236 1.1 takemura /*
237 1.1 takemura * Level 1 interrupts are redirected to HwInt0
238 1.1 takemura */
239 1.1 takemura vr_intr_establish(VR_INTR0, vrip_intr, self);
240 1.2 takemura the_vrip_sc = sc;
241 1.1 takemura /*
242 1.1 takemura * Attach each devices
243 1.12 uch * GIU CMU interface interface is used by other system device.
244 1.12 uch * so attach first
245 1.1 takemura */
246 1.1 takemura sc->sc_pri = 2;
247 1.1 takemura config_search(vrip_search, self, vrip_print);
248 1.1 takemura /* Other system devices. */
249 1.1 takemura sc->sc_pri = 1;
250 1.1 takemura config_search(vrip_search, self, vrip_print);
251 1.1 takemura }
252 1.1 takemura
253 1.1 takemura int
254 1.12 uch vrip_print(void *aux, const char *hoge)
255 1.1 takemura {
256 1.1 takemura struct vrip_attach_args *va = (struct vrip_attach_args*)aux;
257 1.1 takemura
258 1.1 takemura if (va->va_addr)
259 1.5 takemura printf(" addr 0x%lx", va->va_addr);
260 1.1 takemura if (va->va_size > 1)
261 1.5 takemura printf("-0x%lx", va->va_addr + va->va_size - 1);
262 1.12 uch
263 1.1 takemura return (UNCONF);
264 1.1 takemura }
265 1.1 takemura
266 1.1 takemura int
267 1.12 uch vrip_search(struct device *parent, struct cfdata *cf, void *aux)
268 1.1 takemura {
269 1.1 takemura struct vrip_softc *sc = (struct vrip_softc *)parent;
270 1.1 takemura struct vrip_attach_args va;
271 1.1 takemura
272 1.15 takemura va.va_vc = &sc->sc_chipset;
273 1.1 takemura va.va_iot = sc->sc_iot;
274 1.15 takemura va.va_unit = cf->cf_loc[VRIPIFCF_UNIT];
275 1.15 takemura va.va_addr = cf->cf_loc[VRIPIFCF_ADDR];
276 1.15 takemura va.va_size = cf->cf_loc[VRIPIFCF_SIZE];
277 1.15 takemura va.va_addr2 = cf->cf_loc[VRIPIFCF_ADDR2];
278 1.15 takemura va.va_size2 = cf->cf_loc[VRIPIFCF_SIZE2];
279 1.10 takemura va.va_gpio_chips = sc->sc_gpio_chips;
280 1.1 takemura if (((*cf->cf_attach->ca_match)(parent, cf, &va) == sc->sc_pri))
281 1.1 takemura config_attach(parent, cf, &va, vrip_print);
282 1.1 takemura
283 1.12 uch return (0);
284 1.1 takemura }
285 1.1 takemura
286 1.15 takemura int
287 1.15 takemura __vrip_power(vrip_chipset_tag_t vc, int unit, int onoff)
288 1.15 takemura {
289 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
290 1.15 takemura const struct vrip_unit *vu;
291 1.15 takemura
292 1.15 takemura if (sc->sc_chipset.vc_cc == NULL)
293 1.15 takemura return (0); /* You have no clock mask unit yet. */
294 1.15 takemura if (!VALID_UNIT(sc, unit))
295 1.15 takemura return (0);
296 1.15 takemura vu = &sc->sc_units[unit];
297 1.15 takemura
298 1.15 takemura return (*sc->sc_chipset.vc_cc->cc_clock)(sc->sc_chipset.vc_cc,
299 1.15 takemura vu->vu_clkmask, onoff);
300 1.15 takemura }
301 1.15 takemura
302 1.15 takemura vrip_intr_handle_t
303 1.15 takemura __vrip_intr_establish(vrip_chipset_tag_t vc, int unit, int line, int level,
304 1.12 uch int (*ih_fun)(void *), void *ih_arg)
305 1.1 takemura {
306 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
307 1.15 takemura const struct vrip_unit *vu;
308 1.1 takemura struct intrhand *ih;
309 1.1 takemura
310 1.15 takemura if (!VALID_UNIT(sc, unit))
311 1.15 takemura return (NULL);
312 1.15 takemura vu = &sc->sc_units[unit];
313 1.15 takemura ih = &sc->sc_intrhands[vu->vu_intr[line]];
314 1.1 takemura if (ih->ih_fun) /* Can't share level 1 interrupt */
315 1.15 takemura return (NULL);
316 1.1 takemura ih->ih_fun = ih_fun;
317 1.1 takemura ih->ih_arg = ih_arg;
318 1.15 takemura ih->ih_unit = vu;
319 1.1 takemura
320 1.1 takemura /* Mask level 2 interrupt mask register. (disable interrupt) */
321 1.1 takemura vrip_intr_setmask2(vc, ih, ~0, 0);
322 1.1 takemura /* Unmask Level 1 interrupt mask register (enable interrupt) */
323 1.1 takemura vrip_intr_setmask1(vc, ih, 1);
324 1.1 takemura
325 1.12 uch return ((void *)ih);
326 1.1 takemura }
327 1.1 takemura
328 1.1 takemura void
329 1.15 takemura __vrip_intr_disestablish(vrip_chipset_tag_t vc, vrip_intr_handle_t handle)
330 1.1 takemura {
331 1.15 takemura struct intrhand *ih = handle;
332 1.12 uch
333 1.1 takemura ih->ih_fun = NULL;
334 1.1 takemura ih->ih_arg = NULL;
335 1.1 takemura /* Mask level 2 interrupt mask register(if any). (disable interrupt) */
336 1.1 takemura vrip_intr_setmask2(vc, ih, ~0, 0);
337 1.1 takemura /* Mask Level 1 interrupt mask register (disable interrupt) */
338 1.1 takemura vrip_intr_setmask1(vc, ih, 0);
339 1.1 takemura }
340 1.1 takemura
341 1.2 takemura void
342 1.2 takemura vrip_intr_suspend()
343 1.2 takemura {
344 1.2 takemura bus_space_tag_t iot = the_vrip_sc->sc_iot;
345 1.2 takemura bus_space_handle_t ioh = the_vrip_sc->sc_ioh;
346 1.2 takemura
347 1.2 takemura bus_space_write_2 (iot, ioh, MSYSINT1_REG_W, (1<<VRIP_INTR_POWER));
348 1.2 takemura bus_space_write_2 (iot, ioh, MSYSINT2_REG_W, 0);
349 1.2 takemura }
350 1.2 takemura
351 1.2 takemura void
352 1.2 takemura vrip_intr_resume()
353 1.2 takemura {
354 1.2 takemura u_int32_t reg = the_vrip_sc->sc_intrmask;
355 1.2 takemura bus_space_tag_t iot = the_vrip_sc->sc_iot;
356 1.2 takemura bus_space_handle_t ioh = the_vrip_sc->sc_ioh;
357 1.2 takemura
358 1.2 takemura bus_space_write_2 (iot, ioh, MSYSINT1_REG_W, reg & 0xffff);
359 1.2 takemura bus_space_write_2 (iot, ioh, MSYSINT2_REG_W, (reg >> 16) & 0xffff);
360 1.2 takemura }
361 1.2 takemura
362 1.1 takemura /* Set level 1 interrupt mask. */
363 1.1 takemura void
364 1.15 takemura __vrip_intr_setmask1(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
365 1.15 takemura int enable)
366 1.1 takemura {
367 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
368 1.15 takemura struct intrhand *ih = handle;
369 1.15 takemura int level1 = ih - sc->sc_intrhands;
370 1.1 takemura bus_space_tag_t iot = sc->sc_iot;
371 1.1 takemura bus_space_handle_t ioh = sc->sc_ioh;
372 1.2 takemura u_int32_t reg = sc->sc_intrmask;
373 1.1 takemura
374 1.15 takemura printf("__vrip_intr_setmask1: SYSINT: %s %d\n", enable ? "enable" : "disable", level1);
375 1.1 takemura reg = (bus_space_read_2 (iot, ioh, MSYSINT1_REG_W)&0xffff) |
376 1.12 uch ((bus_space_read_2 (iot, ioh, MSYSINT2_REG_W)<< 16)&0xffff0000);
377 1.1 takemura if (enable)
378 1.1 takemura reg |= (1 << level1);
379 1.1 takemura else {
380 1.1 takemura reg &= ~(1 << level1);
381 1.1 takemura }
382 1.2 takemura sc->sc_intrmask = reg;
383 1.1 takemura bus_space_write_2 (iot, ioh, MSYSINT1_REG_W, reg & 0xffff);
384 1.1 takemura bus_space_write_2 (iot, ioh, MSYSINT2_REG_W, (reg >> 16) & 0xffff);
385 1.6 sato DBITDISP32(reg);
386 1.1 takemura
387 1.1 takemura return;
388 1.1 takemura }
389 1.1 takemura
390 1.15 takemura void
391 1.15 takemura __vrip_dump_level2mask(vrip_chipset_tag_t vc, vrip_intr_handle_t handle)
392 1.1 takemura {
393 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
394 1.15 takemura struct intrhand *ih = handle;
395 1.15 takemura const struct vrip_unit *vu = ih->ih_unit;
396 1.1 takemura u_int32_t reg;
397 1.1 takemura
398 1.15 takemura if (vu->vu_mlreg) {
399 1.15 takemura printf ("level1[%d] level2 mask:", vu->vu_intr[0]);
400 1.15 takemura reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg);
401 1.15 takemura if (vu->vu_mhreg) { /* GIU [16:31] case only */
402 1.15 takemura reg |= (bus_space_read_2(sc->sc_iot, sc->sc_ioh, vu->vu_mhreg) << 16);
403 1.1 takemura bitdisp32(reg);
404 1.1 takemura } else
405 1.1 takemura bitdisp16(reg);
406 1.1 takemura }
407 1.1 takemura }
408 1.1 takemura
409 1.1 takemura /* Get level 2 interrupt status */
410 1.1 takemura void
411 1.15 takemura __vrip_intr_getstatus2(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
412 1.12 uch u_int32_t *mask /* Level 2 mask */)
413 1.1 takemura {
414 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
415 1.15 takemura struct intrhand *ih = handle;
416 1.15 takemura const struct vrip_unit *vu = ih->ih_unit;
417 1.1 takemura u_int32_t reg;
418 1.12 uch
419 1.1 takemura reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
420 1.15 takemura vu->vu_lreg);
421 1.1 takemura reg |= ((bus_space_read_2(sc->sc_iot, sc->sc_ioh,
422 1.15 takemura vu->vu_hreg) << 16)&0xffff0000);
423 1.1 takemura /* bitdisp32(reg);*/
424 1.1 takemura *mask = reg;
425 1.1 takemura }
426 1.1 takemura
427 1.1 takemura /* Set level 2 interrupt mask. */
428 1.1 takemura void
429 1.15 takemura __vrip_intr_setmask2(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
430 1.12 uch u_int32_t mask /* Level 2 mask */, int onoff)
431 1.1 takemura {
432 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
433 1.15 takemura struct intrhand *ih = handle;
434 1.15 takemura const struct vrip_unit *vu = ih->ih_unit;
435 1.1 takemura u_int16_t reg;
436 1.3 takemura
437 1.6 sato DPRINTF(("vrip_intr_setmask2:\n"));
438 1.15 takemura DDUMP_LEVEL2MASK(vc, handle);
439 1.1 takemura #ifdef WINCE_DEFAULT_SETTING
440 1.1 takemura #warning WINCE_DEFAULT_SETTING
441 1.1 takemura #else
442 1.15 takemura if (vu->vu_mlreg) {
443 1.15 takemura reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg);
444 1.1 takemura if (onoff)
445 1.1 takemura reg |= (mask&0xffff);
446 1.1 takemura else
447 1.1 takemura reg &= ~(mask&0xffff);
448 1.15 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg, reg);
449 1.15 takemura if (vu->vu_mhreg != -1) { /* GIU [16:31] case only */
450 1.12 uch reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
451 1.15 takemura vu->vu_mhreg);
452 1.1 takemura if (onoff)
453 1.1 takemura reg |= ((mask >> 16) & 0xffff);
454 1.1 takemura else
455 1.12 uch reg &= ~((mask >> 16) & 0xffff);
456 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh,
457 1.15 takemura vu->vu_mhreg, reg);
458 1.1 takemura }
459 1.1 takemura }
460 1.1 takemura #endif /* WINCE_DEFAULT_SETTING */
461 1.15 takemura DDUMP_LEVEL2MASK(vc, handle);
462 1.3 takemura
463 1.1 takemura return;
464 1.1 takemura }
465 1.1 takemura
466 1.1 takemura int
467 1.12 uch vrip_intr(void *arg, u_int32_t pc, u_int32_t statusReg)
468 1.1 takemura {
469 1.1 takemura struct vrip_softc *sc = (struct vrip_softc*)arg;
470 1.1 takemura bus_space_tag_t iot = sc->sc_iot;
471 1.1 takemura bus_space_handle_t ioh = sc->sc_ioh;
472 1.1 takemura int i;
473 1.1 takemura u_int32_t reg, mask;
474 1.1 takemura /*
475 1.1 takemura * Read level1 interrupt status.
476 1.1 takemura */
477 1.1 takemura reg = (bus_space_read_2 (iot, ioh, SYSINT1_REG_W)&0xffff) |
478 1.12 uch ((bus_space_read_2 (iot, ioh, SYSINT2_REG_W)<< 16)&0xffff0000);
479 1.1 takemura mask = (bus_space_read_2 (iot, ioh, MSYSINT1_REG_W)&0xffff) |
480 1.12 uch ((bus_space_read_2 (iot, ioh, MSYSINT2_REG_W)<< 16)&0xffff0000);
481 1.1 takemura reg &= mask;
482 1.1 takemura
483 1.1 takemura /*
484 1.1 takemura * Dispatch each handler.
485 1.1 takemura */
486 1.1 takemura for (i = 0; i < 32; i++) {
487 1.15 takemura register struct intrhand *ih = &sc->sc_intrhands[i];
488 1.1 takemura if (ih->ih_fun && (reg & (1 << i))) {
489 1.1 takemura ih->ih_fun(ih->ih_arg);
490 1.1 takemura }
491 1.1 takemura }
492 1.12 uch
493 1.12 uch return (1);
494 1.1 takemura }
495 1.1 takemura
496 1.1 takemura void
497 1.15 takemura __vrip_register_cmu(vrip_chipset_tag_t vc, vrcmu_chipset_tag_t cmu)
498 1.1 takemura {
499 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
500 1.12 uch
501 1.15 takemura sc->sc_chipset.vc_cc = cmu;
502 1.1 takemura }
503 1.1 takemura
504 1.1 takemura void
505 1.15 takemura __vrip_register_gpio(vrip_chipset_tag_t vc, hpcio_chip_t chip)
506 1.1 takemura {
507 1.15 takemura struct vrip_softc *sc = vc->vc_sc;
508 1.10 takemura
509 1.10 takemura if (chip->hc_chipid < 0 || VRIP_NIOCHIPS <= chip->hc_chipid)
510 1.10 takemura panic("%s: '%s' has unknown id, %d", __FUNCTION__,
511 1.10 takemura chip->hc_name, chip->hc_chipid);
512 1.10 takemura sc->sc_gpio_chips[chip->hc_chipid] = chip;
513 1.1 takemura }
514