rtfps.c revision 1.33
1/* $NetBSD: rtfps.c,v 1.33 1997/10/16 00:29:36 thorpej 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/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 4 51 52struct rtfps_softc { 53 struct device sc_dev; 54 void *sc_ih; 55 56 bus_space_tag_t sc_iot; 57 int sc_iobase; 58 int sc_irqport; 59 bus_space_handle_t sc_irqioh; 60 61 int sc_alive; /* mask of slave units attached */ 62 void *sc_slaves[NSLAVES]; /* com device unit numbers */ 63 bus_space_handle_t sc_slaveioh[NSLAVES]; 64}; 65 66int rtfpsprobe __P((struct device *, void *, void *)); 67void rtfpsattach __P((struct device *, struct device *, void *)); 68int rtfpsintr __P((void *)); 69int rtfpsprint __P((void *, const char *)); 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; 82 void *self; 83 void *aux; 84{ 85 struct isa_attach_args *ia = aux; 86 int iobase = ia->ia_iobase; 87 bus_space_tag_t iot = ia->ia_iot; 88 bus_space_handle_t ioh; 89 int i, rv = 1; 90 91 /* 92 * Do the normal com probe for the first UART and assume 93 * its presence, and the ability to map the other UARTS, 94 * means there is a multiport board there. 95 * XXX Needs more robustness. 96 */ 97 98 /* if the first port is in use as console, then it. */ 99 if (com_is_console(iot, iobase, 0)) 100 goto checkmappings; 101 102 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 103 rv = 0; 104 goto out; 105 } 106 rv = comprobe1(iot, ioh, iobase); 107 bus_space_unmap(iot, ioh, COM_NPORTS); 108 if (rv == 0) 109 goto out; 110 111checkmappings: 112 for (i = 1; i < NSLAVES; i++) { 113 iobase += COM_NPORTS; 114 115 if (com_is_console(iot, iobase, 0)) 116 continue; 117 118 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 119 rv = 0; 120 goto out; 121 } 122 bus_space_unmap(iot, ioh, COM_NPORTS); 123 } 124 125out: 126 if (rv) 127 ia->ia_iosize = NSLAVES * COM_NPORTS; 128 return (rv); 129} 130 131int 132rtfpsprint(aux, pnp) 133 void *aux; 134 const char *pnp; 135{ 136 struct commulti_attach_args *ca = aux; 137 138 if (pnp) 139 printf("com at %s", pnp); 140 printf(" slave %d", ca->ca_slave); 141 return (UNCONF); 142} 143 144void 145rtfpsattach(parent, self, aux) 146 struct device *parent, *self; 147 void *aux; 148{ 149 struct rtfps_softc *sc = (void *)self; 150 struct isa_attach_args *ia = aux; 151 struct commulti_attach_args ca; 152 static int irqport[] = { 153 IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK, 154 IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK, 155 IOBASEUNK, 0x2f2, 0x6f2, 0x6f3, 156 IOBASEUNK, IOBASEUNK, IOBASEUNK, IOBASEUNK 157 }; 158 bus_space_tag_t iot = ia->ia_iot; 159 int i, iobase; 160 161 sc->sc_iot = ia->ia_iot; 162 sc->sc_iobase = ia->ia_iobase; 163 164 if (ia->ia_irq >= 16 || irqport[ia->ia_irq] == IOBASEUNK) 165 panic("rtfpsattach: invalid irq"); 166 sc->sc_irqport = irqport[ia->ia_irq]; 167 168 for (i = 0; i < NSLAVES; i++) { 169 iobase = sc->sc_iobase + i * COM_NPORTS; 170 if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) && 171 bus_space_map(iot, iobase, COM_NPORTS, 0, 172 &sc->sc_slaveioh[i])) 173 panic("rtfpsattach: couldn't map slave %d", i); 174 } 175 if (bus_space_map(iot, sc->sc_irqport, 1, 0, &sc->sc_irqioh)) 176 panic("rtfpsattach: couldn't map irq port at 0x%x\n", 177 sc->sc_irqport); 178 179 bus_space_write_1(iot, sc->sc_irqioh, 0, 0); 180 181 printf("\n"); 182 183 for (i = 0; i < NSLAVES; i++) { 184 ca.ca_slave = i; 185 ca.ca_iot = sc->sc_iot; 186 ca.ca_ioh = sc->sc_slaveioh[i]; 187 ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS; 188 ca.ca_noien = 0; 189 190 sc->sc_slaves[i] = config_found(self, &ca, rtfpsprint); 191 if (sc->sc_slaves[i] != NULL) 192 sc->sc_alive |= 1 << i; 193 } 194 195 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, 196 IPL_SERIAL, rtfpsintr, sc); 197} 198 199int 200rtfpsintr(arg) 201 void *arg; 202{ 203 struct rtfps_softc *sc = arg; 204 bus_space_tag_t iot = sc->sc_iot; 205 int alive = sc->sc_alive; 206 207 bus_space_write_1(iot, sc->sc_irqioh, 0, 0); 208 209#define TRY(n) \ 210 if (alive & (1 << (n))) \ 211 comintr(sc->sc_slaves[n]); 212 TRY(0); 213 TRY(1); 214 TRY(2); 215 TRY(3); 216#undef TRY 217 218 return (1); 219} 220