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