Home | History | Annotate | Line # | Download | only in podulebus
csa.c revision 1.7
      1 /*	$NetBSD: csa.c,v 1.7 2003/07/14 22:48:26 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  * Cumana SCSI 1 driver using the generic NCR5380 driver
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: csa.c,v 1.7 2003/07/14 22:48:26 lukem Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/kernel.h>
     49 #include <sys/device.h>
     50 #include <sys/buf.h>
     51 #include <dev/scsipi/scsi_all.h>
     52 #include <dev/scsipi/scsipi_all.h>
     53 #include <dev/scsipi/scsiconf.h>
     54 
     55 #include <dev/ic/ncr5380reg.h>
     56 #include <dev/ic/ncr5380var.h>
     57 
     58 #include <machine/io.h>
     59 #include <machine/intr.h>
     60 #include <machine/bootconfig.h>
     61 
     62 #include <acorn32/podulebus/podulebus.h>
     63 #include <dev/podulebus/podules.h>
     64 #include <dev/podulebus/powerromreg.h>
     65 
     66 #define CSA_NCR5380_OFFSET	0x2100
     67 #define CSA_CTRL_OFFSET		0x2000 - 2308
     68 #define  CSA_DIRWRITE		0x02
     69 #define  CSA_DIRREAD		0x00
     70 #define  CSA_16BITS		0x00
     71 #define  CSA_8BITS		0x10
     72 #define  CSA_XXX		0x40
     73 #define CSA_DATA_OFFSET		0x2000
     74 #define CSA_INTR_OFFSET		0x2000
     75 #define  CSA_INTR_MASK		0x80
     76 #define CSA_STAT_OFFSET		0x2004
     77 #define  CSA_STAT_DRQ		0x40
     78 #define  CSA_STAT_END		0x80
     79 
     80 void csa_attach __P((struct device *, struct device *, void *));
     81 int  csa_match  __P((struct device *, struct cfdata *, void *));
     82 
     83 /*
     84  * Cumana SCSI 1 softc structure.
     85  *
     86  * Contains the generic ncr5380 device node, podule information and global information
     87  * required by the driver.
     88  */
     89 
     90 struct csa_softc {
     91 	struct ncr5380_softc	sc_ncr5380;
     92 	void			*sc_ih;
     93 	struct evcnt		sc_intrcnt;
     94 	int			sc_podule_number;
     95 	podule_t		*sc_podule;
     96 	volatile u_char		*sc_irqstatus;
     97 	u_char			sc_irqmask;
     98 	volatile u_char		*sc_ctrl;
     99 	volatile u_char		*sc_status;
    100 	volatile u_char		*sc_data;
    101 };
    102 
    103 CFATTACH_DECL(csa, sizeof(struct csa_softc),
    104     csa_match, csa_attach, NULL, NULL);
    105 
    106 int csa_intr		 __P((void *arg));
    107 
    108 /*
    109  * Card probe function
    110  *
    111  * Just match the manufacturer and podule ID's
    112  */
    113 
    114 int
    115 csa_match(parent, cf, aux)
    116 	struct device	*parent;
    117 	struct cfdata	*cf;
    118 	void		*aux;
    119 {
    120 	struct podule_attach_args *pa = aux;
    121 
    122 	if (pa->pa_product == PODULE_CUMANA_SCSI1)
    123 		return(1);
    124 
    125 	/* PowerROM */
    126         if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
    127             podulebus_initloader(pa) == 0 &&
    128             (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 ||
    129 	     podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16))
    130                 return 1;
    131 
    132 	return 0;
    133 }
    134 
    135 /*
    136  * Card attach function
    137  *
    138  */
    139 
    140 void
    141 csa_attach(parent, self, aux)
    142 	struct device	*parent, *self;
    143 	void		*aux;
    144 {
    145 	struct csa_softc *sc = (struct csa_softc *)self;
    146 	struct podule_attach_args *pa = aux;
    147 	u_char *iobase;
    148 	char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
    149 
    150 	/* Note the podule number and validate */
    151 
    152 	if (pa->pa_podule_number == -1)
    153 		panic("Podule has disappeared !");
    154 
    155 	sc->sc_podule_number = pa->pa_podule_number;
    156 	sc->sc_podule = pa->pa_podule;
    157 	podules[sc->sc_podule_number].attached = 1;
    158 
    159 	sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
    160 	sc->sc_ncr5380.sc_min_dma_len = 0;
    161 	sc->sc_ncr5380.sc_no_disconnect = 0x00;
    162 	sc->sc_ncr5380.sc_parity_disable = 0x00;
    163 
    164 	sc->sc_ncr5380.sc_dma_alloc = NULL;
    165 	sc->sc_ncr5380.sc_dma_free = NULL;
    166 	sc->sc_ncr5380.sc_dma_poll = NULL;
    167 	sc->sc_ncr5380.sc_dma_setup = NULL;
    168 	sc->sc_ncr5380.sc_dma_start = NULL;
    169 	sc->sc_ncr5380.sc_dma_eop = NULL;
    170 	sc->sc_ncr5380.sc_dma_stop = NULL;
    171 	sc->sc_ncr5380.sc_intr_on = NULL;
    172 	sc->sc_ncr5380.sc_intr_off = NULL;
    173 
    174 	iobase = (u_char *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET;
    175 	sc->sc_ncr5380.sci_r0 = iobase + 0;
    176 	sc->sc_ncr5380.sci_r1 = iobase + 4;
    177 	sc->sc_ncr5380.sci_r2 = iobase + 8;
    178 	sc->sc_ncr5380.sci_r3 = iobase + 12;
    179 	sc->sc_ncr5380.sci_r4 = iobase + 16;
    180 	sc->sc_ncr5380.sci_r5 = iobase + 20;
    181 	sc->sc_ncr5380.sci_r6 = iobase + 24;
    182 	sc->sc_ncr5380.sci_r7 = iobase + 28;
    183 
    184 	sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380;
    185 
    186 	sc->sc_ctrl = (u_char *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET;
    187 	sc->sc_status = (u_char *)pa->pa_podule->slow_base + CSA_STAT_OFFSET;
    188 	sc->sc_data = (u_char *)pa->pa_podule->slow_base + CSA_DATA_OFFSET;
    189 
    190 	sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
    191 	sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
    192 
    193 	/* Provide an override for the host id */
    194 	sc->sc_ncr5380.sc_channel.chan_id = 7;
    195 	sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
    196 	(void)get_bootconf_option(boot_args, hi_option,
    197 	    BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
    198 	sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
    199 
    200 	printf(": host=%d, using 8 bit PIO",
    201 	    sc->sc_ncr5380.sc_channel.chan_id);
    202 
    203 	sc->sc_irqstatus = (u_char *)pa->pa_podule->slow_base + CSA_INTR_OFFSET;
    204 	sc->sc_irqmask = CSA_INTR_MASK;
    205 
    206 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    207 	    self->dv_xname, "intr");
    208 	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc,
    209 	    &sc->sc_intrcnt);
    210 	if (sc->sc_ih == NULL)
    211 		sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
    212 
    213 	if (sc->sc_ncr5380.sc_flags & NCR5380_FORCE_POLLING)
    214 		printf(", polling");
    215 	printf("\n");
    216 	*sc->sc_ctrl = 0;
    217 
    218 	ncr5380_attach(&sc->sc_ncr5380);
    219 }
    220 
    221 int
    222 csa_intr(arg)
    223 	void *arg;
    224 {
    225 	struct csa_softc *sc = arg;
    226 
    227 	if ((*sc->sc_irqstatus) & sc->sc_irqmask)
    228 		(void)ncr5380_intr(&sc->sc_ncr5380);
    229 
    230 	return(0);
    231 }
    232