1 /* $NetBSD: ioat66.c,v 1.1 1999/11/15 21:13:38 mcr Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 5 * Copyright (c) 1995 Charles M. Hannum. All rights reserved. 6 * 7 * This code is derived from public-domain software written by 8 * Roland McGrath, and information provided by David Muir Sharnoff. 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 Charles M. Hannum. 21 * 4. The name of the author may not be used to endorse or promote products 22 * derived from this software without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/device.h> 39 #include <sys/termios.h> 40 41 #include <machine/bus.h> 42 #include <machine/intr.h> 43 44 #include <dev/ic/comreg.h> 45 #include <dev/ic/comvar.h> 46 47 #include <dev/isa/isavar.h> 48 #include <dev/isa/com_multi.h> 49 50 #define NSLAVES 6 51 52 struct ioat66_softc { 53 struct device sc_dev; 54 void *sc_ih; 55 56 bus_space_tag_t sc_iot; 57 int sc_iobase; 58 59 int sc_alive; /* mask of slave units attached */ 60 void *sc_slaves[NSLAVES]; /* com device unit numbers */ 61 bus_space_handle_t sc_slaveioh[NSLAVES]; 62 bus_space_handle_t sc_intmasq; 63 }; 64 65 int ioatbases[NSLAVES]={0x220,0x228,0x240,0x248,0x260,0x268}; 66 #define IOAT66SHARED 0x208 67 68 int ioat66probe __P((struct device *, struct cfdata *, void *)); 69 void ioat66attach __P((struct device *, struct device *, void *)); 70 int ioat66intr __P((void *)); 71 int ioat66print __P((void *, const char *)); 72 73 struct cfattach ioat_ca = { 74 sizeof(struct ioat66_softc), ioat66probe, ioat66attach, 75 }; 76 77 int 78 ioat66probe(parent, self, aux) 79 struct device *parent; 80 struct cfdata *self; 81 void *aux; 82 { 83 struct isa_attach_args *ia = aux; 84 int iobase = ia->ia_iobase; 85 bus_space_tag_t iot = ia->ia_iot; 86 bus_space_handle_t ioh; 87 int i, rv = 1; 88 89 /* 90 * Do the normal com probe for the first UART and assume 91 * its presence, and the ability to map the other UARTS, 92 * means there is a multiport board there. 93 * XXX Needs more robustness. 94 */ 95 96 /* Disallow wildcarded i/o address. */ 97 if (ia->ia_iobase == ISACF_PORT_DEFAULT) 98 return (0); 99 100 /* if the first port is in use as console, then it. */ 101 if (com_is_console(iot, iobase, 0)) 102 goto checkmappings; 103 104 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 105 rv = 0; 106 goto out; 107 } 108 rv = comprobe1(iot, ioh); 109 bus_space_unmap(iot, ioh, COM_NPORTS); 110 if (rv == 0) 111 goto out; 112 113 checkmappings: 114 for (i = 1; i < NSLAVES; i++) { 115 iobase = ioatbases[i]; 116 117 if (com_is_console(iot, iobase, 0)) 118 continue; 119 120 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 121 rv = 0; 122 goto out; 123 } 124 bus_space_unmap(iot, ioh, COM_NPORTS); 125 } 126 127 out: 128 if (rv) 129 ia->ia_iosize = NSLAVES * COM_NPORTS; 130 return (rv); 131 } 132 133 int 134 ioat66print(aux, pnp) 135 void *aux; 136 const char *pnp; 137 { 138 struct commulti_attach_args *ca = aux; 139 140 if (pnp) 141 printf("com at %s", pnp); 142 printf(" slave %d", ca->ca_slave); 143 return (UNCONF); 144 } 145 146 void 147 ioat66attach(parent, self, aux) 148 struct device *parent, *self; 149 void *aux; 150 { 151 struct ioat66_softc *sc = (void *)self; 152 struct isa_attach_args *ia = aux; 153 struct commulti_attach_args ca; 154 bus_space_tag_t iot = ia->ia_iot; 155 int i, iobase; 156 157 printf("\n"); 158 159 sc->sc_iot = ia->ia_iot; 160 sc->sc_iobase = ia->ia_iobase; 161 162 for (i = 0; i < NSLAVES; i++) { 163 iobase = ioatbases[i]; 164 if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) && 165 bus_space_map(iot, iobase, COM_NPORTS, 0, 166 &sc->sc_slaveioh[i])) { 167 printf("%s: can't map i/o space for slave %d\n", 168 sc->sc_dev.dv_xname, i); 169 return; 170 } 171 } 172 173 if(bus_space_map(iot, IOAT66SHARED, 1, 0, &sc->sc_intmasq)) { 174 printf("%s: can't map shared interupt mask\n", 175 sc->sc_dev.dv_xname); 176 return; 177 } 178 179 for (i = 0; i < NSLAVES; i++) { 180 181 ca.ca_slave = i; 182 ca.ca_iot = sc->sc_iot; 183 ca.ca_ioh = sc->sc_slaveioh[i]; 184 ca.ca_iobase = ioatbases[i]; 185 ca.ca_noien = 0; 186 187 sc->sc_slaves[i] = config_found(self, &ca, ioat66print); 188 if (sc->sc_slaves[i] != NULL) 189 sc->sc_alive |= 1 << i; 190 } 191 192 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, 193 IPL_SERIAL, ioat66intr, sc); 194 } 195 196 int 197 ioat66intr(arg) 198 void *arg; 199 { 200 struct ioat66_softc *sc = arg; 201 bus_space_tag_t iot = sc->sc_iot; 202 int alive = sc->sc_alive; 203 int bits; 204 205 bits = bus_space_read_1(iot, sc->sc_intmasq, 0) & alive; 206 if (bits == 0) 207 return (0); 208 209 for (;;) { 210 #define TRY(n) \ 211 if (bits & (1 << (n))) \ 212 comintr(sc->sc_slaves[n]); 213 TRY(0); 214 TRY(1); 215 TRY(2); 216 TRY(3); 217 TRY(4); 218 TRY(5); 219 #undef TRY 220 bits = bus_space_read_1(iot, sc->sc_intmasq, 0) & alive; 221 if (bits == 0) 222 return (1); 223 } 224 } 225