Home | History | Annotate | Line # | Download | only in isa
addcom_isa.c revision 1.2.6.2
      1  1.2.6.2  bouyer /*	$NetBSD: addcom_isa.c,v 1.2.6.2 2000/11/20 11:41:11 bouyer Exp $	*/
      2  1.2.6.2  bouyer 
      3  1.2.6.2  bouyer /*
      4  1.2.6.2  bouyer  * Copyright (c) 2000 Michael Graff.  All rights reserved.
      5  1.2.6.2  bouyer  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      6  1.2.6.2  bouyer  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      7  1.2.6.2  bouyer  *
      8  1.2.6.2  bouyer  * This code is derived from public-domain software written by
      9  1.2.6.2  bouyer  * Roland McGrath, and information provided by David Muir Sharnoff.
     10  1.2.6.2  bouyer  *
     11  1.2.6.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.2.6.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.2.6.2  bouyer  * are met:
     14  1.2.6.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.2.6.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     16  1.2.6.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.2.6.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     18  1.2.6.2  bouyer  *    documentation and/or other materials provided with the distribution.
     19  1.2.6.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     20  1.2.6.2  bouyer  *    must display the following acknowledgement:
     21  1.2.6.2  bouyer  *	This product includes software developed by Charles M. Hannum.
     22  1.2.6.2  bouyer  * 4. The name of the author may not be used to endorse or promote products
     23  1.2.6.2  bouyer  *    derived from this software without specific prior written permission.
     24  1.2.6.2  bouyer  *
     25  1.2.6.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     26  1.2.6.2  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     27  1.2.6.2  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  1.2.6.2  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     29  1.2.6.2  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     30  1.2.6.2  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     31  1.2.6.2  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     32  1.2.6.2  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     33  1.2.6.2  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     34  1.2.6.2  bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  1.2.6.2  bouyer  */
     36  1.2.6.2  bouyer 
     37  1.2.6.2  bouyer /*
     38  1.2.6.2  bouyer  * This code was written and tested with the Addonics FlexPort 8S.
     39  1.2.6.2  bouyer  * It has 8 ports, using 16650-compatible chips, sharing a single
     40  1.2.6.2  bouyer  * interrupt.
     41  1.2.6.2  bouyer  *
     42  1.2.6.2  bouyer  * An interrupt status register exists at 0x240, according to the
     43  1.2.6.2  bouyer  * skimpy documentation supplied.  It doesn't change depending on
     44  1.2.6.2  bouyer  * io base address, so only one of these cards can ever be used at
     45  1.2.6.2  bouyer  * a time.
     46  1.2.6.2  bouyer  *
     47  1.2.6.2  bouyer  * This card is different from the boca or other cards in that ports
     48  1.2.6.2  bouyer  * 0..5 are from addresses 0x108..0x137, and 6..7 are from 0x200..0x20f,
     49  1.2.6.2  bouyer  * making a gap that the other cards do not have.
     50  1.2.6.2  bouyer  *
     51  1.2.6.2  bouyer  * The addresses which are documented are 0x108, 0x1108, 0x1d08, and
     52  1.2.6.2  bouyer  * 0x8508, for the base (port 0) address.
     53  1.2.6.2  bouyer  *
     54  1.2.6.2  bouyer  * --Michael <explorer (at) netbsd.org> -- April 21, 2000
     55  1.2.6.2  bouyer  */
     56  1.2.6.2  bouyer 
     57  1.2.6.2  bouyer #include <sys/param.h>
     58  1.2.6.2  bouyer #include <sys/systm.h>
     59  1.2.6.2  bouyer #include <sys/device.h>
     60  1.2.6.2  bouyer #include <sys/termios.h>
     61  1.2.6.2  bouyer 
     62  1.2.6.2  bouyer #include <machine/bus.h>
     63  1.2.6.2  bouyer #include <machine/intr.h>
     64  1.2.6.2  bouyer 
     65  1.2.6.2  bouyer #include <dev/ic/comreg.h>
     66  1.2.6.2  bouyer #include <dev/ic/comvar.h>
     67  1.2.6.2  bouyer 
     68  1.2.6.2  bouyer #include <dev/isa/isavar.h>
     69  1.2.6.2  bouyer #include <dev/isa/com_multi.h>
     70  1.2.6.2  bouyer 
     71  1.2.6.2  bouyer #define	NSLAVES	8
     72  1.2.6.2  bouyer 
     73  1.2.6.2  bouyer /*
     74  1.2.6.2  bouyer  * Grr.  This card always uses 0x420 for the status register, regardless
     75  1.2.6.2  bouyer  * of io base address.
     76  1.2.6.2  bouyer  */
     77  1.2.6.2  bouyer #define STATUS_IOADDR	0x420
     78  1.2.6.2  bouyer #define	STATUS_SIZE	8		/* May be bogus... */
     79  1.2.6.2  bouyer 
     80  1.2.6.2  bouyer struct addcom_softc {
     81  1.2.6.2  bouyer 	struct device sc_dev;
     82  1.2.6.2  bouyer 	void *sc_ih;
     83  1.2.6.2  bouyer 
     84  1.2.6.2  bouyer 	bus_space_tag_t sc_iot;
     85  1.2.6.2  bouyer 	int sc_iobase;
     86  1.2.6.2  bouyer 
     87  1.2.6.2  bouyer 	int sc_alive;			/* mask of slave units attached */
     88  1.2.6.2  bouyer 	void *sc_slaves[NSLAVES];	/* com device unit numbers */
     89  1.2.6.2  bouyer 	bus_space_handle_t sc_slaveioh[NSLAVES];
     90  1.2.6.2  bouyer 	bus_space_handle_t sc_statusioh;
     91  1.2.6.2  bouyer };
     92  1.2.6.2  bouyer 
     93  1.2.6.2  bouyer #define SLAVE_IOBASE_OFFSET 0x108
     94  1.2.6.2  bouyer static int slave_iobases[8] = {
     95  1.2.6.2  bouyer 	0x108,	/* port 0, base port */
     96  1.2.6.2  bouyer 	0x110,
     97  1.2.6.2  bouyer 	0x118,
     98  1.2.6.2  bouyer 	0x120,
     99  1.2.6.2  bouyer 	0x128,
    100  1.2.6.2  bouyer 	0x130,
    101  1.2.6.2  bouyer 	0x200,	/* port 7, note address skip... */
    102  1.2.6.2  bouyer 	0x208
    103  1.2.6.2  bouyer };
    104  1.2.6.2  bouyer 
    105  1.2.6.2  bouyer int addcomprobe __P((struct device *, struct cfdata *, void *));
    106  1.2.6.2  bouyer void addcomattach __P((struct device *, struct device *, void *));
    107  1.2.6.2  bouyer int addcomintr __P((void *));
    108  1.2.6.2  bouyer int addcomprint __P((void *, const char *));
    109  1.2.6.2  bouyer 
    110  1.2.6.2  bouyer struct cfattach addcom_isa_ca = {
    111  1.2.6.2  bouyer 	sizeof(struct addcom_softc), addcomprobe, addcomattach,
    112  1.2.6.2  bouyer };
    113  1.2.6.2  bouyer 
    114  1.2.6.2  bouyer int
    115  1.2.6.2  bouyer addcomprobe(struct device *parent, struct cfdata *self, void *aux)
    116  1.2.6.2  bouyer {
    117  1.2.6.2  bouyer 	struct isa_attach_args *ia = aux;
    118  1.2.6.2  bouyer 	int iobase = ia->ia_iobase;
    119  1.2.6.2  bouyer 	bus_space_tag_t iot = ia->ia_iot;
    120  1.2.6.2  bouyer 	bus_space_handle_t ioh;
    121  1.2.6.2  bouyer 	int i, rv = 1;
    122  1.2.6.2  bouyer 
    123  1.2.6.2  bouyer 	/*
    124  1.2.6.2  bouyer 	 * Do the normal com probe for the first UART and assume
    125  1.2.6.2  bouyer 	 * its presence, and the ability to map the other UARTS,
    126  1.2.6.2  bouyer 	 * means there is a multiport board there.
    127  1.2.6.2  bouyer 	 * XXX Needs more robustness.
    128  1.2.6.2  bouyer 	 */
    129  1.2.6.2  bouyer 
    130  1.2.6.2  bouyer 	/* Disallow wildcarded i/o address. */
    131  1.2.6.2  bouyer 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    132  1.2.6.2  bouyer 		return (0);
    133  1.2.6.2  bouyer 
    134  1.2.6.2  bouyer 	/* if the first port is in use as console, then it. */
    135  1.2.6.2  bouyer 	if (com_is_console(iot, iobase, 0))
    136  1.2.6.2  bouyer 		goto checkmappings;
    137  1.2.6.2  bouyer 
    138  1.2.6.2  bouyer 	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    139  1.2.6.2  bouyer 		rv = 0;
    140  1.2.6.2  bouyer 		goto out;
    141  1.2.6.2  bouyer 	}
    142  1.2.6.2  bouyer 	rv = comprobe1(iot, ioh);
    143  1.2.6.2  bouyer 	bus_space_unmap(iot, ioh, COM_NPORTS);
    144  1.2.6.2  bouyer 	if (rv == 0)
    145  1.2.6.2  bouyer 		goto out;
    146  1.2.6.2  bouyer 
    147  1.2.6.2  bouyer checkmappings:
    148  1.2.6.2  bouyer 	for (i = 1; i < NSLAVES; i++) {
    149  1.2.6.2  bouyer 		iobase += slave_iobases[i] - slave_iobases[i - 1];
    150  1.2.6.2  bouyer 
    151  1.2.6.2  bouyer 		if (com_is_console(iot, iobase, 0))
    152  1.2.6.2  bouyer 			continue;
    153  1.2.6.2  bouyer 
    154  1.2.6.2  bouyer 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    155  1.2.6.2  bouyer 			rv = 0;
    156  1.2.6.2  bouyer 			goto out;
    157  1.2.6.2  bouyer 		}
    158  1.2.6.2  bouyer 		bus_space_unmap(iot, ioh, COM_NPORTS);
    159  1.2.6.2  bouyer 	}
    160  1.2.6.2  bouyer 
    161  1.2.6.2  bouyer out:
    162  1.2.6.2  bouyer 	if (rv)
    163  1.2.6.2  bouyer 		ia->ia_iosize = NSLAVES * COM_NPORTS;
    164  1.2.6.2  bouyer 	return (rv);
    165  1.2.6.2  bouyer }
    166  1.2.6.2  bouyer 
    167  1.2.6.2  bouyer int
    168  1.2.6.2  bouyer addcomprint(void *aux, const char *pnp)
    169  1.2.6.2  bouyer {
    170  1.2.6.2  bouyer 	struct commulti_attach_args *ca = aux;
    171  1.2.6.2  bouyer 
    172  1.2.6.2  bouyer 	if (pnp)
    173  1.2.6.2  bouyer 		printf("com at %s", pnp);
    174  1.2.6.2  bouyer 	printf(" slave %d", ca->ca_slave);
    175  1.2.6.2  bouyer 	return (UNCONF);
    176  1.2.6.2  bouyer }
    177  1.2.6.2  bouyer 
    178  1.2.6.2  bouyer void
    179  1.2.6.2  bouyer addcomattach(struct device *parent, struct device *self, void *aux)
    180  1.2.6.2  bouyer {
    181  1.2.6.2  bouyer 	struct addcom_softc *sc = (void *)self;
    182  1.2.6.2  bouyer 	struct isa_attach_args *ia = aux;
    183  1.2.6.2  bouyer 	struct commulti_attach_args ca;
    184  1.2.6.2  bouyer 	bus_space_tag_t iot = ia->ia_iot;
    185  1.2.6.2  bouyer 	int i, iobase;
    186  1.2.6.2  bouyer 
    187  1.2.6.2  bouyer 	printf("\n");
    188  1.2.6.2  bouyer 
    189  1.2.6.2  bouyer 	sc->sc_iot = ia->ia_iot;
    190  1.2.6.2  bouyer 	sc->sc_iobase = ia->ia_iobase;
    191  1.2.6.2  bouyer 
    192  1.2.6.2  bouyer 	if (bus_space_map(iot, STATUS_IOADDR, STATUS_SIZE,
    193  1.2.6.2  bouyer 			  0, &sc->sc_statusioh)) {
    194  1.2.6.2  bouyer 		printf("%s: can't map status space\n", sc->sc_dev.dv_xname);
    195  1.2.6.2  bouyer 		return;
    196  1.2.6.2  bouyer 	}
    197  1.2.6.2  bouyer 
    198  1.2.6.2  bouyer 	for (i = 0; i < NSLAVES; i++) {
    199  1.2.6.2  bouyer 		iobase = sc->sc_iobase
    200  1.2.6.2  bouyer 			+ slave_iobases[i]
    201  1.2.6.2  bouyer 			- SLAVE_IOBASE_OFFSET;
    202  1.2.6.2  bouyer 		if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) &&
    203  1.2.6.2  bouyer 		    bus_space_map(iot, iobase, COM_NPORTS, 0,
    204  1.2.6.2  bouyer 				  &sc->sc_slaveioh[i])) {
    205  1.2.6.2  bouyer 			printf("%s: can't map i/o space for slave %d\n",
    206  1.2.6.2  bouyer 			       sc->sc_dev.dv_xname, i);
    207  1.2.6.2  bouyer 			return;
    208  1.2.6.2  bouyer 		}
    209  1.2.6.2  bouyer 	}
    210  1.2.6.2  bouyer 
    211  1.2.6.2  bouyer 	for (i = 0; i < NSLAVES; i++) {
    212  1.2.6.2  bouyer 		ca.ca_slave = i;
    213  1.2.6.2  bouyer 		ca.ca_iot = sc->sc_iot;
    214  1.2.6.2  bouyer 		ca.ca_ioh = sc->sc_slaveioh[i];
    215  1.2.6.2  bouyer 		ca.ca_iobase = sc->sc_iobase
    216  1.2.6.2  bouyer 			+ slave_iobases[i]
    217  1.2.6.2  bouyer 			- SLAVE_IOBASE_OFFSET;
    218  1.2.6.2  bouyer 		ca.ca_noien = 0;
    219  1.2.6.2  bouyer 
    220  1.2.6.2  bouyer 		sc->sc_slaves[i] = config_found(self, &ca, addcomprint);
    221  1.2.6.2  bouyer 		if (sc->sc_slaves[i] != NULL)
    222  1.2.6.2  bouyer 			sc->sc_alive |= 1 << i;
    223  1.2.6.2  bouyer 	}
    224  1.2.6.2  bouyer 
    225  1.2.6.2  bouyer 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    226  1.2.6.2  bouyer 				       IPL_SERIAL, addcomintr, sc);
    227  1.2.6.2  bouyer }
    228  1.2.6.2  bouyer 
    229  1.2.6.2  bouyer int
    230  1.2.6.2  bouyer addcomintr(void *arg)
    231  1.2.6.2  bouyer {
    232  1.2.6.2  bouyer 	struct addcom_softc *sc = arg;
    233  1.2.6.2  bouyer 	bus_space_tag_t iot = sc->sc_iot;
    234  1.2.6.2  bouyer 	int alive = sc->sc_alive;
    235  1.2.6.2  bouyer 	int bits;
    236  1.2.6.2  bouyer 
    237  1.2.6.2  bouyer 	bits = bus_space_read_1(iot, sc->sc_statusioh, 0) & alive;
    238  1.2.6.2  bouyer 	if (bits == 0)
    239  1.2.6.2  bouyer 		return (0);
    240  1.2.6.2  bouyer 
    241  1.2.6.2  bouyer 	for (;;) {
    242  1.2.6.2  bouyer #define	TRY(n) \
    243  1.2.6.2  bouyer 		if (bits & (1 << (n))) \
    244  1.2.6.2  bouyer 			comintr(sc->sc_slaves[n]);
    245  1.2.6.2  bouyer 		TRY(0);
    246  1.2.6.2  bouyer 		TRY(1);
    247  1.2.6.2  bouyer 		TRY(2);
    248  1.2.6.2  bouyer 		TRY(3);
    249  1.2.6.2  bouyer 		TRY(4);
    250  1.2.6.2  bouyer 		TRY(5);
    251  1.2.6.2  bouyer 		TRY(6);
    252  1.2.6.2  bouyer 		TRY(7);
    253  1.2.6.2  bouyer #undef TRY
    254  1.2.6.2  bouyer 		bits = bus_space_read_1(iot, sc->sc_statusioh, 0) & alive;
    255  1.2.6.2  bouyer 		if (bits == 0)
    256  1.2.6.2  bouyer 			return (1);
    257  1.2.6.2  bouyer  	}
    258  1.2.6.2  bouyer }
    259