Home | History | Annotate | Line # | Download | only in jazz
oosiop_jazzio.c revision 1.3
      1 /* $NetBSD: oosiop_jazzio.c,v 1.3 2005/01/22 07:35:34 tsutsui Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2001 Shuichiro URATA.  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: oosiop_jazzio.c,v 1.3 2005/01/22 07:35:34 tsutsui Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/device.h>
     35 #include <sys/buf.h>
     36 #include <sys/malloc.h>
     37 
     38 #include <dev/scsipi/scsi_all.h>
     39 #include <dev/scsipi/scsipi_all.h>
     40 #include <dev/scsipi/scsiconf.h>
     41 #include <dev/scsipi/scsi_message.h>
     42 
     43 #include <machine/cpu.h>
     44 #include <machine/autoconf.h>
     45 #include <machine/bus.h>
     46 
     47 #include <dev/ic/oosiopreg.h>
     48 #include <dev/ic/oosiopvar.h>
     49 #include <arc/jazz/jazziovar.h>
     50 
     51 int	oosiop_jazzio_match(struct device *, struct cfdata *, void *);
     52 void	oosiop_jazzio_attach(struct device *, struct device *, void *);
     53 
     54 CFATTACH_DECL(oosiop_jazzio, sizeof(struct oosiop_softc),
     55     oosiop_jazzio_match, oosiop_jazzio_attach, NULL, NULL);
     56 extern struct cfdriver oosiop_cd;
     57 
     58 /*
     59  * Match driver based on name
     60  */
     61 int
     62 oosiop_jazzio_match(struct device *parent, struct cfdata *match, void *aux)
     63 {
     64 	struct jazzio_attach_args *ja = aux;
     65 
     66 	if (strcmp(ja->ja_name, "NCRC700") != 0)
     67 		return 0;
     68 
     69 	return 1;
     70 }
     71 
     72 void
     73 oosiop_jazzio_attach(struct device *parent, struct device *self, void *aux)
     74 {
     75 	struct jazzio_attach_args *ja = aux;
     76 	struct oosiop_softc *sc = (void *)self;
     77 	int i, scid;
     78 
     79 	sc->sc_bst = ja->ja_bust;
     80 	sc->sc_dmat = ja->ja_dmat;
     81 
     82 	if (bus_space_map(sc->sc_bst, ja->ja_addr,
     83 	    OOSIOP_NREGS, 0, &sc->sc_bsh) != 0) {
     84 		printf(": failed to map regsters\n");
     85 		return;
     86 	}
     87 
     88 	sc->sc_chip = OOSIOP_700_66;
     89 	sc->sc_freq = 50000000;
     90 
     91 	/* Preserve host id */
     92 	scid = oosiop_read_1(sc, OOSIOP_SCID);
     93 	for (i = 0; i < OOSIOP_NTGT; i++)
     94 		if (scid & (1 << i))
     95 			break;
     96 	if (i == OOSIOP_NTGT)
     97 		i = OOSIOP_NTGT - 1;
     98 
     99 	sc->sc_id = i;
    100 
    101 	jazzio_intr_establish(ja->ja_intr, (intr_handler_t)oosiop_intr, sc);
    102 
    103 	oosiop_attach(sc);
    104 }
    105