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