Home | History | Annotate | Line # | Download | only in podulebus
csa.c revision 1.5
      1  1.5  thorpej /*	$NetBSD: csa.c,v 1.5 2002/10/02 02:23:51 thorpej Exp $	*/
      2  1.1  reinoud 
      3  1.1  reinoud /*
      4  1.1  reinoud  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  reinoud  * All rights reserved.
      6  1.1  reinoud  *
      7  1.1  reinoud  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  reinoud  * by Mark Brinicombe of Causality Limited.
      9  1.1  reinoud  *
     10  1.1  reinoud  * Redistribution and use in source and binary forms, with or without
     11  1.1  reinoud  * modification, are permitted provided that the following conditions
     12  1.1  reinoud  * are met:
     13  1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     14  1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     15  1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     18  1.1  reinoud  * 3. All advertising materials mentioning features or use of this software
     19  1.1  reinoud  *    must display the following acknowledgement:
     20  1.1  reinoud  *	This product includes software developed by the NetBSD
     21  1.1  reinoud  *	Foundation, Inc. and its contributors.
     22  1.1  reinoud  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  reinoud  *    contributors may be used to endorse or promote products derived
     24  1.1  reinoud  *    from this software without specific prior written permission.
     25  1.1  reinoud  *
     26  1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  reinoud  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  reinoud  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  reinoud  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  reinoud  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  reinoud  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  reinoud  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  reinoud  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  reinoud  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  reinoud  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  reinoud  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  reinoud  */
     38  1.1  reinoud 
     39  1.1  reinoud /*
     40  1.1  reinoud  * Cumana SCSI 1 driver using the generic NCR5380 driver
     41  1.1  reinoud  */
     42  1.1  reinoud 
     43  1.1  reinoud #include <sys/param.h>
     44  1.1  reinoud #include <sys/systm.h>
     45  1.1  reinoud #include <sys/kernel.h>
     46  1.1  reinoud #include <sys/device.h>
     47  1.1  reinoud #include <sys/buf.h>
     48  1.1  reinoud #include <dev/scsipi/scsi_all.h>
     49  1.1  reinoud #include <dev/scsipi/scsipi_all.h>
     50  1.1  reinoud #include <dev/scsipi/scsiconf.h>
     51  1.1  reinoud 
     52  1.1  reinoud #include <dev/ic/ncr5380reg.h>
     53  1.1  reinoud #include <dev/ic/ncr5380var.h>
     54  1.1  reinoud 
     55  1.1  reinoud #include <machine/io.h>
     56  1.2  thorpej #include <machine/intr.h>
     57  1.1  reinoud #include <machine/bootconfig.h>
     58  1.1  reinoud 
     59  1.1  reinoud #include <acorn32/podulebus/podulebus.h>
     60  1.1  reinoud #include <dev/podulebus/podules.h>
     61  1.1  reinoud #include <dev/podulebus/powerromreg.h>
     62  1.1  reinoud 
     63  1.1  reinoud #define CSA_NCR5380_OFFSET	0x2100
     64  1.1  reinoud #define CSA_CTRL_OFFSET		0x2000 - 2308
     65  1.1  reinoud #define  CSA_DIRWRITE		0x02
     66  1.1  reinoud #define  CSA_DIRREAD		0x00
     67  1.1  reinoud #define  CSA_16BITS		0x00
     68  1.1  reinoud #define  CSA_8BITS		0x10
     69  1.1  reinoud #define  CSA_XXX		0x40
     70  1.1  reinoud #define CSA_DATA_OFFSET		0x2000
     71  1.1  reinoud #define CSA_INTR_OFFSET		0x2000
     72  1.1  reinoud #define  CSA_INTR_MASK		0x80
     73  1.1  reinoud #define CSA_STAT_OFFSET		0x2004
     74  1.1  reinoud #define  CSA_STAT_DRQ		0x40
     75  1.1  reinoud #define  CSA_STAT_END		0x80
     76  1.1  reinoud 
     77  1.1  reinoud void csa_attach __P((struct device *, struct device *, void *));
     78  1.1  reinoud int  csa_match  __P((struct device *, struct cfdata *, void *));
     79  1.1  reinoud 
     80  1.1  reinoud /*
     81  1.1  reinoud  * Cumana SCSI 1 softc structure.
     82  1.1  reinoud  *
     83  1.1  reinoud  * Contains the generic ncr5380 device node, podule information and global information
     84  1.1  reinoud  * required by the driver.
     85  1.1  reinoud  */
     86  1.1  reinoud 
     87  1.1  reinoud struct csa_softc {
     88  1.1  reinoud 	struct ncr5380_softc	sc_ncr5380;
     89  1.1  reinoud 	void			*sc_ih;
     90  1.1  reinoud 	struct evcnt		sc_intrcnt;
     91  1.1  reinoud 	int			sc_podule_number;
     92  1.1  reinoud 	podule_t		*sc_podule;
     93  1.1  reinoud 	volatile u_char		*sc_irqstatus;
     94  1.1  reinoud 	u_char			sc_irqmask;
     95  1.1  reinoud 	volatile u_char		*sc_ctrl;
     96  1.1  reinoud 	volatile u_char		*sc_status;
     97  1.1  reinoud 	volatile u_char		*sc_data;
     98  1.1  reinoud };
     99  1.1  reinoud 
    100  1.5  thorpej CFATTACH_DECL(csa, sizeof(struct csa_softc),
    101  1.5  thorpej 	csa_match, csa_attach, NULL, NULL);
    102  1.1  reinoud 
    103  1.1  reinoud int csa_intr		 __P((void *arg));
    104  1.1  reinoud 
    105  1.1  reinoud /*
    106  1.1  reinoud  * Card probe function
    107  1.1  reinoud  *
    108  1.1  reinoud  * Just match the manufacturer and podule ID's
    109  1.1  reinoud  */
    110  1.1  reinoud 
    111  1.1  reinoud int
    112  1.1  reinoud csa_match(parent, cf, aux)
    113  1.1  reinoud 	struct device	*parent;
    114  1.1  reinoud 	struct cfdata	*cf;
    115  1.1  reinoud 	void		*aux;
    116  1.1  reinoud {
    117  1.1  reinoud 	struct podule_attach_args *pa = aux;
    118  1.1  reinoud 
    119  1.3    bjh21 	if (pa->pa_product == PODULE_CUMANA_SCSI1)
    120  1.1  reinoud 		return(1);
    121  1.1  reinoud 
    122  1.1  reinoud 	/* PowerROM */
    123  1.1  reinoud         if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
    124  1.1  reinoud             podulebus_initloader(pa) == 0 &&
    125  1.1  reinoud             (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 ||
    126  1.1  reinoud 	     podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16))
    127  1.1  reinoud                 return 1;
    128  1.1  reinoud 
    129  1.1  reinoud 	return 0;
    130  1.1  reinoud }
    131  1.1  reinoud 
    132  1.1  reinoud /*
    133  1.1  reinoud  * Card attach function
    134  1.1  reinoud  *
    135  1.1  reinoud  */
    136  1.1  reinoud 
    137  1.1  reinoud void
    138  1.1  reinoud csa_attach(parent, self, aux)
    139  1.1  reinoud 	struct device	*parent, *self;
    140  1.1  reinoud 	void		*aux;
    141  1.1  reinoud {
    142  1.1  reinoud 	struct csa_softc *sc = (struct csa_softc *)self;
    143  1.1  reinoud 	struct podule_attach_args *pa = aux;
    144  1.1  reinoud 	u_char *iobase;
    145  1.1  reinoud 	char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
    146  1.1  reinoud 
    147  1.1  reinoud 	/* Note the podule number and validate */
    148  1.1  reinoud 
    149  1.1  reinoud 	if (pa->pa_podule_number == -1)
    150  1.1  reinoud 		panic("Podule has disappeared !");
    151  1.1  reinoud 
    152  1.1  reinoud 	sc->sc_podule_number = pa->pa_podule_number;
    153  1.1  reinoud 	sc->sc_podule = pa->pa_podule;
    154  1.1  reinoud 	podules[sc->sc_podule_number].attached = 1;
    155  1.1  reinoud 
    156  1.1  reinoud 	sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
    157  1.1  reinoud 	sc->sc_ncr5380.sc_min_dma_len = 0;
    158  1.1  reinoud 	sc->sc_ncr5380.sc_no_disconnect = 0x00;
    159  1.1  reinoud 	sc->sc_ncr5380.sc_parity_disable = 0x00;
    160  1.1  reinoud 
    161  1.1  reinoud 	sc->sc_ncr5380.sc_dma_alloc = NULL;
    162  1.1  reinoud 	sc->sc_ncr5380.sc_dma_free = NULL;
    163  1.1  reinoud 	sc->sc_ncr5380.sc_dma_poll = NULL;
    164  1.1  reinoud 	sc->sc_ncr5380.sc_dma_setup = NULL;
    165  1.1  reinoud 	sc->sc_ncr5380.sc_dma_start = NULL;
    166  1.1  reinoud 	sc->sc_ncr5380.sc_dma_eop = NULL;
    167  1.1  reinoud 	sc->sc_ncr5380.sc_dma_stop = NULL;
    168  1.1  reinoud 	sc->sc_ncr5380.sc_intr_on = NULL;
    169  1.1  reinoud 	sc->sc_ncr5380.sc_intr_off = NULL;
    170  1.1  reinoud 
    171  1.1  reinoud 	iobase = (u_char *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET;
    172  1.1  reinoud 	sc->sc_ncr5380.sci_r0 = iobase + 0;
    173  1.1  reinoud 	sc->sc_ncr5380.sci_r1 = iobase + 4;
    174  1.1  reinoud 	sc->sc_ncr5380.sci_r2 = iobase + 8;
    175  1.1  reinoud 	sc->sc_ncr5380.sci_r3 = iobase + 12;
    176  1.1  reinoud 	sc->sc_ncr5380.sci_r4 = iobase + 16;
    177  1.1  reinoud 	sc->sc_ncr5380.sci_r5 = iobase + 20;
    178  1.1  reinoud 	sc->sc_ncr5380.sci_r6 = iobase + 24;
    179  1.1  reinoud 	sc->sc_ncr5380.sci_r7 = iobase + 28;
    180  1.1  reinoud 
    181  1.1  reinoud 	sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380;
    182  1.1  reinoud 
    183  1.1  reinoud 	sc->sc_ctrl = (u_char *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET;
    184  1.1  reinoud 	sc->sc_status = (u_char *)pa->pa_podule->slow_base + CSA_STAT_OFFSET;
    185  1.1  reinoud 	sc->sc_data = (u_char *)pa->pa_podule->slow_base + CSA_DATA_OFFSET;
    186  1.1  reinoud 
    187  1.1  reinoud 	sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
    188  1.1  reinoud 	sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
    189  1.1  reinoud 
    190  1.1  reinoud 	/* Provide an override for the host id */
    191  1.1  reinoud 	sc->sc_ncr5380.sc_channel.chan_id = 7;
    192  1.1  reinoud 	sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
    193  1.1  reinoud 	(void)get_bootconf_option(boot_args, hi_option,
    194  1.1  reinoud 	    BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
    195  1.1  reinoud 	sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
    196  1.1  reinoud 
    197  1.1  reinoud 	printf(": host=%d, using 8 bit PIO",
    198  1.1  reinoud 	    sc->sc_ncr5380.sc_channel.chan_id);
    199  1.1  reinoud 
    200  1.1  reinoud 	sc->sc_irqstatus = (u_char *)pa->pa_podule->slow_base + CSA_INTR_OFFSET;
    201  1.1  reinoud 	sc->sc_irqmask = CSA_INTR_MASK;
    202  1.1  reinoud 
    203  1.1  reinoud 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    204  1.1  reinoud 	    self->dv_xname, "intr");
    205  1.1  reinoud 	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc,
    206  1.1  reinoud 	    &sc->sc_intrcnt);
    207  1.1  reinoud 	if (sc->sc_ih == NULL)
    208  1.1  reinoud 		sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
    209  1.1  reinoud 
    210  1.1  reinoud 	if (sc->sc_ncr5380.sc_flags & NCR5380_FORCE_POLLING)
    211  1.1  reinoud 		printf(", polling");
    212  1.1  reinoud 	printf("\n");
    213  1.1  reinoud 	*sc->sc_ctrl = 0;
    214  1.1  reinoud 
    215  1.1  reinoud 	ncr5380_attach(&sc->sc_ncr5380);
    216  1.1  reinoud }
    217  1.1  reinoud 
    218  1.1  reinoud int
    219  1.1  reinoud csa_intr(arg)
    220  1.1  reinoud 	void *arg;
    221  1.1  reinoud {
    222  1.1  reinoud 	struct csa_softc *sc = arg;
    223  1.1  reinoud 
    224  1.1  reinoud 	if ((*sc->sc_irqstatus) & sc->sc_irqmask)
    225  1.1  reinoud 		(void)ncr5380_intr(&sc->sc_ncr5380);
    226  1.1  reinoud 
    227  1.1  reinoud 	return(0);
    228  1.1  reinoud }
    229