Home | History | Annotate | Line # | Download | only in qbus
dz_uba.c revision 1.24
      1  1.24   thorpej /*	$NetBSD: dz_uba.c,v 1.24 2006/03/29 18:17:36 thorpej Exp $ */
      2   1.1     ragge /*
      3   1.1     ragge  * Copyright (c) 1998 Ludd, University of Lule}, Sweden. All rights reserved.
      4   1.1     ragge  * Copyright (c) 1996  Ken C. Wellsch.  All rights reserved.
      5   1.1     ragge  *
      6   1.1     ragge  * Redistribution and use in source and binary forms, with or without
      7   1.1     ragge  * modification, are permitted provided that the following conditions
      8   1.1     ragge  * are met:
      9   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     10   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     11   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     13   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     14   1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     15   1.1     ragge  *    must display the following acknowledgement:
     16  1.22    simonb  *      This product includes software developed at Ludd, University of
     17   1.1     ragge  *      Lule}, Sweden and its contributors.
     18   1.1     ragge  * 4. The name of the author may not be used to endorse or promote products
     19   1.1     ragge  *    derived from this software without specific prior written permission
     20   1.1     ragge  *
     21   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1     ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1     ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1     ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1     ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1     ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1     ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1     ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1     ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1     ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1     ragge  */
     32  1.13     lukem 
     33  1.13     lukem #include <sys/cdefs.h>
     34  1.24   thorpej __KERNEL_RCSID(0, "$NetBSD: dz_uba.c,v 1.24 2006/03/29 18:17:36 thorpej Exp $");
     35   1.1     ragge 
     36   1.1     ragge #include <sys/param.h>
     37   1.1     ragge #include <sys/systm.h>
     38   1.1     ragge #include <sys/ioctl.h>
     39   1.1     ragge #include <sys/tty.h>
     40   1.1     ragge #include <sys/proc.h>
     41   1.1     ragge #include <sys/buf.h>
     42   1.1     ragge #include <sys/conf.h>
     43   1.1     ragge #include <sys/file.h>
     44   1.1     ragge #include <sys/uio.h>
     45   1.1     ragge #include <sys/kernel.h>
     46   1.1     ragge #include <sys/syslog.h>
     47   1.1     ragge #include <sys/device.h>
     48   1.1     ragge 
     49   1.4     ragge #include <machine/bus.h>
     50   1.1     ragge #include <machine/pte.h>
     51   1.1     ragge #include <machine/trap.h>
     52   1.2     ragge #include <machine/scb.h>
     53   1.1     ragge 
     54   1.7     ragge #include <dev/qbus/ubavar.h>
     55   1.1     ragge 
     56  1.14        ad #include <dev/dec/dzreg.h>
     57  1.14        ad #include <dev/dec/dzvar.h>
     58   1.1     ragge 
     59   1.1     ragge #include "ioconf.h"
     60   1.1     ragge 
     61  1.21     perry static	int	dz_uba_match(struct device *, struct cfdata *, void *);
     62  1.21     perry static	void	dz_uba_attach(struct device *, struct device *, void *);
     63   1.1     ragge 
     64  1.18   thorpej CFATTACH_DECL(dz_uba, sizeof(struct dz_softc),
     65  1.19   thorpej     dz_uba_match, dz_uba_attach, NULL, NULL);
     66   1.1     ragge 
     67   1.1     ragge /* Autoconfig handles: setup the controller to interrupt, */
     68   1.1     ragge /* then complete the housecleaning for full operation */
     69   1.1     ragge 
     70   1.1     ragge static int
     71   1.1     ragge dz_uba_match(parent, cf, aux)
     72  1.22    simonb 	struct device *parent;
     73   1.1     ragge 	struct cfdata *cf;
     74  1.22    simonb 	void *aux;
     75   1.1     ragge {
     76   1.1     ragge 	struct uba_attach_args *ua = aux;
     77   1.4     ragge 	bus_space_tag_t	iot = ua->ua_iot;
     78   1.4     ragge 	bus_space_handle_t ioh = ua->ua_ioh;
     79   1.9  augustss 	int n;
     80   1.1     ragge 
     81   1.4     ragge 	iot = iot; /* Silly GCC */
     82   1.1     ragge 	/* Reset controller to initialize, enable TX interrupts */
     83   1.1     ragge 	/* to catch floating vector info elsewhere when completed */
     84   1.1     ragge 
     85   1.4     ragge 	bus_space_write_2(iot, ioh, DZ_UBA_CSR, DZ_CSR_MSE | DZ_CSR_TXIE);
     86   1.4     ragge 	bus_space_write_1(iot, ioh, DZ_UBA_TCR, 1);
     87   1.1     ragge 
     88   1.1     ragge 	DELAY(100000);	/* delay 1/10 second */
     89   1.1     ragge 
     90   1.4     ragge 	bus_space_write_2(iot, ioh, DZ_UBA_CSR, DZ_CSR_RESET);
     91   1.1     ragge 
     92   1.1     ragge 	/* Now wait up to 3 seconds for reset/clear to complete. */
     93   1.1     ragge 
     94   1.1     ragge 	for (n = 0; n < 300; n++) {
     95   1.1     ragge 		DELAY(10000);
     96   1.4     ragge 		if ((bus_space_read_2(iot, ioh, DZ_UBA_CSR)&DZ_CSR_RESET) == 0)
     97   1.1     ragge 			break;
     98   1.1     ragge 	}
     99   1.1     ragge 
    100   1.1     ragge 	/* If the RESET did not clear after 3 seconds, */
    101   1.1     ragge 	/* the controller must be broken. */
    102   1.1     ragge 
    103   1.1     ragge 	if (n >= 300)
    104   1.1     ragge 		return (0);
    105   1.1     ragge 
    106   1.1     ragge 	/* Register the TX interrupt handler */
    107   1.1     ragge 
    108   1.1     ragge 
    109  1.22    simonb 	return (1);
    110   1.1     ragge }
    111   1.1     ragge 
    112   1.1     ragge static void
    113   1.1     ragge dz_uba_attach(parent, self, aux)
    114  1.22    simonb 	struct device *parent, *self;
    115  1.22    simonb 	void *aux;
    116   1.1     ragge {
    117  1.24   thorpej 	struct dz_softc *sc = device_private(self);
    118   1.9  augustss 	struct uba_attach_args *ua = aux;
    119   1.1     ragge 
    120   1.4     ragge 	sc->sc_iot = ua->ua_iot;
    121   1.4     ragge 	sc->sc_ioh = ua->ua_ioh;
    122   1.4     ragge 
    123   1.4     ragge 	sc->sc_dr.dr_csr = DZ_UBA_CSR;
    124   1.4     ragge 	sc->sc_dr.dr_rbuf = DZ_UBA_RBUF;
    125   1.4     ragge 	sc->sc_dr.dr_dtr = DZ_UBA_DTR;
    126   1.4     ragge 	sc->sc_dr.dr_break = DZ_UBA_BREAK;
    127   1.4     ragge 	sc->sc_dr.dr_tbuf = DZ_UBA_TBUF;
    128   1.4     ragge 	sc->sc_dr.dr_tcr = DZ_UBA_TCR;
    129   1.4     ragge 	sc->sc_dr.dr_dcd = DZ_UBA_DCD;
    130   1.4     ragge 	sc->sc_dr.dr_ring = DZ_UBA_RING;
    131  1.20        ad 
    132  1.20        ad 	sc->sc_dr.dr_firstreg = DZ_UBA_FIRSTREG;
    133  1.20        ad 	sc->sc_dr.dr_winsize = DZ_UBA_WINSIZE;
    134   1.4     ragge 
    135   1.4     ragge 	sc->sc_type = DZ_DZ;
    136   1.1     ragge 
    137   1.8      matt 	/* Now register the TX & RX interrupt handlers */
    138  1.11      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec,
    139  1.11      matt 		dzxint, sc, &sc->sc_tintrcnt);
    140  1.11      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec - 4,
    141  1.11      matt 		dzrint, sc, &sc->sc_rintrcnt);
    142  1.10     ragge 	uba_reset_establish(dzreset, self);
    143   1.1     ragge 
    144  1.16        ad 	dzattach(sc, ua->ua_evcnt, -1);
    145   1.1     ragge }
    146