Home | History | Annotate | Line # | Download | only in isa
boca.c revision 1.29
      1 /*	$NetBSD: boca.c,v 1.29 1998/01/14 12:14:44 drochner 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/systm.h>
     38 #include <sys/device.h>
     39 #include <sys/termios.h>
     40 
     41 #include <machine/bus.h>
     42 #include <machine/intr.h>
     43 
     44 #include <dev/ic/comreg.h>
     45 #include <dev/ic/comvar.h>
     46 
     47 #include <dev/isa/isavar.h>
     48 #include <dev/isa/com_multi.h>
     49 
     50 #define	NSLAVES	8
     51 
     52 struct boca_softc {
     53 	struct device sc_dev;
     54 	void *sc_ih;
     55 
     56 	bus_space_tag_t sc_iot;
     57 	int sc_iobase;
     58 
     59 	int sc_alive;			/* mask of slave units attached */
     60 	void *sc_slaves[NSLAVES];	/* com device unit numbers */
     61 	bus_space_handle_t sc_slaveioh[NSLAVES];
     62 };
     63 
     64 #ifdef __BROKEN_INDIRECT_CONFIG
     65 int bocaprobe __P((struct device *, void *, void *));
     66 #else
     67 int bocaprobe __P((struct device *, struct cfdata *, void *));
     68 #endif
     69 void bocaattach __P((struct device *, struct device *, void *));
     70 int bocaintr __P((void *));
     71 int bocaprint __P((void *, const char *));
     72 
     73 struct cfattach boca_ca = {
     74 	sizeof(struct boca_softc), bocaprobe, bocaattach,
     75 };
     76 
     77 int
     78 bocaprobe(parent, self, aux)
     79 	struct device *parent;
     80 #ifdef __BROKEN_INDIRECT_CONFIG
     81 	void *self;
     82 #else
     83 	struct cfdata *self;
     84 #endif
     85 	void *aux;
     86 {
     87 	struct isa_attach_args *ia = aux;
     88 	int iobase = ia->ia_iobase;
     89 	bus_space_tag_t iot = ia->ia_iot;
     90 	bus_space_handle_t ioh;
     91 	int i, rv = 1;
     92 
     93 	/*
     94 	 * Do the normal com probe for the first UART and assume
     95 	 * its presence, and the ability to map the other UARTS,
     96 	 * means there is a multiport board there.
     97 	 * XXX Needs more robustness.
     98 	 */
     99 
    100 	/* Disallow wildcarded i/o address. */
    101 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    102 		return (0);
    103 
    104 	/* if the first port is in use as console, then it. */
    105 	if (com_is_console(iot, iobase, 0))
    106 		goto checkmappings;
    107 
    108 	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    109 		rv = 0;
    110 		goto out;
    111 	}
    112 	rv = comprobe1(iot, ioh, iobase);
    113 	bus_space_unmap(iot, ioh, COM_NPORTS);
    114 	if (rv == 0)
    115 		goto out;
    116 
    117 checkmappings:
    118 	for (i = 1; i < NSLAVES; i++) {
    119 		iobase += COM_NPORTS;
    120 
    121 		if (com_is_console(iot, iobase, 0))
    122 			continue;
    123 
    124 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    125 			rv = 0;
    126 			goto out;
    127 		}
    128 		bus_space_unmap(iot, ioh, COM_NPORTS);
    129 	}
    130 
    131 out:
    132 	if (rv)
    133 		ia->ia_iosize = NSLAVES * COM_NPORTS;
    134 	return (rv);
    135 }
    136 
    137 int
    138 bocaprint(aux, pnp)
    139 	void *aux;
    140 	const char *pnp;
    141 {
    142 	struct commulti_attach_args *ca = aux;
    143 
    144 	if (pnp)
    145 		printf("com at %s", pnp);
    146 	printf(" slave %d", ca->ca_slave);
    147 	return (UNCONF);
    148 }
    149 
    150 void
    151 bocaattach(parent, self, aux)
    152 	struct device *parent, *self;
    153 	void *aux;
    154 {
    155 	struct boca_softc *sc = (void *)self;
    156 	struct isa_attach_args *ia = aux;
    157 	struct commulti_attach_args ca;
    158 	bus_space_tag_t iot = ia->ia_iot;
    159 	int i, iobase;
    160 
    161 	printf("\n");
    162 
    163 	sc->sc_iot = ia->ia_iot;
    164 	sc->sc_iobase = ia->ia_iobase;
    165 
    166 	for (i = 0; i < NSLAVES; i++) {
    167 		iobase = sc->sc_iobase + i * COM_NPORTS;
    168 		if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) &&
    169 		    bus_space_map(iot, iobase, COM_NPORTS, 0,
    170 			&sc->sc_slaveioh[i])) {
    171 			printf("%s: can't map i/o space for slave %d\n",
    172 			     sc->sc_dev.dv_xname, i);
    173 			return;
    174 		}
    175 	}
    176 
    177 	for (i = 0; i < NSLAVES; i++) {
    178 
    179 		ca.ca_slave = i;
    180 		ca.ca_iot = sc->sc_iot;
    181 		ca.ca_ioh = sc->sc_slaveioh[i];
    182 		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
    183 		ca.ca_noien = 0;
    184 
    185 		sc->sc_slaves[i] = config_found(self, &ca, bocaprint);
    186 		if (sc->sc_slaves[i] != NULL)
    187 			sc->sc_alive |= 1 << i;
    188 	}
    189 
    190 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    191 	    IPL_SERIAL, bocaintr, sc);
    192 }
    193 
    194 int
    195 bocaintr(arg)
    196 	void *arg;
    197 {
    198 	struct boca_softc *sc = arg;
    199 	bus_space_tag_t iot = sc->sc_iot;
    200 	int alive = sc->sc_alive;
    201 	int bits;
    202 
    203 	bits = bus_space_read_1(iot, sc->sc_slaveioh[0], 7) & alive;
    204 	if (bits == 0)
    205 		return (0);
    206 
    207 	for (;;) {
    208 #define	TRY(n) \
    209 		if (bits & (1 << (n))) \
    210 			comintr(sc->sc_slaves[n]);
    211 		TRY(0);
    212 		TRY(1);
    213 		TRY(2);
    214 		TRY(3);
    215 		TRY(4);
    216 		TRY(5);
    217 		TRY(6);
    218 		TRY(7);
    219 #undef TRY
    220 		bits = bus_space_read_1(iot, sc->sc_slaveioh[0], 7) & alive;
    221 		if (bits == 0)
    222 			return (1);
    223  	}
    224 }
    225