csa.c revision 1.2 1 1.2 thorpej /* $NetBSD: csa.c,v 1.2 2001/11/27 00:53:12 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.1 reinoud struct cfattach csa_ca = {
101 1.1 reinoud sizeof(struct csa_softc), csa_match, csa_attach
102 1.1 reinoud };
103 1.1 reinoud
104 1.1 reinoud int csa_intr __P((void *arg));
105 1.1 reinoud
106 1.1 reinoud /*
107 1.1 reinoud * Card probe function
108 1.1 reinoud *
109 1.1 reinoud * Just match the manufacturer and podule ID's
110 1.1 reinoud */
111 1.1 reinoud
112 1.1 reinoud int
113 1.1 reinoud csa_match(parent, cf, aux)
114 1.1 reinoud struct device *parent;
115 1.1 reinoud struct cfdata *cf;
116 1.1 reinoud void *aux;
117 1.1 reinoud {
118 1.1 reinoud struct podule_attach_args *pa = aux;
119 1.1 reinoud
120 1.1 reinoud if (matchpodule(pa, MANUFACTURER_CUMANA, PODULE_CUMANA_SCSI1, -1))
121 1.1 reinoud return(1);
122 1.1 reinoud
123 1.1 reinoud /* PowerROM */
124 1.1 reinoud if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
125 1.1 reinoud podulebus_initloader(pa) == 0 &&
126 1.1 reinoud (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 ||
127 1.1 reinoud podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16))
128 1.1 reinoud return 1;
129 1.1 reinoud
130 1.1 reinoud return 0;
131 1.1 reinoud }
132 1.1 reinoud
133 1.1 reinoud /*
134 1.1 reinoud * Card attach function
135 1.1 reinoud *
136 1.1 reinoud */
137 1.1 reinoud
138 1.1 reinoud void
139 1.1 reinoud csa_attach(parent, self, aux)
140 1.1 reinoud struct device *parent, *self;
141 1.1 reinoud void *aux;
142 1.1 reinoud {
143 1.1 reinoud struct csa_softc *sc = (struct csa_softc *)self;
144 1.1 reinoud struct podule_attach_args *pa = aux;
145 1.1 reinoud u_char *iobase;
146 1.1 reinoud char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
147 1.1 reinoud
148 1.1 reinoud /* Note the podule number and validate */
149 1.1 reinoud
150 1.1 reinoud if (pa->pa_podule_number == -1)
151 1.1 reinoud panic("Podule has disappeared !");
152 1.1 reinoud
153 1.1 reinoud sc->sc_podule_number = pa->pa_podule_number;
154 1.1 reinoud sc->sc_podule = pa->pa_podule;
155 1.1 reinoud podules[sc->sc_podule_number].attached = 1;
156 1.1 reinoud
157 1.1 reinoud sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
158 1.1 reinoud sc->sc_ncr5380.sc_min_dma_len = 0;
159 1.1 reinoud sc->sc_ncr5380.sc_no_disconnect = 0x00;
160 1.1 reinoud sc->sc_ncr5380.sc_parity_disable = 0x00;
161 1.1 reinoud
162 1.1 reinoud sc->sc_ncr5380.sc_dma_alloc = NULL;
163 1.1 reinoud sc->sc_ncr5380.sc_dma_free = NULL;
164 1.1 reinoud sc->sc_ncr5380.sc_dma_poll = NULL;
165 1.1 reinoud sc->sc_ncr5380.sc_dma_setup = NULL;
166 1.1 reinoud sc->sc_ncr5380.sc_dma_start = NULL;
167 1.1 reinoud sc->sc_ncr5380.sc_dma_eop = NULL;
168 1.1 reinoud sc->sc_ncr5380.sc_dma_stop = NULL;
169 1.1 reinoud sc->sc_ncr5380.sc_intr_on = NULL;
170 1.1 reinoud sc->sc_ncr5380.sc_intr_off = NULL;
171 1.1 reinoud
172 1.1 reinoud iobase = (u_char *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET;
173 1.1 reinoud sc->sc_ncr5380.sci_r0 = iobase + 0;
174 1.1 reinoud sc->sc_ncr5380.sci_r1 = iobase + 4;
175 1.1 reinoud sc->sc_ncr5380.sci_r2 = iobase + 8;
176 1.1 reinoud sc->sc_ncr5380.sci_r3 = iobase + 12;
177 1.1 reinoud sc->sc_ncr5380.sci_r4 = iobase + 16;
178 1.1 reinoud sc->sc_ncr5380.sci_r5 = iobase + 20;
179 1.1 reinoud sc->sc_ncr5380.sci_r6 = iobase + 24;
180 1.1 reinoud sc->sc_ncr5380.sci_r7 = iobase + 28;
181 1.1 reinoud
182 1.1 reinoud sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380;
183 1.1 reinoud
184 1.1 reinoud sc->sc_ctrl = (u_char *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET;
185 1.1 reinoud sc->sc_status = (u_char *)pa->pa_podule->slow_base + CSA_STAT_OFFSET;
186 1.1 reinoud sc->sc_data = (u_char *)pa->pa_podule->slow_base + CSA_DATA_OFFSET;
187 1.1 reinoud
188 1.1 reinoud sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
189 1.1 reinoud sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
190 1.1 reinoud
191 1.1 reinoud /* Provide an override for the host id */
192 1.1 reinoud sc->sc_ncr5380.sc_channel.chan_id = 7;
193 1.1 reinoud sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
194 1.1 reinoud (void)get_bootconf_option(boot_args, hi_option,
195 1.1 reinoud BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
196 1.1 reinoud sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
197 1.1 reinoud
198 1.1 reinoud printf(": host=%d, using 8 bit PIO",
199 1.1 reinoud sc->sc_ncr5380.sc_channel.chan_id);
200 1.1 reinoud
201 1.1 reinoud sc->sc_irqstatus = (u_char *)pa->pa_podule->slow_base + CSA_INTR_OFFSET;
202 1.1 reinoud sc->sc_irqmask = CSA_INTR_MASK;
203 1.1 reinoud
204 1.1 reinoud evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
205 1.1 reinoud self->dv_xname, "intr");
206 1.1 reinoud sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc,
207 1.1 reinoud &sc->sc_intrcnt);
208 1.1 reinoud if (sc->sc_ih == NULL)
209 1.1 reinoud sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
210 1.1 reinoud
211 1.1 reinoud if (sc->sc_ncr5380.sc_flags & NCR5380_FORCE_POLLING)
212 1.1 reinoud printf(", polling");
213 1.1 reinoud printf("\n");
214 1.1 reinoud *sc->sc_ctrl = 0;
215 1.1 reinoud
216 1.1 reinoud ncr5380_attach(&sc->sc_ncr5380);
217 1.1 reinoud }
218 1.1 reinoud
219 1.1 reinoud int
220 1.1 reinoud csa_intr(arg)
221 1.1 reinoud void *arg;
222 1.1 reinoud {
223 1.1 reinoud struct csa_softc *sc = arg;
224 1.1 reinoud
225 1.1 reinoud if ((*sc->sc_irqstatus) & sc->sc_irqmask)
226 1.1 reinoud (void)ncr5380_intr(&sc->sc_ncr5380);
227 1.1 reinoud
228 1.1 reinoud return(0);
229 1.1 reinoud }
230