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