Home | History | Annotate | Line # | Download | only in isa
ast.c revision 1.40
      1 /*	$NetBSD: ast.c,v 1.40 1997/10/19 18:56:46 thorpej 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.
      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	4
     51 
     52 struct ast_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 astprobe __P((struct device *, void *, void *));
     66 #else
     67 int astprobe __P((struct device *, struct cfdata *, void *));
     68 #endif
     69 void astattach __P((struct device *, struct device *, void *));
     70 int astintr __P((void *));
     71 int astprint __P((void *, const char *));
     72 
     73 struct cfattach ast_ca = {
     74 	sizeof(struct ast_softc), astprobe, astattach
     75 };
     76 
     77 struct cfdriver ast_cd = {
     78 	NULL, "ast", DV_TTY
     79 };
     80 
     81 int
     82 astprobe(parent, self, aux)
     83 	struct device *parent;
     84 #ifdef __BROKEN_INDIRECT_CONFIG
     85 	void *self;
     86 #else
     87 	struct cfdata *self;
     88 #endif
     89 	void *aux;
     90 {
     91 	struct isa_attach_args *ia = aux;
     92 	int iobase = ia->ia_iobase;
     93 	bus_space_tag_t iot = ia->ia_iot;
     94 	bus_space_handle_t ioh;
     95 	int i, rv = 1;
     96 
     97 	/*
     98 	 * Do the normal com probe for the first UART and assume
     99 	 * its presence, and the ability to map the other UARTS,
    100 	 * means there is a multiport board there.
    101 	 * XXX Needs more robustness.
    102 	 */
    103 
    104 	/* Disallow wildcarded i/o address. */
    105 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    106 		return (0);
    107 
    108 	/* if the first port is in use as console, then it. */
    109 	if (com_is_console(iot, iobase, 0))
    110 		goto checkmappings;
    111 
    112 	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    113 		rv = 0;
    114 		goto out;
    115 	}
    116 	rv = comprobe1(iot, ioh, iobase);
    117 	bus_space_unmap(iot, ioh, COM_NPORTS);
    118 	if (rv == 0)
    119 		goto out;
    120 
    121 checkmappings:
    122 	for (i = 1; i < NSLAVES; i++) {
    123 		iobase += COM_NPORTS;
    124 
    125 		if (com_is_console(iot, iobase, 0))
    126 			continue;
    127 
    128 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    129 			rv = 0;
    130 			goto out;
    131 		}
    132 		bus_space_unmap(iot, ioh, COM_NPORTS);
    133 	}
    134 
    135 out:
    136 	if (rv)
    137 		ia->ia_iosize = NSLAVES * COM_NPORTS;
    138 	return (rv);
    139 }
    140 
    141 int
    142 astprint(aux, pnp)
    143 	void *aux;
    144 	const char *pnp;
    145 {
    146 	struct commulti_attach_args *ca = aux;
    147 
    148 	if (pnp)
    149 		printf("com at %s", pnp);
    150 	printf(" slave %d", ca->ca_slave);
    151 	return (UNCONF);
    152 }
    153 
    154 void
    155 astattach(parent, self, aux)
    156 	struct device *parent, *self;
    157 	void *aux;
    158 {
    159 	struct ast_softc *sc = (void *)self;
    160 	struct isa_attach_args *ia = aux;
    161 	struct commulti_attach_args ca;
    162 	bus_space_tag_t iot = ia->ia_iot;
    163 	int i, iobase;
    164 
    165 	sc->sc_iot = ia->ia_iot;
    166 	sc->sc_iobase = ia->ia_iobase;
    167 
    168 	for (i = 0; i < NSLAVES; i++) {
    169 		iobase = sc->sc_iobase + i * COM_NPORTS;
    170 		if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) &&
    171 		    bus_space_map(iot, iobase, COM_NPORTS, 0,
    172 			&sc->sc_slaveioh[i]))
    173 			panic("astattach: couldn't map slave %d", i);
    174 	}
    175 
    176 	/*
    177 	 * Enable the master interrupt.
    178 	 */
    179 	bus_space_write_1(iot, sc->sc_slaveioh[3], 7, 0x80);
    180 
    181 	printf("\n");
    182 
    183 	for (i = 0; i < NSLAVES; i++) {
    184 		ca.ca_slave = i;
    185 		ca.ca_iot = sc->sc_iot;
    186 		ca.ca_ioh = sc->sc_slaveioh[i];
    187 		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
    188 		ca.ca_noien = 1;
    189 
    190 		sc->sc_slaves[i] = config_found(self, &ca, astprint);
    191 		if (sc->sc_slaves[i] != NULL)
    192 			sc->sc_alive |= 1 << i;
    193 	}
    194 
    195 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    196 	    IPL_SERIAL, astintr, sc);
    197 }
    198 
    199 int
    200 astintr(arg)
    201 	void *arg;
    202 {
    203 	struct ast_softc *sc = arg;
    204 	bus_space_tag_t iot = sc->sc_iot;
    205 	int alive = sc->sc_alive;
    206 	int bits;
    207 
    208 	bits = ~bus_space_read_1(iot, sc->sc_slaveioh[3], 7) & alive;
    209 	if (bits == 0)
    210 		return (0);
    211 
    212 	for (;;) {
    213 #define	TRY(n) \
    214 		if (bits & (1 << (n))) \
    215 			comintr(sc->sc_slaves[n]);
    216 		TRY(0);
    217 		TRY(1);
    218 		TRY(2);
    219 		TRY(3);
    220 #undef TRY
    221 		bits = ~bus_space_read_1(iot, sc->sc_slaveioh[3], 7) & alive;
    222 		if (bits == 0)
    223 			return (1);
    224  	}
    225 }
    226