Home | History | Annotate | Line # | Download | only in isa
boca.c revision 1.50.4.2
      1  1.50.4.2      yamt /*	$NetBSD: boca.c,v 1.50.4.2 2009/05/16 10:41:25 yamt Exp $	*/
      2       1.1   mycroft 
      3       1.1   mycroft /*
      4       1.9       cgd  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      5      1.31   mycroft  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      6       1.1   mycroft  *
      7       1.2   mycroft  * This code is derived from public-domain software written by
      8       1.2   mycroft  * Roland McGrath, and information provided by David Muir Sharnoff.
      9       1.1   mycroft  *
     10       1.2   mycroft  * Redistribution and use in source and binary forms, with or without
     11       1.2   mycroft  * modification, are permitted provided that the following conditions
     12       1.2   mycroft  * are met:
     13       1.2   mycroft  * 1. Redistributions of source code must retain the above copyright
     14       1.2   mycroft  *    notice, this list of conditions and the following disclaimer.
     15       1.2   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.2   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17       1.2   mycroft  *    documentation and/or other materials provided with the distribution.
     18       1.2   mycroft  * 3. All advertising materials mentioning features or use of this software
     19       1.2   mycroft  *    must display the following acknowledgement:
     20      1.31   mycroft  *	This product includes software developed by Charles M. Hannum.
     21       1.2   mycroft  * 4. The name of the author may not be used to endorse or promote products
     22       1.2   mycroft  *    derived from this software without specific prior written permission.
     23       1.2   mycroft  *
     24       1.2   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25       1.2   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26       1.2   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27       1.2   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28       1.2   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29       1.2   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30       1.2   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31       1.2   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32       1.2   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33       1.2   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34       1.1   mycroft  */
     35      1.35     lukem 
     36      1.35     lukem #include <sys/cdefs.h>
     37  1.50.4.2      yamt __KERNEL_RCSID(0, "$NetBSD: boca.c,v 1.50.4.2 2009/05/16 10:41:25 yamt Exp $");
     38       1.1   mycroft 
     39       1.1   mycroft #include <sys/param.h>
     40      1.14  christos #include <sys/systm.h>
     41       1.1   mycroft #include <sys/device.h>
     42      1.13       cgd #include <sys/termios.h>
     43      1.34    bouyer #include <sys/kernel.h>
     44      1.34    bouyer #include <sys/callout.h>
     45       1.1   mycroft 
     46      1.49        ad #include <sys/bus.h>
     47      1.49        ad #include <sys/intr.h>
     48       1.1   mycroft 
     49      1.25   thorpej #include <dev/ic/comreg.h>
     50      1.25   thorpej #include <dev/ic/comvar.h>
     51      1.25   thorpej 
     52       1.4       cgd #include <dev/isa/isavar.h>
     53      1.20   mycroft #include <dev/isa/com_multi.h>
     54       1.7       cgd 
     55       1.7       cgd #define	NSLAVES	8
     56       1.1   mycroft 
     57       1.1   mycroft struct boca_softc {
     58       1.1   mycroft 	struct device sc_dev;
     59       1.4       cgd 	void *sc_ih;
     60       1.1   mycroft 
     61      1.19   thorpej 	bus_space_tag_t sc_iot;
     62       1.1   mycroft 	int sc_iobase;
     63       1.9       cgd 
     64       1.7       cgd 	int sc_alive;			/* mask of slave units attached */
     65       1.7       cgd 	void *sc_slaves[NSLAVES];	/* com device unit numbers */
     66      1.19   thorpej 	bus_space_handle_t sc_slaveioh[NSLAVES];
     67      1.48        ad 	callout_t fixup;
     68       1.1   mycroft };
     69       1.1   mycroft 
     70  1.50.4.2      yamt int bocaprobe(device_t, cfdata_t, void *);
     71  1.50.4.2      yamt void bocaattach(device_t, device_t, void *);
     72      1.44     perry int bocaintr(void *);
     73      1.44     perry void boca_fixup(void *);
     74       1.1   mycroft 
     75      1.38   thorpej CFATTACH_DECL(boca, sizeof(struct boca_softc),
     76      1.39   thorpej     bocaprobe, bocaattach, NULL, NULL);
     77       1.1   mycroft 
     78       1.1   mycroft int
     79  1.50.4.2      yamt bocaprobe(device_t parent, cfdata_t self, void *aux)
     80       1.1   mycroft {
     81       1.1   mycroft 	struct isa_attach_args *ia = aux;
     82      1.19   thorpej 	bus_space_tag_t iot = ia->ia_iot;
     83      1.19   thorpej 	bus_space_handle_t ioh;
     84      1.36   thorpej 	int i, iobase, rv = 1;
     85       1.1   mycroft 
     86       1.1   mycroft 	/*
     87       1.1   mycroft 	 * Do the normal com probe for the first UART and assume
     88       1.9       cgd 	 * its presence, and the ability to map the other UARTS,
     89       1.9       cgd 	 * means there is a multiport board there.
     90       1.1   mycroft 	 * XXX Needs more robustness.
     91       1.1   mycroft 	 */
     92      1.26   thorpej 
     93      1.36   thorpej 	if (ia->ia_nio < 1)
     94      1.36   thorpej 		return (0);
     95      1.36   thorpej 	if (ia->ia_nirq < 1)
     96      1.36   thorpej 		return (0);
     97      1.36   thorpej 
     98      1.36   thorpej 	if (ISA_DIRECT_CONFIG(ia))
     99      1.36   thorpej 		return (0);
    100      1.36   thorpej 
    101      1.26   thorpej 	/* Disallow wildcarded i/o address. */
    102      1.43  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    103      1.36   thorpej 		return (0);
    104      1.43  drochner 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
    105      1.26   thorpej 		return (0);
    106       1.1   mycroft 
    107      1.40       chs 	iobase = ia->ia_io[0].ir_addr;
    108      1.40       chs 
    109       1.9       cgd 	/* if the first port is in use as console, then it. */
    110      1.23  drochner 	if (com_is_console(iot, iobase, 0))
    111       1.9       cgd 		goto checkmappings;
    112       1.9       cgd 
    113      1.19   thorpej 	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    114       1.9       cgd 		rv = 0;
    115       1.9       cgd 		goto out;
    116       1.9       cgd 	}
    117      1.32     enami 	rv = comprobe1(iot, ioh);
    118      1.19   thorpej 	bus_space_unmap(iot, ioh, COM_NPORTS);
    119       1.9       cgd 	if (rv == 0)
    120       1.9       cgd 		goto out;
    121       1.9       cgd 
    122       1.9       cgd checkmappings:
    123      1.40       chs 	for (i = 1; i < NSLAVES; i++) {
    124       1.9       cgd 		iobase += COM_NPORTS;
    125       1.9       cgd 
    126      1.23  drochner 		if (com_is_console(iot, iobase, 0))
    127      1.23  drochner 			continue;
    128       1.9       cgd 
    129      1.19   thorpej 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    130       1.9       cgd 			rv = 0;
    131       1.9       cgd 			goto out;
    132       1.9       cgd 		}
    133      1.19   thorpej 		bus_space_unmap(iot, ioh, COM_NPORTS);
    134       1.9       cgd 	}
    135       1.1   mycroft 
    136       1.9       cgd out:
    137      1.36   thorpej 	if (rv) {
    138      1.36   thorpej 		ia->ia_nio = 1;
    139      1.36   thorpej 		ia->ia_io[0].ir_size = NSLAVES * COM_NPORTS;
    140      1.36   thorpej 
    141      1.36   thorpej 		ia->ia_nirq = 1;
    142      1.36   thorpej 
    143      1.36   thorpej 		ia->ia_niomem = 0;
    144      1.36   thorpej 		ia->ia_ndrq = 0;
    145      1.36   thorpej 	}
    146       1.9       cgd 	return (rv);
    147       1.1   mycroft }
    148       1.1   mycroft 
    149       1.1   mycroft void
    150  1.50.4.2      yamt bocaattach(device_t parent, device_t self, void *aux)
    151       1.1   mycroft {
    152       1.1   mycroft 	struct boca_softc *sc = (void *)self;
    153       1.1   mycroft 	struct isa_attach_args *ia = aux;
    154       1.8       cgd 	struct commulti_attach_args ca;
    155      1.19   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    156      1.24  drochner 	int i, iobase;
    157       1.1   mycroft 
    158      1.27   thorpej 	printf("\n");
    159      1.27   thorpej 
    160      1.19   thorpej 	sc->sc_iot = ia->ia_iot;
    161      1.36   thorpej 	sc->sc_iobase = ia->ia_io[0].ir_addr;
    162       1.1   mycroft 
    163      1.24  drochner 	for (i = 0; i < NSLAVES; i++) {
    164      1.24  drochner 		iobase = sc->sc_iobase + i * COM_NPORTS;
    165      1.24  drochner 		if (!com_is_console(iot, iobase, &sc->sc_slaveioh[i]) &&
    166      1.24  drochner 		    bus_space_map(iot, iobase, COM_NPORTS, 0,
    167      1.27   thorpej 			&sc->sc_slaveioh[i])) {
    168      1.50    cegger 			aprint_error_dev(&sc->sc_dev, "can't map i/o space for slave %d\n", i);
    169      1.27   thorpej 			return;
    170      1.27   thorpej 		}
    171      1.24  drochner 	}
    172       1.1   mycroft 
    173       1.9       cgd 	for (i = 0; i < NSLAVES; i++) {
    174       1.9       cgd 
    175       1.9       cgd 		ca.ca_slave = i;
    176      1.19   thorpej 		ca.ca_iot = sc->sc_iot;
    177       1.9       cgd 		ca.ca_ioh = sc->sc_slaveioh[i];
    178       1.9       cgd 		ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
    179       1.9       cgd 		ca.ca_noien = 0;
    180       1.9       cgd 
    181      1.42  drochner 		sc->sc_slaves[i] = config_found(self, &ca, commultiprint);
    182      1.11       cgd 		if (sc->sc_slaves[i] != NULL)
    183       1.9       cgd 			sc->sc_alive |= 1 << i;
    184       1.1   mycroft 	}
    185       1.1   mycroft 
    186      1.36   thorpej 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    187      1.36   thorpej 	    IST_EDGE, IPL_SERIAL, bocaintr, sc);
    188      1.48        ad 	callout_init(&sc->fixup, 0);
    189      1.34    bouyer 	callout_reset(&sc->fixup, hz/10, boca_fixup, sc);
    190       1.1   mycroft }
    191       1.1   mycroft 
    192       1.1   mycroft int
    193  1.50.4.1      yamt bocaintr(void *arg)
    194       1.1   mycroft {
    195       1.4       cgd 	struct boca_softc *sc = arg;
    196      1.19   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    197       1.1   mycroft 	int alive = sc->sc_alive;
    198       1.1   mycroft 	int bits;
    199       1.1   mycroft 
    200      1.33   thorpej 	bits = bus_space_read_1(iot, sc->sc_slaveioh[0], com_scratch) & alive;
    201       1.1   mycroft 	if (bits == 0)
    202       1.1   mycroft 		return (0);
    203       1.1   mycroft 
    204       1.1   mycroft 	for (;;) {
    205       1.1   mycroft #define	TRY(n) \
    206      1.34    bouyer 		if (bits & (1 << (n))) { \
    207      1.34    bouyer 			if (comintr(sc->sc_slaves[n]) == 0) { \
    208      1.34    bouyer 				printf("%s: bogus intr for port %d\n", \
    209      1.50    cegger 				    device_xname(&sc->sc_dev), n); \
    210      1.34    bouyer 			} \
    211      1.34    bouyer 		}
    212       1.1   mycroft 		TRY(0);
    213       1.1   mycroft 		TRY(1);
    214       1.1   mycroft 		TRY(2);
    215       1.1   mycroft 		TRY(3);
    216       1.1   mycroft 		TRY(4);
    217       1.1   mycroft 		TRY(5);
    218       1.1   mycroft 		TRY(6);
    219       1.1   mycroft 		TRY(7);
    220       1.1   mycroft #undef TRY
    221      1.33   thorpej 		bits = bus_space_read_1(iot, sc->sc_slaveioh[0],
    222      1.33   thorpej 		    com_scratch) & alive;
    223      1.34    bouyer 		if (bits == 0) {
    224       1.1   mycroft 			return (1);
    225      1.34    bouyer 		}
    226       1.1   mycroft  	}
    227      1.34    bouyer }
    228      1.34    bouyer 
    229      1.34    bouyer void
    230  1.50.4.1      yamt boca_fixup(void *v)
    231      1.34    bouyer {
    232      1.34    bouyer 	struct boca_softc *sc = v;
    233      1.34    bouyer 	int alive = sc->sc_alive;
    234      1.34    bouyer 	int i, s;
    235      1.34    bouyer 
    236      1.34    bouyer 	s = splserial();
    237      1.34    bouyer 
    238      1.34    bouyer 	for (i = 0; i < 8; i++) {
    239      1.34    bouyer 		if (alive & (1 << (i)))
    240      1.34    bouyer 			comintr(sc->sc_slaves[i]);
    241      1.34    bouyer 	}
    242      1.34    bouyer 	callout_reset(&sc->fixup, hz/10, boca_fixup, sc);
    243      1.34    bouyer 	splx(s);
    244       1.1   mycroft }
    245