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