1/*	$NetBSD: hil_intio.c,v 1.5 2024/01/16 05:48:28 thorpej Exp $	*/
2/*	$OpenBSD: hil_intio.c,v 1.8 2007/01/06 20:10:57 miod Exp $	*/
3
4/*
5 * Copyright (c) 2005, Miodrag Vallat.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31#include "wsdisplay.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/device.h>
36#include <sys/conf.h>
37#include <sys/bus.h>
38#include <sys/cpu.h>
39
40#include <machine/intr.h>
41
42#include <dev/cons.h>
43#if NWSDISPLAY > 0
44#include <dev/wscons/wsdisplayvar.h>
45#endif
46
47#include <hp300/dev/intiovar.h>
48
49#include <machine/hil_machdep.h>
50#include <dev/hil/hilvar.h>
51
52static int	hil_intio_match(device_t, cfdata_t, void *);
53static void	hil_intio_attach(device_t, device_t, void *);
54
55CFATTACH_DECL_NEW(hil_intio, sizeof(struct hil_softc),
56    hil_intio_match, hil_intio_attach, NULL, NULL);
57
58int
59hil_intio_match(device_t parent, cfdata_t cf, void *aux)
60{
61	struct intio_attach_args *ia = aux;
62	static int hil_matched = 0;
63
64	if (strcmp("hil", ia->ia_modname) != 0)
65		return 0;
66
67	/* Allow only one instance. */
68	if (hil_matched != 0)
69		return 0;
70
71	if (badaddr((void *)ia->ia_addr))	/* should not happen! */
72		return 0;
73
74	return 1;
75}
76
77int hil_is_console = -1;	/* undecided */
78
79void
80hil_intio_attach(device_t parent, device_t self, void *aux)
81{
82	struct hil_softc *sc = device_private(self);
83	struct intio_attach_args *ia = aux;
84
85	sc->sc_dev = self;
86	sc->sc_bst = ia->ia_bst;
87	if (bus_space_map(sc->sc_bst, ia->ia_iobase,
88	    HILMAPSIZE, 0, &sc->sc_bsh) != 0) {
89		aprint_error(": couldn't map hil controller\n");
90		return;
91	}
92
93	/*
94	 * Check that the configured console device is a wsdisplay.
95	 */
96#if NWSDISPLAY > 0
97	if (cn_tab->cn_putc != wsdisplay_cnputc)
98#endif
99	{
100		hil_is_console = 0;
101	}
102
103	hil_attach(sc, &hil_is_console);
104	intr_establish(hil_intr, sc, ia->ia_ipl, ISRPRI_TTY);
105
106	config_interrupts(self, hil_attach_deferred);
107}
108