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