xref: /openbsd/sys/arch/hppa/gsc/hil_gsc.c (revision f307151f)
1*f307151fSmiod /*	$OpenBSD: hil_gsc.c,v 1.2 2003/02/15 23:42:45 miod Exp $	*/
2e03ba6a3Smiod /*
3e03ba6a3Smiod  * Copyright (c) 2003, Miodrag Vallat.
4e03ba6a3Smiod  * All rights reserved.
5e03ba6a3Smiod  *
6e03ba6a3Smiod  * Redistribution and use in source and binary forms, with or without
7e03ba6a3Smiod  * modification, are permitted provided that the following conditions
8e03ba6a3Smiod  * are met:
9e03ba6a3Smiod  * 1. Redistributions of source code must retain the above copyright
10e03ba6a3Smiod  *    notice, this list of conditions and the following disclaimer.
11e03ba6a3Smiod  * 2. Redistributions in binary form must reproduce the above copyright
12e03ba6a3Smiod  *    notice, this list of conditions and the following disclaimer in the
13e03ba6a3Smiod  *    documentation and/or other materials provided with the distribution.
14e03ba6a3Smiod  *
15e03ba6a3Smiod  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16e03ba6a3Smiod  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17e03ba6a3Smiod  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18e03ba6a3Smiod  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19e03ba6a3Smiod  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20e03ba6a3Smiod  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21e03ba6a3Smiod  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22e03ba6a3Smiod  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23e03ba6a3Smiod  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24e03ba6a3Smiod  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25e03ba6a3Smiod  * POSSIBILITY OF SUCH DAMAGE.
26e03ba6a3Smiod  *
27e03ba6a3Smiod  */
28e03ba6a3Smiod 
29e03ba6a3Smiod #include <sys/param.h>
30e03ba6a3Smiod #include <sys/systm.h>
31e03ba6a3Smiod #include <sys/device.h>
32e03ba6a3Smiod 
33e03ba6a3Smiod #include <machine/cpu.h>
34e03ba6a3Smiod #include <machine/intr.h>
35e03ba6a3Smiod #include <machine/iomod.h>
36e03ba6a3Smiod #include <machine/autoconf.h>
37e03ba6a3Smiod #include <machine/bus.h>
38e03ba6a3Smiod 
39e03ba6a3Smiod #include <hppa/dev/cpudevs.h>
40e03ba6a3Smiod #include <hppa/gsc/gscbusvar.h>
41e03ba6a3Smiod 
42e03ba6a3Smiod #include <machine/hil_machdep.h>
43e03ba6a3Smiod 
44e03ba6a3Smiod #include <dev/hil/hilvar.h>
45e03ba6a3Smiod 
46e03ba6a3Smiod int	hil_gsc_match(struct device *, void *, void *);
47e03ba6a3Smiod void	hil_gsc_attach(struct device *, struct device *, void *);
48e03ba6a3Smiod 
49e03ba6a3Smiod struct cfattach hil_gsc_ca = {
50e03ba6a3Smiod 	sizeof(struct hil_softc), hil_gsc_match, hil_gsc_attach
51e03ba6a3Smiod };
52e03ba6a3Smiod 
53e03ba6a3Smiod int
54e03ba6a3Smiod hil_gsc_match(struct device *parent, void *match, void *aux)
55e03ba6a3Smiod {
56e03ba6a3Smiod 	struct gsc_attach_args *ga = aux;
57e03ba6a3Smiod 
58e03ba6a3Smiod 	if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
59e03ba6a3Smiod 	    ga->ga_type.iodc_sv_model != HPPA_FIO_HIL)
60e03ba6a3Smiod 		return (0);
61e03ba6a3Smiod 
62e03ba6a3Smiod 	return (1);
63e03ba6a3Smiod }
64e03ba6a3Smiod 
65e03ba6a3Smiod void
66e03ba6a3Smiod hil_gsc_attach(struct device *parent, struct device *self, void *aux)
67e03ba6a3Smiod {
68e03ba6a3Smiod 	struct hil_softc *sc = (void *)self;
69e03ba6a3Smiod 	struct gsc_attach_args *ga = aux;
70*f307151fSmiod 	int hil_is_console;
71e03ba6a3Smiod 
72e03ba6a3Smiod 	sc->sc_bst = ga->ga_iot;
73e03ba6a3Smiod 	if (bus_space_map(ga->ga_iot, ga->ga_hpa,
74e03ba6a3Smiod 	    HILMAPSIZE, 0, &sc->sc_bsh)) {
75e03ba6a3Smiod 		printf(": couldn't map hil controller\n");
76e03ba6a3Smiod 		return;
77e03ba6a3Smiod 	}
78e03ba6a3Smiod 
79*f307151fSmiod 	hil_is_console = ga->ga_dp.dp_mod == PAGE0->mem_kbd.pz_dp.dp_mod &&
80*f307151fSmiod 	    bcmp(ga->ga_dp.dp_bc, PAGE0->mem_kbd.pz_dp.dp_bc, 6) == 0;
81*f307151fSmiod 
82*f307151fSmiod 	hil_attach(sc, hil_is_console);
83e03ba6a3Smiod 
84e03ba6a3Smiod 	gsc_intr_establish((struct gsc_softc *)parent, IPL_TTY,
85e03ba6a3Smiod 	    ga->ga_irq, hil_intr, sc, &sc->sc_dev);
86e03ba6a3Smiod 
87e03ba6a3Smiod 	startuphook_establish(hil_attach_deferred, sc);
88e03ba6a3Smiod }
89