1 /* $OpenBSD: com_gsc.c,v 1.22 2022/03/13 08:04:38 mpi Exp $ */
2
3 /*
4 * Copyright (c) 1998-2003 Michael Shalayeff
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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
32 #include <sys/tty.h>
33
34 #include <machine/bus.h>
35 #include <machine/intr.h>
36 #include <machine/iomod.h>
37 #include <machine/autoconf.h>
38
39 #include <dev/ic/comreg.h>
40 #include <dev/ic/comvar.h>
41
42 #include <hppa/dev/cpudevs.h>
43 #include <hppa/gsc/gscbusvar.h>
44
45 #define COM_GSC_FREQ 7372800
46
47 struct com_gsc_regs {
48 u_int8_t reset;
49 };
50
51 int com_gsc_probe(struct device *, void *, void *);
52 void com_gsc_attach(struct device *, struct device *, void *);
53
54 const struct cfattach com_gsc_ca = {
55 sizeof(struct com_softc), com_gsc_probe, com_gsc_attach
56 };
57
58 int
com_gsc_probe(parent,match,aux)59 com_gsc_probe(parent, match, aux)
60 struct device *parent;
61 void *match, *aux;
62 {
63 struct gsc_attach_args *ga = aux;
64
65 if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
66 (ga->ga_type.iodc_sv_model != HPPA_FIO_GRS232 &&
67 ga->ga_type.iodc_sv_model != HPPA_FIO_RS232 &&
68 ga->ga_type.iodc_sv_model != HPPA_FIO_GRJ16))
69 return (0);
70
71 return (1);
72 /* HOZER comprobe1(ga->ga_iot, ga->ga_hpa + IOMOD_DEVOFFSET); */
73 }
74
75 void
com_gsc_attach(parent,self,aux)76 com_gsc_attach(parent, self, aux)
77 struct device *parent, *self;
78 void *aux;
79 {
80 struct com_softc *sc = (void *)self;
81 struct gsc_attach_args *ga = aux;
82
83 sc->sc_iot = ga->ga_iot;
84 sc->sc_iobase = (bus_addr_t)ga->ga_hpa;
85 if (ga->ga_type.iodc_sv_model != HPPA_FIO_GRJ16)
86 sc->sc_iobase += IOMOD_DEVOFFSET;
87
88 if (bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS,
89 0, &sc->sc_ioh)) {
90 printf(": cannot map io space\n");
91 return;
92 }
93
94 if (PAGE0->mem_cons.pz_class == PCL_DUPLEX &&
95 PAGE0->mem_cons.pz_hpa == ga->ga_hpa) {
96 bus_space_unmap(sc->sc_iot, sc->sc_ioh, COM_NPORTS);
97 comcnattach(sc->sc_iot, sc->sc_iobase, comdefaultrate,
98 COM_GSC_FREQ, comconscflag);
99 }
100
101 sc->sc_frequency = COM_GSC_FREQ;
102 com_attach_subr(sc);
103
104 sc->sc_ih = gsc_intr_establish((struct gsc_softc *)parent,
105 ga->ga_irq, IPL_TTY, comintr, sc, sc->sc_dev.dv_xname);
106 }
107