rtfps.c revision 1.21
1/* $NetBSD: rtfps.c,v 1.21 1996/04/15 18:55:31 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 5 * Copyright (c) 1995 Charles Hannum. All rights reserved. 6 * 7 * This code is derived from public-domain software written by 8 * Roland McGrath. 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 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/device.h> 38#include <sys/termios.h> 39 40#ifdef i386 /* XXX */ 41#include <machine/cpu.h> /* XXX */ 42#else /* XXX */ 43#include <machine/intr.h> 44#endif /* XXX */ 45#include <machine/bus.h> 46 47#include <dev/isa/isavar.h> 48#include <dev/isa/comreg.h> 49#include <dev/isa/comvar.h> 50 51#define NSLAVES 4 52 53struct rtfps_softc { 54 struct device sc_dev; 55 void *sc_ih; 56 57 bus_chipset_tag_t sc_bc; 58 int sc_iobase; 59 int sc_irqport; 60 bus_io_handle_t sc_irqioh; 61 62 int sc_alive; /* mask of slave units attached */ 63 void *sc_slaves[NSLAVES]; /* com device unit numbers */ 64 bus_io_handle_t sc_slaveioh[NSLAVES]; 65}; 66 67int rtfpsprobe(); 68void rtfpsattach(); 69int rtfpsintr __P((void *)); 70 71struct cfattach rtfps_ca = { 72 sizeof(struct rtfps_softc), rtfpsprobe, rtfpsattach 73}; 74 75struct cfdriver rtfps_cd = { 76 NULL, "rtfps", DV_TTY 77}; 78 79int 80rtfpsprobe(parent, self, aux) 81 struct device *parent, *self; 82 void *aux; 83{ 84 struct isa_attach_args *ia = aux; 85 int iobase = ia->ia_iobase; 86 bus_chipset_tag_t bc = ia->ia_bc; 87 bus_io_handle_t ioh; 88 int i, rv = 1; 89 90 /* 91 * Do the normal com probe for the first UART and assume 92 * its presence, and the ability to map the other UARTS, 93 * means there is a multiport board there. 94 * XXX Needs more robustness. 95 */ 96 97 /* if the first port is in use as console, then it. */ 98 if (iobase == comconsaddr && !comconsattached) 99 goto checkmappings; 100 101 if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) { 102 rv = 0; 103 goto out; 104 } 105 rv = comprobe1(bc, ioh, iobase); 106 bus_io_unmap(bc, ioh, COM_NPORTS); 107 if (rv == 0) 108 goto out; 109 110checkmappings: 111 for (i = 1; i < NSLAVES; i++) { 112 iobase += COM_NPORTS; 113 114 if (iobase == comconsaddr && !comconsattached) 115 continue; 116 117 if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) { 118 rv = 0; 119 goto out; 120 } 121 bus_io_unmap(bc, ioh, COM_NPORTS); 122 } 123 124out: 125 if (rv) 126 ia->ia_iosize = NSLAVES * COM_NPORTS; 127 return (rv); 128} 129 130int 131rtfpsprint(aux, pnp) 132 void *aux; 133 char *pnp; 134{ 135 struct commulti_attach_args *ca = aux; 136 137 if (pnp) 138 printf("com at %s", pnp); 139 printf(" slave %d", ca->ca_slave); 140 return (UNCONF); 141} 142 143void 144rtfpsattach(parent, self, aux) 145 struct device *parent, *self; 146 void *aux; 147{ 148 struct rtfps_softc *sc = (void *)self; 149 struct isa_attach_args *ia = aux; 150 struct commulti_attach_args ca; 151 static int irqport[] = { 152 IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK, 153 IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK, 154 IOBASEUNK, 0x2f2, 0x6f2, 0x6f3, 155 IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK 156 }; 157 int i, subunit; 158 159 sc->sc_bc = ia->ia_bc; 160 sc->sc_iobase = ia->ia_iobase; 161 162 if (ia->ia_irq >= 16 || irqport[ia->ia_irq] == IOBASEUNK) 163 panic("rtfpsattach: invalid irq"); 164 sc->sc_irqport = irqport[ia->ia_irq]; 165 166 for (i = 0; i < NSLAVES; i++) 167 if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS, 168 &sc->sc_slaveioh[i])) 169 panic("rtfpsattach: couldn't map slave %d", i); 170 if (bus_io_map(bc, sc->sc_irqport, 1, &sc->sc_irqioh)) 171 panic("rtfpsattach: couldn't map irq port at 0x%x\n", 172 sc->sc_irqport); 173 174 bus_io_write_1(bc, sc->sc_irqioh, 0, 0); 175 176 printf("\n"); 177 178 for (i = 0; i < NSLAVES; i++) { 179 struct cfdata *match; 180 181 ca.ca_slave = i; 182 ca.ca_bc = sc->sc_bc; 183 ca.ca_ioh = sc->sc_slaveioh[i]; 184 ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS; 185 ca.ca_noien = 0; 186 187 sc->sc_slaves[i] = config_found(self, &ca, rtfpsprint); 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_TTY, rtfpsintr, sc); 194} 195 196int 197rtfpsintr(arg) 198 void *arg; 199{ 200 struct rtfps_softc *sc = arg; 201 bus_chipset_tag_t bc = sc->sc_bc; 202 int alive = sc->sc_alive; 203 204 bus_io_write_1(bc, sc->sc_irqioh, 0, 0); 205 206#define TRY(n) \ 207 if (alive & (1 << (n))) \ 208 comintr(sc->sc_slaves[n]); 209 TRY(0); 210 TRY(1); 211 TRY(2); 212 TRY(3); 213#undef TRY 214 215 return (1); 216} 217