1 /* $NetBSD: otgsc.c,v 1.28.6.3 2004/09/21 13:12:31 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: otgsc.c,v 1.28.6.3 2004/09/21 13:12:31 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 otgscattach(struct device
*, struct device
*, void *);
77 int otgscmatch(struct device
*, struct cfdata
*, void *);
79 int otgsc_dma_xfer_in(struct sci_softc
*dev
, int len
,
80 register u_char
*buf
, int phase
);
81 int otgsc_dma_xfer_out(struct sci_softc
*dev
, int len
,
82 register u_char
*buf
, int phase
);
83 int otgsc_intr(void *);
88 #define QPRINTF(a) if (sci_debug > 1) printf a
93 extern int sci_data_wait
;
95 CFATTACH_DECL(otgsc
, sizeof(struct sci_softc
),
96 otgscmatch
, otgscattach
, NULL
, NULL
);
99 * if we are my Hacker's SCSI board we are here.
102 otgscmatch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
104 struct zbus_args
*zap
;
109 * Check manufacturer and product id.
111 if (zap
->manid
== 1058 && zap
->prodid
== 21)
118 otgscattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
121 struct sci_softc
*sc
= (struct sci_softc
*)dp
;
122 struct zbus_args
*zap
;
123 struct scsipi_adapter
*adapt
= &sc
->sc_adapter
;
124 struct scsipi_channel
*chan
= &sc
->sc_channel
;
130 sc
= (struct sci_softc
*)dp
;
131 rp
= (u_char
*)zap
->va
+ 0x2000;
134 sc
->sci_icmd
= rp
+ 0x10;
135 sc
->sci_mode
= rp
+ 0x20;
136 sc
->sci_tcmd
= rp
+ 0x30;
137 sc
->sci_bus_csr
= rp
+ 0x40;
138 sc
->sci_sel_enb
= rp
+ 0x40;
139 sc
->sci_csr
= rp
+ 0x50;
140 sc
->sci_dma_send
= rp
+ 0x50;
141 sc
->sci_idata
= rp
+ 0x60;
142 sc
->sci_trecv
= rp
+ 0x60;
143 sc
->sci_iack
= rp
+ 0x70;
144 sc
->sci_irecv
= rp
+ 0x70;
146 sc
->dma_xfer_in
= otgsc_dma_xfer_in
;
147 sc
->dma_xfer_out
= otgsc_dma_xfer_out
;
149 sc
->sc_isr
.isr_intr
= otgsc_intr
;
150 sc
->sc_isr
.isr_arg
= sc
;
151 sc
->sc_isr
.isr_ipl
= 2;
152 add_isr(&sc
->sc_isr
);
157 * Fill in the scsipi_adapter.
159 memset(adapt
, 0, sizeof(*adapt
));
160 adapt
->adapt_dev
= &sc
->sc_dev
;
161 adapt
->adapt_nchannels
= 1;
162 adapt
->adapt_openings
= 7;
163 adapt
->adapt_max_periph
= 1;
164 adapt
->adapt_request
= sci_scsipi_request
;
165 adapt
->adapt_minphys
= sci_minphys
;
168 * Fill in the scsipi_channel.
170 memset(chan
, 0, sizeof(*chan
));
171 chan
->chan_adapter
= adapt
;
172 chan
->chan_bustype
= &scsi_bustype
;
173 chan
->chan_channel
= 0;
174 chan
->chan_ntargets
= 8;
175 chan
->chan_nluns
= 8;
179 * attach all scsi units on us
181 config_found(dp
, chan
, scsiprint
);
185 otgsc_dma_xfer_in(struct sci_softc
*dev
, int len
, register u_char
*buf
,
188 int wait
= sci_data_wait
;
189 volatile register u_char
*sci_dma
= dev
->sci_data
+ 0x100;
190 volatile register u_char
*sci_csr
= dev
->sci_csr
;
195 QPRINTF(("otgsc_dma_in %d, csr=%02x\n", len
, *dev
->sci_bus_csr
));
197 *dev
->sci_tcmd
= phase
;
198 *dev
->sci_mode
|= SCI_MODE_DMA
;
202 wait
= sci_data_wait
;
203 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
204 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
205 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
206 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
210 printf("otgsc_dma_in fail: l%d i%x w%d\n",
211 len
, *dev
->sci_bus_csr
, wait
);
213 *dev
->sci_mode
&= ~SCI_MODE_DMA
;
222 QPRINTF(("otgsc_dma_in {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
223 len
, obp
[0], obp
[1], obp
[2], obp
[3], obp
[4], obp
[5],
224 obp
[6], obp
[7], obp
[8], obp
[9]));
226 *dev
->sci_mode
&= ~SCI_MODE_DMA
;
231 otgsc_dma_xfer_out(struct sci_softc
*dev
, int len
, register u_char
*buf
,
234 int wait
= sci_data_wait
;
235 volatile register u_char
*sci_dma
= dev
->sci_data
+ 0x100;
236 volatile register u_char
*sci_csr
= dev
->sci_csr
;
238 QPRINTF(("otgsc_dma_out %d, csr=%02x\n", len
, *dev
->sci_bus_csr
));
240 QPRINTF(("otgsc_dma_out {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
241 len
, buf
[0], buf
[1], buf
[2], buf
[3], buf
[4], buf
[5],
242 buf
[6], buf
[7], buf
[8], buf
[9]));
244 *dev
->sci_tcmd
= phase
;
245 *dev
->sci_mode
|= SCI_MODE_DMA
;
246 *dev
->sci_icmd
= SCI_ICMD_DATA
;
247 *dev
->sci_dma_send
= 0;
249 wait
= sci_data_wait
;
250 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) !=
251 (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) {
252 if (!(*sci_csr
& SCI_CSR_PHASE_MATCH
)
253 || !(*dev
->sci_bus_csr
& SCI_BUS_BSY
)
257 printf("otgsc_dma_out fail: l%d i%x w%d\n",
258 len
, *dev
->sci_bus_csr
, wait
);
260 *dev
->sci_mode
&= ~SCI_MODE_DMA
;
269 wait
= sci_data_wait
;
270 while ((*sci_csr
& (SCI_CSR_DREQ
|SCI_CSR_PHASE_MATCH
)) ==
271 SCI_CSR_PHASE_MATCH
&& --wait
);
274 *dev
->sci_mode
&= ~SCI_MODE_DMA
;
279 otgsc_intr(void *arg
)
281 struct sci_softc
*dev
= arg
;
284 if ((*dev
->sci_csr
& SCI_CSR_INT
) == 0)
286 stat
= *dev
->sci_iack
;