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