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