Home | History | Annotate | Line # | Download | only in vr
vrgiu.c revision 1.18
      1 /*	$NetBSD: vrgiu.c,v 1.18 2001/04/18 11:11:11 sato Exp $	*/
      2 /*-
      3  * Copyright (c) 1999
      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 "opt_vr41xx.h"
     50 #include <hpcmips/vr/vrcpudef.h>
     51 #include <hpcmips/vr/vripreg.h>
     52 #include <hpcmips/vr/vripvar.h>
     53 #include <hpcmips/vr/vrgiureg.h>
     54 
     55 #include "locators.h"
     56 
     57 #define VRGIUDEBUG
     58 #ifdef VRGIUDEBUG
     59 #define DEBUG_IO	1
     60 #define DEBUG_INTR	2
     61 #ifndef VRGIUDEBUG_CONF
     62 #define VRGIUDEBUG_CONF 0
     63 #endif /* VRGIUDEBUG_CONF */
     64 int	vrgiu_debug = VRGIUDEBUG_CONF;
     65 #define	DPRINTF(flag, arg) if (vrgiu_debug & flag) printf arg;
     66 #define DDUMP_IO(flag, sc) if (vrgiu_debug & flag) vrgiu_dump_io(sc);
     67 #define DDUMP_IOSETTING(flag, sc) \
     68 		if (vrgiu_debug & flag) vrgiu_dump_iosetting(sc);
     69 #define	VPRINTF(flag, arg) \
     70 		if (bootverbose || vrgiu_debug & flag) printf arg;
     71 #define VDUMP_IO(flag, sc) \
     72 		if (bootverbose || vrgiu_debug & flag) vrgiu_dump_io(sc);
     73 #define VDUMP_IOSETTING(flag, sc) \
     74 		if (bootverbose || vrgiu_debug & flag) vrgiu_dump_iosetting(sc);
     75 #else
     76 #define	DPRINTF(flag, arg)
     77 #define DDUMP_IO(flag, sc)
     78 #define DDUMP_IOSETTING(flag, sc)
     79 #define	VPRINTF(flag, arg) if (bootverbose) printf arg;
     80 #define VDUMP_IO(flag, sc) if (bootverbose) vrgiu_dump_io(sc);
     81 #define VDUMP_IOSETTING(flag, sc) \
     82 			if (bootverbose) vrgiu_dump_iosetting(sc);
     83 #endif
     84 
     85 #ifdef VRGIU_INTR_NOLED
     86 int vrgiu_intr_led = 0;
     87 #else /* VRGIU_INTR_NOLED */
     88 int vrgiu_intr_led = 1;
     89 #endif /* VRGIU_INTR_NOLED */
     90 
     91 #define	LEGAL_INTR_PORT(x)	((x) >= 0 && (x) < MAX_GPIO_INOUT)
     92 #define	LEGAL_OUT_PORT(x)	((x) >= 0 && (x) < MAX_GPIO_OUT)
     93 
     94 int vrgiu_match __P((struct device*, struct cfdata*, void*));
     95 void vrgiu_attach __P((struct device*, struct device*, void*));
     96 int vrgiu_intr __P((void*));
     97 int vrgiu_print __P((void*, const char*));
     98 void vrgiu_callback __P((struct device*));
     99 
    100 void	vrgiu_dump_regs __P((struct vrgiu_softc *sc));
    101 void	vrgiu_dump_io __P((struct vrgiu_softc *sc));
    102 void	vrgiu_diff_io __P((void));
    103 void	vrgiu_dump_iosetting __P((struct vrgiu_softc *sc));
    104 void	vrgiu_diff_iosetting __P((void));
    105 u_int32_t vrgiu_regread_4 __P((vrgiu_chipset_tag_t, bus_addr_t));
    106 u_int16_t vrgiu_regread __P((vrgiu_chipset_tag_t, bus_addr_t));
    107 void	vrgiu_regwrite_4 __P((vrgiu_chipset_tag_t, bus_addr_t, u_int32_t));
    108 void	vrgiu_regwrite __P((vrgiu_chipset_tag_t, bus_addr_t, u_int16_t));
    109 
    110 int vrgiu_port_read __P((vrgiu_chipset_tag_t, int));
    111 int vrgiu_port_write __P((vrgiu_chipset_tag_t, int, int));
    112 
    113 void *vrgiu_intr_establish __P((vrgiu_chipset_tag_t, int, int, int, int (*)(void *), void*));
    114 void vrgiu_intr_disestablish __P((vrgiu_chipset_tag_t, void*));
    115 
    116 struct vrgiu_function_tag vrgiu_functions = {
    117 	vrgiu_port_read,
    118 	vrgiu_port_write,
    119 	vrgiu_regread_4,
    120 	vrgiu_regwrite_4,
    121 	vrgiu_intr_establish,
    122 	vrgiu_intr_disestablish
    123 };
    124 
    125 struct cfattach vrgiu_ca = {
    126 	sizeof(struct vrgiu_softc), vrgiu_match, vrgiu_attach
    127 };
    128 
    129 struct vrgiu_softc *this_giu;
    130 
    131 int
    132 vrgiu_match(parent, cf, aux)
    133 	struct device *parent;
    134 	struct cfdata *cf;
    135 	void *aux;
    136 {
    137 	return 2; /* 1st attach group of vrip */
    138 }
    139 
    140 void
    141 vrgiu_attach(parent, self, aux)
    142 	struct device *parent;
    143 	struct device *self;
    144 	void *aux;
    145 {
    146 	struct vrip_attach_args *va = aux;
    147 	struct vrgiu_softc *sc = (void*)self;
    148 	struct gpbus_attach_args gpa;
    149 	int i;
    150 
    151 	this_giu = sc;
    152 	sc->sc_vc = va->va_vc;
    153 	sc->sc_iot = va->va_iot;
    154 	bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
    155 		      0 /* no cache */, &sc->sc_ioh);
    156 	/*
    157 	 *  Disable all interrupts.
    158 	 */
    159 	sc->sc_intr_mask = 0;
    160 	printf("\n");
    161 #ifdef WINCE_DEFAULT_SETTING
    162 #warning WINCE_DEFAULT_SETTING
    163 #else
    164 	VPRINTF(DEBUG_IO, ("WIN setting:                                "));
    165 	VDUMP_IOSETTING(DEBUG_IO, sc);
    166 	VPRINTF(DEBUG_IO, ("\n"));
    167 	vrgiu_regwrite_4(sc, GIUINTEN_REG, sc->sc_intr_mask);
    168 #endif
    169 
    170 	for (i = 0; i < MAX_GPIO_INOUT; i++)
    171 		TAILQ_INIT(&sc->sc_intr_head[i]);
    172 	if (!(sc->sc_ih = vrip_intr_establish(va->va_vc, va->va_intr, IPL_BIO,
    173 					      vrgiu_intr, sc))) {
    174 		printf("%s: can't establish interrupt\n", sc->sc_dev.dv_xname);
    175 		return;
    176 	}
    177 	vrgiu_functions.gf_intr_establish = vrgiu_intr_establish;
    178 	vrgiu_functions.gf_intr_disestablish = vrgiu_intr_disestablish;
    179 	/*
    180 	 * Register functions to upper interface.
    181 	 */
    182 	vrip_giu_function_register(va->va_vc, &vrgiu_functions, self);
    183 
    184 	/* Display port status (Input/Output) for debugging */
    185 	VPRINTF(DEBUG_IO, ("I/O setting:                                "));
    186 	DDUMP_IOSETTING(DEBUG_IO, sc);
    187 	VPRINTF(DEBUG_IO, ("\n"));
    188 	VPRINTF(DEBUG_IO, ("       data:"));
    189 	VDUMP_IO(DEBUG_IO, sc);
    190 
    191 	/*
    192 	 *  General purpose bus
    193 	 */
    194 	gpa.gpa_busname = "gpbus";
    195 	gpa.gpa_gc = sc;
    196 	gpa.gpa_gf = &vrgiu_functions;
    197 	while (config_found(self, &gpa, vrgiu_print)) ;
    198 	/*
    199 	 * GIU-ISA bridge
    200 	 */
    201 #if 1 /* XXX Sometimes mounting root device failed. Why? XXX*/
    202 	config_defer(self, vrgiu_callback);
    203 #else
    204 	vrgiu_callback(self);
    205 #endif
    206 }
    207 
    208 void
    209 vrgiu_callback(self)
    210 	struct device *self;
    211 {
    212 	struct vrgiu_softc *sc = (void*)self;
    213 	struct gpbus_attach_args gpa;
    214 
    215 	gpa.gpa_busname = "vrisab";
    216 	gpa.gpa_gc = sc;
    217 	gpa.gpa_gf = &vrgiu_functions;
    218 	config_found(self, &gpa, vrgiu_print);
    219 }
    220 
    221 int
    222 vrgiu_print(aux, pnp)
    223 	void *aux;
    224 	const char *pnp;
    225 {
    226 	if (pnp)
    227 		return (QUIET);
    228 	return (UNCONF);
    229 }
    230 
    231 void
    232 vrgiu_dump_iosetting(sc)
    233 	struct vrgiu_softc *sc;
    234 {
    235 	long iosel, inten, useupdn, termupdn;
    236 	u_int32_t m;
    237 	iosel= vrgiu_regread_4(sc, GIUIOSEL_REG);
    238 	inten= vrgiu_regread_4(sc, GIUINTEN_REG);
    239 	useupdn = vrgiu_regread(sc, GIUUSEUPDN_REG_W);
    240 	termupdn = vrgiu_regread(sc, GIUTERMUPDN_REG_W);
    241 	for (m = 0x80000000; m; m >>=1)
    242 		printf ("%c" , (useupdn&m) ?
    243 			((termupdn&m) ? 'U' : 'D') :
    244 			((iosel&m) ? 'o' : ((inten&m)?'I':'i')));
    245 }
    246 
    247 void
    248 vrgiu_diff_iosetting()
    249 {
    250 	struct vrgiu_softc *sc = this_giu;
    251 	static long oiosel = 0, ointen = 0, ouseupdn = 0, otermupdn = 0;
    252 	long iosel, inten, useupdn, termupdn;
    253 	u_int32_t m;
    254 
    255 	iosel= vrgiu_regread_4(sc, GIUIOSEL_REG);
    256 	inten= vrgiu_regread_4(sc, GIUINTEN_REG);
    257 	useupdn = vrgiu_regread(sc, GIUUSEUPDN_REG_W);
    258 	termupdn = vrgiu_regread(sc, GIUTERMUPDN_REG_W);
    259 	if (oiosel != iosel || ointen != inten ||
    260 	    ouseupdn != useupdn || otermupdn != termupdn) {
    261 		for (m = 0x80000000; m; m >>=1)
    262 			printf ("%c" , (useupdn&m) ?
    263 				((termupdn&m) ? 'U' : 'D') :
    264 				((iosel&m) ? 'o' : ((inten&m)?'I':'i')));
    265 	}
    266 	oiosel = iosel;
    267 	ointen = inten;
    268 	ouseupdn = useupdn;
    269 	otermupdn = termupdn;
    270 }
    271 
    272 void
    273 vrgiu_dump_io(sc)
    274 	struct vrgiu_softc *sc;
    275 {
    276 	u_int32_t preg[2];
    277 
    278 	preg[0] = vrgiu_regread_4(sc, GIUPIOD_REG);
    279 	preg[1] = vrgiu_regread_4(sc, GIUPODAT_REG);
    280 
    281 	bitdisp64(preg);
    282 }
    283 
    284 void
    285 vrgiu_diff_io()
    286 {
    287 	struct vrgiu_softc *sc  = this_giu;
    288 	static u_int32_t opreg[2] = {0, 0};
    289 	u_int32_t preg[2];
    290 
    291 	preg[0] = vrgiu_regread_4(sc, GIUPIOD_REG);
    292 	preg[1] = vrgiu_regread_4(sc, GIUPODAT_REG);
    293 
    294 	if (opreg[0] != preg[0] || opreg[1] != preg[1]) {
    295 		printf("giu data: ");
    296 		bitdisp64(preg);
    297 	}
    298 	opreg[0] = preg[0];
    299 	opreg[1] = preg[1];
    300 }
    301 
    302 void
    303 vrgiu_dump_regs(sc)
    304 	struct vrgiu_softc *sc;
    305 {
    306 	if (sc == NULL) {
    307 		panic("%s(%d): VRGIU device not initialized\n",
    308 		      __FILE__, __LINE__);
    309 	}
    310 	printf("    IOSEL: %08x\n", vrgiu_regread_4(sc, GIUIOSEL_REG));
    311 	printf("     PIOD: %08x\n", vrgiu_regread_4(sc, GIUPIOD_REG));
    312 	printf("    PODAT: %08x\n", vrgiu_regread_4(sc, GIUPODAT_REG));
    313 	printf("  INTSTAT: %08x\n", vrgiu_regread_4(sc, GIUINTSTAT_REG));
    314 	printf("    INTEN: %08x\n", vrgiu_regread_4(sc, GIUINTEN_REG));
    315 	printf("   INTTYP: %08x\n", vrgiu_regread_4(sc, GIUINTTYP_REG));
    316 	printf(" INTALSEL: %08x\n", vrgiu_regread_4(sc, GIUINTALSEL_REG));
    317 	printf(" INTHTSEL: %08x\n", vrgiu_regread_4(sc, GIUINTHTSEL_REG));
    318 }
    319 /*
    320  * GIU regster access method.
    321  */
    322 u_int32_t
    323 vrgiu_regread_4(vc, offs)
    324 	vrgiu_chipset_tag_t vc;
    325 	bus_addr_t offs;
    326 {
    327 	struct vrgiu_softc *sc = (void*)vc;
    328 	u_int16_t reg[2];
    329 	bus_space_read_region_2 (sc->sc_iot, sc->sc_ioh, offs, reg, 2);
    330 	return reg[0]|(reg[1]<<16);
    331 }
    332 
    333 u_int16_t
    334 vrgiu_regread(vc, off)
    335 	vrgiu_chipset_tag_t vc;
    336 	bus_addr_t off;
    337 {
    338 	struct vrgiu_softc *sc = (void*)vc;
    339 	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, off);
    340 }
    341 
    342 void
    343 vrgiu_regwrite_4(vc, offs, data)
    344 	vrgiu_chipset_tag_t vc;
    345 	bus_addr_t offs;
    346 	u_int32_t data;
    347 {
    348 	struct vrgiu_softc *sc = (void*)vc;
    349 
    350 	u_int16_t reg[2];
    351 	reg[0] = data & 0xffff;
    352 	reg[1] = (data>>16)&0xffff;
    353 	bus_space_write_region_2 (sc->sc_iot, sc->sc_ioh, offs, reg, 2);
    354 }
    355 
    356 void
    357 vrgiu_regwrite(vc, off, data)
    358 	vrgiu_chipset_tag_t vc;
    359 	bus_addr_t off;
    360 	u_int16_t data;
    361 {
    362 	struct vrgiu_softc *sc = (void*)vc;
    363 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, off, data);
    364 }
    365 
    366 /*
    367  * PORT
    368  */
    369 int
    370 vrgiu_port_read(vc, port)
    371 	vrgiu_chipset_tag_t vc;
    372 	int port;
    373 {
    374 	int on;
    375 
    376 	if (!LEGAL_OUT_PORT(port))
    377 		panic("vrgiu_port_read: illegal gpio port");
    378 
    379 	if (port < 32)
    380 		on = (vrgiu_regread_4(vc, GIUPIOD_REG) & (1 << port));
    381 	else
    382 		on = (vrgiu_regread_4(vc, GIUPODAT_REG) & (1 << (port - 32)));
    383 
    384 	return (on ? 1 : 0);
    385 }
    386 
    387 int
    388 vrgiu_port_write(vc, port, onoff)
    389 	vrgiu_chipset_tag_t vc;
    390 	int port;
    391 	int onoff;
    392 {
    393 	u_int32_t reg[2];
    394 	int bank;
    395 
    396 	if (!LEGAL_OUT_PORT(port))
    397 		panic("vrgiu_port_write: illegal gpio port");
    398 
    399 	reg[0] = vrgiu_regread_4(vc, GIUPIOD_REG);
    400 	reg[1] = vrgiu_regread_4(vc, GIUPODAT_REG);
    401 	bank = port < 32 ? 0 : 1;
    402 	if (bank == 1)
    403 		port -= 32;
    404 
    405 	if (onoff)
    406 		reg[bank] |= (1<<port);
    407 	else
    408 		reg[bank] &= ~(1<<port);
    409 	vrgiu_regwrite_4(vc, GIUPIOD_REG, reg[0]);
    410 	vrgiu_regwrite_4(vc, GIUPODAT_REG, reg[1]);
    411 
    412 	return 0;
    413 }
    414 /*
    415  *  For before autoconfiguration.
    416  */
    417 void
    418 __vrgiu_out(port, data)
    419 	int port;
    420 	int data;
    421 {
    422 	u_int16_t reg;
    423 	u_int32_t addr;
    424 	int offs;
    425 
    426 	if (!LEGAL_OUT_PORT(port))
    427 		panic("__vrgiu_out: illegal gpio port");
    428 	if (port < 16) {
    429 		addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPIOD_L_REG_W));
    430 		offs = port;
    431 	} else if (port < 32) {
    432 		addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPIOD_H_REG_W));
    433 		offs = port - 16;
    434 	} else if (port < 48) {
    435 		addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPODAT_L_REG_W));
    436 		offs = port - 32;
    437 	} else {
    438 		addr = MIPS_PHYS_TO_KSEG1((VRIP_GIU_ADDR + GIUPODAT_H_REG_W));
    439 		offs = port - 48;
    440 		panic ("__vrgiu_out: not coded yet.");
    441 	}
    442 	DPRINTF(DEBUG_IO, ("__vrgiu_out: addr %08x bit %d\n", addr, offs));
    443 
    444 	wbflush();
    445 	reg = *((volatile u_int16_t*)addr);
    446 	if (data) {
    447 		reg |= (1 << offs);
    448 	} else {
    449 		reg &= ~(1 << offs);
    450 	}
    451 	*((volatile u_int16_t*)addr) = reg;
    452 	wbflush();
    453 }
    454 /*
    455  * Interrupt staff
    456  */
    457 void *
    458 vrgiu_intr_establish(ic, port, mode, level, ih_fun, ih_arg)
    459 	vrgiu_chipset_tag_t ic;
    460 	int port; /* GPIO pin # */
    461 	int mode; /* GIU trigger setting */
    462 	int level;  /* XXX not yet */
    463 	int (*ih_fun) __P((void*));
    464 	void *ih_arg;
    465 {
    466 	struct vrgiu_softc *sc = (void*)ic;
    467 	int s;
    468 	u_int32_t reg, mask;
    469 	struct vrgiu_intr_entry *ih;
    470 
    471 	if (!LEGAL_INTR_PORT(port))
    472 		panic ("vrgiu_intr_establish: bogus interrupt line.");
    473 	if (sc->sc_intr_mode[port] && mode != sc->sc_intr_mode[port])
    474 		panic ("vrgiu_intr_establish: bogus interrupt type.");
    475 	else
    476 		sc->sc_intr_mode[port] = mode;
    477 	mask = (1 << port);
    478 
    479 	s = splhigh();
    480 
    481 	if (!(ih = malloc(sizeof(struct vrgiu_intr_entry), M_DEVBUF, M_NOWAIT)))
    482 		panic ("vrgiu_intr_establish: no memory.");
    483 
    484 	ih->ih_port = port;
    485 	ih->ih_fun = ih_fun;
    486 	ih->ih_arg = ih_arg;
    487 	TAILQ_INSERT_TAIL(&sc->sc_intr_head[port], ih, ih_link);
    488 #ifdef WINCE_DEFAULT_SETTING
    489 #warning WINCE_DEFAULT_SETTING
    490 #else
    491 	/*
    492 	 *  Setup registers
    493 	 */
    494 	/* Input mode */
    495 	reg = vrgiu_regread_4(sc, GIUIOSEL_REG);
    496 	reg &= ~mask;
    497 	vrgiu_regwrite_4(sc, GIUIOSEL_REG, reg);
    498 
    499 	/* interrupt type */
    500 	reg = vrgiu_regread_4(sc, GIUINTTYP_REG);
    501 	DPRINTF(DEBUG_INTR, ("[%s->",reg & mask ? "edge" : "level"));
    502 	if (mode & VRGIU_INTR_EDGE) {
    503 		DPRINTF(DEBUG_INTR, ("edge]"));
    504 		reg |= mask;	/* edge */
    505 	} else {
    506 		DPRINTF(DEBUG_INTR, ("level]"));
    507 		reg &= ~mask;	/* level */
    508 	}
    509 	vrgiu_regwrite_4(sc, GIUINTTYP_REG, reg);
    510 
    511 	/* interrupt level */
    512 	if (!(mode & VRGIU_INTR_EDGE)) {
    513 		reg = vrgiu_regread_4(sc, GIUINTALSEL_REG);
    514 		DPRINTF(DEBUG_INTR, ("[%s->",reg & mask ? "high" : "low"));
    515 		if (mode & VRGIU_INTR_HIGH) {
    516 			DPRINTF(DEBUG_INTR, ("high]"));
    517 			reg |= mask;	/* high */
    518 		} else {
    519 			DPRINTF(DEBUG_INTR, ("low]"));
    520 			reg &= ~mask;	/* low */
    521 		}
    522 		vrgiu_regwrite_4(sc, GIUINTALSEL_REG, reg);
    523 	}
    524 	/* hold or through */
    525 	reg = vrgiu_regread_4(sc, GIUINTHTSEL_REG);
    526 	DPRINTF(DEBUG_INTR, ("[%s->",reg & mask ? "hold" : "through"));
    527 	if (mode & VRGIU_INTR_HOLD) {
    528 		DPRINTF(DEBUG_INTR, ("hold]"));
    529 		reg |= mask;	/* hold */
    530 	} else {
    531 		DPRINTF(DEBUG_INTR, ("through]"));
    532 		reg &= ~mask;	/* through */
    533 	}
    534 	vrgiu_regwrite_4(sc, GIUINTHTSEL_REG, reg);
    535 #endif
    536 	/*
    537 	 *  clear interrupt status
    538 	 */
    539 	reg = vrgiu_regread_4(sc, GIUINTSTAT_REG);
    540 	reg &= ~mask;
    541 	vrgiu_regwrite_4(sc, GIUINTSTAT_REG, reg);
    542 	/*
    543 	 *  enable interrupt
    544 	 */
    545 #ifdef WINCE_DEFAULT_SETTING
    546 #warning WINCE_DEFAULT_SETTING
    547 #else
    548 	sc->sc_intr_mask |= mask;
    549 	vrgiu_regwrite_4(sc, GIUINTEN_REG, sc->sc_intr_mask);
    550 	/* Unmask GIU level 2 mask register */
    551 	vrip_intr_setmask2(sc->sc_vc, sc->sc_ih, (1<<port), 1);
    552 #endif
    553 	splx(s);
    554 
    555 	DPRINTF(DEBUG_INTR, ("\n"));
    556 
    557 	return ih;
    558 }
    559 
    560 void
    561 vrgiu_intr_disestablish(ic, arg)
    562 	vrgiu_chipset_tag_t ic;
    563 	void *arg;
    564 {
    565 	struct vrgiu_intr_entry *ihe = arg;
    566 	struct vrgiu_softc *sc = (void*)ic;
    567 	int port = ihe->ih_port;
    568 	struct vrgiu_intr_entry *ih;
    569 	int s;
    570 
    571 	s = splhigh();
    572 	TAILQ_FOREACH(ih, &sc->sc_intr_head[port], ih_link) {
    573 		if (ih == ihe) {
    574 			TAILQ_REMOVE(&sc->sc_intr_head[port], ih, ih_link);
    575 			free(ih, M_DEVBUF);
    576 			if (TAILQ_EMPTY(&sc->sc_intr_head[port])) {
    577 				/* Disable interrupt */
    578 #ifdef WINCE_DEFAULT_SETTING
    579 #warning WINCE_DEFAULT_SETTING
    580 #else
    581 				sc->sc_intr_mask &= ~(1<<port);
    582 				vrgiu_regwrite_4(sc, GIUINTEN_REG, sc->sc_intr_mask);
    583 #endif
    584 			}
    585 			splx(s);
    586 			return;
    587 		}
    588 	}
    589 	panic("vrgiu_intr_disetablish: no such a handle.");
    590 	/* NOTREACHED */
    591 }
    592 
    593 int
    594 vrgiu_intr(arg)
    595 	void *arg;
    596 {
    597 #ifdef DUMP_GIU_LEVEL2_INTR
    598 #warning DUMP_GIU_LEVEL2_INTR
    599 	static u_int32_t oreg;
    600 #endif
    601 	struct vrgiu_softc *sc = arg;
    602 	int i;
    603 	u_int32_t reg;
    604 	int ledvalue = CONFIG_HOOK_LED_FLASH;
    605 
    606 	/* Get Level 2 interrupt status */
    607 	vrip_intr_get_status2 (sc->sc_vc, sc->sc_ih, &reg);
    608 #ifdef DUMP_GIU_LEVEL2_INTR
    609 #warning DUMP_GIU_LEVEL2_INTR
    610 	{
    611 		u_int32_t uedge, dedge, j;
    612 		for (j = 0x80000000; j > 0; j >>=1)
    613 			printf ("%c" , reg&j ? '|' : '.');
    614 		uedge = (reg ^ oreg) & reg;
    615 		dedge = (reg ^ oreg) & ~reg;
    616 		if (uedge || dedge) {
    617 			for (j = 0; j < 32; j++) {
    618 				if (uedge & (1 << j))
    619 					printf ("+%d", j);
    620 				else if (dedge & (1 << j))
    621 					printf ("-%d", j);
    622 			}
    623 		}
    624 		oreg = reg;
    625 		printf ("\n");
    626 	}
    627 #endif
    628 	/* Clear interrupt */
    629 	vrgiu_regwrite_4(sc, GIUINTSTAT_REG, vrgiu_regread_4(sc, GIUINTSTAT_REG));
    630 
    631 	/* Dispatch handler */
    632 	for (i = 0; i < MAX_GPIO_INOUT; i++) {
    633 		if (reg & (1 << i)) {
    634 			register struct vrgiu_intr_entry *ih;
    635 			TAILQ_FOREACH(ih, &sc->sc_intr_head[i], ih_link) {
    636 				ih->ih_fun(ih->ih_arg);
    637 			}
    638 		}
    639 	}
    640 
    641 	if (vrgiu_intr_led)
    642 		config_hook_call(CONFIG_HOOK_SET,
    643 				 CONFIG_HOOK_LED,
    644 				(void *)&ledvalue);
    645 	return 0;
    646 }
    647