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