xref: /openbsd-src/sys/arch/hppa/gsc/mongoose_gsc.c (revision 78d5ff0ec949396ff3bbc97f51b741a17179ba18)
1*78d5ff0eSmpi /*	$OpenBSD: mongoose_gsc.c,v 1.2 2022/03/13 08:04:38 mpi Exp $	*/
2da7236ebSmiod 
3da7236ebSmiod /*
4da7236ebSmiod  * Copyright (c) 2004, Miodrag Vallat.
5da7236ebSmiod  *
6da7236ebSmiod  * Redistribution and use in source and binary forms, with or without
7da7236ebSmiod  * modification, are permitted provided that the following conditions
8da7236ebSmiod  * are met:
9da7236ebSmiod  * 1. Redistributions of source code must retain the above copyright
10da7236ebSmiod  *    notice, this list of conditions and the following disclaimer.
11da7236ebSmiod  * 2. Redistributions in binary form must reproduce the above copyright
12da7236ebSmiod  *    notice, this list of conditions and the following disclaimer in the
13da7236ebSmiod  *    documentation and/or other materials provided with the distribution.
14da7236ebSmiod  *
15da7236ebSmiod  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16da7236ebSmiod  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17da7236ebSmiod  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18da7236ebSmiod  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19da7236ebSmiod  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20da7236ebSmiod  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21da7236ebSmiod  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22da7236ebSmiod  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23da7236ebSmiod  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24da7236ebSmiod  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25da7236ebSmiod  * POSSIBILITY OF SUCH DAMAGE.
26da7236ebSmiod  */
27da7236ebSmiod 
28da7236ebSmiod #include <sys/param.h>
29da7236ebSmiod #include <sys/systm.h>
30da7236ebSmiod #include <sys/device.h>
31da7236ebSmiod 
32da7236ebSmiod #include <machine/bus.h>
33da7236ebSmiod #include <machine/autoconf.h>
34da7236ebSmiod 
35da7236ebSmiod #include <hppa/dev/cpudevs.h>
36da7236ebSmiod 
37da7236ebSmiod #include <dev/eisa/eisavar.h>
38da7236ebSmiod #include <dev/isa/isavar.h>
39da7236ebSmiod 
40da7236ebSmiod #include <hppa/dev/mongoosereg.h>
41da7236ebSmiod #include <hppa/dev/mongoosevar.h>
42da7236ebSmiod 
43da7236ebSmiod #include <hppa/gsc/gscbusvar.h>
44da7236ebSmiod 
45da7236ebSmiod void	mgattach_gsc(struct device *, struct device *, void *);
46da7236ebSmiod int	mgmatch_gsc(struct device *, void *, void *);
47da7236ebSmiod 
48*78d5ff0eSmpi const struct cfattach mg_gsc_ca = {
49da7236ebSmiod 	sizeof(struct mongoose_softc), mgmatch_gsc, mgattach_gsc
50da7236ebSmiod };
51da7236ebSmiod 
52da7236ebSmiod int
mgmatch_gsc(struct device * parent,void * cfdata,void * aux)53da7236ebSmiod mgmatch_gsc(struct device *parent, void *cfdata, void *aux)
54da7236ebSmiod {
55da7236ebSmiod 	struct gsc_attach_args *ga = aux;
56da7236ebSmiod 
57da7236ebSmiod 	if (ga->ga_type.iodc_type != HPPA_TYPE_BHA ||
58da7236ebSmiod 	    ga->ga_type.iodc_sv_model != HPPA_BHA_WEISA)
59da7236ebSmiod 		return (0);
60da7236ebSmiod 
61da7236ebSmiod 	return (1);
62da7236ebSmiod }
63da7236ebSmiod 
64da7236ebSmiod void
mgattach_gsc(struct device * parent,struct device * self,void * aux)65da7236ebSmiod mgattach_gsc(struct device *parent, struct device *self, void *aux)
66da7236ebSmiod {
67da7236ebSmiod 	struct mongoose_softc *sc = (struct mongoose_softc *)self;
68da7236ebSmiod 	struct gsc_attach_args *ga = aux;
69da7236ebSmiod 	bus_space_handle_t ioh;
70da7236ebSmiod 
71da7236ebSmiod 	sc->sc_bt = ga->ga_iot;
72da7236ebSmiod 	sc->sc_iomap = ga->ga_hpa;
73da7236ebSmiod 
74da7236ebSmiod 	if (bus_space_map(ga->ga_iot, ga->ga_hpa + MONGOOSE_MONGOOSE,
75da7236ebSmiod 	    sizeof(struct mongoose_regs), 0, &ioh) != 0) {
76da7236ebSmiod 		printf(": can't map IO space\n");
77da7236ebSmiod 		return;
78da7236ebSmiod 	}
79da7236ebSmiod 	sc->sc_regs = (struct mongoose_regs *)ioh;
80da7236ebSmiod 
81da7236ebSmiod 	if (bus_space_map(ga->ga_iot, ga->ga_hpa + MONGOOSE_CTRL,
82da7236ebSmiod 	    sizeof(struct mongoose_ctrl), 0, &ioh) != 0) {
83da7236ebSmiod 		printf(": can't map control registers\n");
84da7236ebSmiod 		bus_space_unmap(ga->ga_iot, (bus_space_handle_t)sc->sc_regs,
85da7236ebSmiod 		    sizeof(struct mongoose_regs));
86da7236ebSmiod 		return;
87da7236ebSmiod 	}
88da7236ebSmiod 	sc->sc_ctrl = (struct mongoose_ctrl *)ioh;
89da7236ebSmiod 
90da7236ebSmiod 	if (mgattach_common(sc) != 0)
91da7236ebSmiod 		return;
92da7236ebSmiod 
93da7236ebSmiod 	sc->sc_ih = gsc_intr_establish((struct gsc_softc *)parent,
94da7236ebSmiod 	    ga->ga_irq, IPL_HIGH, mg_intr, sc, sc->sc_dev.dv_xname);
95da7236ebSmiod }
96