com_isa.c revision 1.25 1 /* $NetBSD: com_isa.c,v 1.25 2006/07/13 22:56:02 gdamore 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 Charles M. Hannum.
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) 1991 The Regents of the University of California.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)com.c 7.5 (Berkeley) 5/16/91
68 */
69
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: com_isa.c,v 1.25 2006/07/13 22:56:02 gdamore Exp $");
72
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/ioctl.h>
76 #include <sys/select.h>
77 #include <sys/tty.h>
78 #include <sys/proc.h>
79 #include <sys/user.h>
80 #include <sys/file.h>
81 #include <sys/uio.h>
82 #include <sys/kernel.h>
83 #include <sys/syslog.h>
84 #include <sys/device.h>
85
86 #include <machine/intr.h>
87 #include <machine/bus.h>
88
89 #include <dev/ic/comreg.h>
90 #include <dev/ic/comvar.h>
91 #ifdef COM_HAYESP
92 #include <dev/ic/hayespreg.h>
93 #endif
94
95 #include <dev/isa/isavar.h>
96
97 struct com_isa_softc {
98 struct com_softc sc_com; /* real "com" softc */
99
100 /* ISA-specific goo. */
101 void *sc_ih; /* interrupt handler */
102 };
103
104 int com_isa_probe(struct device *, struct cfdata *, void *);
105 void com_isa_attach(struct device *, struct device *, void *);
106 #ifdef COM_HAYESP
107 int com_isa_isHAYESP(bus_space_handle_t, struct com_softc *);
108 #endif
109
110
111 CFATTACH_DECL(com_isa, sizeof(struct com_isa_softc),
112 com_isa_probe, com_isa_attach, NULL, NULL);
113
114 int
115 com_isa_probe(parent, match, aux)
116 struct device *parent;
117 struct cfdata *match;
118 void *aux;
119 {
120 bus_space_tag_t iot;
121 bus_space_handle_t ioh;
122 int iobase;
123 int rv = 1;
124 struct isa_attach_args *ia = aux;
125
126 if (ia->ia_nio < 1)
127 return (0);
128 if (ia->ia_nirq < 1)
129 return (0);
130
131 if (ISA_DIRECT_CONFIG(ia))
132 return (0);
133
134 /* Disallow wildcarded i/o address. */
135 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
136 return (0);
137
138 /* Don't allow wildcarded IRQ. */
139 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
140 return (0);
141
142 iot = ia->ia_iot;
143 iobase = ia->ia_io[0].ir_addr;
144
145 /* if it's in use as console, it's there. */
146 if (!com_is_console(iot, iobase, 0)) {
147 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
148 return 0;
149 }
150 rv = comprobe1(iot, ioh);
151 bus_space_unmap(iot, ioh, COM_NPORTS);
152 }
153
154 if (rv) {
155 ia->ia_nio = 1;
156 ia->ia_io[0].ir_size = COM_NPORTS;
157
158 ia->ia_nirq = 1;
159
160 ia->ia_niomem = 0;
161 ia->ia_ndrq = 0;
162 }
163 return (rv);
164 }
165
166 void
167 com_isa_attach(parent, self, aux)
168 struct device *parent, *self;
169 void *aux;
170 {
171 struct com_isa_softc *isc = (void *)self;
172 struct com_softc *sc = &isc->sc_com;
173 int iobase, irq;
174 bus_space_tag_t iot;
175 bus_space_handle_t ioh;
176 struct isa_attach_args *ia = aux;
177 #ifdef COM_HAYESP
178 int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 };
179 int *hayespp;
180 #endif
181
182 /*
183 * We're living on an isa.
184 */
185 iobase = ia->ia_io[0].ir_addr;
186 iot = ia->ia_iot;
187
188 if (!com_is_console(iot, iobase, &ioh) &&
189 bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
190 printf(": can't map i/o space\n");
191 return;
192 }
193
194 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
195
196 sc->sc_frequency = COM_FREQ;
197 irq = ia->ia_irq[0].ir_irq;
198
199 #ifdef COM_HAYESP
200 for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) {
201 bus_space_handle_t hayespioh;
202 #define HAYESP_NPORTS 8
203 if (bus_space_map(iot, *hayespp, HAYESP_NPORTS, 0, &hayespioh))
204 continue;
205 if (com_isa_isHAYESP(hayespioh, sc)) {
206 break;
207 }
208 bus_space_unmap(iot, hayespioh, HAYESP_NPORTS);
209 }
210 #endif
211
212 com_attach_subr(sc);
213
214 isc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE, IPL_SERIAL,
215 comintr, sc);
216
217 /*
218 * Shutdown hook for buggy BIOSs that don't recognize the UART
219 * without a disabled FIFO.
220 */
221 if (shutdownhook_establish(com_cleanup, sc) == NULL)
222 panic("com_isa_attach: could not establish shutdown hook");
223 }
224
225 #ifdef COM_HAYESP
226 int
227 com_isa_isHAYESP(bus_space_handle_t hayespioh, struct com_softc *sc)
228 {
229 char val, dips;
230 int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
231 bus_space_tag_t iot = sc->sc_iot;
232
233 /*
234 * Hayes ESP cards have two iobases. One is for compatibility with
235 * 16550 serial chips, and at the same ISA PC base addresses. The
236 * other is for ESP-specific enhanced features, and lies at a
237 * different addressing range entirely (0x140, 0x180, 0x280, or 0x300).
238 */
239
240 /* Test for ESP signature */
241 if ((bus_space_read_1(iot, hayespioh, 0) & 0xf3) == 0)
242 return (0);
243
244 /*
245 * ESP is present at ESP enhanced base address; unknown com port
246 */
247
248 /* Get the dip-switch configurations */
249 bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS);
250 dips = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1);
251
252 /* Determine which com port this ESP card services: bits 0,1 of */
253 /* dips is the port # (0-3); combaselist[val] is the com_iobase */
254 if (sc->sc_regs.cr_iobase != combaselist[dips & 0x03])
255 return (0);
256
257 printf(": ESP");
258
259 /* Check ESP Self Test bits. */
260 /* Check for ESP version 2.0: bits 4,5,6 == 010 */
261 bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETTEST);
262 val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1); /* Clear reg1 */
263 val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS2);
264 if ((val & 0x70) < 0x20) {
265 printf("-old (%o)", val & 0x70);
266 /* we do not support the necessary features */
267 return (0);
268 }
269
270 /* Check for ability to emulate 16550: bit 8 == 1 */
271 if ((dips & 0x80) == 0) {
272 printf(" slave");
273 /* XXX Does slave really mean no 16550 support?? */
274 return (0);
275 }
276
277 /*
278 * If we made it this far, we are a full-featured ESP v2.0 (or
279 * better), at the correct com port address.
280 */
281 sc->sc_type = COM_TYPE_HAYESP;
282 sc->sc_hayespioh = hayespioh;
283 sc->sc_fifolen = 1024;
284 sc->sc_prescaler = 0; /* set prescaler to x1. */
285 printf(", 1024 byte fifo\n");
286 return (1);
287 }
288 #endif
289