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