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