Home | History | Annotate | Line # | Download | only in isa
ast.c revision 1.24
      1 /*	$NetBSD: ast.c,v 1.24 1996/04/04 07:08:10 cgd 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/device.h>
     38 
     39 #include <machine/bus.h>
     40 
     41 #include <dev/isa/isavar.h>
     42 #include <dev/isa/comreg.h>
     43 #include <dev/isa/comvar.h>
     44 
     45 #define	NSLAVES	4
     46 
     47 struct ast_softc {
     48 	struct device sc_dev;
     49 	void *sc_ih;
     50 
     51 	bus_chipset_tag_t sc_bc;
     52 	int sc_iobase;
     53 
     54 	int sc_alive;			/* mask of slave units attached */
     55 	void *sc_slaves[NSLAVES];	/* com device unit numbers */
     56 	bus_io_handle_t sc_slaveioh[NSLAVES];
     57 };
     58 
     59 int astprobe();
     60 void astattach();
     61 int astintr __P((void *));
     62 
     63 struct cfattach ast_ca = {
     64 	sizeof(struct ast_softc), astprobe, astattach
     65 };
     66 
     67 struct cfdriver ast_cd = {
     68 	NULL, "ast", DV_TTY
     69 };
     70 
     71 int
     72 astprobe(parent, self, aux)
     73 	struct device *parent, *self;
     74 	void *aux;
     75 {
     76 	struct isa_attach_args *ia = aux;
     77 	int iobase = ia->ia_iobase;
     78 	bus_chipset_tag_t bc = ia->ia_bc;
     79 	bus_io_handle_t ioh;
     80 	int i, rv = 1;
     81 
     82 	/*
     83 	 * Do the normal com probe for the first UART and assume
     84 	 * its presence, and the ability to map the other UARTS,
     85 	 * means there is a multiport board there.
     86 	 * XXX Needs more robustness.
     87 	 */
     88 
     89 	/* if the first port is in use as console, then it. */
     90 	if (iobase == comconsaddr && !comconsattached)
     91 		goto checkmappings;
     92 
     93 	if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
     94 		rv = 0;
     95 		goto out;
     96 	}
     97 	rv = comprobe1(bc, ioh, iobase);
     98 	bus_io_unmap(bc, ioh, COM_NPORTS);
     99 	if (rv == 0)
    100 		goto out;
    101 
    102 checkmappings:
    103 	for (i = 1; i < NSLAVES; i++) {
    104 		iobase += COM_NPORTS;
    105 
    106 		if (iobase == comconsaddr && !comconsattached)
    107 			continue;
    108 
    109 		if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
    110 			rv = 0;
    111 			goto out;
    112 		}
    113 		bus_io_unmap(bc, ioh, COM_NPORTS);
    114 	}
    115 
    116 out:
    117 	if (rv)
    118 		ia->ia_iosize = NSLAVES * COM_NPORTS;
    119 	return (rv);
    120 }
    121 
    122 int
    123 astprint(aux, pnp)
    124 	void *aux;
    125 	char *pnp;
    126 {
    127 	struct commulti_attach_args *ca = aux;
    128 
    129 	if (pnp)
    130 		printf("com at %s", pnp);
    131 	printf(" slave %d", ca->ca_slave);
    132 	return (UNCONF);
    133 }
    134 
    135 void
    136 astattach(parent, self, aux)
    137 	struct device *parent, *self;
    138 	void *aux;
    139 {
    140 	struct ast_softc *sc = (void *)self;
    141 	struct isa_attach_args *ia = aux;
    142 	struct commulti_attach_args ca;
    143 	int i, subunit;
    144 
    145 	sc->sc_bc = ia->ia_bc;
    146 	sc->sc_iobase = ia->ia_iobase;
    147 
    148 	for (i = 0; i < NSLAVES; i++)
    149 		if (bus_io_map(bc, sc->sc_iobase + i * COM_NPORTS, COM_NPORTS,
    150 		    &sc->sc_slaveioh[i]))
    151 			panic("astattach: couldn't map slave %d", i);
    152 
    153 	/*
    154 	 * Enable the master interrupt.
    155 	 */
    156 	bus_io_write_1(bc, sc->sc_slaveioh[3], 7, 0x80);
    157 
    158 	printf("\n");
    159 
    160 	for (i = 0; i < NSLAVES; i++) {
    161 		struct cfdata *match;
    162 
    163 		ca.ca_slave = i;
    164 		ca.ca_bc = sc->sc_bc;
    165 		ca.ca_ioh = sc->sc_slaveioh[i];
    166 		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
    167 		ca.ca_noien = 1;
    168 
    169 		sc->sc_slaves[i] = config_found(self, &ca, astprint);
    170 		if (sc->sc_slaves[i] != NULL)
    171 			sc->sc_alive |= 1 << i;
    172 	}
    173 
    174 	sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, astintr,
    175 	    sc);
    176 }
    177 
    178 int
    179 astintr(arg)
    180 	void *arg;
    181 {
    182 	struct ast_softc *sc = arg;
    183 	bus_chipset_tag_t bc = sc->sc_bc;
    184 	int alive = sc->sc_alive;
    185 	int bits;
    186 
    187 	bits = ~bus_io_read_1(bc, sc->sc_slaveioh[3], 7) & alive;
    188 	if (bits == 0)
    189 		return (0);
    190 
    191 	for (;;) {
    192 #define	TRY(n) \
    193 		if (bits & (1 << (n))) \
    194 			comintr(sc->sc_slaves[n]);
    195 		TRY(0);
    196 		TRY(1);
    197 		TRY(2);
    198 		TRY(3);
    199 #undef TRY
    200 		bits = ~bus_io_read_1(bc, sc->sc_slaveioh[3], 7) & alive;
    201 		if (bits == 0)
    202 			return (1);
    203  	}
    204 }
    205