1 /* $NetBSD: empsc.c,v 1.30 2021/08/07 16:18:41 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
18 *
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
29 * SUCH DAMAGE.
30 *
31 */
32
33 /*
34
35 * Copyright (c) 1995 Sean Riddle, Bo Najdrovsky
36 * Copyright (c) 1994 Michael L. Hitch
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: empsc.c,v 1.30 2021/08/07 16:18:41 thorpej Exp $");
70
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/kernel.h>
74 #include <sys/device.h>
75 #include <dev/scsipi/scsi_all.h>
76 #include <dev/scsipi/scsipi_all.h>
77 #include <dev/scsipi/scsiconf.h>
78 #include <amiga/amiga/custom.h>
79 #include <amiga/amiga/device.h>
80 #include <amiga/amiga/isr.h>
81 #include <amiga/dev/scireg.h>
82 #include <amiga/dev/scivar.h>
83 #include <amiga/dev/zbusvar.h>
84
85 void empscattach(device_t, device_t, void *);
86 int empscmatch(device_t, cfdata_t, void *);
87 int empsc_intr(void *);
88
89 #ifdef DEBUG
90 extern int sci_debug;
91 #endif
92
93 extern int sci_data_wait;
94
95 CFATTACH_DECL_NEW(empsc, sizeof(struct sci_softc),
96 empscmatch, empscattach, NULL, NULL);
97
98 /*
99 * if this is an EMPLANT board
100 */
101 int
empscmatch(device_t parent,cfdata_t cf,void * aux)102 empscmatch(device_t parent, cfdata_t cf, void *aux)
103 {
104 struct zbus_args *zap;
105
106 zap = aux;
107
108 /*
109 * Check manufacturer and product id.
110 */
111 if (zap->manid == 2171 && ((zap->prodid == 21)||(zap->prodid==32)))
112 return(1);
113 else
114 return(0);
115 }
116
117 void
empscattach(device_t parent,device_t self,void * aux)118 empscattach(device_t parent, device_t self, void *aux)
119 {
120 volatile u_char *rp;
121 struct sci_softc *sc = device_private(self);
122 struct zbus_args *zap;
123 struct scsipi_adapter *adapt = &sc->sc_adapter;
124 struct scsipi_channel *chan = &sc->sc_channel;
125
126 printf("\n");
127
128 zap = aux;
129
130 rp = (u_char *)zap->va + 0x5000;
131
132 sc->sc_dev = self;
133 sc->sci_data = rp;
134 sc->sci_odata = rp;
135 sc->sci_icmd = rp + 0x10;
136 sc->sci_mode = rp + 0x20;
137 sc->sci_tcmd = rp + 0x30;
138 sc->sci_bus_csr = rp + 0x40;
139 sc->sci_sel_enb = rp + 0x40;
140 sc->sci_csr = rp + 0x50;
141 sc->sci_dma_send = rp + 0x50;
142 sc->sci_idata = rp + 0x60;
143 sc->sci_trecv = rp + 0x60;
144 sc->sci_iack = rp + 0x70;
145 sc->sci_irecv = rp + 0x70;
146 sc->sc_isr.isr_intr = empsc_intr;
147 sc->sc_isr.isr_arg = sc;
148 sc->sc_isr.isr_ipl = 2;
149 add_isr(&sc->sc_isr);
150
151 scireset(sc);
152
153 /*
154 * Fill in the scsipi_adapter.
155 */
156 memset(adapt, 0, sizeof(*adapt));
157 adapt->adapt_dev = self;
158 adapt->adapt_nchannels = 1;
159 adapt->adapt_openings = 7;
160 adapt->adapt_max_periph = 1;
161 adapt->adapt_request = sci_scsipi_request;
162 adapt->adapt_minphys = sci_minphys;
163
164 /*
165 * Fill in the scsipi_channel.
166 */
167 memset(chan, 0, sizeof(*chan));
168 chan->chan_adapter = adapt;
169 chan->chan_bustype = &scsi_bustype;
170 chan->chan_channel = 0;
171 chan->chan_ntargets = 8;
172 chan->chan_nluns = 8;
173 chan->chan_id = 7;
174
175 /*
176 * attach all scsi units on us
177 */
178 config_found(self, chan, scsiprint, CFARGS_NONE);
179 }
180
181 int
empsc_intr(void * arg)182 empsc_intr(void *arg)
183 {
184 struct sci_softc *dev = arg;
185 u_char stat;
186
187 if ((*dev->sci_csr & SCI_CSR_INT) == 0)
188 return(0);
189 stat = *dev->sci_iack;
190 __USE(stat);
191 /* XXXX is: something is missing here, at least a: */
192 return(1);
193 }
194