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