tcom.c revision 1.2 1 1.2 lukem /* $NetBSD: tcom.c,v 1.2 2001/11/13 08:01:32 lukem 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.2 lukem __KERNEL_RCSID(0, "$NetBSD: tcom.c,v 1.2 2001/11/13 08:01:32 lukem 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 int tcomprint __P((void *, const char *));
117 1.1 christos
118 1.1 christos struct cfattach tcom_ca = {
119 1.1 christos sizeof(struct tcom_softc), tcomprobe, tcomattach
120 1.1 christos };
121 1.1 christos
122 1.1 christos int
123 1.1 christos tcomprobe(parent, self, aux)
124 1.1 christos struct device *parent;
125 1.1 christos struct cfdata *self;
126 1.1 christos void *aux;
127 1.1 christos {
128 1.1 christos struct isa_attach_args *ia = aux;
129 1.1 christos int iobase = ia->ia_iobase;
130 1.1 christos bus_space_tag_t iot = ia->ia_iot;
131 1.1 christos bus_space_handle_t ioh;
132 1.1 christos int i, rv = 1;
133 1.1 christos
134 1.1 christos /*
135 1.1 christos * Do the normal com probe for the first UART and assume
136 1.1 christos * its presence, and the ability to map the other UARTS,
137 1.1 christos * means there is a multiport board there.
138 1.1 christos * XXX Needs more robustness.
139 1.1 christos */
140 1.1 christos
141 1.1 christos /* Disallow wildcarded i/o address. */
142 1.1 christos if (ia->ia_iobase == ISACF_PORT_DEFAULT)
143 1.1 christos return (0);
144 1.1 christos
145 1.1 christos /* if the first port is in use as console, then it. */
146 1.1 christos if (com_is_console(iot, iobase, 0))
147 1.1 christos goto checkmappings;
148 1.1 christos
149 1.1 christos if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
150 1.1 christos rv = 0;
151 1.1 christos goto out;
152 1.1 christos }
153 1.1 christos rv = comprobe1(iot, ioh);
154 1.1 christos bus_space_unmap(iot, ioh, COM_NPORTS);
155 1.1 christos if (rv == 0)
156 1.1 christos goto out;
157 1.1 christos
158 1.1 christos checkmappings:
159 1.1 christos for (i = 1; i < NSLAVES; i++) {
160 1.1 christos iobase += COM_NPORTS;
161 1.1 christos
162 1.1 christos if (com_is_console(iot, iobase, 0))
163 1.1 christos continue;
164 1.1 christos
165 1.1 christos if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
166 1.1 christos rv = 0;
167 1.1 christos goto out;
168 1.1 christos }
169 1.1 christos bus_space_unmap(iot, ioh, COM_NPORTS);
170 1.1 christos }
171 1.1 christos
172 1.1 christos out:
173 1.1 christos if (rv)
174 1.1 christos ia->ia_iosize = NSLAVES * COM_NPORTS;
175 1.1 christos return (rv);
176 1.1 christos }
177 1.1 christos
178 1.1 christos int
179 1.1 christos tcomprint(aux, pnp)
180 1.1 christos void *aux;
181 1.1 christos const char *pnp;
182 1.1 christos {
183 1.1 christos struct commulti_attach_args *ca = aux;
184 1.1 christos
185 1.1 christos if (pnp)
186 1.1 christos printf("com at %s", pnp);
187 1.1 christos printf(" slave %d", ca->ca_slave);
188 1.1 christos return (UNCONF);
189 1.1 christos }
190 1.1 christos
191 1.1 christos void
192 1.1 christos tcomattach(parent, self, aux)
193 1.1 christos struct device *parent, *self;
194 1.1 christos void *aux;
195 1.1 christos {
196 1.1 christos struct tcom_softc *sc = (void *)self;
197 1.1 christos struct isa_attach_args *ia = aux;
198 1.1 christos struct commulti_attach_args ca;
199 1.1 christos bus_space_tag_t iot = ia->ia_iot;
200 1.1 christos int i, iobase;
201 1.1 christos
202 1.1 christos printf("\n");
203 1.1 christos
204 1.1 christos sc->sc_iot = ia->ia_iot;
205 1.1 christos sc->sc_iobase = ia->ia_iobase;
206 1.1 christos
207 1.1 christos for (i = 0; i < NSLAVES; i++) {
208 1.1 christos iobase = sc->sc_iobase + i * COM_NPORTS;
209 1.1 christos if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) &&
210 1.1 christos bus_space_map(iot, iobase, COM_NPORTS, 0,
211 1.1 christos &sc->sc_slaveioh[i])) {
212 1.1 christos printf("%s: can't map i/o space for slave %d\n",
213 1.1 christos sc->sc_dev.dv_xname, i);
214 1.1 christos return;
215 1.1 christos }
216 1.1 christos }
217 1.1 christos
218 1.1 christos if (bus_space_map(iot, sc->sc_iobase + STATUS_OFFSET, STATUS_SIZE, 0, &sc->sc_statusioh)) {
219 1.1 christos printf("%s: can't map status space\n", sc->sc_dev.dv_xname);
220 1.1 christos return;
221 1.1 christos }
222 1.1 christos
223 1.1 christos for (i = 0; i < NSLAVES; i++) {
224 1.1 christos ca.ca_slave = i;
225 1.1 christos ca.ca_iot = sc->sc_iot;
226 1.1 christos ca.ca_ioh = sc->sc_slaveioh[i];
227 1.1 christos ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
228 1.1 christos ca.ca_noien = 0;
229 1.1 christos
230 1.1 christos sc->sc_slaves[i] = config_found(self, &ca, tcomprint);
231 1.1 christos if (sc->sc_slaves[i] != NULL)
232 1.1 christos sc->sc_alive |= 1 << i;
233 1.1 christos }
234 1.1 christos
235 1.1 christos sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
236 1.1 christos IPL_SERIAL, tcomintr, sc);
237 1.1 christos }
238 1.1 christos
239 1.1 christos int
240 1.1 christos tcomintr(arg)
241 1.1 christos void *arg;
242 1.1 christos {
243 1.1 christos struct tcom_softc *sc = arg;
244 1.1 christos bus_space_tag_t iot = sc->sc_iot;
245 1.1 christos int alive = sc->sc_alive;
246 1.1 christos int bits;
247 1.1 christos
248 1.1 christos bits = ~bus_space_read_1(iot, sc->sc_statusioh, 0) & alive;
249 1.1 christos if (bits == 0)
250 1.1 christos return (0);
251 1.1 christos
252 1.1 christos for (;;) {
253 1.1 christos #define TRY(n) \
254 1.1 christos if (bits & (1 << (n))) \
255 1.1 christos comintr(sc->sc_slaves[n]);
256 1.1 christos TRY(0);
257 1.1 christos TRY(1);
258 1.1 christos TRY(2);
259 1.1 christos TRY(3);
260 1.1 christos TRY(4);
261 1.1 christos TRY(5);
262 1.1 christos TRY(6);
263 1.1 christos TRY(7);
264 1.1 christos #undef TRY
265 1.1 christos bits = ~bus_space_read_1(iot, sc->sc_statusioh, 0) & alive;
266 1.1 christos if (bits == 0)
267 1.1 christos return (1);
268 1.1 christos }
269 1.1 christos }
270