boca.c revision 1.20.4.1 1 1.20.4.1 thorpej /* $NetBSD: boca.c,v 1.20.4.1 1997/08/23 07:13:11 thorpej Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*
4 1.9 cgd * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 1.2 mycroft * Copyright (c) 1995 Charles Hannum. All rights reserved.
6 1.1 mycroft *
7 1.2 mycroft * This code is derived from public-domain software written by
8 1.2 mycroft * Roland McGrath, and information provided by David Muir Sharnoff.
9 1.1 mycroft *
10 1.2 mycroft * Redistribution and use in source and binary forms, with or without
11 1.2 mycroft * modification, are permitted provided that the following conditions
12 1.2 mycroft * are met:
13 1.2 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.2 mycroft * notice, this list of conditions and the following disclaimer.
15 1.2 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.2 mycroft * documentation and/or other materials provided with the distribution.
18 1.2 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.2 mycroft * must display the following acknowledgement:
20 1.2 mycroft * This product includes software developed by Charles Hannum.
21 1.2 mycroft * 4. The name of the author may not be used to endorse or promote products
22 1.2 mycroft * derived from this software without specific prior written permission.
23 1.2 mycroft *
24 1.2 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 1.2 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.2 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.2 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.2 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.2 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.2 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.2 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.2 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.2 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 mycroft */
35 1.1 mycroft
36 1.1 mycroft #include <sys/param.h>
37 1.14 christos #include <sys/systm.h>
38 1.1 mycroft #include <sys/device.h>
39 1.13 cgd #include <sys/termios.h>
40 1.1 mycroft
41 1.15 mycroft #include <machine/bus.h>
42 1.12 cgd #include <machine/intr.h>
43 1.1 mycroft
44 1.4 cgd #include <dev/isa/isavar.h>
45 1.7 cgd #include <dev/isa/comreg.h>
46 1.8 cgd #include <dev/isa/comvar.h>
47 1.20 mycroft #include <dev/isa/com_multi.h>
48 1.7 cgd
49 1.7 cgd #define NSLAVES 8
50 1.1 mycroft
51 1.1 mycroft struct boca_softc {
52 1.1 mycroft struct device sc_dev;
53 1.4 cgd void *sc_ih;
54 1.1 mycroft
55 1.19 thorpej bus_space_tag_t sc_iot;
56 1.1 mycroft int sc_iobase;
57 1.9 cgd
58 1.7 cgd int sc_alive; /* mask of slave units attached */
59 1.7 cgd void *sc_slaves[NSLAVES]; /* com device unit numbers */
60 1.19 thorpej bus_space_handle_t sc_slaveioh[NSLAVES];
61 1.1 mycroft };
62 1.1 mycroft
63 1.14 christos int bocaprobe __P((struct device *, void *, void *));
64 1.14 christos void bocaattach __P((struct device *, struct device *, void *));
65 1.4 cgd int bocaintr __P((void *));
66 1.16 cgd int bocaprint __P((void *, const char *));
67 1.1 mycroft
68 1.10 thorpej struct cfattach boca_ca = {
69 1.10 thorpej sizeof(struct boca_softc), bocaprobe, bocaattach,
70 1.10 thorpej };
71 1.10 thorpej
72 1.10 thorpej struct cfdriver boca_cd = {
73 1.10 thorpej NULL, "boca", DV_TTY
74 1.1 mycroft };
75 1.1 mycroft
76 1.1 mycroft int
77 1.1 mycroft bocaprobe(parent, self, aux)
78 1.14 christos struct device *parent;
79 1.14 christos void *self;
80 1.1 mycroft void *aux;
81 1.1 mycroft {
82 1.1 mycroft struct isa_attach_args *ia = aux;
83 1.9 cgd int iobase = ia->ia_iobase;
84 1.19 thorpej bus_space_tag_t iot = ia->ia_iot;
85 1.19 thorpej bus_space_handle_t ioh;
86 1.9 cgd int i, rv = 1;
87 1.1 mycroft
88 1.1 mycroft /*
89 1.1 mycroft * Do the normal com probe for the first UART and assume
90 1.9 cgd * its presence, and the ability to map the other UARTS,
91 1.9 cgd * means there is a multiport board there.
92 1.1 mycroft * XXX Needs more robustness.
93 1.1 mycroft */
94 1.1 mycroft
95 1.9 cgd /* if the first port is in use as console, then it. */
96 1.20.4.1 thorpej if ((iobase == comconsaddr && !comconsattached)
97 1.20.4.1 thorpej #ifdef KGDB
98 1.20.4.1 thorpej || iobase == com_kgdb_addr
99 1.20.4.1 thorpej #endif
100 1.20.4.1 thorpej )
101 1.9 cgd goto checkmappings;
102 1.9 cgd
103 1.19 thorpej if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
104 1.9 cgd rv = 0;
105 1.9 cgd goto out;
106 1.9 cgd }
107 1.19 thorpej rv = comprobe1(iot, ioh, iobase);
108 1.19 thorpej bus_space_unmap(iot, ioh, COM_NPORTS);
109 1.9 cgd if (rv == 0)
110 1.9 cgd goto out;
111 1.9 cgd
112 1.9 cgd checkmappings:
113 1.9 cgd for (i = 1; i < NSLAVES; i++) {
114 1.9 cgd iobase += COM_NPORTS;
115 1.9 cgd
116 1.20.4.1 thorpej if ((iobase == comconsaddr && !comconsattached)
117 1.20.4.1 thorpej #ifdef KGDB
118 1.20.4.1 thorpej || iobase == com_kgdb_addr
119 1.20.4.1 thorpej #endif
120 1.20.4.1 thorpej )
121 1.9 cgd
122 1.19 thorpej if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
123 1.9 cgd rv = 0;
124 1.9 cgd goto out;
125 1.9 cgd }
126 1.19 thorpej bus_space_unmap(iot, ioh, COM_NPORTS);
127 1.9 cgd }
128 1.1 mycroft
129 1.9 cgd out:
130 1.9 cgd if (rv)
131 1.9 cgd ia->ia_iosize = NSLAVES * COM_NPORTS;
132 1.9 cgd return (rv);
133 1.1 mycroft }
134 1.1 mycroft
135 1.1 mycroft int
136 1.9 cgd bocaprint(aux, pnp)
137 1.1 mycroft void *aux;
138 1.16 cgd const char *pnp;
139 1.1 mycroft {
140 1.9 cgd struct commulti_attach_args *ca = aux;
141 1.1 mycroft
142 1.9 cgd if (pnp)
143 1.18 christos printf("com at %s", pnp);
144 1.18 christos printf(" slave %d", ca->ca_slave);
145 1.9 cgd return (UNCONF);
146 1.1 mycroft }
147 1.1 mycroft
148 1.1 mycroft void
149 1.1 mycroft bocaattach(parent, self, aux)
150 1.1 mycroft struct device *parent, *self;
151 1.1 mycroft void *aux;
152 1.1 mycroft {
153 1.1 mycroft struct boca_softc *sc = (void *)self;
154 1.1 mycroft struct isa_attach_args *ia = aux;
155 1.8 cgd struct commulti_attach_args ca;
156 1.19 thorpej bus_space_tag_t iot = ia->ia_iot;
157 1.14 christos int i;
158 1.1 mycroft
159 1.19 thorpej sc->sc_iot = ia->ia_iot;
160 1.1 mycroft sc->sc_iobase = ia->ia_iobase;
161 1.1 mycroft
162 1.9 cgd for (i = 0; i < NSLAVES; i++)
163 1.19 thorpej if (bus_space_map(iot, sc->sc_iobase + i * COM_NPORTS,
164 1.19 thorpej COM_NPORTS, 0, &sc->sc_slaveioh[i]))
165 1.9 cgd panic("bocaattach: couldn't map slave %d", i);
166 1.9 cgd
167 1.18 christos printf("\n");
168 1.1 mycroft
169 1.9 cgd for (i = 0; i < NSLAVES; i++) {
170 1.9 cgd
171 1.9 cgd ca.ca_slave = i;
172 1.19 thorpej ca.ca_iot = sc->sc_iot;
173 1.9 cgd ca.ca_ioh = sc->sc_slaveioh[i];
174 1.9 cgd ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
175 1.9 cgd ca.ca_noien = 0;
176 1.9 cgd
177 1.11 cgd sc->sc_slaves[i] = config_found(self, &ca, bocaprint);
178 1.11 cgd if (sc->sc_slaves[i] != NULL)
179 1.9 cgd sc->sc_alive |= 1 << i;
180 1.1 mycroft }
181 1.1 mycroft
182 1.12 cgd sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
183 1.20 mycroft IPL_SERIAL, bocaintr, sc);
184 1.1 mycroft }
185 1.1 mycroft
186 1.1 mycroft int
187 1.4 cgd bocaintr(arg)
188 1.4 cgd void *arg;
189 1.1 mycroft {
190 1.4 cgd struct boca_softc *sc = arg;
191 1.19 thorpej bus_space_tag_t iot = sc->sc_iot;
192 1.1 mycroft int alive = sc->sc_alive;
193 1.1 mycroft int bits;
194 1.1 mycroft
195 1.19 thorpej bits = bus_space_read_1(iot, sc->sc_slaveioh[0], 7) & alive;
196 1.1 mycroft if (bits == 0)
197 1.1 mycroft return (0);
198 1.1 mycroft
199 1.1 mycroft for (;;) {
200 1.1 mycroft #define TRY(n) \
201 1.1 mycroft if (bits & (1 << (n))) \
202 1.1 mycroft comintr(sc->sc_slaves[n]);
203 1.1 mycroft TRY(0);
204 1.1 mycroft TRY(1);
205 1.1 mycroft TRY(2);
206 1.1 mycroft TRY(3);
207 1.1 mycroft TRY(4);
208 1.1 mycroft TRY(5);
209 1.1 mycroft TRY(6);
210 1.1 mycroft TRY(7);
211 1.1 mycroft #undef TRY
212 1.19 thorpej bits = bus_space_read_1(iot, sc->sc_slaveioh[0], 7) & alive;
213 1.1 mycroft if (bits == 0)
214 1.1 mycroft return (1);
215 1.1 mycroft }
216 1.1 mycroft }
217