Home | History | Annotate | Line # | Download | only in jazz
osiop_jazzio.c revision 1.2
      1 /* $NetBSD: osiop_jazzio.c,v 1.2 2002/09/27 20:30:33 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/param.h>
     30 #include <sys/systm.h>
     31 #include <sys/device.h>
     32 #include <sys/buf.h>
     33 #include <sys/malloc.h>
     34 
     35 #include <dev/scsipi/scsi_all.h>
     36 #include <dev/scsipi/scsipi_all.h>
     37 #include <dev/scsipi/scsiconf.h>
     38 
     39 #include <machine/cpu.h>
     40 #include <machine/autoconf.h>
     41 #include <machine/bus.h>
     42 
     43 #include <dev/ic/osiopreg.h>
     44 #include <dev/ic/osiopvar.h>
     45 
     46 #include <arc/jazz/jazziovar.h>
     47 
     48 int osiop_jazzio_match(struct device *, struct cfdata *, void *);
     49 void osiop_jazzio_attach(struct device *, struct device *, void *);
     50 int osiop_jazzio_intr(void *);
     51 
     52 const struct cfattach osiop_jazzio_ca = {
     53 	sizeof(struct osiop_softc), osiop_jazzio_match, osiop_jazzio_attach
     54 };
     55 
     56 int
     57 osiop_jazzio_match(parent, match, aux)
     58 	struct device *parent;
     59 	struct cfdata *match;
     60 	void *aux;
     61 {
     62 	struct jazzio_attach_args *ja = aux;
     63 
     64 	if (strcmp(ja->ja_name, "osiop") != 0)
     65 		return (0);
     66 
     67 	return (1);
     68 }
     69 
     70 void
     71 osiop_jazzio_attach(parent, self, aux)
     72 	struct device *parent;
     73 	struct device *self;
     74 	void *aux;
     75 {
     76 	struct jazzio_attach_args *ja = aux;
     77 	struct osiop_softc *sc = (void *)self;
     78 	int err, scid;
     79 
     80 	sc->sc_bst = ja->ja_bust;
     81 	sc->sc_dmat = ja->ja_dmat;
     82 
     83 	/*
     84 	 * Map registers
     85 	 */
     86 	err = bus_space_map(sc->sc_bst, ja->ja_addr,
     87 	    OSIOP_NREGS, 0, &sc->sc_reg);
     88 	if (err) {
     89 		printf("%s: failed to map registers, err=%d\n",
     90 		    sc->sc_dev.dv_xname, err);
     91 		return;
     92 	}
     93 
     94 	sc->sc_clock_freq = 50;	/* MHz */
     95 	sc->sc_ctest7 = 0; /* | OSIOP_CTEST7_TT1 */
     96 	sc->sc_dcntl = OSIOP_DCNTL_EA;
     97 
     98 	/* XXX should check ID in BIOS variables? */
     99 	scid = ffs(osiop_read_1(sc, OSIOP_SCID));
    100 
    101 	if (scid == 0)
    102 		scid = 7;
    103 	else
    104 		scid--;
    105 
    106 	sc->sc_id = scid;
    107 
    108 	/*
    109 	 * Call common attachment
    110 	 */
    111 	osiop_attach(sc);
    112 
    113 	/*
    114 	 * Set up interrupt handler.
    115          */
    116 	jazzio_intr_establish(ja->ja_intr,
    117 	    (intr_handler_t)osiop_jazzio_intr, sc);
    118 }
    119 
    120 /*
    121  * interrupt handler
    122  */
    123 int
    124 osiop_jazzio_intr(arg)
    125 	void *arg;
    126 {
    127 	struct osiop_softc *sc = arg;
    128 	u_int8_t istat;
    129 
    130 	/* This is potentially nasty, since the IRQ is level triggered... */
    131 	if (sc->sc_flags & OSIOP_INTSOFF)
    132 		return (0);
    133 
    134 	istat = osiop_read_1(sc, OSIOP_ISTAT);
    135 
    136 	if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
    137 		return (0);
    138 
    139 	/* Save interrupt details for the back-end interrupt handler */
    140 	sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0);
    141 	sc->sc_istat = istat;
    142 	sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT);
    143 
    144 	/* Deal with the interrupt */
    145 	osiop_intr(sc);
    146 
    147 	return (1);
    148 }
    149