Home | History | Annotate | Line # | Download | only in isa
boca.c revision 1.9
      1  1.9      cgd /*	$NetBSD: boca.c,v 1.9 1996/03/10 09:01:22 cgd Exp $	*/
      2  1.1  mycroft 
      3  1.1  mycroft /*
      4  1.9      cgd  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      5  1.2  mycroft  * Copyright (c) 1995 Charles Hannum.  All rights reserved.
      6  1.1  mycroft  *
      7  1.2  mycroft  * This code is derived from public-domain software written by
      8  1.2  mycroft  * Roland McGrath, and information provided by David Muir Sharnoff.
      9  1.1  mycroft  *
     10  1.2  mycroft  * Redistribution and use in source and binary forms, with or without
     11  1.2  mycroft  * modification, are permitted provided that the following conditions
     12  1.2  mycroft  * are met:
     13  1.2  mycroft  * 1. Redistributions of source code must retain the above copyright
     14  1.2  mycroft  *    notice, this list of conditions and the following disclaimer.
     15  1.2  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  mycroft  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  mycroft  *    documentation and/or other materials provided with the distribution.
     18  1.2  mycroft  * 3. All advertising materials mentioning features or use of this software
     19  1.2  mycroft  *    must display the following acknowledgement:
     20  1.2  mycroft  *	This product includes software developed by Charles Hannum.
     21  1.2  mycroft  * 4. The name of the author may not be used to endorse or promote products
     22  1.2  mycroft  *    derived from this software without specific prior written permission.
     23  1.2  mycroft  *
     24  1.2  mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  1.2  mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  1.2  mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  1.2  mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  1.2  mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  1.2  mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  1.2  mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  1.2  mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  1.2  mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  1.2  mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  1.1  mycroft  */
     35  1.1  mycroft 
     36  1.1  mycroft #include <sys/param.h>
     37  1.1  mycroft #include <sys/device.h>
     38  1.1  mycroft 
     39  1.9      cgd #include <machine/bus.h>
     40  1.1  mycroft 
     41  1.4      cgd #include <dev/isa/isavar.h>
     42  1.7      cgd #include <dev/isa/comreg.h>
     43  1.8      cgd #include <dev/isa/comvar.h>
     44  1.7      cgd 
     45  1.7      cgd #define	NSLAVES	8
     46  1.1  mycroft 
     47  1.1  mycroft struct boca_softc {
     48  1.1  mycroft 	struct device sc_dev;
     49  1.4      cgd 	void *sc_ih;
     50  1.1  mycroft 
     51  1.9      cgd 	bus_chipset_tag_t sc_bc;
     52  1.1  mycroft 	int sc_iobase;
     53  1.9      cgd 
     54  1.7      cgd 	int sc_alive;			/* mask of slave units attached */
     55  1.7      cgd 	void *sc_slaves[NSLAVES];	/* com device unit numbers */
     56  1.9      cgd 	bus_io_handle_t sc_slaveioh[NSLAVES];
     57  1.1  mycroft };
     58  1.1  mycroft 
     59  1.1  mycroft int bocaprobe();
     60  1.1  mycroft void bocaattach();
     61  1.4      cgd int bocaintr __P((void *));
     62  1.1  mycroft 
     63  1.1  mycroft struct cfdriver bocacd = {
     64  1.1  mycroft 	NULL, "boca", bocaprobe, bocaattach, DV_TTY, sizeof(struct boca_softc)
     65  1.1  mycroft };
     66  1.1  mycroft 
     67  1.1  mycroft int
     68  1.1  mycroft bocaprobe(parent, self, aux)
     69  1.1  mycroft 	struct device *parent, *self;
     70  1.1  mycroft 	void *aux;
     71  1.1  mycroft {
     72  1.1  mycroft 	struct isa_attach_args *ia = aux;
     73  1.9      cgd 	int iobase = ia->ia_iobase;
     74  1.9      cgd 	bus_chipset_tag_t bc = ia->ia_bc;
     75  1.9      cgd 	bus_io_handle_t ioh;
     76  1.9      cgd 	int i, rv = 1;
     77  1.1  mycroft 
     78  1.1  mycroft 	/*
     79  1.1  mycroft 	 * Do the normal com probe for the first UART and assume
     80  1.9      cgd 	 * its presence, and the ability to map the other UARTS,
     81  1.9      cgd 	 * means there is a multiport board there.
     82  1.1  mycroft 	 * XXX Needs more robustness.
     83  1.1  mycroft 	 */
     84  1.1  mycroft 
     85  1.9      cgd 	/* if the first port is in use as console, then it. */
     86  1.9      cgd 	if (iobase == comconsaddr && !comconsattached)
     87  1.9      cgd 		goto checkmappings;
     88  1.9      cgd 
     89  1.9      cgd 	if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
     90  1.9      cgd 		rv = 0;
     91  1.9      cgd 		goto out;
     92  1.9      cgd 	}
     93  1.9      cgd 	rv = comprobe1(bc, ioh, iobase);
     94  1.9      cgd 	bus_io_unmap(bc, ioh, COM_NPORTS);
     95  1.9      cgd 	if (rv == 0)
     96  1.9      cgd 		goto out;
     97  1.9      cgd 
     98  1.9      cgd checkmappings:
     99  1.9      cgd 	for (i = 1; i < NSLAVES; i++) {
    100  1.9      cgd 		iobase += COM_NPORTS;
    101  1.9      cgd 
    102  1.9      cgd 		if (iobase == comconsaddr && !comconsattached)
    103  1.9      cgd 			continue;
    104  1.9      cgd 
    105  1.9      cgd 		if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
    106  1.9      cgd 			rv = 0;
    107  1.9      cgd 			goto out;
    108  1.9      cgd 		}
    109  1.9      cgd 		bus_io_unmap(bc, ioh, COM_NPORTS);
    110  1.9      cgd 	}
    111  1.1  mycroft 
    112  1.9      cgd out:
    113  1.9      cgd 	if (rv)
    114  1.9      cgd 		ia->ia_iosize = NSLAVES * COM_NPORTS;
    115  1.9      cgd 	return (rv);
    116  1.1  mycroft }
    117  1.1  mycroft 
    118  1.1  mycroft int
    119  1.9      cgd bocaprint(aux, pnp)
    120  1.1  mycroft 	void *aux;
    121  1.9      cgd 	char *pnp;
    122  1.1  mycroft {
    123  1.9      cgd 	struct commulti_attach_args *ca = aux;
    124  1.1  mycroft 
    125  1.9      cgd 	if (pnp)
    126  1.9      cgd 		printf("com at %s", pnp);
    127  1.8      cgd 	printf(" slave %d", ca->ca_slave);
    128  1.9      cgd 	return (UNCONF);
    129  1.1  mycroft }
    130  1.1  mycroft 
    131  1.1  mycroft void
    132  1.1  mycroft bocaattach(parent, self, aux)
    133  1.1  mycroft 	struct device *parent, *self;
    134  1.1  mycroft 	void *aux;
    135  1.1  mycroft {
    136  1.1  mycroft 	struct boca_softc *sc = (void *)self;
    137  1.1  mycroft 	struct isa_attach_args *ia = aux;
    138  1.8      cgd 	struct commulti_attach_args ca;
    139  1.9      cgd 	int i, subunit;
    140  1.1  mycroft 
    141  1.9      cgd 	sc->sc_bc = ia->ia_bc;
    142  1.1  mycroft 	sc->sc_iobase = ia->ia_iobase;
    143  1.1  mycroft 
    144  1.9      cgd 	for (i = 0; i < NSLAVES; i++)
    145  1.9      cgd 		if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS,
    146  1.9      cgd 		    &sc->sc_slaveioh[i]))
    147  1.9      cgd 			panic("bocaattach: couldn't map slave %d", i);
    148  1.9      cgd 
    149  1.1  mycroft 	printf("\n");
    150  1.1  mycroft 
    151  1.9      cgd 	for (i = 0; i < NSLAVES; i++) {
    152  1.9      cgd 		struct cfdata *match;
    153  1.9      cgd 
    154  1.9      cgd 		ca.ca_slave = i;
    155  1.9      cgd 		ca.ca_bc = sc->sc_bc;
    156  1.9      cgd 		ca.ca_ioh = sc->sc_slaveioh[i];
    157  1.9      cgd 		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
    158  1.9      cgd 		ca.ca_noien = 0;
    159  1.9      cgd 
    160  1.9      cgd 		/* mimic config_found(), but with special functionality */
    161  1.9      cgd 		if ((match = config_search(NULL, self, &ca)) != NULL) {
    162  1.9      cgd 			subunit = match->cf_unit; /* can change if unit == * */
    163  1.9      cgd 			config_attach(self, match, &ca, bocaprint);
    164  1.9      cgd 			sc->sc_slaves[i] = match->cf_driver->cd_devs[subunit];
    165  1.9      cgd 			sc->sc_alive |= 1 << i;
    166  1.9      cgd 		} else {
    167  1.9      cgd 			bocaprint(&ca, self->dv_xname);
    168  1.9      cgd 			printf(" not configured\n");
    169  1.1  mycroft 		}
    170  1.1  mycroft 	}
    171  1.1  mycroft 
    172  1.6  mycroft 	sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, bocaintr,
    173  1.6  mycroft 	    sc);
    174  1.1  mycroft }
    175  1.1  mycroft 
    176  1.1  mycroft int
    177  1.4      cgd bocaintr(arg)
    178  1.4      cgd 	void *arg;
    179  1.1  mycroft {
    180  1.4      cgd 	struct boca_softc *sc = arg;
    181  1.9      cgd 	bus_chipset_tag_t bc = sc->sc_bc;
    182  1.1  mycroft 	int alive = sc->sc_alive;
    183  1.1  mycroft 	int bits;
    184  1.1  mycroft 
    185  1.9      cgd 	bits = bus_io_read_1(bc, sc->sc_slaveioh[0], 7) & alive;
    186  1.1  mycroft 	if (bits == 0)
    187  1.1  mycroft 		return (0);
    188  1.1  mycroft 
    189  1.1  mycroft 	for (;;) {
    190  1.1  mycroft #define	TRY(n) \
    191  1.1  mycroft 		if (bits & (1 << (n))) \
    192  1.1  mycroft 			comintr(sc->sc_slaves[n]);
    193  1.1  mycroft 		TRY(0);
    194  1.1  mycroft 		TRY(1);
    195  1.1  mycroft 		TRY(2);
    196  1.1  mycroft 		TRY(3);
    197  1.1  mycroft 		TRY(4);
    198  1.1  mycroft 		TRY(5);
    199  1.1  mycroft 		TRY(6);
    200  1.1  mycroft 		TRY(7);
    201  1.1  mycroft #undef TRY
    202  1.9      cgd 		bits = bus_io_read_1(bc, sc->sc_slaveioh[0], 7) & alive;
    203  1.1  mycroft 		if (bits == 0)
    204  1.1  mycroft 			return (1);
    205  1.1  mycroft  	}
    206  1.1  mycroft }
    207