Home | History | Annotate | Line # | Download | only in podulebus
oak.c revision 1.6
      1 /*	$NetBSD: oak.c,v 1.6 2001/11/13 07:23:16 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Mark Brinicombe of Causality Limited.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Oak SCSI 1 driver using the generic NCR5380 driver
     41  *
     42  * This driver is a bit crude, and only uses 8-bit PIO accesses to the
     43  * card.  It looks like the card can support pseudo-DMA, and can
     44  * handle converting between the 5380's 8-bit data bus and the 16-bit
     45  * podule bus in the process.  We support none of this cleverness.
     46  *
     47  * This card has to be polled: it doesn't have anything connected to
     48  * PIRQ*.  This seems to be a common failing of Archimedes disc
     49  * controllers.
     50  */
     51 
     52 #include <sys/cdefs.h>
     53 __KERNEL_RCSID(0, "$NetBSD: oak.c,v 1.6 2001/11/13 07:23:16 lukem Exp $");
     54 
     55 #include <sys/param.h>
     56 
     57 #include <sys/systm.h>
     58 #include <sys/kernel.h>
     59 #include <sys/device.h>
     60 #include <sys/buf.h>
     61 #include <dev/scsipi/scsi_all.h>
     62 #include <dev/scsipi/scsipi_all.h>
     63 #include <dev/scsipi/scsiconf.h>
     64 
     65 #include <dev/ic/ncr5380reg.h>
     66 #include <dev/ic/ncr5380var.h>
     67 
     68 #include <machine/bootconfig.h>
     69 
     70 #include <dev/podulebus/podulebus.h>
     71 #include <dev/podulebus/podules.h>
     72 #include <dev/podulebus/powerromreg.h>
     73 
     74 void oak_attach (struct device *, struct device *, void *);
     75 int  oak_match  (struct device *, struct cfdata *, void *);
     76 
     77 /*
     78  * Oak SCSI 1 softc structure.
     79  *
     80  * Contains the generic ncr5380 device node, podule information and
     81  * global information required by the driver.
     82  */
     83 
     84 struct oak_softc {
     85 	struct ncr5380_softc	sc_ncr5380;
     86 };
     87 
     88 struct cfattach oak_ca = {
     89 	sizeof(struct oak_softc), oak_match, oak_attach
     90 };
     91 
     92 /*
     93  * Card probe function
     94  *
     95  * Just match the manufacturer and podule ID's
     96  */
     97 
     98 int
     99 oak_match(struct device *parent, struct cfdata *cf, void *aux)
    100 {
    101 	struct podulebus_attach_args *pa = aux;
    102 
    103 	if (matchpodule(pa, MANUFACTURER_OAK, PODULE_OAK_SCSI, -1))
    104 		return 1;
    105 
    106 	/* PowerROM */
    107 	if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
    108 	    podulebus_initloader(pa) == 0 &&
    109 	    podloader_callloader(pa, 0, 0) == PRID_OAK_SCSI1)
    110 		return 1;
    111 
    112 	return 0;
    113 }
    114 
    115 /*
    116  * Card attach function
    117  *
    118  */
    119 
    120 void
    121 oak_attach(struct device *parent, struct device *self, void *aux)
    122 {
    123 	struct oak_softc *sc = (struct oak_softc *)self;
    124 	struct podulebus_attach_args *pa = aux;
    125 	u_char *iobase;
    126 	char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
    127 
    128 	sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
    129 	sc->sc_ncr5380.sc_min_dma_len = 0;
    130 	sc->sc_ncr5380.sc_no_disconnect = 0xff;
    131 	sc->sc_ncr5380.sc_parity_disable = 0xff;
    132 
    133 	sc->sc_ncr5380.sc_dma_alloc = NULL;
    134 	sc->sc_ncr5380.sc_dma_free = NULL;
    135 	sc->sc_ncr5380.sc_dma_poll = NULL;
    136 	sc->sc_ncr5380.sc_dma_setup = NULL;
    137 	sc->sc_ncr5380.sc_dma_start = NULL;
    138 	sc->sc_ncr5380.sc_dma_eop = NULL;
    139 	sc->sc_ncr5380.sc_dma_stop = NULL;
    140 	sc->sc_ncr5380.sc_intr_on = NULL;
    141 	sc->sc_ncr5380.sc_intr_off = NULL;
    142 
    143 #ifdef NCR5380_USE_BUS_SPACE
    144 	sc->sc_ncr5380.sc_regt = pa->pa_mod_t;
    145 	bus_space_map(sc->sc_ncr5380.sc_regt, pa->pa_mod_base, 8, 0,
    146 	    &sc->sc_ncr5380.sc_regh);
    147 	sc->sc_ncr5380.sci_r0 = 0;
    148 	sc->sc_ncr5380.sci_r1 = 1;
    149 	sc->sc_ncr5380.sci_r2 = 2;
    150 	sc->sc_ncr5380.sci_r3 = 3;
    151 	sc->sc_ncr5380.sci_r4 = 4;
    152 	sc->sc_ncr5380.sci_r5 = 5;
    153 	sc->sc_ncr5380.sci_r6 = 6;
    154 	sc->sc_ncr5380.sci_r7 = 7;
    155 #else
    156 	iobase = (u_char *)pa->pa_mod_base;
    157 	sc->sc_ncr5380.sci_r0 = iobase + 0;
    158 	sc->sc_ncr5380.sci_r1 = iobase + 4;
    159 	sc->sc_ncr5380.sci_r2 = iobase + 8;
    160 	sc->sc_ncr5380.sci_r3 = iobase + 12;
    161 	sc->sc_ncr5380.sci_r4 = iobase + 16;
    162 	sc->sc_ncr5380.sci_r5 = iobase + 20;
    163 	sc->sc_ncr5380.sci_r6 = iobase + 24;
    164 	sc->sc_ncr5380.sci_r7 = iobase + 28;
    165 #endif
    166 
    167 	sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380;
    168 
    169 	sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
    170 	sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
    171 
    172 	/* Provide an override for the host id */
    173 	sc->sc_ncr5380.sc_channel.chan_id = 7;
    174 	sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
    175 	(void)get_bootconf_option(boot_args, hi_option,
    176 	    BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
    177 	sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
    178 
    179 	printf(": host=%d, using 8 bit PIO\n",
    180 	    sc->sc_ncr5380.sc_channel.chan_id);
    181 
    182 	ncr5380_attach(&sc->sc_ncr5380);
    183 }
    184