1 /* $NetBSD: com_isa.c,v 1.26 2006/10/12 01:31:16 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 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.26 2006/10/12 01:31:16 christos 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(struct device *parent __unused, struct cfdata *match __unused, 116 void *aux) 117 { 118 bus_space_tag_t iot; 119 bus_space_handle_t ioh; 120 int iobase; 121 int rv = 1; 122 struct isa_attach_args *ia = aux; 123 124 if (ia->ia_nio < 1) 125 return (0); 126 if (ia->ia_nirq < 1) 127 return (0); 128 129 if (ISA_DIRECT_CONFIG(ia)) 130 return (0); 131 132 /* Disallow wildcarded i/o address. */ 133 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 134 return (0); 135 136 /* Don't allow wildcarded IRQ. */ 137 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) 138 return (0); 139 140 iot = ia->ia_iot; 141 iobase = ia->ia_io[0].ir_addr; 142 143 /* if it's in use as console, it's there. */ 144 if (!com_is_console(iot, iobase, 0)) { 145 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 146 return 0; 147 } 148 rv = comprobe1(iot, ioh); 149 bus_space_unmap(iot, ioh, COM_NPORTS); 150 } 151 152 if (rv) { 153 ia->ia_nio = 1; 154 ia->ia_io[0].ir_size = COM_NPORTS; 155 156 ia->ia_nirq = 1; 157 158 ia->ia_niomem = 0; 159 ia->ia_ndrq = 0; 160 } 161 return (rv); 162 } 163 164 void 165 com_isa_attach(struct device *parent __unused, struct device *self, 166 void *aux) 167 { 168 struct com_isa_softc *isc = (void *)self; 169 struct com_softc *sc = &isc->sc_com; 170 int iobase, irq; 171 bus_space_tag_t iot; 172 bus_space_handle_t ioh; 173 struct isa_attach_args *ia = aux; 174 #ifdef COM_HAYESP 175 int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 }; 176 int *hayespp; 177 #endif 178 179 /* 180 * We're living on an isa. 181 */ 182 iobase = ia->ia_io[0].ir_addr; 183 iot = ia->ia_iot; 184 185 if (!com_is_console(iot, iobase, &ioh) && 186 bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 187 printf(": can't map i/o space\n"); 188 return; 189 } 190 191 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase); 192 193 sc->sc_frequency = COM_FREQ; 194 irq = ia->ia_irq[0].ir_irq; 195 196 #ifdef COM_HAYESP 197 for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) { 198 bus_space_handle_t hayespioh; 199 #define HAYESP_NPORTS 8 200 if (bus_space_map(iot, *hayespp, HAYESP_NPORTS, 0, &hayespioh)) 201 continue; 202 if (com_isa_isHAYESP(hayespioh, sc)) { 203 break; 204 } 205 bus_space_unmap(iot, hayespioh, HAYESP_NPORTS); 206 } 207 #endif 208 209 com_attach_subr(sc); 210 211 isc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE, IPL_SERIAL, 212 comintr, sc); 213 214 /* 215 * Shutdown hook for buggy BIOSs that don't recognize the UART 216 * without a disabled FIFO. 217 */ 218 if (shutdownhook_establish(com_cleanup, sc) == NULL) 219 panic("com_isa_attach: could not establish shutdown hook"); 220 } 221 222 #ifdef COM_HAYESP 223 int 224 com_isa_isHAYESP(bus_space_handle_t hayespioh, struct com_softc *sc) 225 { 226 char val, dips; 227 int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; 228 bus_space_tag_t iot = sc->sc_iot; 229 230 /* 231 * Hayes ESP cards have two iobases. One is for compatibility with 232 * 16550 serial chips, and at the same ISA PC base addresses. The 233 * other is for ESP-specific enhanced features, and lies at a 234 * different addressing range entirely (0x140, 0x180, 0x280, or 0x300). 235 */ 236 237 /* Test for ESP signature */ 238 if ((bus_space_read_1(iot, hayespioh, 0) & 0xf3) == 0) 239 return (0); 240 241 /* 242 * ESP is present at ESP enhanced base address; unknown com port 243 */ 244 245 /* Get the dip-switch configurations */ 246 bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS); 247 dips = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1); 248 249 /* Determine which com port this ESP card services: bits 0,1 of */ 250 /* dips is the port # (0-3); combaselist[val] is the com_iobase */ 251 if (sc->sc_regs.cr_iobase != combaselist[dips & 0x03]) 252 return (0); 253 254 printf(": ESP"); 255 256 /* Check ESP Self Test bits. */ 257 /* Check for ESP version 2.0: bits 4,5,6 == 010 */ 258 bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETTEST); 259 val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1); /* Clear reg1 */ 260 val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS2); 261 if ((val & 0x70) < 0x20) { 262 printf("-old (%o)", val & 0x70); 263 /* we do not support the necessary features */ 264 return (0); 265 } 266 267 /* Check for ability to emulate 16550: bit 8 == 1 */ 268 if ((dips & 0x80) == 0) { 269 printf(" slave"); 270 /* XXX Does slave really mean no 16550 support?? */ 271 return (0); 272 } 273 274 /* 275 * If we made it this far, we are a full-featured ESP v2.0 (or 276 * better), at the correct com port address. 277 */ 278 sc->sc_type = COM_TYPE_HAYESP; 279 sc->sc_hayespioh = hayespioh; 280 sc->sc_fifolen = 1024; 281 sc->sc_prescaler = 0; /* set prescaler to x1. */ 282 printf(", 1024 byte fifo\n"); 283 return (1); 284 } 285 #endif 286