1 /* $NetBSD: wstsc.c,v 1.28.6.4 2005/11/10 13:51:36 skrll Exp $ */
4 * Copyright (c) 1982, 1990 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Copyright (c) 1994 Michael L. Hitch
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: wstsc.c,v 1.28.6.4 2005/11/10 13:51:36 skrll Exp $");
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/device.h>
67 #include <dev/scsipi/scsi_all.h>
68 #include <dev/scsipi/scsipi_all.h>
69 #include <dev/scsipi/scsiconf.h>
70 #include <amiga/amiga/device.h>
71 #include <amiga/amiga/isr.h>
72 #include <amiga/dev/scireg.h>
73 #include <amiga/dev/scivar.h>
74 #include <amiga/dev/zbusvar.h>
76 void wstscattach(struct device
*, struct device
*, void *);
77 int wstscmatch(struct device
*, struct cfdata
*, void *);
79 int wstsc_dma_xfer_in(struct sci_softc
*dev
, int len
,
80 register u_char
*buf
, int phase
);
81 int wstsc_dma_xfer_out(struct sci_softc
*dev
, int len
,
82 register u_char
*buf
, int phase
);
83 int wstsc_dma_xfer_in2(struct sci_softc
*dev
, int len
,
84 register u_short
*buf
, int phase
);
85 int wstsc_dma_xfer_out2(struct sci_softc
*dev
, int len
,
86 register u_short
*buf
, int phase
);
87 int wstsc_intr(void *);
91 #define QPRINTF(a) if (sci_debug > 1) printf a
96 extern int sci_data_wait
;
98 int supradma_pseudo
= 0; /* 0=none, 1=byte, 2=word */
100 CFATTACH_DECL(wstsc
, sizeof(struct sci_softc
),
101 wstscmatch
, wstscattach
, NULL
, NULL
);
104 * if this a Supra WordSync board
107 wstscmatch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
109 struct zbus_args
*zap
;
114 * Check manufacturer and product id.
116 if (zap
->manid
== 1056 && (
117 zap
->prodid
== 12 || /* WordSync */
118 zap
->prodid
== 13)) /* ByteSync */
125 wstscattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
128 struct sci_softc
*sc
= (struct sci_softc
*)dp
;
129 struct zbus_args
*zap
;
130 struct scsipi_adapter
*adapt
= &sc
->sc_adapter
;
131 struct scsipi_channel
*chan
= &sc
->sc_channel
;
139 * set up 5380 register pointers
140 * (Needs check on which Supra board this is - for now,
141 * just do the WordSync)
143 sc
->sci_data
= rp
+ 0;
144 sc
->sci_odata
= rp
+ 0;
145 sc
->sci_icmd
= rp
+ 2;
146 sc
->sci_mode
= rp
+ 4;
147 sc
->sci_tcmd
= rp
+ 6;
148 sc
->sci_bus_csr
= rp
+ 8;
149 sc
->sci_sel_enb
= rp
+ 8;
150 sc
->sci_csr
= rp
+ 10;
151 sc
->sci_dma_send
= rp
+ 10;
152 sc
->sci_idata
= rp
+ 12;
153 sc
->sci_trecv
= rp
+ 12;
154 sc
->sci_iack
= rp
+ 14;
155 sc
->sci_irecv
= rp
+ 14;
157 if (supradma_pseudo
== 2) {
158 sc
->dma_xfer_in
= (int(*)(struct sci_softc
*, int, u_char
*, int))wstsc_dma_xfer_in2
;
159 sc
->dma_xfer_out
= (int(*)(struct sci_softc
*, int, u_char
*, int))wstsc_dma_xfer_out2
;
161 else if (supradma_pseudo
== 1) {
162 sc
->dma_xfer_in
= wstsc_dma_xfer_in
;
163 sc
->dma_xfer_out
= wstsc_dma_xfer_out
;
166 sc
->sc_isr
.isr_intr
= wstsc_intr
;
167 sc
->sc_isr
.isr_arg
= sc
;
168 sc
->sc_isr
.isr_ipl
= 2;
169 add_isr(&sc
->sc_isr
);
174 * Fill in the scsipi_adapter.
176 memset(adapt
, 0, sizeof(*adapt
));
177 adapt
->adapt_dev
= &sc
->sc_dev
;
178 adapt
->adapt_nchannels
= 1;
179 adapt
->adapt_openings
= 7;
180 adapt
->adapt_max_periph
= 1;
181 adapt
->adapt_request
= sci_scsipi_request
;
182 adapt
->adapt_minphys
= sci_minphys
;
185 * Fill in the scsipi_channel.
187 memset(chan
, 0, sizeof(*chan
));
188 chan
->chan_adapter
= adapt
;
189 chan
->chan_bustype
= &scsi_bustype
;
190 chan
->chan_channel
= 0;
191 chan
->chan_ntargets
= 8;
192 chan
->chan_nluns
= 8;
196 * attach all scsi units on us
198 config_found(dp
, chan
, scsiprint
);
202 wstsc_dma_xfer_in(struct sci_softc
*dev
, int len
, register u_char
*buf
,
205 int wait
= sci_data_wait
;
206 volatile register u_char
*sci_dma
= dev
->sci_idata
;
207 volatile register u_char
*sci_csr
= dev
->sci_csr
;
209 u_char
*obp
= (u_char
*) buf
;
212 QPRINTF(("supradma_in %d, csr=%02x\n", len
, *dev
->sci_bus_csr
));
214 *dev
->sci_tcmd
= phase
;
216 *dev
->sci_mode
= SCI_MODE_DMA
;
220 wait
= sci_data_wait
;
221 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
222 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
223 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
224 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
228 printf("supradma2_in fail: l%d i%x w%d\n",
229 len
, *dev
->sci_bus_csr
, wait
);
236 #define R1 (*buf++ = *sci_dma)
237 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
238 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
239 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
240 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
241 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
242 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
243 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
244 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
245 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
246 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
247 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
248 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
249 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
250 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
251 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
252 R1
; R1
; R1
; R1
; R1
; R1
; R1
; R1
;
257 wait
= sci_data_wait
;
258 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
259 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
260 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
261 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
265 printf("supradma1_in fail: l%d i%x w%d\n",
266 len
, *dev
->sci_bus_csr
, wait
);
277 QPRINTF(("supradma_in {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
278 len
, obp
[0], obp
[1], obp
[2], obp
[3], obp
[4], obp
[5],
279 obp
[6], obp
[7], obp
[8], obp
[9]));
286 wstsc_dma_xfer_out(struct sci_softc
*dev
, int len
, register u_char
*buf
,
289 int wait
= sci_data_wait
;
290 volatile register u_char
*sci_dma
= dev
->sci_data
;
291 volatile register u_char
*sci_csr
= dev
->sci_csr
;
293 QPRINTF(("supradma_out %d, csr=%02x\n", len
, *dev
->sci_bus_csr
));
295 QPRINTF(("supradma_out {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
296 len
, buf
[0], buf
[1], buf
[2], buf
[3], buf
[4], buf
[5],
297 buf
[6], buf
[7], buf
[8], buf
[9]));
299 *dev
->sci_tcmd
= phase
;
300 *dev
->sci_mode
= SCI_MODE_DMA
;
301 *dev
->sci_icmd
= SCI_ICMD_DATA
;
302 *dev
->sci_dma_send
= 0;
304 wait
= sci_data_wait
;
305 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
306 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
307 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
308 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
312 printf("supradma_out fail: l%d i%x w%d\n",
313 len
, *dev
->sci_bus_csr
, wait
);
324 wait
= sci_data_wait
;
325 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) ==
326 SCI_CSR_PHASE_MATCH
&& --wait
);
336 wstsc_dma_xfer_in2(struct sci_softc
*dev
, int len
, register u_short
*buf
,
339 volatile register u_short
*sci_dma
=
340 (volatile u_short
*)(dev
->sci_idata
+ 0x10);
341 volatile register u_char
*sci_csr
= dev
->sci_csr
+ 0x10;
343 u_char
*obp
= (u_char
*) buf
;
346 int wait
= sci_data_wait
;
349 QPRINTF(("supradma_in2 %d, csr=%02x\n", len
, *dev
->sci_bus_csr
));
351 *dev
->sci_tcmd
= phase
;
352 *dev
->sci_mode
= SCI_MODE_DMA
;
354 *(dev
->sci_irecv
+ 16) = 0;
357 wait
= sci_data_wait
;
358 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
359 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
360 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
361 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
365 printf("supradma2_in2 fail: l%d i%x w%d\n",
366 len
, *dev
->sci_bus_csr
, wait
);
368 *dev
->sci_mode
&= ~SCI_MODE_DMA
;
373 while (!(*sci_csr
& SCI_CSR_DREQ
))
377 #define R2 (*buf++ = *sci_dma)
378 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
379 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
380 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
381 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
382 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
383 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
384 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
385 R2
; R2
; R2
; R2
; R2
; R2
; R2
; R2
;
390 wait
= sci_data_wait
;
391 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
392 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
393 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
394 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
398 printf("supradma1_in2 fail: l%d i%x w%d\n",
399 len
, *dev
->sci_bus_csr
, wait
);
401 *dev
->sci_mode
&= ~SCI_MODE_DMA
;
406 while (!(*sci_csr
* SCI_CSR_DREQ
))
414 QPRINTF(("supradma_in2 {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
415 len
, obp
[0], obp
[1], obp
[2], obp
[3], obp
[4], obp
[5],
416 obp
[6], obp
[7], obp
[8], obp
[9]));
424 wstsc_dma_xfer_out2(struct sci_softc
*dev
, int len
, register u_short
*buf
,
427 volatile register u_short
*sci_dma
=
428 (volatile ushort
*)(dev
->sci_data
+ 0x10);
429 volatile register u_char
*sci_bus_csr
= dev
->sci_bus_csr
;
431 u_char
*obp
= (u_char
*) buf
;
434 int wait
= sci_data_wait
;
437 QPRINTF(("supradma_out2 %d, csr=%02x\n", len
, *dev
->sci_bus_csr
));
439 QPRINTF(("supradma_out2 {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
440 len
, obp
[0], obp
[1], obp
[2], obp
[3], obp
[4], obp
[5],
441 obp
[6], obp
[7], obp
[8], obp
[9]));
443 *dev
->sci_tcmd
= phase
;
444 *dev
->sci_mode
= SCI_MODE_DMA
;
445 *dev
->sci_icmd
= SCI_ICMD_DATA
;
446 *dev
->sci_dma_send
= 0;
449 wait
= sci_data_wait
;
450 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
451 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
452 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
453 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
457 printf("supradma_out2 fail: l%d i%x w%d\n",
466 *dev
->sci_icmd
&= ~SCI_ICMD_ACK
;
467 while (!(*sci_bus_csr
& SCI_BUS_REQ
))
469 *dev
->sci_mode
= SCI_MODE_DMA
;
470 *dev
->sci_dma_send
= 0;
473 #define W2 (*sci_dma = *buf++)
474 W2
; W2
; W2
; W2
; W2
; W2
; W2
; W2
;
475 W2
; W2
; W2
; W2
; W2
; W2
; W2
; W2
;
476 if (*(sci_bus_csr
+ 0x10) & SCI_BUS_REQ
)
483 wait
= sci_data_wait
;
484 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
485 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
486 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
487 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
491 printf("supradma_out2 fail: l%d i%x w%d\n",
500 *dev
->sci_icmd
&= ~SCI_ICMD_ACK
;
501 while (!(*sci_bus_csr
& SCI_BUS_REQ
))
503 *dev
->sci_mode
= SCI_MODE_DMA
;
504 *dev
->sci_dma_send
= 0;
508 if (*(sci_bus_csr
+ 0x10) & SCI_BUS_REQ
)
514 wait
= sci_data_wait
;
515 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) ==
516 SCI_CSR_PHASE_MATCH
&& --wait
);
521 *dev
->sci_icmd
&= ~SCI_ICMD_ACK
;
528 wstsc_intr(void *arg
)
530 struct sci_softc
*dev
= arg
;
533 if ((*(dev
->sci_csr
+ 0x10) & SCI_CSR_INT
) == 0)
535 stat
= *(dev
->sci_iack
+ 0x10);