tcom.c revision 1.9 1 1.9 drochner /* $NetBSD: tcom.c,v 1.9 2004/09/14 20:20:49 drochner Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by Eric S. Hvozda.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos * 3. All advertising materials mentioning features or use of this software
19 1.1 christos * must display the following acknowledgement:
20 1.1 christos * This product includes software developed by the NetBSD
21 1.1 christos * Foundation, Inc. and its contributors.
22 1.1 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 christos * contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos */
38 1.1 christos
39 1.1 christos /*
40 1.1 christos * Copyright (c) 1998 Jukka Marin. All rights reserved.
41 1.1 christos * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
42 1.1 christos * Copyright (c) 1995 Charles Hannum. All rights reserved.
43 1.1 christos *
44 1.1 christos * This code is derived from public-domain software written by
45 1.1 christos * Roland McGrath.
46 1.1 christos *
47 1.1 christos * Redistribution and use in source and binary forms, with or without
48 1.1 christos * modification, are permitted provided that the following conditions
49 1.1 christos * are met:
50 1.1 christos * 1. Redistributions of source code must retain the above copyright
51 1.1 christos * notice, this list of conditions and the following disclaimer.
52 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
53 1.1 christos * notice, this list of conditions and the following disclaimer in the
54 1.1 christos * documentation and/or other materials provided with the distribution.
55 1.1 christos * 3. All advertising materials mentioning features or use of this software
56 1.1 christos * must display the following acknowledgement:
57 1.1 christos * This product includes software developed by Charles Hannum.
58 1.1 christos * 4. The name of the author may not be used to endorse or promote products
59 1.1 christos * derived from this software without specific prior written permission.
60 1.1 christos *
61 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
62 1.1 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
63 1.1 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
64 1.1 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
65 1.1 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
66 1.1 christos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
67 1.1 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
68 1.1 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
69 1.1 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
70 1.1 christos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71 1.1 christos */
72 1.1 christos
73 1.1 christos /*
74 1.1 christos * NOTE: This driver has been tested in TCOM "UNIX mode" with base address
75 1.1 christos * set to 0x100 or 0x200 and baud rate jumpers to "normal". This code
76 1.1 christos * does NOT know about the 2x and 4x baud rates available on TCOM cards.
77 1.1 christos */
78 1.2 lukem
79 1.2 lukem #include <sys/cdefs.h>
80 1.9 drochner __KERNEL_RCSID(0, "$NetBSD: tcom.c,v 1.9 2004/09/14 20:20:49 drochner Exp $");
81 1.1 christos
82 1.1 christos #include <sys/param.h>
83 1.1 christos #include <sys/systm.h>
84 1.1 christos #include <sys/device.h>
85 1.1 christos #include <sys/termios.h>
86 1.1 christos
87 1.1 christos #include <machine/bus.h>
88 1.1 christos #include <machine/intr.h>
89 1.1 christos
90 1.1 christos #include <dev/ic/comreg.h>
91 1.1 christos #include <dev/ic/comvar.h>
92 1.1 christos
93 1.1 christos #include <dev/isa/isavar.h>
94 1.1 christos #include <dev/isa/com_multi.h>
95 1.1 christos
96 1.1 christos #define NSLAVES 8 /* TCOM cards have 4 or 8 UARTs */
97 1.1 christos #define STATUS_OFFSET 0x40 /* offset from board base address */
98 1.1 christos #define STATUS_SIZE 8 /* 8 bytes reserved for irq status */
99 1.1 christos
100 1.1 christos struct tcom_softc {
101 1.1 christos struct device sc_dev;
102 1.1 christos void *sc_ih;
103 1.1 christos
104 1.1 christos bus_space_tag_t sc_iot;
105 1.1 christos int sc_iobase;
106 1.1 christos
107 1.1 christos int sc_alive; /* mask of slave units attached */
108 1.1 christos void *sc_slaves[NSLAVES]; /* com device unit numbers */
109 1.1 christos bus_space_handle_t sc_slaveioh[NSLAVES];
110 1.1 christos bus_space_handle_t sc_statusioh;
111 1.1 christos };
112 1.1 christos
113 1.1 christos int tcomprobe __P((struct device *, struct cfdata *, void *));
114 1.1 christos void tcomattach __P((struct device *, struct device *, void *));
115 1.1 christos int tcomintr __P((void *));
116 1.1 christos
117 1.5 thorpej CFATTACH_DECL(tcom, sizeof(struct tcom_softc),
118 1.6 thorpej tcomprobe, tcomattach, NULL, NULL);
119 1.1 christos
120 1.1 christos int
121 1.1 christos tcomprobe(parent, self, aux)
122 1.1 christos struct device *parent;
123 1.1 christos struct cfdata *self;
124 1.1 christos void *aux;
125 1.1 christos {
126 1.1 christos struct isa_attach_args *ia = aux;
127 1.1 christos bus_space_tag_t iot = ia->ia_iot;
128 1.1 christos bus_space_handle_t ioh;
129 1.3 thorpej int i, iobase, rv = 1;
130 1.1 christos
131 1.1 christos /*
132 1.1 christos * Do the normal com probe for the first UART and assume
133 1.1 christos * its presence, and the ability to map the other UARTS,
134 1.1 christos * means there is a multiport board there.
135 1.1 christos * XXX Needs more robustness.
136 1.1 christos */
137 1.1 christos
138 1.3 thorpej if (ia->ia_nio < 1)
139 1.3 thorpej return (0);
140 1.3 thorpej if (ia->ia_nirq < 1)
141 1.3 thorpej return (1);
142 1.3 thorpej
143 1.3 thorpej if (ISA_DIRECT_CONFIG(ia))
144 1.3 thorpej return (0);
145 1.3 thorpej
146 1.1 christos /* Disallow wildcarded i/o address. */
147 1.9 drochner if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
148 1.3 thorpej return (0);
149 1.9 drochner if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
150 1.1 christos return (0);
151 1.1 christos
152 1.1 christos /* if the first port is in use as console, then it. */
153 1.3 thorpej if (com_is_console(iot, ia->ia_io[0].ir_addr, 0))
154 1.1 christos goto checkmappings;
155 1.1 christos
156 1.3 thorpej if (bus_space_map(iot, ia->ia_io[0].ir_addr, COM_NPORTS, 0, &ioh)) {
157 1.1 christos rv = 0;
158 1.1 christos goto out;
159 1.1 christos }
160 1.1 christos rv = comprobe1(iot, ioh);
161 1.1 christos bus_space_unmap(iot, ioh, COM_NPORTS);
162 1.1 christos if (rv == 0)
163 1.1 christos goto out;
164 1.1 christos
165 1.1 christos checkmappings:
166 1.3 thorpej for (i = 1, iobase = ia->ia_io[0].ir_addr; i < NSLAVES; i++) {
167 1.1 christos iobase += COM_NPORTS;
168 1.1 christos
169 1.1 christos if (com_is_console(iot, iobase, 0))
170 1.1 christos continue;
171 1.1 christos
172 1.1 christos if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
173 1.1 christos rv = 0;
174 1.1 christos goto out;
175 1.1 christos }
176 1.1 christos bus_space_unmap(iot, ioh, COM_NPORTS);
177 1.1 christos }
178 1.1 christos
179 1.1 christos out:
180 1.3 thorpej if (rv) {
181 1.3 thorpej ia->ia_nio = 1;
182 1.3 thorpej ia->ia_io[0].ir_size = NSLAVES * COM_NPORTS;
183 1.3 thorpej
184 1.3 thorpej ia->ia_nirq = 1;
185 1.3 thorpej
186 1.3 thorpej ia->ia_niomem = 0;
187 1.3 thorpej ia->ia_ndrq = 0;
188 1.3 thorpej }
189 1.1 christos return (rv);
190 1.1 christos }
191 1.1 christos
192 1.1 christos void
193 1.1 christos tcomattach(parent, self, aux)
194 1.1 christos struct device *parent, *self;
195 1.1 christos void *aux;
196 1.1 christos {
197 1.1 christos struct tcom_softc *sc = (void *)self;
198 1.1 christos struct isa_attach_args *ia = aux;
199 1.1 christos struct commulti_attach_args ca;
200 1.1 christos bus_space_tag_t iot = ia->ia_iot;
201 1.1 christos int i, iobase;
202 1.1 christos
203 1.1 christos printf("\n");
204 1.1 christos
205 1.1 christos sc->sc_iot = ia->ia_iot;
206 1.3 thorpej sc->sc_iobase = ia->ia_io[0].ir_addr;
207 1.1 christos
208 1.1 christos for (i = 0; i < NSLAVES; i++) {
209 1.1 christos iobase = sc->sc_iobase + i * COM_NPORTS;
210 1.1 christos if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) &&
211 1.1 christos bus_space_map(iot, iobase, COM_NPORTS, 0,
212 1.1 christos &sc->sc_slaveioh[i])) {
213 1.1 christos printf("%s: can't map i/o space for slave %d\n",
214 1.1 christos sc->sc_dev.dv_xname, i);
215 1.1 christos return;
216 1.1 christos }
217 1.1 christos }
218 1.1 christos
219 1.3 thorpej if (bus_space_map(iot, sc->sc_iobase + STATUS_OFFSET, STATUS_SIZE, 0,
220 1.3 thorpej &sc->sc_statusioh)) {
221 1.1 christos printf("%s: can't map status space\n", sc->sc_dev.dv_xname);
222 1.1 christos return;
223 1.1 christos }
224 1.1 christos
225 1.1 christos for (i = 0; i < NSLAVES; i++) {
226 1.1 christos ca.ca_slave = i;
227 1.1 christos ca.ca_iot = sc->sc_iot;
228 1.1 christos ca.ca_ioh = sc->sc_slaveioh[i];
229 1.1 christos ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
230 1.1 christos ca.ca_noien = 0;
231 1.1 christos
232 1.8 drochner sc->sc_slaves[i] = config_found(self, &ca, commultiprint);
233 1.1 christos if (sc->sc_slaves[i] != NULL)
234 1.1 christos sc->sc_alive |= 1 << i;
235 1.1 christos }
236 1.1 christos
237 1.3 thorpej sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
238 1.3 thorpej IST_EDGE, IPL_SERIAL, tcomintr, sc);
239 1.1 christos }
240 1.1 christos
241 1.1 christos int
242 1.1 christos tcomintr(arg)
243 1.1 christos void *arg;
244 1.1 christos {
245 1.1 christos struct tcom_softc *sc = arg;
246 1.1 christos bus_space_tag_t iot = sc->sc_iot;
247 1.1 christos int alive = sc->sc_alive;
248 1.1 christos int bits;
249 1.1 christos
250 1.1 christos bits = ~bus_space_read_1(iot, sc->sc_statusioh, 0) & alive;
251 1.1 christos if (bits == 0)
252 1.1 christos return (0);
253 1.1 christos
254 1.1 christos for (;;) {
255 1.1 christos #define TRY(n) \
256 1.1 christos if (bits & (1 << (n))) \
257 1.1 christos comintr(sc->sc_slaves[n]);
258 1.1 christos TRY(0);
259 1.1 christos TRY(1);
260 1.1 christos TRY(2);
261 1.1 christos TRY(3);
262 1.1 christos TRY(4);
263 1.1 christos TRY(5);
264 1.1 christos TRY(6);
265 1.1 christos TRY(7);
266 1.1 christos #undef TRY
267 1.1 christos bits = ~bus_space_read_1(iot, sc->sc_statusioh, 0) & alive;
268 1.1 christos if (bits == 0)
269 1.1 christos return (1);
270 1.1 christos }
271 1.1 christos }
272