Home | History | Annotate | Line # | Download | only in isa
boca.c revision 1.13
      1 /*	$NetBSD: boca.c,v 1.13 1996/04/15 18:55:28 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, 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 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	8
     52 
     53 struct boca_softc {
     54 	struct device sc_dev;
     55 	void *sc_ih;
     56 
     57 	bus_chipset_tag_t sc_bc;
     58 	int sc_iobase;
     59 
     60 	int sc_alive;			/* mask of slave units attached */
     61 	void *sc_slaves[NSLAVES];	/* com device unit numbers */
     62 	bus_io_handle_t sc_slaveioh[NSLAVES];
     63 };
     64 
     65 int bocaprobe();
     66 void bocaattach();
     67 int bocaintr __P((void *));
     68 
     69 struct cfattach boca_ca = {
     70 	sizeof(struct boca_softc), bocaprobe, bocaattach,
     71 };
     72 
     73 struct cfdriver boca_cd = {
     74 	NULL, "boca", DV_TTY
     75 };
     76 
     77 int
     78 bocaprobe(parent, self, aux)
     79 	struct device *parent, *self;
     80 	void *aux;
     81 {
     82 	struct isa_attach_args *ia = aux;
     83 	int iobase = ia->ia_iobase;
     84 	bus_chipset_tag_t bc = ia->ia_bc;
     85 	bus_io_handle_t ioh;
     86 	int i, rv = 1;
     87 
     88 	/*
     89 	 * Do the normal com probe for the first UART and assume
     90 	 * its presence, and the ability to map the other UARTS,
     91 	 * means there is a multiport board there.
     92 	 * XXX Needs more robustness.
     93 	 */
     94 
     95 	/* if the first port is in use as console, then it. */
     96 	if (iobase == comconsaddr && !comconsattached)
     97 		goto checkmappings;
     98 
     99 	if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
    100 		rv = 0;
    101 		goto out;
    102 	}
    103 	rv = comprobe1(bc, ioh, iobase);
    104 	bus_io_unmap(bc, ioh, COM_NPORTS);
    105 	if (rv == 0)
    106 		goto out;
    107 
    108 checkmappings:
    109 	for (i = 1; i < NSLAVES; i++) {
    110 		iobase += COM_NPORTS;
    111 
    112 		if (iobase == comconsaddr && !comconsattached)
    113 			continue;
    114 
    115 		if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
    116 			rv = 0;
    117 			goto out;
    118 		}
    119 		bus_io_unmap(bc, ioh, COM_NPORTS);
    120 	}
    121 
    122 out:
    123 	if (rv)
    124 		ia->ia_iosize = NSLAVES * COM_NPORTS;
    125 	return (rv);
    126 }
    127 
    128 int
    129 bocaprint(aux, pnp)
    130 	void *aux;
    131 	char *pnp;
    132 {
    133 	struct commulti_attach_args *ca = aux;
    134 
    135 	if (pnp)
    136 		printf("com at %s", pnp);
    137 	printf(" slave %d", ca->ca_slave);
    138 	return (UNCONF);
    139 }
    140 
    141 void
    142 bocaattach(parent, self, aux)
    143 	struct device *parent, *self;
    144 	void *aux;
    145 {
    146 	struct boca_softc *sc = (void *)self;
    147 	struct isa_attach_args *ia = aux;
    148 	struct commulti_attach_args ca;
    149 	int i, subunit;
    150 
    151 	sc->sc_bc = ia->ia_bc;
    152 	sc->sc_iobase = ia->ia_iobase;
    153 
    154 	for (i = 0; i < NSLAVES; i++)
    155 		if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS,
    156 		    &sc->sc_slaveioh[i]))
    157 			panic("bocaattach: couldn't map slave %d", i);
    158 
    159 	printf("\n");
    160 
    161 	for (i = 0; i < NSLAVES; i++) {
    162 		struct cfdata *match;
    163 
    164 		ca.ca_slave = i;
    165 		ca.ca_bc = sc->sc_bc;
    166 		ca.ca_ioh = sc->sc_slaveioh[i];
    167 		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
    168 		ca.ca_noien = 0;
    169 
    170 		sc->sc_slaves[i] = config_found(self, &ca, bocaprint);
    171 		if (sc->sc_slaves[i] != NULL)
    172 			sc->sc_alive |= 1 << i;
    173 	}
    174 
    175 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    176 	    IPL_TTY, bocaintr, sc);
    177 }
    178 
    179 int
    180 bocaintr(arg)
    181 	void *arg;
    182 {
    183 	struct boca_softc *sc = arg;
    184 	bus_chipset_tag_t bc = sc->sc_bc;
    185 	int alive = sc->sc_alive;
    186 	int bits;
    187 
    188 	bits = bus_io_read_1(bc, sc->sc_slaveioh[0], 7) & alive;
    189 	if (bits == 0)
    190 		return (0);
    191 
    192 	for (;;) {
    193 #define	TRY(n) \
    194 		if (bits & (1 << (n))) \
    195 			comintr(sc->sc_slaves[n]);
    196 		TRY(0);
    197 		TRY(1);
    198 		TRY(2);
    199 		TRY(3);
    200 		TRY(4);
    201 		TRY(5);
    202 		TRY(6);
    203 		TRY(7);
    204 #undef TRY
    205 		bits = bus_io_read_1(bc, sc->sc_slaveioh[0], 7) & alive;
    206 		if (bits == 0)
    207 			return (1);
    208  	}
    209 }
    210