csa.c revision 1.9 1 /* $NetBSD: csa.c,v 1.9 2008/04/04 16:00:57 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mark Brinicombe of Causality Limited.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Cumana SCSI 1 driver using the generic NCR5380 driver
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: csa.c,v 1.9 2008/04/04 16:00:57 tsutsui Exp $");
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/device.h>
50 #include <sys/buf.h>
51 #include <dev/scsipi/scsi_all.h>
52 #include <dev/scsipi/scsipi_all.h>
53 #include <dev/scsipi/scsiconf.h>
54
55 #include <dev/ic/ncr5380reg.h>
56 #include <dev/ic/ncr5380var.h>
57
58 #include <machine/io.h>
59 #include <machine/intr.h>
60 #include <machine/bootconfig.h>
61
62 #include <acorn32/podulebus/podulebus.h>
63 #include <dev/podulebus/podules.h>
64 #include <dev/podulebus/powerromreg.h>
65
66 #define CSA_NCR5380_OFFSET 0x2100
67 #define CSA_CTRL_OFFSET 0x2000 - 2308
68 #define CSA_DIRWRITE 0x02
69 #define CSA_DIRREAD 0x00
70 #define CSA_16BITS 0x00
71 #define CSA_8BITS 0x10
72 #define CSA_XXX 0x40
73 #define CSA_DATA_OFFSET 0x2000
74 #define CSA_INTR_OFFSET 0x2000
75 #define CSA_INTR_MASK 0x80
76 #define CSA_STAT_OFFSET 0x2004
77 #define CSA_STAT_DRQ 0x40
78 #define CSA_STAT_END 0x80
79
80 int csa_match(device_t, cfdata_t, void *);
81 void csa_attach(device_t, device_t, void *);
82
83 /*
84 * Cumana SCSI 1 softc structure.
85 *
86 * Contains the generic ncr5380 device node,
87 * podule information and global information
88 * required by the driver.
89 */
90
91 struct csa_softc {
92 struct ncr5380_softc sc_ncr5380;
93 void *sc_ih;
94 struct evcnt sc_intrcnt;
95 int sc_podule_number;
96 podule_t *sc_podule;
97 volatile uint8_t *sc_irqstatus;
98 uint8_t sc_irqmask;
99 volatile uint8_t *sc_ctrl;
100 volatile uint8_t *sc_status;
101 volatile uint8_t *sc_data;
102 };
103
104 CFATTACH_DECL_NEW(csa, sizeof(struct csa_softc),
105 csa_match, csa_attach, NULL, NULL);
106
107 int csa_intr(void *arg);
108
109 /*
110 * Card probe function
111 *
112 * Just match the manufacturer and podule ID's
113 */
114
115 int
116 csa_match(device_t parent, cfdata_t cf, void *aux)
117 {
118 struct podule_attach_args *pa = aux;
119
120 if (pa->pa_product == PODULE_CUMANA_SCSI1)
121 return 1;
122
123 /* PowerROM */
124 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
125 podulebus_initloader(pa) == 0 &&
126 (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 ||
127 podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16))
128 return 1;
129
130 return 0;
131 }
132
133 /*
134 * Card attach function
135 *
136 */
137
138 void
139 csa_attach(device_t parent, device_t self, void *aux)
140 {
141 struct csa_softc *sc = device_private(self);
142 struct ncr5380_softc *ncr_sc = &sc->sc_ncr5380;
143 struct podule_attach_args *pa = aux;
144 uint8_t *iobase;
145 char hi_option[sizeof(self->dv_xname) + 8];
146
147 ncr_sc->sc_dev = self;
148
149 /* Note the podule number and validate */
150
151 if (pa->pa_podule_number == -1)
152 panic("Podule has disappeared !");
153
154 sc->sc_podule_number = pa->pa_podule_number;
155 sc->sc_podule = pa->pa_podule;
156 podules[sc->sc_podule_number].attached = 1;
157
158 ncr_sc->sc_flags |= NCR5380_FORCE_POLLING;
159 ncr_sc->sc_min_dma_len = 0;
160 ncr_sc->sc_no_disconnect = 0x00;
161 ncr_sc->sc_parity_disable = 0x00;
162
163 ncr_sc->sc_dma_alloc = NULL;
164 ncr_sc->sc_dma_free = NULL;
165 ncr_sc->sc_dma_poll = NULL;
166 ncr_sc->sc_dma_setup = NULL;
167 ncr_sc->sc_dma_start = NULL;
168 ncr_sc->sc_dma_eop = NULL;
169 ncr_sc->sc_dma_stop = NULL;
170 ncr_sc->sc_intr_on = NULL;
171 ncr_sc->sc_intr_off = NULL;
172
173 iobase = (uint8_t *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET;
174 ncr_sc->sci_r0 = iobase + 0;
175 ncr_sc->sci_r1 = iobase + 4;
176 ncr_sc->sci_r2 = iobase + 8;
177 ncr_sc->sci_r3 = iobase + 12;
178 ncr_sc->sci_r4 = iobase + 16;
179 ncr_sc->sci_r5 = iobase + 20;
180 ncr_sc->sci_r6 = iobase + 24;
181 ncr_sc->sci_r7 = iobase + 28;
182
183 ncr_sc->sc_rev = NCR_VARIANT_NCR5380;
184
185 sc->sc_ctrl = (uint8_t *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET;
186 sc->sc_status = (uint8_t *)pa->pa_podule->slow_base + CSA_STAT_OFFSET;
187 sc->sc_data = (uint8_t *)pa->pa_podule->slow_base + CSA_DATA_OFFSET;
188
189 ncr_sc->sc_pio_in = ncr5380_pio_in;
190 ncr_sc->sc_pio_out = ncr5380_pio_out;
191
192 /* Provide an override for the host id */
193 ncr_sc->sc_channel.chan_id = 7;
194 sprintf(hi_option, "%s.hostid", device_xname(self));
195 (void)get_bootconf_option(boot_args, hi_option,
196 BOOTOPT_TYPE_INT, &ncr_sc->sc_channel.chan_id);
197 ncr_sc->sc_adapter.adapt_minphys = minphys;
198
199 aprint_normal(": host=%d, using 8 bit PIO",
200 ncr_sc->sc_channel.chan_id);
201
202 sc->sc_irqstatus =
203 (uint8_t *)pa->pa_podule->slow_base + CSA_INTR_OFFSET;
204 sc->sc_irqmask = CSA_INTR_MASK;
205
206 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
207 device_xname(self), "intr");
208 sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc,
209 &sc->sc_intrcnt);
210 if (sc->sc_ih == NULL)
211 ncr_sc->sc_flags |= NCR5380_FORCE_POLLING;
212
213 if (ncr_sc->sc_flags & NCR5380_FORCE_POLLING)
214 aprint_normal(", polling");
215 aprint_normal("\n");
216 *sc->sc_ctrl = 0;
217
218 ncr5380_attach(ncr_sc);
219 }
220
221 int
222 csa_intr(void *arg)
223 {
224 struct csa_softc *sc = arg;
225
226 if ((*sc->sc_irqstatus) & sc->sc_irqmask)
227 (void)ncr5380_intr(&sc->sc_ncr5380);
228
229 return 0;
230 }
231