xref: /openbsd-src/sys/arch/hppa/dev/com_ssio.c (revision 78d5ff0ec949396ff3bbc97f51b741a17179ba18)
1*78d5ff0eSmpi /*	$OpenBSD: com_ssio.c,v 1.3 2022/03/13 08:04:38 mpi Exp $	*/
2340b0d88Skettenis 
3340b0d88Skettenis /*
4340b0d88Skettenis  * Copyright (c) 2007 Mark Kettenis
5340b0d88Skettenis  *
6340b0d88Skettenis  * Permission to use, copy, modify, and distribute this software for any
7340b0d88Skettenis  * purpose with or without fee is hereby granted, provided that the above
8340b0d88Skettenis  * copyright notice and this permission notice appear in all copies.
9340b0d88Skettenis  *
10340b0d88Skettenis  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11340b0d88Skettenis  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12340b0d88Skettenis  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13340b0d88Skettenis  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14340b0d88Skettenis  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15340b0d88Skettenis  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16340b0d88Skettenis  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17340b0d88Skettenis  */
18340b0d88Skettenis 
19340b0d88Skettenis #include <sys/param.h>
20340b0d88Skettenis #include <sys/systm.h>
21340b0d88Skettenis #include <sys/device.h>
22340b0d88Skettenis #include <sys/tty.h>
23340b0d88Skettenis 
24340b0d88Skettenis #include <machine/bus.h>
258554cfa0Skettenis #include <machine/iomod.h>
26340b0d88Skettenis 
27340b0d88Skettenis #include <dev/ic/comreg.h>
28340b0d88Skettenis #include <dev/ic/comvar.h>
29340b0d88Skettenis 
30340b0d88Skettenis #include <hppa/dev/ssiovar.h>
31340b0d88Skettenis 
32340b0d88Skettenis #define COM_SSIO_FREQ	1843200
33340b0d88Skettenis 
34340b0d88Skettenis int com_ssio_match(struct device *, void *, void *);
35340b0d88Skettenis void com_ssio_attach(struct device *, struct device *, void *);
36340b0d88Skettenis 
37*78d5ff0eSmpi const struct cfattach com_ssio_ca = {
38340b0d88Skettenis 	sizeof(struct com_softc), com_ssio_match, com_ssio_attach
39340b0d88Skettenis };
40340b0d88Skettenis 
41340b0d88Skettenis int
com_ssio_match(struct device * parent,void * match,void * aux)42340b0d88Skettenis com_ssio_match(struct device *parent, void *match, void *aux)
43340b0d88Skettenis {
44340b0d88Skettenis 	struct cfdata *cf = match;
45340b0d88Skettenis 	struct ssio_attach_args *saa = aux;
46340b0d88Skettenis 
47340b0d88Skettenis 	if (strcmp(saa->saa_name, "com") != 0)
48340b0d88Skettenis 		return (0);
49340b0d88Skettenis 
50340b0d88Skettenis 	/* Check locators. */
51340b0d88Skettenis 	if (cf->ssiocf_irq != SSIO_UNK_IRQ && cf->ssiocf_irq != saa->saa_irq)
52340b0d88Skettenis 		return (0);
53340b0d88Skettenis 
54340b0d88Skettenis 	return (1);
55340b0d88Skettenis }
56340b0d88Skettenis 
57340b0d88Skettenis void
com_ssio_attach(struct device * parent,struct device * self,void * aux)58340b0d88Skettenis com_ssio_attach(struct device *parent, struct device *self, void *aux)
59340b0d88Skettenis {
60340b0d88Skettenis 	struct com_softc *sc = (void *)self;
61340b0d88Skettenis 	struct ssio_attach_args *saa = aux;
62340b0d88Skettenis 
63340b0d88Skettenis 	sc->sc_iot = saa->saa_iot;
64340b0d88Skettenis 	sc->sc_iobase = saa->saa_iobase;
65340b0d88Skettenis 	if (bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS,
66340b0d88Skettenis 	    0, &sc->sc_ioh)) {
67340b0d88Skettenis 		printf(": cannot map io space\n");
68340b0d88Skettenis 		return;
69340b0d88Skettenis 	}
70340b0d88Skettenis 
718554cfa0Skettenis 	if (PAGE0->mem_cons.pz_class == PCL_DUPLEX &&
728554cfa0Skettenis 	    PAGE0->mem_cons.pz_hpa == sc->sc_ioh) {
738554cfa0Skettenis 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, COM_NPORTS);
748554cfa0Skettenis 		comcnattach(sc->sc_iot, sc->sc_iobase, comdefaultrate,
758554cfa0Skettenis 		    COM_SSIO_FREQ, comconscflag);
768554cfa0Skettenis 	}
778554cfa0Skettenis 
78340b0d88Skettenis 	sc->sc_frequency = COM_SSIO_FREQ;
79340b0d88Skettenis 	com_attach_subr(sc);
80340b0d88Skettenis 
81340b0d88Skettenis 	sc->sc_ih = ssio_intr_establish(IPL_TTY, saa->saa_irq,
82340b0d88Skettenis 	    comintr, sc, sc->sc_dev.dv_xname);
83340b0d88Skettenis }
84