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