xref: /netbsd/sys/arch/hpcmips/vr/vrc4173bcu.c (revision bf9ec67e)
1 /*	$NetBSD: vrc4173bcu.c,v 1.8 2002/03/10 10:13:32 takemura Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001,2002 Enami Tsugutomo.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
32 
33 #include <machine/bus.h>
34 
35 #include <dev/pci/pcivar.h>
36 #include <dev/pci/pcidevs.h>
37 
38 #include <machine/platid.h>
39 #include <machine/platid_mask.h>
40 #include <machine/config_hook.h>
41 
42 #include <hpcmips/vr/vripunit.h>
43 #include <hpcmips/vr/vripif.h>
44 #include <hpcmips/vr/vrc4173bcuvar.h>
45 #include <hpcmips/vr/vrc4173icureg.h>
46 #include <hpcmips/vr/vrc4173cmureg.h>
47 
48 #ifdef VRC4173BCU_DEBUG
49 #define DPRINTF_ENABLE
50 #define DPRINTF_DEBUG	vrc4173bcu_debug
51 #endif
52 #define USE_HPC_DPRINTF
53 #include <machine/debug.h>
54 
55 #define	VRC4173BCU_BADR		0x10
56 #define USE_WINCE_CLKMASK	(~0)
57 
58 static int	vrc4173bcu_match(struct device *, struct cfdata *, void *);
59 static void	vrc4173bcu_attach(struct device *, struct device *, void *);
60 static int	vrc4173bcu_intr(void *);
61 static int	vrc4173bcu_print(void *, const char *);
62 static int	vrc4173bcu_search(struct device *, struct cfdata *cf, void *);
63 static int	vrc4173bcu_pci_intr(void *);
64 #ifdef VRC4173BCU_DEBUG
65 static void	vrc4173bcu_dump_level2mask(vrip_chipset_tag_t,
66 		    vrip_intr_handle_t);
67 #endif
68 
69 int __vrc4173bcu_power(vrip_chipset_tag_t, int, int);
70 vrip_intr_handle_t __vrc4173bcu_intr_establish(vrip_chipset_tag_t, int, int,
71     int, int(*)(void*), void*);
72 void __vrc4173bcu_intr_disestablish(vrip_chipset_tag_t, vrip_intr_handle_t);
73 void __vrc4173bcu_intr_setmask1(vrip_chipset_tag_t, vrip_intr_handle_t, int);
74 void __vrc4173bcu_intr_setmask2(vrip_chipset_tag_t, vrip_intr_handle_t,
75     u_int32_t, int);
76 void __vrc4173bcu_intr_getstatus2(vrip_chipset_tag_t, vrip_intr_handle_t,
77     u_int32_t*);
78 void __vrc4173bcu_register_cmu(vrip_chipset_tag_t, vrcmu_chipset_tag_t);
79 void __vrc4173bcu_register_gpio(vrip_chipset_tag_t, hpcio_chip_t);
80 void __vrc4173bcu_register_dmaau(vrip_chipset_tag_t, vrdmaau_chipset_tag_t);
81 void __vrc4173bcu_register_dcu(vrip_chipset_tag_t, vrdcu_chipset_tag_t);
82 int __vrc4173bcu_clock(vrcmu_chipset_tag_t, u_int16_t, int);
83 
84 /*
85  * machine dependent info
86  */
87 static struct vrc4173bcu_platdep {
88 	platid_mask_t *platidmask;
89 	u_int32_t clkmask;
90 	int intrmask;
91 } platdep_table[] = {
92 	{
93 		&platid_mask_MACH_VICTOR_INTERLINK_MPC303,
94 		USE_WINCE_CLKMASK,		/* clock mask */
95 		(1 << VRC4173ICU_USBINTR)|	/* intrrupts */
96 		(1 << VRC4173ICU_PCMCIA1INTR)|
97 		(1 << VRC4173ICU_PCMCIA2INTR),
98 	},
99 	{
100 		&platid_mask_MACH_VICTOR_INTERLINK_MPC304,
101 		USE_WINCE_CLKMASK,		/* clock mask */
102 		(1 << VRC4173ICU_USBINTR)|	/* intrrupts */
103 		(1 << VRC4173ICU_PCMCIA1INTR)|
104 		(1 << VRC4173ICU_PCMCIA2INTR),
105 	},
106 	{
107 		&platid_mask_MACH_NEC_MCR_SIGMARION2,
108 		USE_WINCE_CLKMASK,		/* clock mask */
109 		(1 << VRC4173ICU_USBINTR),	/* intrrupts */
110 	},
111 	{
112 		&platid_wild,
113 		USE_WINCE_CLKMASK,	/* XXX */
114 		-1,
115 	},
116 };
117 
118 struct vrc4173bcu_unit {
119 	char	*vu_name;
120 	int	vu_intr[2];
121 	int	vu_clkmask;
122 	bus_addr_t	vu_lreg;
123 	bus_addr_t	vu_mlreg;
124 	bus_addr_t	vu_hreg;
125 	bus_addr_t	vu_mhreg;
126 };
127 
128 struct vrc4173bcu_softc {
129 	struct device sc_dev;
130 	struct vrip_chipset_tag sc_chipset;
131 	struct vrcmu_chipset_tag sc_cmuchip;
132 
133 	pci_chipset_tag_t sc_pc;
134 	bus_space_tag_t sc_iot;
135 	bus_space_handle_t sc_ioh;
136 	bus_size_t sc_size;
137 
138 	bus_space_handle_t sc_icuh;	/* I/O handle for ICU. */
139 	bus_space_handle_t sc_cmuh;	/* I/O handle for CMU. */
140 	void *sc_ih;
141 #define VRC4173BCU_NINTRS	16
142 	int sc_intrmask;
143 	struct vrc4173bcu_intrhand {
144 		int	(*ih_fun)(void *);
145 		void	*ih_arg;
146 		const struct vrc4173bcu_unit *ih_unit;
147 	} sc_intrhands[32];
148 
149 	struct vrc4173bcu_unit *sc_units;
150 	int sc_nunits;
151 	int sc_pri;
152 
153 	struct vrc4173bcu_platdep *sc_platdep;
154 };
155 
156 #define VALID_UNIT(sc, unit)	(0 <= (unit) && (unit) < (sc)->sc_nunits)
157 
158 static struct vrc4173bcu_unit vrc4173bcu_units[] = {
159 	[VRIP_UNIT_KIU] = {
160 		"kiu",
161 		{ VRC4173ICU_KIUINTR,	},
162 		VRC4173CMU_CLKMSK_KIU,
163 		VRC4173ICU_KIUINT,	VRC4173ICU_MKIUINT,
164 	},
165 	[VRIP_UNIT_PIU] = {
166 		"piu",
167 		{ VRC4173ICU_PIUINTR, VRC4173ICU_DOZEPIUINTR},
168 		VRC4173CMU_CLKMSK_PIU,
169 		VRC4173ICU_PIUINT,	VRC4173ICU_MPIUINT,
170 	},
171 	[VRIP_UNIT_AIU] = {
172 		"aiu",
173 		{ VRC4173ICU_AIUINTR,	},
174 		VRC4173CMU_CLKMSK_AIU,
175 		VRC4173ICU_AIUINT,	VRC4173ICU_MAIUINT,
176 	},
177 	[VRIP_UNIT_GIU] = {
178 		"giu",
179 		{ VRC4173ICU_GIUINTR,	},
180 		0,
181 		VRC4173ICU_GIULINT,	VRC4173ICU_MGIULINT,
182 		VRC4173ICU_GIUHINT,	VRC4173ICU_MGIUHINT,
183 	},
184 	[VRIP_UNIT_PS2U0] = {
185 		"PS/2-Ch1",
186 		{ VRC4173ICU_PS2CH1INTR,	},
187 		VRC4173CMU_CLKMSK_PS2CH1,
188 	},
189 	[VRIP_UNIT_PS2U1] = {
190 		"PS/2-Ch2",
191 		{ VRC4173ICU_PS2CH2INTR,	},
192 		VRC4173CMU_CLKMSK_PS2CH2,
193 	},
194 	[VRIP_UNIT_USBU] = {
195 		"usbu",
196 		{ VRC4173ICU_USBINTR,	},
197 		VRC4173CMU_CLKMSK_USB,
198 	},
199 	[VRIP_UNIT_CARDU0] = {
200 		"cardu0",
201 		{ VRC4173ICU_PCMCIA1INTR,	},
202 		VRC4173CMU_CLKMSK_CARD1,
203 	},
204 	[VRIP_UNIT_CARDU1] = {
205 		"cardu1",
206 		{ VRC4173ICU_PCMCIA2INTR,	},
207 		VRC4173CMU_CLKMSK_CARD2,
208 	},
209 };
210 
211 struct cfattach vrc4173bcu_ca = {
212 	sizeof(struct vrc4173bcu_softc), vrc4173bcu_match, vrc4173bcu_attach,
213 };
214 
215 static const struct vrip_chipset_tag vrc4173bcu_chipset_methods = {
216 	.vc_power		= __vrc4173bcu_power,
217 	.vc_intr_establish	= __vrc4173bcu_intr_establish,
218 	.vc_intr_disestablish	= __vrc4173bcu_intr_disestablish,
219 	.vc_intr_setmask1	= __vrc4173bcu_intr_setmask1,
220 	.vc_intr_setmask2	= __vrc4173bcu_intr_setmask2,
221 	.vc_intr_getstatus2	= __vrc4173bcu_intr_getstatus2,
222 	.vc_register_cmu	= __vrc4173bcu_register_cmu,
223 	.vc_register_gpio	= __vrc4173bcu_register_gpio,
224 	.vc_register_dmaau	= __vrc4173bcu_register_dmaau,
225 	.vc_register_dcu	= __vrc4173bcu_register_dcu,
226 };
227 
228 int
229 vrc4173bcu_match(struct device *parent, struct cfdata *match, void *aux)
230 {
231 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
232 
233 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NEC &&
234 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NEC_VRC4173_BCU)
235 		return (1);
236 
237 	return (0);
238 }
239 
240 void
241 vrc4173bcu_attach(struct device *parent, struct device *self, void *aux)
242 {
243 	struct vrc4173bcu_softc *sc = (struct vrc4173bcu_softc *)self;
244 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
245 	pci_chipset_tag_t pc = pa->pa_pc;
246 	pcitag_t tag = pa->pa_tag;
247 	pcireg_t csr;
248 	char devinfo[256];
249 	u_int16_t reg;
250 	pci_intr_handle_t ih;
251 	const char *intrstr;
252 	int bus, device, function;
253 #ifdef DEBUG
254 	char buf[80];
255 #endif
256 
257 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
258 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
259 
260 #if 0
261 	printf("%s: ", sc->sc_dev.dv_xname);
262 	pci_conf_print(pa->pa_pc, pa->pa_tag, NULL);
263 #endif
264 
265 	sc->sc_pc = pc;
266 	sc->sc_cmuchip.cc_sc = sc;
267 	sc->sc_cmuchip.cc_clock = __vrc4173bcu_clock;
268 	sc->sc_units = vrc4173bcu_units;
269 	sc->sc_nunits = sizeof(vrc4173bcu_units)/sizeof(struct vrc4173bcu_unit);
270 	sc->sc_chipset = vrc4173bcu_chipset_methods; /* structure assignment */
271 	sc->sc_chipset.vc_sc = sc;
272 
273 	sc->sc_platdep = platid_search(&platid, platdep_table,
274 	    sizeof(platdep_table)/sizeof(*platdep_table),
275 	    sizeof(*platdep_table));
276 
277 	/* Map I/O registers */
278 	if (pci_mapreg_map(pa, VRC4173BCU_BADR, PCI_MAPREG_TYPE_IO, 0,
279 	    &sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_size)) {
280 		printf("%s: can't map mem space\n", sc->sc_dev.dv_xname);
281 		return;
282 	}
283 
284 	/* Enable the device. */
285 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
286 	DPRINTF(("%s: csr = 0x%08x", sc->sc_dev.dv_xname, csr));
287 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG,
288 	    csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
289 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
290 	DPRINTF((" -> 0x%08x\n", csr));
291 
292 	csr = pci_conf_read(pc, tag, VRC4173BCU_BADR);
293 	DPRINTF(("%s: base addr = %x@0x%08x\n", sc->sc_dev.dv_xname,
294 	    (int)sc->sc_size, csr));
295 	DPRINTF(("%s: iot = 0x%08x, ioh = 0x%08x\n", sc->sc_dev.dv_xname,
296 	    (int)sc->sc_iot, (int)sc->sc_ioh));
297 
298 	/*
299 	 * Map I/O space for ICU.
300 	 */
301 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
302 	    VRC4173ICU_IOBASE, VRC4173ICU_IOSIZE, &sc->sc_icuh)) {
303 		printf(": can't map ICU i/o space\n");
304 		return;
305 	}
306 
307 	/*
308 	 * Map I/O space for CMU.
309 	 */
310 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
311 	    VRC4173CMU_IOBASE, VRC4173CMU_IOSIZE, &sc->sc_cmuh)) {
312 		printf(": can't map CMU i/o space\n");
313 		return;
314 	}
315 
316 	/* machine dependent setup */
317 	if (sc->sc_platdep->clkmask == USE_WINCE_CLKMASK) {
318 		/* XXX, You can nothing! */
319 		reg = bus_space_read_2(sc->sc_iot, sc->sc_cmuh,
320 		    VRC4173CMU_CLKMSK);
321 		printf("%s: default clock mask is %04x\n",
322 		    sc->sc_dev.dv_xname, reg);
323 	} else {
324 		/* assert all reset bits */
325 		bus_space_write_2(sc->sc_iot, sc->sc_cmuh, VRC4173CMU_SRST,
326 		    VRC4173CMU_SRST_AC97 | VRC4173CMU_SRST_USB |
327 		    VRC4173CMU_SRST_CARD2 | VRC4173CMU_SRST_CARD1);
328 		/* set clock mask */
329 		bus_space_write_2(sc->sc_iot, sc->sc_cmuh,
330 		    VRC4173CMU_CLKMSK, sc->sc_platdep->clkmask);
331 		/* clear reset bit */
332 		bus_space_write_2(sc->sc_iot, sc->sc_cmuh, VRC4173CMU_SRST, 0);
333 	}
334 
335 #ifdef DEBUG
336 	reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_SYSINT1);
337 	bitmask_snprintf(reg,
338 	    "\20\1USB\2PCMCIA2\3PCMCIA1\4PS2CH2\5PS2CH1\6PIU\7AIU\10KIU"
339 	    "\11GIU\12AC97\13AC97-1\14B11\15B12\16DOZEPIU\17B14\20B15",
340 	    buf, sizeof(buf));
341 	printf("%s: SYSINT1 = 0x%s\n", sc->sc_dev.dv_xname, buf);
342 
343 	reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_MKIUINT);
344 	bitmask_snprintf(reg,
345 	    "\20\1SCANINT\2KDATRDY\3KDATLOST\4B3\5B4\6B5\7B6\10B7"
346 	    "\11B8\12B9\13B10\14B11\15B12\16B13\17B14\20B15",
347 	    buf, sizeof(buf));
348 	printf("%s: MKIUINT = 0x%s\n", sc->sc_dev.dv_xname, buf);
349 
350 	reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_MSYSINT1);
351 	bitmask_snprintf(reg,
352 	    "\20\1USB\2PCMCIA2\3PCMCIA1\4PS2CH2\5PS2CH1\6PIU\7AIU\10KIU"
353 	    "\11GIU\12AC97\13AC97-1\14B11\15B12\16DOZEPIU\17B14\20B15",
354 	    buf, sizeof(buf));
355 	printf("%s: MSYSINT1 = 0x%s\n", sc->sc_dev.dv_xname, buf);
356 
357 #if 1
358 	reg = VRC4173ICU_USBINTR | VRC4173ICU_PIUINTR | VRC4173ICU_KIUINTR |
359 	    VRC4173ICU_DOZEPIUINTR;
360 	bus_space_write_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_MSYSINT1, reg);
361 
362 	reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_MSYSINT1);
363 	bitmask_snprintf(reg,
364 	    "\20\1USB\2PCMCIA2\3PCMCIA1\4PS2CH2\5PS2CH1\6PIU\7AIU\10KIU"
365 	    "\11GIU\12AC97\13AC97-1\14B11\15B12\16DOZEPIU\17B14\20B15",
366 	    buf, sizeof(buf));
367 	printf("%s: MSYSINT1 = 0x%s\n", sc->sc_dev.dv_xname, buf);
368 #endif
369 #endif
370 
371 	/*
372 	 * set interrupt mask
373 	 */
374 	sc->sc_intrmask = sc->sc_platdep->intrmask;
375 	bus_space_write_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_MSYSINT1,
376 	    sc->sc_intrmask);
377 
378 	/*
379 	 * install interrupt handler
380 	 */
381 	if (pci_intr_map(pa, &ih)) {
382 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
383 		return;
384 	}
385 	intrstr = pci_intr_string(pc, ih);
386 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, vrc4173bcu_intr, sc);
387 	if (sc->sc_ih == NULL) {
388 		printf("%s: couldn't establish interrupt",
389 		    sc->sc_dev.dv_xname);
390 		if (intrstr != NULL)
391 			printf(" at %s", intrstr);
392 		printf("\n");
393 		return;
394 	}
395 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
396 
397 	/*
398 	 * install pci intr hooks
399 	 */
400 	pci_decompose_tag(pc, pa->pa_intrtag, &bus, &device, &function);
401 	/* USB unit */
402 	if (sc->sc_intrmask & (1 << VRC4173ICU_USBINTR))
403 		vrip_intr_establish(&sc->sc_chipset, VRIP_UNIT_USBU, 0,
404 		    IPL_NET, vrc4173bcu_pci_intr,
405 		    config_connect(CONFIG_HOOK_PCIINTR,
406 			CONFIG_HOOK_PCIINTR_ID(bus, device, 2)));
407 	/* PC card unit 1 */
408 	if (sc->sc_intrmask & (1 << VRC4173ICU_PCMCIA1INTR))
409 		vrip_intr_establish(&sc->sc_chipset, VRIP_UNIT_CARDU0, 0,
410 		    IPL_NET, vrc4173bcu_pci_intr,
411 		    config_connect(CONFIG_HOOK_PCIINTR,
412 			CONFIG_HOOK_PCIINTR_ID(bus, 1, 0)));
413 	/* PC card unit 2 */
414 	if (sc->sc_intrmask & (1 << VRC4173ICU_PCMCIA2INTR))
415 		vrip_intr_establish(&sc->sc_chipset, VRIP_UNIT_CARDU1, 0,
416 		    IPL_NET, vrc4173bcu_pci_intr,
417 		    config_connect(CONFIG_HOOK_PCIINTR,
418 			CONFIG_HOOK_PCIINTR_ID(bus, 2, 0)));
419 
420 	/*
421 	 *  Attach each devices
422 	 *  sc->sc_pri = 2~1
423 	 */
424 	for (sc->sc_pri = 2; 0 < sc->sc_pri; sc->sc_pri--)
425 		config_search(vrc4173bcu_search, self, vrc4173bcu_print);
426 }
427 
428 int
429 vrc4173bcu_print(void *aux, const char *hoge)
430 {
431 	struct vrip_attach_args *va = (struct vrip_attach_args*)aux;
432 
433 	if (va->va_addr != VRIPIFCF_ADDR_DEFAULT)
434 		printf(" addr 0x%04lx", va->va_addr);
435 	if (va->va_size != VRIPIFCF_SIZE_DEFAULT)
436 		printf("-%04lx", (va->va_addr + va->va_size - 1) & 0xffff);
437 	if (va->va_addr2 != VRIPIFCF_ADDR2_DEFAULT)
438 		printf(", 0x%04lx", va->va_addr2);
439 	if (va->va_size2 != VRIPIFCF_SIZE2_DEFAULT)
440 		printf("-%04lx", (va->va_addr2 + va->va_size2 - 1) & 0xffff);
441 
442 	return (UNCONF);
443 }
444 
445 int
446 vrc4173bcu_search(struct device *parent, struct cfdata *cf, void *aux)
447 {
448 	struct vrc4173bcu_softc *sc = (struct vrc4173bcu_softc *)parent;
449 	struct vrip_attach_args va;
450 
451 	memset(&va, 0, sizeof(va));
452 	va.va_vc = &sc->sc_chipset;
453 	va.va_iot = sc->sc_iot;
454 	va.va_parent_ioh = sc->sc_ioh;
455 	va.va_unit = cf->cf_loc[VRIPIFCF_UNIT];
456 	va.va_addr = cf->cf_loc[VRIPIFCF_ADDR];
457 	va.va_size = cf->cf_loc[VRIPIFCF_SIZE];
458 	va.va_addr2 = cf->cf_loc[VRIPIFCF_ADDR2];
459 	va.va_size2 = cf->cf_loc[VRIPIFCF_SIZE2];
460 	va.va_gpio_chips = NULL;	/* XXX */
461 	va.va_cc = sc->sc_chipset.vc_cc;
462 	va.va_ac = sc->sc_chipset.vc_ac;
463 	va.va_dc = sc->sc_chipset.vc_dc;
464 	if (((*cf->cf_attach->ca_match)(parent, cf, &va) == sc->sc_pri))
465 		config_attach(parent, cf, &va, vrc4173bcu_print);
466 
467 	return (0);
468 }
469 
470 int
471 vrc4173bcu_intr(void *arg)
472 {
473 	struct vrc4173bcu_softc *sc = (struct vrc4173bcu_softc *)arg;
474 	u_int16_t reg;
475 	struct vrc4173bcu_intrhand *ih;
476 	int i;
477 
478 	reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, VRC4173ICU_SYSINT1);
479 	reg &= sc->sc_intrmask;
480 	if (reg == 0)
481 		return (0);
482 
483 #if 0
484     {
485 	char buf[80];
486 	bitmask_snprintf(reg,
487 	    "\20\1USB\2PCMCIA2\3PCMCIA1\4PS2CH2\5PS2CH1\6PIU\7AIU\10KIU"
488 	    "\11GIU\12AC97\13AC97-1\14B11\15B12\16DOZEPIU\17B14\20B15",
489 	    buf, sizeof(buf));
490 	printf("%s: %s\n", sc->sc_dev.dv_xname, buf);
491     }
492 #endif
493 	for (ih = sc->sc_intrhands, i = 0; i < VRC4173BCU_NINTRS; i++, ih++)
494 		if ((reg & (1 << i)) && ih->ih_fun != NULL)
495 			ih->ih_fun(ih->ih_arg);
496 
497 	return (1);
498 }
499 
500 static int
501 vrc4173bcu_pci_intr(void *arg)
502 {
503 	config_call_tag ct = (config_call_tag)arg;
504 	config_connected_call(ct, NULL);
505 
506 	return (0);
507 }
508 
509 #ifdef VRC4173BCU_DEBUG
510 static void
511 vrc4173bcu_dump_level2mask(vrip_chipset_tag_t vc, vrip_intr_handle_t handle)
512 {
513 	struct vrc4173bcu_softc *sc = vc->vc_sc;
514 	struct vrc4173bcu_intrhand *ih = handle;
515 	const struct vrc4173bcu_unit *vu = ih->ih_unit;
516 	u_int32_t reg;
517 
518 	if (vu->vu_mlreg) {
519 		DPRINTF(("level1[%d] level2 mask:", vu->vu_intr[0]));
520 		reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, vu->vu_mlreg);
521 		if (vu->vu_mhreg) {
522 			reg |= (bus_space_read_2(sc->sc_iot, sc->sc_icuh,
523 			    vu->vu_mhreg) << 16);
524 			dbg_bit_print(reg);
525 		} else
526 			dbg_bit_print(reg);
527 	}
528 }
529 #endif
530 
531 int
532 __vrc4173bcu_power(vrip_chipset_tag_t vc, int unit, int onoff)
533 {
534 	struct vrc4173bcu_softc *sc = vc->vc_sc;
535 	const struct vrc4173bcu_unit *vu;
536 
537 	if (sc->sc_chipset.vc_cc == NULL)
538 		return (0);	/* You have no clock mask unit yet. */
539 	if (!VALID_UNIT(sc, unit))
540 		return (0);
541 	vu = &sc->sc_units[unit];
542 
543 	return (*sc->sc_chipset.vc_cc->cc_clock)(sc->sc_chipset.vc_cc,
544 	    vu->vu_clkmask, onoff);
545 }
546 
547 vrip_intr_handle_t
548 __vrc4173bcu_intr_establish(vrip_chipset_tag_t vc, int unit, int line,
549     int level, int (*ih_fun)(void *), void *ih_arg)
550 {
551 	struct vrc4173bcu_softc *sc = vc->vc_sc;
552 	const struct vrc4173bcu_unit *vu;
553 	struct vrc4173bcu_intrhand *ih;
554 
555 	if (!VALID_UNIT(sc, unit))
556 		return (NULL);
557 	vu = &sc->sc_units[unit];
558 	ih = &sc->sc_intrhands[vu->vu_intr[line]];
559 	if (ih->ih_fun) /* Can't share level 1 interrupt */
560 		return (NULL);
561 	ih->ih_fun = ih_fun;
562 	ih->ih_arg = ih_arg;
563 	ih->ih_unit = vu;
564 
565 	/* Mask level 2 interrupt mask register. (disable interrupt) */
566 	vrip_intr_setmask2(vc, ih, ~0, 0);
567 	/* Unmask  Level 1 interrupt mask register (enable interrupt) */
568 	vrip_intr_setmask1(vc, ih, 1);
569 
570 	return ((void *)ih);
571 }
572 
573 void
574 __vrc4173bcu_intr_disestablish(vrip_chipset_tag_t vc, vrip_intr_handle_t handle)
575 {
576 	struct vrc4173bcu_intrhand *ih = handle;
577 
578 	/* Mask  Level 1 interrupt mask register (disable interrupt) */
579 	vrip_intr_setmask1(vc, ih, 0);
580 	/* Mask level 2 interrupt mask register(if any). (disable interrupt) */
581 	vrip_intr_setmask2(vc, ih, ~0, 0);
582 	ih->ih_fun = NULL;
583 	ih->ih_arg = NULL;
584 }
585 
586 /* Set level 1 interrupt mask. */
587 void
588 __vrc4173bcu_intr_setmask1(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
589     int enable)
590 {
591 	struct vrc4173bcu_softc *sc = vc->vc_sc;
592 	struct vrc4173bcu_intrhand *ih = handle;
593 	int level1 = ih - sc->sc_intrhands;
594 
595 	DPRINTF(("__vrc4173bcu_intr_setmask1: SYSINT: %s %d\n",
596 		 enable ? "enable" : "disable", level1));
597 	if (enable)
598 		sc->sc_intrmask |= (1 << level1);
599 	else
600 		sc->sc_intrmask &= ~(1 << level1);
601 	bus_space_write_2 (sc->sc_iot, sc->sc_icuh, VRC4173ICU_MSYSINT1,
602 	    sc->sc_intrmask);
603 #ifdef VRC4173BCU_DEBUG
604 	if (vrc4173bcu_debug)
605 		dbg_bit_print(sc->sc_intrmask);
606 #endif
607 
608 	return;
609 }
610 
611 /* Get level 2 interrupt status */
612 void
613 __vrc4173bcu_intr_getstatus2(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
614     u_int32_t *status /* Level 2 status */)
615 {
616 	struct vrc4173bcu_softc *sc = vc->vc_sc;
617 	struct vrc4173bcu_intrhand *ih = handle;
618 	const struct vrc4173bcu_unit *vu = ih->ih_unit;
619 	u_int32_t reg;
620 
621 	reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, vu->vu_lreg);
622 	reg |= (bus_space_read_2(sc->sc_iot, sc->sc_icuh,  vu->vu_hreg) << 16);
623 	*status = reg;
624 }
625 
626 /* Set level 2 interrupt mask. */
627 void
628 __vrc4173bcu_intr_setmask2(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
629     u_int32_t mask /* Level 2 mask */, int onoff)
630 {
631 	struct vrc4173bcu_softc *sc = vc->vc_sc;
632 	struct vrc4173bcu_intrhand *ih = handle;
633 	const struct vrc4173bcu_unit *vu = ih->ih_unit;
634 	u_int16_t reg;
635 
636 	DPRINTF(("vrc4173bcu_intr_setmask2:\n"));
637 #ifdef VRC4173BCU_DEBUG
638 	if (vrc4173bcu_debug)
639 		vrc4173bcu_dump_level2mask(vc, handle);
640 #endif
641 	if (vu->vu_mlreg) {
642 		reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, vu->vu_mlreg);
643 		if (onoff)
644 			reg |= (mask & 0xffff);
645 		else
646 			reg &= ~(mask & 0xffff);
647 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg, reg);
648 	}
649 	if (vu->vu_mhreg) {
650 		reg = bus_space_read_2(sc->sc_iot, sc->sc_icuh, vu->vu_mhreg);
651 		if (onoff)
652 			reg |= ((mask >> 16) & 0xffff);
653 		else
654 			reg &= ~((mask >> 16) & 0xffff);
655 		bus_space_write_2(sc->sc_iot, sc->sc_icuh, vu->vu_mhreg, reg);
656 	}
657 #ifdef VRC4173BCU_DEBUG
658 	if (vrc4173bcu_debug)
659 		vrc4173bcu_dump_level2mask(vc, handle);
660 #endif
661 
662 	return;
663 }
664 
665 int
666 __vrc4173bcu_clock(vrcmu_chipset_tag_t cc, u_int16_t mask, int onoff)
667 {
668 	struct vrc4173bcu_softc *sc = cc->cc_sc;
669 	u_int16_t reg;
670 
671 	reg = bus_space_read_2(sc->sc_iot, sc->sc_cmuh, VRC4173CMU_CLKMSK);
672 #if 0
673 	printf("cmu register(enter):");
674 	dbg_bit_print(reg);
675 #endif
676 	if (onoff)
677 		reg |= mask;
678 	else
679 		reg &= ~mask;
680 	bus_space_write_2(sc->sc_iot, sc->sc_cmuh, VRC4173CMU_CLKMSK, reg);
681 #if 0
682 	printf("cmu register(exit) :");
683 	dbg_bit_print(reg);
684 #endif
685 	return (0);
686 }
687 
688 void
689 __vrc4173bcu_register_cmu(vrip_chipset_tag_t vc, vrcmu_chipset_tag_t cmu)
690 {
691 	vc->vc_cc = cmu;
692 }
693 
694 void
695 __vrc4173bcu_register_gpio(vrip_chipset_tag_t vc, hpcio_chip_t chip)
696 {
697 	/* XXX, not implemented yet */
698 }
699 
700 void
701 __vrc4173bcu_register_dmaau(vrip_chipset_tag_t vc, vrdmaau_chipset_tag_t dmaau)
702 {
703 
704 	vc->vc_ac = dmaau;
705 }
706 
707 void
708 __vrc4173bcu_register_dcu(vrip_chipset_tag_t vc, vrdcu_chipset_tag_t dcu)
709 {
710 
711 	vc->vc_dc = dcu;
712 }
713