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