Home | History | Annotate | Line # | Download | only in sbd
osiop_sbdio.c revision 1.2
      1 /*	$NetBSD: osiop_sbdio.c,v 1.2 2008/03/29 08:14:41 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001, 2005 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/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: osiop_sbdio.c,v 1.2 2008/03/29 08:14:41 tsutsui Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/device.h>
     35 
     36 #include <machine/bus.h>
     37 #include <machine/sbdiovar.h>
     38 
     39 #include <dev/scsipi/scsi_all.h>
     40 #include <dev/scsipi/scsipi_all.h>
     41 #include <dev/scsipi/scsiconf.h>
     42 
     43 #include <dev/ic/osiopreg.h>
     44 #include <dev/ic/osiopvar.h>
     45 
     46 int osiop_sbdio_match(struct device *, struct cfdata *, void *);
     47 void osiop_sbdio_attach(struct device *, struct device *, void *);
     48 int osiop_sbdio_intr(void *);
     49 
     50 CFATTACH_DECL(osiop_sbdio, sizeof(struct osiop_softc),
     51     osiop_sbdio_match, osiop_sbdio_attach, NULL, NULL);
     52 
     53 int
     54 osiop_sbdio_match(struct device *parent, struct cfdata *match, void *aux)
     55 {
     56 	struct sbdio_attach_args *sa = aux;
     57 
     58 	return strcmp(sa->sa_name, "osiop") ? 0 : 1;
     59 }
     60 
     61 void
     62 osiop_sbdio_attach(struct device *parent, struct device *self, void *aux)
     63 {
     64 	struct sbdio_attach_args *sa = aux;
     65 	struct osiop_softc *sc = (void *)self;
     66 	int error, scid;
     67 
     68 	sc->sc_dmat = sa->sa_dmat;
     69 	sc->sc_bst  = sa->sa_bust;
     70 
     71 	error = bus_space_map(sc->sc_bst, sa->sa_addr1, OSIOP_NREGS, 0,
     72 	    &sc->sc_reg);
     73 	if (error != 0) {
     74 		printf(": can't map registers, error = %d\n", error);
     75 		return;
     76 	}
     77 
     78 	sc->sc_clock_freq = 25;	/* MHz */
     79 	sc->sc_ctest7 = 0;
     80 	sc->sc_dcntl = OSIOP_DCNTL_EA;
     81 	if (sa->sa_flags == 0x0001) /* TR2A */
     82 		sc->sc_ctest4 = OSIOP_CTEST4_MUX; /* Host bus multiplex mode */
     83 
     84 	scid = ffs(osiop_read_1(sc, OSIOP_SCID));
     85 	if (scid == 0)
     86 		scid = 7;
     87 	else
     88 		scid--;
     89 	sc->sc_id = scid;
     90 
     91 	intr_establish(sa->sa_irq, osiop_sbdio_intr, self);
     92 
     93 	osiop_attach(sc);
     94 }
     95 
     96 int
     97 osiop_sbdio_intr(void *arg)
     98 {
     99 	struct osiop_softc *sc = arg;
    100 	uint8_t istat;
    101 
    102 	if (sc->sc_flags & OSIOP_INTSOFF)
    103 		return 0;
    104 
    105 	istat = osiop_read_1(sc, OSIOP_ISTAT);
    106 
    107 	if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
    108 		return 0;
    109 
    110 	/* Save interrupt details for the back-end interrupt handler */
    111 	sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0);
    112 	sc->sc_istat = istat;
    113 	sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT);
    114 
    115 	osiop_intr(sc);
    116 
    117 	return 1;
    118 }
    119