Home | History | Annotate | Line # | Download | only in jazz
osiop_jazzio.c revision 1.1.4.1
      1 /* $NetBSD: osiop_jazzio.c,v 1.1.4.1 2002/10/10 18:31:42 jdolecek 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 CFATTACH_DECL(osiop_jazzio, sizeof(struct osiop_softc),
     53     osiop_jazzio_match, osiop_jazzio_attach, NULL, NULL);
     54 
     55 int
     56 osiop_jazzio_match(parent, match, aux)
     57 	struct device *parent;
     58 	struct cfdata *match;
     59 	void *aux;
     60 {
     61 	struct jazzio_attach_args *ja = aux;
     62 
     63 	if (strcmp(ja->ja_name, "osiop") != 0)
     64 		return (0);
     65 
     66 	return (1);
     67 }
     68 
     69 void
     70 osiop_jazzio_attach(parent, self, aux)
     71 	struct device *parent;
     72 	struct device *self;
     73 	void *aux;
     74 {
     75 	struct jazzio_attach_args *ja = aux;
     76 	struct osiop_softc *sc = (void *)self;
     77 	int err, scid;
     78 
     79 	sc->sc_bst = ja->ja_bust;
     80 	sc->sc_dmat = ja->ja_dmat;
     81 
     82 	/*
     83 	 * Map registers
     84 	 */
     85 	err = bus_space_map(sc->sc_bst, ja->ja_addr,
     86 	    OSIOP_NREGS, 0, &sc->sc_reg);
     87 	if (err) {
     88 		printf("%s: failed to map registers, err=%d\n",
     89 		    sc->sc_dev.dv_xname, err);
     90 		return;
     91 	}
     92 
     93 	sc->sc_clock_freq = 50;	/* MHz */
     94 	sc->sc_ctest7 = 0; /* | OSIOP_CTEST7_TT1 */
     95 	sc->sc_dcntl = OSIOP_DCNTL_EA;
     96 
     97 	/* XXX should check ID in BIOS variables? */
     98 	scid = ffs(osiop_read_1(sc, OSIOP_SCID));
     99 
    100 	if (scid == 0)
    101 		scid = 7;
    102 	else
    103 		scid--;
    104 
    105 	sc->sc_id = scid;
    106 
    107 	/*
    108 	 * Call common attachment
    109 	 */
    110 	osiop_attach(sc);
    111 
    112 	/*
    113 	 * Set up interrupt handler.
    114          */
    115 	jazzio_intr_establish(ja->ja_intr,
    116 	    (intr_handler_t)osiop_jazzio_intr, sc);
    117 }
    118 
    119 /*
    120  * interrupt handler
    121  */
    122 int
    123 osiop_jazzio_intr(arg)
    124 	void *arg;
    125 {
    126 	struct osiop_softc *sc = arg;
    127 	u_int8_t istat;
    128 
    129 	/* This is potentially nasty, since the IRQ is level triggered... */
    130 	if (sc->sc_flags & OSIOP_INTSOFF)
    131 		return (0);
    132 
    133 	istat = osiop_read_1(sc, OSIOP_ISTAT);
    134 
    135 	if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
    136 		return (0);
    137 
    138 	/* Save interrupt details for the back-end interrupt handler */
    139 	sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0);
    140 	sc->sc_istat = istat;
    141 	sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT);
    142 
    143 	/* Deal with the interrupt */
    144 	osiop_intr(sc);
    145 
    146 	return (1);
    147 }
    148