vrgiu.c revision 1.20 1 /* $NetBSD: vrgiu.c,v 1.20 2001/04/30 11:42:19 takemura Exp $ */
2 /*-
3 * Copyright (c) 1999-2001
4 * Shin Takemura and PocketBSD Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the PocketBSD project
17 * and its contributors.
18 * 4. Neither the name of the project nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/malloc.h>
40 #include <sys/queue.h>
41 #include <sys/reboot.h>
42
43 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
44
45 #include <mips/cpuregs.h>
46 #include <machine/bus.h>
47 #include <machine/config_hook.h>
48
49 #include <dev/hpc/hpciovar.h>
50
51 #include "opt_vr41xx.h"
52 #include <hpcmips/vr/vrcpudef.h>
53 #include <hpcmips/vr/vripreg.h>
54 #include <hpcmips/vr/vripvar.h>
55 #include <hpcmips/vr/vrgiureg.h>
56 #include <hpcmips/vr/vrgiuvar.h>
57
58 #include "locators.h"
59
60 #define VRGIUDEBUG
61 #ifdef VRGIUDEBUG
62 #define DEBUG_IO 1
63 #define DEBUG_INTR 2
64 #ifndef VRGIUDEBUG_CONF
65 #define VRGIUDEBUG_CONF 0
66 #endif /* VRGIUDEBUG_CONF */
67 int vrgiu_debug = VRGIUDEBUG_CONF;
68 #define DPRINTF(flag, arg) if (vrgiu_debug & flag) printf arg;
69 #define DDUMP_IO(flag, sc) if (vrgiu_debug & flag) vrgiu_dump_io(sc);
70 #define DDUMP_IOSETTING(flag, sc) \
71 if (vrgiu_debug & flag) vrgiu_dump_iosetting(sc);
72 #define VPRINTF(flag, arg) \
73 if (bootverbose || vrgiu_debug & flag) printf arg;
74 #define VDUMP_IO(flag, sc) \
75 if (bootverbose || vrgiu_debug & flag) vrgiu_dump_io(sc);
76 #define VDUMP_IOSETTING(flag, sc) \
77 if (bootverbose || vrgiu_debug & flag) vrgiu_dump_iosetting(sc);
78 #else
79 #define DPRINTF(flag, arg)
80 #define DDUMP_IO(flag, sc)
81 #define DDUMP_IOSETTING(flag, sc)
82 #define VPRINTF(flag, arg) if (bootverbose) printf arg;
83 #define VDUMP_IO(flag, sc) if (bootverbose) vrgiu_dump_io(sc);
84 #define VDUMP_IOSETTING(flag, sc) \
85 if (bootverbose) vrgiu_dump_iosetting(sc);
86 #endif
87
88 #ifdef VRGIU_INTR_NOLED
89 int vrgiu_intr_led = 0;
90 #else /* VRGIU_INTR_NOLED */
91 int vrgiu_intr_led = 1;
92 #endif /* VRGIU_INTR_NOLED */
93
94 #define LEGAL_INTR_PORT(x) ((x) >= 0 && (x) < MAX_GPIO_INOUT)
95 #define LEGAL_OUT_PORT(x) ((x) >= 0 && (x) < MAX_GPIO_OUT)
96
97 int vrgiu_match(struct device*, struct cfdata*, void*);
98 void vrgiu_attach(struct device*, struct device*, void*);
99 int vrgiu_intr(void*);
100 int vrgiu_print(void*, const char*);
101 void vrgiu_callback(struct device*);
102
103 void vrgiu_dump_regs(struct vrgiu_softc *);
104 void vrgiu_dump_io(struct vrgiu_softc *);
105 void vrgiu_diff_io(void);
106 void vrgiu_dump_iosetting(struct vrgiu_softc *);
107 void vrgiu_diff_iosetting(void);
108 u_int32_t vrgiu_regread_4(struct vrgiu_softc *, bus_addr_t);
109 u_int16_t vrgiu_regread(struct vrgiu_softc *, bus_addr_t);
110 void vrgiu_regwrite_4(struct vrgiu_softc *, bus_addr_t, u_int32_t);
111 void vrgiu_regwrite(struct vrgiu_softc *, bus_addr_t, u_int16_t);
112
113 static int vrgiu_port_read(hpcio_chip_t, int);
114 static void vrgiu_port_write(hpcio_chip_t, int, int);
115 static void *vrgiu_intr_establish(hpcio_chip_t, int, int, int (*)(void *), void*);
116 static void vrgiu_intr_disestablish(hpcio_chip_t, void*);
117 static void vrgiu_intr_clear(hpcio_chip_t, void*);
118 static void vrgiu_update(hpcio_chip_t);
119 static void vrgiu_dump(hpcio_chip_t);
120 static hpcio_chip_t vrgiu_getchip(void*, int);
121
122 static struct hpcio_chip vrgiu_iochip = {
123 .hc_portread = vrgiu_port_read,
124 .hc_portwrite = vrgiu_port_write,
125 .hc_intr_establish = vrgiu_intr_establish,
126 .hc_intr_disestablish = vrgiu_intr_disestablish,
127 .hc_intr_clear = vrgiu_intr_clear,
128 .hc_update = vrgiu_update,
129 .hc_dump = vrgiu_dump,
130 };
131
132 struct cfattach vrgiu_ca = {
133 sizeof(struct vrgiu_softc), vrgiu_match, vrgiu_attach
134 };
135
136 struct vrgiu_softc *this_giu;
137
138 int
139 vrgiu_match(parent, cf, aux)
140 struct device *parent;
141 struct cfdata *cf;
142 void *aux;
143 {
144 return 2; /* 1st attach group of vrip */
145 }
146
147 void
148 vrgiu_attach(parent, self, aux)
149 struct device *parent;
150 struct device *self;
151 void *aux;
152 {
153 struct vrip_attach_args *va = aux;
154 struct vrgiu_softc *sc = (void*)self;
155 struct hpcio_attach_args haa;
156 int i;
157
158 this_giu = sc;
159 sc->sc_vc = va->va_vc;
160 sc->sc_iot = va->va_iot;
161 bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
162 0 /* no cache */, &sc->sc_ioh);
163 /*
164 * Disable all interrupts.
165 */
166 sc->sc_intr_mask = 0;
167 printf("\n");
168 #ifdef WINCE_DEFAULT_SETTING
169 #warning WINCE_DEFAULT_SETTING
170 #else
171 VPRINTF(DEBUG_IO, ("WIN setting: "));
172 VDUMP_IOSETTING(DEBUG_IO, sc);
173 VPRINTF(DEBUG_IO, ("\n"));
174 vrgiu_regwrite_4(sc, GIUINTEN_REG, sc->sc_intr_mask);
175 #endif
176
177 for (i = 0; i < MAX_GPIO_INOUT; i++)
178 TAILQ_INIT(&sc->sc_intr_head[i]);
179 if (!(sc->sc_ih = vrip_intr_establish(va->va_vc, va->va_intr, IPL_BIO,
180 vrgiu_intr, sc))) {
181 printf("%s: can't establish interrupt\n", sc->sc_dev.dv_xname);
182 return;
183 }
184 /*
185 * fill hpcio_chip structure
186 */
187 sc->sc_iochip = vrgiu_iochip; /* structure copy */
188 sc->sc_iochip.hc_chipid = VRIP_IOCHIP_VRGIU;
189 sc->sc_iochip.hc_name = sc->sc_dev.dv_xname;
190 sc->sc_iochip.hc_sc = sc;
191 /* Register functions to upper interface */
192 vrip_gpio_register(va->va_vc, &sc->sc_iochip);
193
194 /* Display port status (Input/Output) for debugging */
195 VPRINTF(DEBUG_IO, ("I/O setting: "));
196 VDUMP_IOSETTING(DEBUG_IO, sc);
197 VPRINTF(DEBUG_IO, ("\n"));
198 VPRINTF(DEBUG_IO, (" data:"));
199 VDUMP_IO(DEBUG_IO, sc);
200
201 /*
202 * hpcio I/F
203 */
204 haa.haa_busname = "hpcio";
205 haa.haa_sc = sc;
206 haa.haa_getchip = vrgiu_getchip;
207 while (config_found(self, &haa, vrgiu_print)) ;
208 /*
209 * GIU-ISA bridge
210 */
211 #if 1 /* XXX Sometimes mounting root device failed. Why? XXX*/
212 config_defer(self, vrgiu_callback);
213 #else
214 vrgiu_callback(self);
215 #endif
216 }
217
218 void
219 vrgiu_callback(self)
220 struct device *self;
221 {
222 struct vrgiu_softc *sc = (void*)self;
223 struct hpcio_attach_args haa;
224
225 haa.haa_busname = "vrisab";
226 haa.haa_sc = sc;
227 haa.haa_getchip = vrgiu_getchip;
228 config_found(self, &haa, vrgiu_print);
229 }
230
231 int
232 vrgiu_print(aux, pnp)
233 void *aux;
234 const char *pnp;
235 {
236 if (pnp)
237 return (QUIET);
238 return (UNCONF);
239 }
240
241 void
242 vrgiu_dump_iosetting(sc)
243 struct vrgiu_softc *sc;
244 {
245 long iosel, inten, useupdn, termupdn;
246 u_int32_t m;
247 iosel= vrgiu_regread_4(sc, GIUIOSEL_REG);
248 inten= vrgiu_regread_4(sc, GIUINTEN_REG);
249 useupdn = vrgiu_regread(sc, GIUUSEUPDN_REG_W);
250 termupdn = vrgiu_regread(sc, GIUTERMUPDN_REG_W);
251 for (m = 0x80000000; m; m >>=1)
252 printf ("%c" , (useupdn&m) ?
253 ((termupdn&m) ? 'U' : 'D') :
254 ((iosel&m) ? 'o' : ((inten&m)?'I':'i')));
255 }
256
257 void
258 vrgiu_diff_iosetting()
259 {
260 struct vrgiu_softc *sc = this_giu;
261 static long oiosel = 0, ointen = 0, ouseupdn = 0, otermupdn = 0;
262 long iosel, inten, useupdn, termupdn;
263 u_int32_t m;
264
265 iosel= vrgiu_regread_4(sc, GIUIOSEL_REG);
266 inten= vrgiu_regread_4(sc, GIUINTEN_REG);
267 useupdn = vrgiu_regread(sc, GIUUSEUPDN_REG_W);
268 termupdn = vrgiu_regread(sc, GIUTERMUPDN_REG_W);
269 if (oiosel != iosel || ointen != inten ||
270 ouseupdn != useupdn || otermupdn != termupdn) {
271 for (m = 0x80000000; m; m >>=1)
272 printf ("%c" , (useupdn&m) ?
273 ((termupdn&m) ? 'U' : 'D') :
274 ((iosel&m) ? 'o' : ((inten&m)?'I':'i')));
275 }
276 oiosel = iosel;
277 ointen = inten;
278 ouseupdn = useupdn;
279 otermupdn = termupdn;
280 }
281
282 void
283 vrgiu_dump_io(sc)
284 struct vrgiu_softc *sc;
285 {
286 u_int32_t preg[2];
287
288 preg[0] = vrgiu_regread_4(sc, GIUPIOD_REG);
289 preg[1] = vrgiu_regread_4(sc, GIUPODAT_REG);
290
291 bitdisp64(preg);
292 }
293
294 void
295 vrgiu_diff_io()
296 {
297 struct vrgiu_softc *sc = this_giu;
298 static u_int32_t opreg[2] = {0, 0};
299 u_int32_t preg[2];
300
301 preg[0] = vrgiu_regread_4(sc, GIUPIOD_REG);
302 preg[1] = vrgiu_regread_4(sc, GIUPODAT_REG);
303
304 if (opreg[0] != preg[0] || opreg[1] != preg[1]) {
305 printf("giu data: ");
306 bitdisp64(preg);
307 }
308 opreg[0] = preg[0];
309 opreg[1] = preg[1];
310 }
311
312 void
313 vrgiu_dump_regs(sc)
314 struct vrgiu_softc *sc;
315 {
316 if (sc == NULL) {
317 panic("%s(%d): VRGIU device not initialized\n",
318 __FILE__, __LINE__);
319 }
320 printf(" IOSEL: %08x\n", vrgiu_regread_4(sc, GIUIOSEL_REG));
321 printf(" PIOD: %08x\n", vrgiu_regread_4(sc, GIUPIOD_REG));
322 printf(" PODAT: %08x\n", vrgiu_regread_4(sc, GIUPODAT_REG));
323 printf(" INTSTAT: %08x\n", vrgiu_regread_4(sc, GIUINTSTAT_REG));
324 printf(" INTEN: %08x\n", vrgiu_regread_4(sc, GIUINTEN_REG));
325 printf(" INTTYP: %08x\n", vrgiu_regread_4(sc, GIUINTTYP_REG));
326 printf(" INTALSEL: %08x\n", vrgiu_regread_4(sc, GIUINTALSEL_REG));
327 printf(" INTHTSEL: %08x\n", vrgiu_regread_4(sc, GIUINTHTSEL_REG));
328 }
329 /*
330 * GIU regster access method.
331 */
332 u_int32_t
333 vrgiu_regread_4(sc, offs)
334 struct vrgiu_softc *sc;
335 bus_addr_t offs;
336 {
337 u_int16_t reg[2];
338 bus_space_read_region_2 (sc->sc_iot, sc->sc_ioh, offs, reg, 2);
339 return reg[0]|(reg[1]<<16);
340 }
341
342 u_int16_t
343 vrgiu_regread(sc, off)
344 struct vrgiu_softc *sc;
345 bus_addr_t off;
346 {
347 return bus_space_read_2(sc->sc_iot, sc->sc_ioh, off);
348 }
349
350 void
351 vrgiu_regwrite_4(sc, offs, data)
352 struct vrgiu_softc *sc;
353 bus_addr_t offs;
354 u_int32_t data;
355 {
356 u_int16_t reg[2];
357 reg[0] = data & 0xffff;
358 reg[1] = (data>>16)&0xffff;
359 bus_space_write_region_2 (sc->sc_iot, sc->sc_ioh, offs, reg, 2);
360 }
361
362 void
363 vrgiu_regwrite(sc, off, data)
364 struct vrgiu_softc *sc;
365 bus_addr_t off;
366 u_int16_t data;
367 {
368 bus_space_write_2(sc->sc_iot, sc->sc_ioh, off, data);
369 }
370
371 /*
372 * PORT
373 */
374 int
375 vrgiu_port_read(hc, port)
376 hpcio_chip_t hc;
377 int port;
378 {
379 struct vrgiu_softc *sc = hc->hc_sc;
380 int on;
381
382 if (!LEGAL_OUT_PORT(port))
383 panic("vrgiu_port_read: illegal gpio port");
384
385 if (port < 32)
386 on = (vrgiu_regread_4(sc, GIUPIOD_REG) & (1 << port));
387 else
388 on = (vrgiu_regread_4(sc, GIUPODAT_REG) & (1 << (port - 32)));
389
390 return (on ? 1 : 0);
391 }
392
393 void
394 vrgiu_port_write(hc, port, onoff)
395 hpcio_chip_t hc;
396 int port;
397 int onoff;
398 {
399 struct vrgiu_softc *sc = hc->hc_sc;
400 u_int32_t reg[2];
401 int bank;
402
403 if (!LEGAL_OUT_PORT(port))
404 panic("vrgiu_port_write: illegal gpio port");
405
406 reg[0] = vrgiu_regread_4(sc, GIUPIOD_REG);
407 reg[1] = vrgiu_regread_4(sc, GIUPODAT_REG);
408 bank = port < 32 ? 0 : 1;
409 if (bank == 1)
410 port -= 32;
411
412 if (onoff)
413 reg[bank] |= (1<<port);
414 else
415 reg[bank] &= ~(1<<port);
416 vrgiu_regwrite_4(sc, GIUPIOD_REG, reg[0]);
417 vrgiu_regwrite_4(sc, GIUPODAT_REG, reg[1]);
418 }
419
420 static void
421 vrgiu_update(hc)
422 hpcio_chip_t hc;
423 {
424 }
425
426 static void
427 vrgiu_dump(hc)
428 hpcio_chip_t hc;
429 {
430 }
431
432 static hpcio_chip_t
433 vrgiu_getchip(scx, chipid)
434 void* scx;
435 int chipid;
436 {
437 struct vrgiu_softc *sc = scx;
438
439 return (&sc->sc_iochip);
440 }
441
442 /*
443 * For before autoconfiguration.
444 */
445 void
446 __vrgiu_out(port, data)
447 int port;
448 int data;
449 {
450 u_int16_t reg;
451 u_int32_t addr;
452 int offs;
453
454 if (!LEGAL_OUT_PORT(port))
455 panic("__vrgiu_out: illegal gpio port");
456 if (port < 16) {
457 addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPIOD_L_REG_W));
458 offs = port;
459 } else if (port < 32) {
460 addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPIOD_H_REG_W));
461 offs = port - 16;
462 } else if (port < 48) {
463 addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPODAT_L_REG_W));
464 offs = port - 32;
465 } else {
466 addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPODAT_H_REG_W));
467 offs = port - 48;
468 panic ("__vrgiu_out: not coded yet.");
469 }
470 DPRINTF(DEBUG_IO, ("__vrgiu_out: addr %08x bit %d\n", addr, offs));
471
472 wbflush();
473 reg = *((volatile u_int16_t*)addr);
474 if (data) {
475 reg |= (1 << offs);
476 } else {
477 reg &= ~(1 << offs);
478 }
479 *((volatile u_int16_t*)addr) = reg;
480 wbflush();
481 }
482 /*
483 * Interrupt staff
484 */
485 void *
486 vrgiu_intr_establish(hc, port, mode, ih_fun, ih_arg)
487 hpcio_chip_t hc;
488 int port; /* GPIO pin # */
489 int mode; /* GIU trigger setting */
490 int (*ih_fun) __P((void*));
491 void *ih_arg;
492 {
493 struct vrgiu_softc *sc = hc->hc_sc;
494 int s;
495 u_int32_t reg, mask;
496 struct vrgiu_intr_entry *ih;
497
498 if (!LEGAL_INTR_PORT(port))
499 panic ("vrgiu_intr_establish: bogus interrupt line.");
500 if (sc->sc_intr_mode[port] && mode != sc->sc_intr_mode[port])
501 panic ("vrgiu_intr_establish: bogus interrupt type.");
502 else
503 sc->sc_intr_mode[port] = mode;
504 mask = (1 << port);
505
506 s = splhigh();
507
508 if (!(ih = malloc(sizeof(struct vrgiu_intr_entry), M_DEVBUF, M_NOWAIT)))
509 panic ("vrgiu_intr_establish: no memory.");
510
511 ih->ih_port = port;
512 ih->ih_fun = ih_fun;
513 ih->ih_arg = ih_arg;
514 TAILQ_INSERT_TAIL(&sc->sc_intr_head[port], ih, ih_link);
515 #ifdef WINCE_DEFAULT_SETTING
516 #warning WINCE_DEFAULT_SETTING
517 #else
518 /*
519 * Setup registers
520 */
521 /* Input mode */
522 reg = vrgiu_regread_4(sc, GIUIOSEL_REG);
523 reg &= ~mask;
524 vrgiu_regwrite_4(sc, GIUIOSEL_REG, reg);
525
526 /* interrupt type */
527 reg = vrgiu_regread_4(sc, GIUINTTYP_REG);
528 DPRINTF(DEBUG_INTR, ("[%s->",reg & mask ? "edge" : "level"));
529 if (mode & HPCIO_INTR_EDGE) {
530 DPRINTF(DEBUG_INTR, ("edge]"));
531 reg |= mask; /* edge */
532 } else {
533 DPRINTF(DEBUG_INTR, ("level]"));
534 reg &= ~mask; /* level */
535 }
536 vrgiu_regwrite_4(sc, GIUINTTYP_REG, reg);
537
538 /* interrupt level */
539 if (!(mode & HPCIO_INTR_EDGE)) {
540 reg = vrgiu_regread_4(sc, GIUINTALSEL_REG);
541 DPRINTF(DEBUG_INTR, ("[%s->",reg & mask ? "high" : "low"));
542 if (mode & HPCIO_INTR_HIGH) {
543 DPRINTF(DEBUG_INTR, ("high]"));
544 reg |= mask; /* high */
545 } else {
546 DPRINTF(DEBUG_INTR, ("low]"));
547 reg &= ~mask; /* low */
548 }
549 vrgiu_regwrite_4(sc, GIUINTALSEL_REG, reg);
550 }
551 /* hold or through */
552 reg = vrgiu_regread_4(sc, GIUINTHTSEL_REG);
553 DPRINTF(DEBUG_INTR, ("[%s->",reg & mask ? "hold" : "through"));
554 if (mode & HPCIO_INTR_HOLD) {
555 DPRINTF(DEBUG_INTR, ("hold]"));
556 reg |= mask; /* hold */
557 } else {
558 DPRINTF(DEBUG_INTR, ("through]"));
559 reg &= ~mask; /* through */
560 }
561 vrgiu_regwrite_4(sc, GIUINTHTSEL_REG, reg);
562 #endif
563 /*
564 * clear interrupt status
565 */
566 reg = vrgiu_regread_4(sc, GIUINTSTAT_REG);
567 reg &= ~mask;
568 vrgiu_regwrite_4(sc, GIUINTSTAT_REG, reg);
569 /*
570 * enable interrupt
571 */
572 #ifdef WINCE_DEFAULT_SETTING
573 #warning WINCE_DEFAULT_SETTING
574 #else
575 sc->sc_intr_mask |= mask;
576 vrgiu_regwrite_4(sc, GIUINTEN_REG, sc->sc_intr_mask);
577 /* Unmask GIU level 2 mask register */
578 vrip_intr_setmask2(sc->sc_vc, sc->sc_ih, (1<<port), 1);
579 #endif
580 splx(s);
581
582 DPRINTF(DEBUG_INTR, ("\n"));
583
584 return ih;
585 }
586
587 void
588 vrgiu_intr_disestablish(hc, arg)
589 hpcio_chip_t hc;
590 void *arg;
591 {
592 struct vrgiu_intr_entry *ihe = arg;
593 struct vrgiu_softc *sc = hc->hc_sc;
594 int port = ihe->ih_port;
595 struct vrgiu_intr_entry *ih;
596 int s;
597
598 s = splhigh();
599 TAILQ_FOREACH(ih, &sc->sc_intr_head[port], ih_link) {
600 if (ih == ihe) {
601 TAILQ_REMOVE(&sc->sc_intr_head[port], ih, ih_link);
602 free(ih, M_DEVBUF);
603 if (TAILQ_EMPTY(&sc->sc_intr_head[port])) {
604 /* Disable interrupt */
605 #ifdef WINCE_DEFAULT_SETTING
606 #warning WINCE_DEFAULT_SETTING
607 #else
608 sc->sc_intr_mask &= ~(1<<port);
609 vrgiu_regwrite_4(sc, GIUINTEN_REG, sc->sc_intr_mask);
610 #endif
611 }
612 splx(s);
613 return;
614 }
615 }
616 panic("vrgiu_intr_disetablish: no such a handle.");
617 /* NOTREACHED */
618 }
619
620 /* Clear interrupt */
621 void
622 vrgiu_intr_clear(hc, arg)
623 hpcio_chip_t hc;
624 void *arg;
625 {
626 struct vrgiu_softc *sc = hc->hc_sc;
627 struct vrgiu_intr_entry *ihe = arg;
628 u_int32_t reg;
629
630 reg = vrgiu_regread_4(sc, GIUINTSTAT_REG);
631 vrgiu_regwrite_4(sc, GIUINTSTAT_REG, reg & ~(1 << ihe->ih_port));
632 }
633
634 /* interrupt handler */
635 int
636 vrgiu_intr(arg)
637 void *arg;
638 {
639 #ifdef DUMP_GIU_LEVEL2_INTR
640 #warning DUMP_GIU_LEVEL2_INTR
641 static u_int32_t oreg;
642 #endif
643 struct vrgiu_softc *sc = arg;
644 int i;
645 u_int32_t reg;
646 int ledvalue = CONFIG_HOOK_LED_FLASH;
647
648 /* Get Level 2 interrupt status */
649 vrip_intr_get_status2 (sc->sc_vc, sc->sc_ih, ®);
650 #ifdef DUMP_GIU_LEVEL2_INTR
651 #warning DUMP_GIU_LEVEL2_INTR
652 {
653 u_int32_t uedge, dedge, j;
654 for (j = 0x80000000; j > 0; j >>=1)
655 printf ("%c" , reg&j ? '|' : '.');
656 uedge = (reg ^ oreg) & reg;
657 dedge = (reg ^ oreg) & ~reg;
658 if (uedge || dedge) {
659 for (j = 0; j < 32; j++) {
660 if (uedge & (1 << j))
661 printf ("+%d", j);
662 else if (dedge & (1 << j))
663 printf ("-%d", j);
664 }
665 }
666 oreg = reg;
667 printf ("\n");
668 }
669 #endif
670 /* Clear interrupt */
671 vrgiu_regwrite_4(sc, GIUINTSTAT_REG, vrgiu_regread_4(sc, GIUINTSTAT_REG));
672
673 /* Dispatch handler */
674 for (i = 0; i < MAX_GPIO_INOUT; i++) {
675 if (reg & (1 << i)) {
676 register struct vrgiu_intr_entry *ih;
677 TAILQ_FOREACH(ih, &sc->sc_intr_head[i], ih_link) {
678 ih->ih_fun(ih->ih_arg);
679 }
680 }
681 }
682
683 if (vrgiu_intr_led)
684 config_hook_call(CONFIG_HOOK_SET,
685 CONFIG_HOOK_LED,
686 (void *)&ledvalue);
687 return 0;
688 }
689