1 1.12 christos /* $NetBSD: csa.c,v 1.12 2014/03/21 16:43:00 christos 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 * 19 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 reinoud * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 reinoud * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 reinoud * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 reinoud * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 reinoud * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 reinoud * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 reinoud * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 reinoud * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 reinoud * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 reinoud * POSSIBILITY OF SUCH DAMAGE. 30 1.1 reinoud */ 31 1.1 reinoud 32 1.1 reinoud /* 33 1.1 reinoud * Cumana SCSI 1 driver using the generic NCR5380 driver 34 1.1 reinoud */ 35 1.7 lukem 36 1.7 lukem #include <sys/cdefs.h> 37 1.12 christos __KERNEL_RCSID(0, "$NetBSD: csa.c,v 1.12 2014/03/21 16:43:00 christos Exp $"); 38 1.1 reinoud 39 1.1 reinoud #include <sys/param.h> 40 1.1 reinoud #include <sys/systm.h> 41 1.1 reinoud #include <sys/kernel.h> 42 1.1 reinoud #include <sys/device.h> 43 1.1 reinoud #include <sys/buf.h> 44 1.1 reinoud #include <dev/scsipi/scsi_all.h> 45 1.1 reinoud #include <dev/scsipi/scsipi_all.h> 46 1.1 reinoud #include <dev/scsipi/scsiconf.h> 47 1.1 reinoud 48 1.1 reinoud #include <dev/ic/ncr5380reg.h> 49 1.1 reinoud #include <dev/ic/ncr5380var.h> 50 1.1 reinoud 51 1.1 reinoud #include <machine/io.h> 52 1.2 thorpej #include <machine/intr.h> 53 1.1 reinoud #include <machine/bootconfig.h> 54 1.1 reinoud 55 1.1 reinoud #include <acorn32/podulebus/podulebus.h> 56 1.1 reinoud #include <dev/podulebus/podules.h> 57 1.1 reinoud #include <dev/podulebus/powerromreg.h> 58 1.1 reinoud 59 1.1 reinoud #define CSA_NCR5380_OFFSET 0x2100 60 1.1 reinoud #define CSA_CTRL_OFFSET 0x2000 - 2308 61 1.1 reinoud #define CSA_DIRWRITE 0x02 62 1.1 reinoud #define CSA_DIRREAD 0x00 63 1.1 reinoud #define CSA_16BITS 0x00 64 1.1 reinoud #define CSA_8BITS 0x10 65 1.1 reinoud #define CSA_XXX 0x40 66 1.1 reinoud #define CSA_DATA_OFFSET 0x2000 67 1.1 reinoud #define CSA_INTR_OFFSET 0x2000 68 1.1 reinoud #define CSA_INTR_MASK 0x80 69 1.1 reinoud #define CSA_STAT_OFFSET 0x2004 70 1.1 reinoud #define CSA_STAT_DRQ 0x40 71 1.1 reinoud #define CSA_STAT_END 0x80 72 1.1 reinoud 73 1.9 tsutsui int csa_match(device_t, cfdata_t, void *); 74 1.9 tsutsui void csa_attach(device_t, device_t, void *); 75 1.1 reinoud 76 1.1 reinoud /* 77 1.1 reinoud * Cumana SCSI 1 softc structure. 78 1.1 reinoud * 79 1.9 tsutsui * Contains the generic ncr5380 device node, 80 1.9 tsutsui * podule information and global information 81 1.1 reinoud * required by the driver. 82 1.1 reinoud */ 83 1.1 reinoud 84 1.1 reinoud struct csa_softc { 85 1.1 reinoud struct ncr5380_softc sc_ncr5380; 86 1.1 reinoud void *sc_ih; 87 1.1 reinoud struct evcnt sc_intrcnt; 88 1.1 reinoud int sc_podule_number; 89 1.1 reinoud podule_t *sc_podule; 90 1.9 tsutsui volatile uint8_t *sc_irqstatus; 91 1.9 tsutsui uint8_t sc_irqmask; 92 1.9 tsutsui volatile uint8_t *sc_ctrl; 93 1.9 tsutsui volatile uint8_t *sc_status; 94 1.9 tsutsui volatile uint8_t *sc_data; 95 1.1 reinoud }; 96 1.1 reinoud 97 1.9 tsutsui CFATTACH_DECL_NEW(csa, sizeof(struct csa_softc), 98 1.6 thorpej csa_match, csa_attach, NULL, NULL); 99 1.1 reinoud 100 1.9 tsutsui int csa_intr(void *arg); 101 1.1 reinoud 102 1.1 reinoud /* 103 1.1 reinoud * Card probe function 104 1.1 reinoud * 105 1.1 reinoud * Just match the manufacturer and podule ID's 106 1.1 reinoud */ 107 1.1 reinoud 108 1.1 reinoud int 109 1.9 tsutsui csa_match(device_t parent, cfdata_t cf, void *aux) 110 1.1 reinoud { 111 1.1 reinoud struct podule_attach_args *pa = aux; 112 1.1 reinoud 113 1.3 bjh21 if (pa->pa_product == PODULE_CUMANA_SCSI1) 114 1.9 tsutsui return 1; 115 1.1 reinoud 116 1.1 reinoud /* PowerROM */ 117 1.1 reinoud if (pa->pa_product == PODULE_ALSYSTEMS_SCSI && 118 1.1 reinoud podulebus_initloader(pa) == 0 && 119 1.1 reinoud (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 || 120 1.1 reinoud podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16)) 121 1.1 reinoud return 1; 122 1.1 reinoud 123 1.1 reinoud return 0; 124 1.1 reinoud } 125 1.1 reinoud 126 1.1 reinoud /* 127 1.1 reinoud * Card attach function 128 1.1 reinoud * 129 1.1 reinoud */ 130 1.1 reinoud 131 1.1 reinoud void 132 1.9 tsutsui csa_attach(device_t parent, device_t self, void *aux) 133 1.1 reinoud { 134 1.9 tsutsui struct csa_softc *sc = device_private(self); 135 1.9 tsutsui struct ncr5380_softc *ncr_sc = &sc->sc_ncr5380; 136 1.1 reinoud struct podule_attach_args *pa = aux; 137 1.9 tsutsui uint8_t *iobase; 138 1.11 chs char hi_option[sizeof(device_xname(self)) + 8]; 139 1.9 tsutsui 140 1.9 tsutsui ncr_sc->sc_dev = self; 141 1.1 reinoud 142 1.1 reinoud /* Note the podule number and validate */ 143 1.1 reinoud 144 1.1 reinoud if (pa->pa_podule_number == -1) 145 1.1 reinoud panic("Podule has disappeared !"); 146 1.1 reinoud 147 1.1 reinoud sc->sc_podule_number = pa->pa_podule_number; 148 1.1 reinoud sc->sc_podule = pa->pa_podule; 149 1.1 reinoud podules[sc->sc_podule_number].attached = 1; 150 1.1 reinoud 151 1.9 tsutsui ncr_sc->sc_flags |= NCR5380_FORCE_POLLING; 152 1.9 tsutsui ncr_sc->sc_min_dma_len = 0; 153 1.9 tsutsui ncr_sc->sc_no_disconnect = 0x00; 154 1.9 tsutsui ncr_sc->sc_parity_disable = 0x00; 155 1.9 tsutsui 156 1.9 tsutsui ncr_sc->sc_dma_alloc = NULL; 157 1.9 tsutsui ncr_sc->sc_dma_free = NULL; 158 1.9 tsutsui ncr_sc->sc_dma_poll = NULL; 159 1.9 tsutsui ncr_sc->sc_dma_setup = NULL; 160 1.9 tsutsui ncr_sc->sc_dma_start = NULL; 161 1.9 tsutsui ncr_sc->sc_dma_eop = NULL; 162 1.9 tsutsui ncr_sc->sc_dma_stop = NULL; 163 1.9 tsutsui ncr_sc->sc_intr_on = NULL; 164 1.9 tsutsui ncr_sc->sc_intr_off = NULL; 165 1.9 tsutsui 166 1.9 tsutsui iobase = (uint8_t *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET; 167 1.9 tsutsui ncr_sc->sci_r0 = iobase + 0; 168 1.9 tsutsui ncr_sc->sci_r1 = iobase + 4; 169 1.9 tsutsui ncr_sc->sci_r2 = iobase + 8; 170 1.9 tsutsui ncr_sc->sci_r3 = iobase + 12; 171 1.9 tsutsui ncr_sc->sci_r4 = iobase + 16; 172 1.9 tsutsui ncr_sc->sci_r5 = iobase + 20; 173 1.9 tsutsui ncr_sc->sci_r6 = iobase + 24; 174 1.9 tsutsui ncr_sc->sci_r7 = iobase + 28; 175 1.9 tsutsui 176 1.9 tsutsui ncr_sc->sc_rev = NCR_VARIANT_NCR5380; 177 1.9 tsutsui 178 1.9 tsutsui sc->sc_ctrl = (uint8_t *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET; 179 1.9 tsutsui sc->sc_status = (uint8_t *)pa->pa_podule->slow_base + CSA_STAT_OFFSET; 180 1.9 tsutsui sc->sc_data = (uint8_t *)pa->pa_podule->slow_base + CSA_DATA_OFFSET; 181 1.1 reinoud 182 1.9 tsutsui ncr_sc->sc_pio_in = ncr5380_pio_in; 183 1.9 tsutsui ncr_sc->sc_pio_out = ncr5380_pio_out; 184 1.1 reinoud 185 1.1 reinoud /* Provide an override for the host id */ 186 1.9 tsutsui ncr_sc->sc_channel.chan_id = 7; 187 1.12 christos snprintf(hi_option, sizeof(hi_option), "%s.hostid", device_xname(self)); 188 1.1 reinoud (void)get_bootconf_option(boot_args, hi_option, 189 1.9 tsutsui BOOTOPT_TYPE_INT, &ncr_sc->sc_channel.chan_id); 190 1.9 tsutsui ncr_sc->sc_adapter.adapt_minphys = minphys; 191 1.1 reinoud 192 1.9 tsutsui aprint_normal(": host=%d, using 8 bit PIO", 193 1.9 tsutsui ncr_sc->sc_channel.chan_id); 194 1.1 reinoud 195 1.9 tsutsui sc->sc_irqstatus = 196 1.9 tsutsui (uint8_t *)pa->pa_podule->slow_base + CSA_INTR_OFFSET; 197 1.1 reinoud sc->sc_irqmask = CSA_INTR_MASK; 198 1.1 reinoud 199 1.1 reinoud evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 200 1.9 tsutsui device_xname(self), "intr"); 201 1.1 reinoud sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc, 202 1.1 reinoud &sc->sc_intrcnt); 203 1.1 reinoud if (sc->sc_ih == NULL) 204 1.9 tsutsui ncr_sc->sc_flags |= NCR5380_FORCE_POLLING; 205 1.1 reinoud 206 1.9 tsutsui if (ncr_sc->sc_flags & NCR5380_FORCE_POLLING) 207 1.9 tsutsui aprint_normal(", polling"); 208 1.9 tsutsui aprint_normal("\n"); 209 1.1 reinoud *sc->sc_ctrl = 0; 210 1.1 reinoud 211 1.9 tsutsui ncr5380_attach(ncr_sc); 212 1.1 reinoud } 213 1.1 reinoud 214 1.1 reinoud int 215 1.9 tsutsui csa_intr(void *arg) 216 1.1 reinoud { 217 1.1 reinoud struct csa_softc *sc = arg; 218 1.1 reinoud 219 1.1 reinoud if ((*sc->sc_irqstatus) & sc->sc_irqmask) 220 1.1 reinoud (void)ncr5380_intr(&sc->sc_ncr5380); 221 1.1 reinoud 222 1.9 tsutsui return 0; 223 1.1 reinoud } 224