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