Home | History | Annotate | Line # | Download | only in sbd
      1  1.4  tsutsui /*	$NetBSD: osiop_sbdio.c,v 1.4 2008/05/14 13:29:28 tsutsui Exp $	*/
      2  1.1  tsutsui 
      3  1.4  tsutsui /*-
      4  1.1  tsutsui  * Copyright (c) 2001, 2005 Izumi Tsutsui.  All rights reserved.
      5  1.1  tsutsui  *
      6  1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      7  1.1  tsutsui  * modification, are permitted provided that the following conditions
      8  1.1  tsutsui  * are met:
      9  1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     10  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     11  1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     14  1.1  tsutsui  *
     15  1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  1.1  tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  1.1  tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  1.1  tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  1.1  tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  1.1  tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  1.1  tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  1.1  tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  1.1  tsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  1.1  tsutsui  */
     26  1.1  tsutsui 
     27  1.1  tsutsui #include <sys/cdefs.h>
     28  1.4  tsutsui __KERNEL_RCSID(0, "$NetBSD: osiop_sbdio.c,v 1.4 2008/05/14 13:29:28 tsutsui Exp $");
     29  1.1  tsutsui 
     30  1.1  tsutsui #include <sys/param.h>
     31  1.1  tsutsui #include <sys/systm.h>
     32  1.1  tsutsui #include <sys/device.h>
     33  1.1  tsutsui 
     34  1.1  tsutsui #include <machine/bus.h>
     35  1.1  tsutsui #include <machine/sbdiovar.h>
     36  1.1  tsutsui 
     37  1.1  tsutsui #include <dev/scsipi/scsi_all.h>
     38  1.1  tsutsui #include <dev/scsipi/scsipi_all.h>
     39  1.1  tsutsui #include <dev/scsipi/scsiconf.h>
     40  1.1  tsutsui 
     41  1.1  tsutsui #include <dev/ic/osiopreg.h>
     42  1.1  tsutsui #include <dev/ic/osiopvar.h>
     43  1.1  tsutsui 
     44  1.3  tsutsui int osiop_sbdio_match(device_t, cfdata_t, void *);
     45  1.3  tsutsui void osiop_sbdio_attach(device_t, device_t, void *);
     46  1.1  tsutsui int osiop_sbdio_intr(void *);
     47  1.1  tsutsui 
     48  1.3  tsutsui CFATTACH_DECL_NEW(osiop_sbdio, sizeof(struct osiop_softc),
     49  1.1  tsutsui     osiop_sbdio_match, osiop_sbdio_attach, NULL, NULL);
     50  1.1  tsutsui 
     51  1.1  tsutsui int
     52  1.3  tsutsui osiop_sbdio_match(device_t parent, cfdata_t cf, void *aux)
     53  1.1  tsutsui {
     54  1.1  tsutsui 	struct sbdio_attach_args *sa = aux;
     55  1.1  tsutsui 
     56  1.1  tsutsui 	return strcmp(sa->sa_name, "osiop") ? 0 : 1;
     57  1.1  tsutsui }
     58  1.1  tsutsui 
     59  1.1  tsutsui void
     60  1.3  tsutsui osiop_sbdio_attach(device_t parent, device_t self, void *aux)
     61  1.1  tsutsui {
     62  1.3  tsutsui 	struct osiop_softc *sc = device_private(self);
     63  1.1  tsutsui 	struct sbdio_attach_args *sa = aux;
     64  1.1  tsutsui 	int error, scid;
     65  1.1  tsutsui 
     66  1.3  tsutsui 	sc->sc_dev = self;
     67  1.1  tsutsui 	sc->sc_dmat = sa->sa_dmat;
     68  1.1  tsutsui 	sc->sc_bst  = sa->sa_bust;
     69  1.1  tsutsui 
     70  1.1  tsutsui 	error = bus_space_map(sc->sc_bst, sa->sa_addr1, OSIOP_NREGS, 0,
     71  1.1  tsutsui 	    &sc->sc_reg);
     72  1.1  tsutsui 	if (error != 0) {
     73  1.3  tsutsui 		aprint_error(": can't map registers, error = %d\n", error);
     74  1.1  tsutsui 		return;
     75  1.1  tsutsui 	}
     76  1.1  tsutsui 
     77  1.1  tsutsui 	sc->sc_clock_freq = 25;	/* MHz */
     78  1.1  tsutsui 	sc->sc_ctest7 = 0;
     79  1.1  tsutsui 	sc->sc_dcntl = OSIOP_DCNTL_EA;
     80  1.1  tsutsui 	if (sa->sa_flags == 0x0001) /* TR2A */
     81  1.1  tsutsui 		sc->sc_ctest4 = OSIOP_CTEST4_MUX; /* Host bus multiplex mode */
     82  1.1  tsutsui 
     83  1.1  tsutsui 	scid = ffs(osiop_read_1(sc, OSIOP_SCID));
     84  1.1  tsutsui 	if (scid == 0)
     85  1.1  tsutsui 		scid = 7;
     86  1.1  tsutsui 	else
     87  1.1  tsutsui 		scid--;
     88  1.1  tsutsui 	sc->sc_id = scid;
     89  1.1  tsutsui 
     90  1.3  tsutsui 	intr_establish(sa->sa_irq, osiop_sbdio_intr, sc);
     91  1.1  tsutsui 
     92  1.1  tsutsui 	osiop_attach(sc);
     93  1.1  tsutsui }
     94  1.1  tsutsui 
     95  1.1  tsutsui int
     96  1.1  tsutsui osiop_sbdio_intr(void *arg)
     97  1.1  tsutsui {
     98  1.1  tsutsui 	struct osiop_softc *sc = arg;
     99  1.1  tsutsui 	uint8_t istat;
    100  1.1  tsutsui 
    101  1.1  tsutsui 	if (sc->sc_flags & OSIOP_INTSOFF)
    102  1.1  tsutsui 		return 0;
    103  1.1  tsutsui 
    104  1.1  tsutsui 	istat = osiop_read_1(sc, OSIOP_ISTAT);
    105  1.1  tsutsui 
    106  1.1  tsutsui 	if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
    107  1.1  tsutsui 		return 0;
    108  1.1  tsutsui 
    109  1.1  tsutsui 	/* Save interrupt details for the back-end interrupt handler */
    110  1.1  tsutsui 	sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0);
    111  1.1  tsutsui 	sc->sc_istat = istat;
    112  1.1  tsutsui 	sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT);
    113  1.1  tsutsui 
    114  1.1  tsutsui 	osiop_intr(sc);
    115  1.1  tsutsui 
    116  1.1  tsutsui 	return 1;
    117  1.1  tsutsui }
    118