1 /* $NetBSD: nca_pcmcia.c,v 1.9 2002/10/02 16:52:19 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: nca_pcmcia.c,v 1.9 2002/10/02 16:52:19 thorpej Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/buf.h>
46
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49
50 #include <dev/scsipi/scsi_all.h>
51 #include <dev/scsipi/scsipi_all.h>
52 #include <dev/scsipi/scsiconf.h>
53
54 #include <dev/pcmcia/pcmciareg.h>
55 #include <dev/pcmcia/pcmciavar.h>
56 #include <dev/pcmcia/pcmciadevs.h>
57
58 #include <dev/ic/ncr5380reg.h>
59 #include <dev/ic/ncr5380var.h>
60 #include <dev/ic/ncr53c400reg.h>
61
62 struct nca_pcmcia_softc {
63 struct ncr5380_softc sc_ncr5380; /* glue to MI code */
64
65 /* PCMCIA-specific goo. */
66 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
67 int sc_io_window; /* our i/o window */
68 struct pcmcia_function *sc_pf; /* our PCMCIA function */
69 void *sc_ih; /* interrupt handler */
70 int sc_flags;
71 #define NCA_PCMCIA_ATTACHED 1 /* attach completed */
72 #define NCA_PCMCIA_ATTACHING 2 /* attach in progress */
73 };
74
75 int nca_pcmcia_match __P((struct device *, struct cfdata *, void *));
76 void nca_pcmcia_attach __P((struct device *, struct device *, void *));
77 int nca_pcmcia_detach __P((struct device *, int));
78 int nca_pcmcia_enable __P((struct device *, int));
79
80 CFATTACH_DECL(nca_pcmcia, sizeof(struct nca_pcmcia_softc),
81 nca_pcmcia_match, nca_pcmcia_attach, nca_pcmcia_detach, NULL);
82
83 #define MIN_DMA_LEN 128
84
85 /* Options for disconnect/reselect, DMA, and interrupts. */
86 #define NCA_NO_DISCONNECT 0x00ff
87 #define NCA_NO_PARITY_CHK 0xff00
88
89 const struct pcmcia_product nca_pcmcia_products[] = {
90
91 { NULL }
92 };
93
94 int
95 nca_pcmcia_match(parent, match, aux)
96 struct device *parent;
97 struct cfdata *match;
98 void *aux;
99 {
100 struct pcmcia_attach_args *pa = aux;
101
102 if (pcmcia_product_lookup(pa, nca_pcmcia_products,
103 sizeof nca_pcmcia_products[0], NULL) != NULL)
104 return (1);
105 return (0);
106 }
107
108 void
109 nca_pcmcia_attach(parent, self, aux)
110 struct device *parent, *self;
111 void *aux;
112 {
113 struct nca_pcmcia_softc *esc = (void *)self;
114 struct ncr5380_softc *sc = &esc->sc_ncr5380;
115 struct pcmcia_attach_args *pa = aux;
116 struct pcmcia_config_entry *cfe;
117 struct pcmcia_function *pf = pa->pf;
118 const struct pcmcia_product *pp;
119 int flags;
120
121 esc->sc_pf = pf;
122
123 SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
124 if (cfe->num_memspace != 0 ||
125 cfe->num_iospace != 1)
126 continue;
127
128 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
129 cfe->iospace[0].length, 0, &esc->sc_pcioh) == 0)
130 break;
131 }
132
133 if (cfe == 0) {
134 printf(": can't alloc i/o space\n");
135 goto no_config_entry;
136 }
137
138 /* Enable the card. */
139 pcmcia_function_init(pf, cfe);
140 if (pcmcia_function_enable(pf)) {
141 printf(": function enable failed\n");
142 goto enable_failed;
143 }
144
145 /* Map in the I/O space */
146 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, esc->sc_pcioh.size,
147 &esc->sc_pcioh, &esc->sc_io_window)) {
148 printf(": can't map i/o space\n");
149 goto iomap_failed;
150 }
151
152 pp = pcmcia_product_lookup(pa, nca_pcmcia_products,
153 sizeof nca_pcmcia_products[0], NULL);
154 if (pp == NULL) {
155 printf("\n");
156 panic("nca_pcmcia_attach: impossible");
157 }
158
159 printf(": %s\n", pp->pp_name);
160
161 /* We can enable and disable the controller. */
162 sc->sc_adapter.adapt_enable = nca_pcmcia_enable;
163
164 /* Reset into 5380-compat. mode */
165 bus_space_write_1(esc->sc_pcioh.iot, esc->sc_pcioh.ioh, C400_CSR,
166 C400_CSR_5380_ENABLE);
167
168 /* Initialize 5380 compatible register offsets. */
169 sc->sci_r0 = C400_5380_REG_OFFSET + 0;
170 sc->sci_r1 = C400_5380_REG_OFFSET + 1;
171 sc->sci_r2 = C400_5380_REG_OFFSET + 2;
172 sc->sci_r3 = C400_5380_REG_OFFSET + 3;
173 sc->sci_r4 = C400_5380_REG_OFFSET + 4;
174 sc->sci_r5 = C400_5380_REG_OFFSET + 5;
175 sc->sci_r6 = C400_5380_REG_OFFSET + 6;
176 sc->sci_r7 = C400_5380_REG_OFFSET + 7;
177
178 sc->sc_rev = NCR_VARIANT_NCR53C400;
179
180 /*
181 * MD function pointers used by the MI code.
182 */
183 sc->sc_pio_out = ncr5380_pio_out;
184 sc->sc_pio_in = ncr5380_pio_in;
185 sc->sc_dma_alloc = NULL;
186 sc->sc_dma_free = NULL;
187 sc->sc_dma_setup = NULL;
188 sc->sc_dma_start = NULL;
189 sc->sc_dma_poll = NULL;
190 sc->sc_dma_eop = NULL;
191 sc->sc_dma_stop = NULL;
192 sc->sc_intr_on = NULL;
193 sc->sc_intr_off = NULL;
194
195
196 /*
197 * Support the "options" (config file flags).
198 * Disconnect/reselect is a per-target mask.
199 * Interrupts and DMA are per-controller.
200 */
201 #if 0
202 flags = 0x0000; /* no options */
203 #else
204 flags = 0xffff; /* all options except force poll */
205 #endif
206
207 sc->sc_no_disconnect = (flags & NCA_NO_DISCONNECT);
208 sc->sc_parity_disable = (flags & NCA_NO_PARITY_CHK) >> 8;
209 sc->sc_min_dma_len = MIN_DMA_LEN;
210
211 /*
212 * Initialize fields used by the MI code
213 */
214 sc->sc_regt = esc->sc_pcioh.iot;
215 sc->sc_regh = esc->sc_pcioh.ioh;
216
217 /*
218 * Initialize nca board itself.
219 */
220 esc->sc_flags |= NCA_PCMCIA_ATTACHING;
221 ncr5380_attach(sc);
222 esc->sc_flags &= ~NCA_PCMCIA_ATTACHING;
223 esc->sc_flags |= NCA_PCMCIA_ATTACHED;
224 return;
225
226 iomap_failed:
227 /* Disable the device. */
228 pcmcia_function_disable(esc->sc_pf);
229
230 enable_failed:
231 /* Unmap our I/O space. */
232 pcmcia_io_free(esc->sc_pf, &esc->sc_pcioh);
233
234 no_config_entry:
235 return;
236 }
237
238 int
239 nca_pcmcia_detach(self, flags)
240 struct device *self;
241 int flags;
242 {
243 struct nca_pcmcia_softc *esc = (void *)self;
244 int error;
245
246 if ((esc->sc_flags & NCA_PCMCIA_ATTACHED) == 0) {
247 /* Nothing to detach. */
248 return (0);
249 }
250
251 if ((error = ncr5380_detach(&esc->sc_ncr5380, flags)) != 0)
252 return (error);
253
254 /* Unmap our i/o window and i/o space. */
255 pcmcia_io_unmap(esc->sc_pf, esc->sc_io_window);
256 pcmcia_io_free(esc->sc_pf, &esc->sc_pcioh);
257
258 return (0);
259 }
260
261 int
262 nca_pcmcia_enable(arg, onoff)
263 struct device *arg;
264 int onoff;
265 {
266 struct nca_pcmcia_softc *esc = (struct nca_pcmcia_softc*)arg;
267
268 if (onoff) {
269 /* Establish the interrupt handler. */
270 esc->sc_ih = pcmcia_intr_establish(esc->sc_pf, IPL_BIO,
271 ncr5380_intr, &esc->sc_ncr5380);
272 if (esc->sc_ih == NULL) {
273 printf("%s: couldn't establish interrupt handler\n",
274 esc->sc_ncr5380.sc_dev.dv_xname);
275 return (EIO);
276 }
277
278 /*
279 * If attach is in progress, we know that card power is
280 * enabled and chip will be initialized later.
281 * Otherwise, enable and reset now.
282 */
283 if ((esc->sc_flags & NCA_PCMCIA_ATTACHING) == 0) {
284 if (pcmcia_function_enable(esc->sc_pf)) {
285 printf("%s: couldn't enable PCMCIA function\n",
286 esc->sc_ncr5380.sc_dev.dv_xname);
287 pcmcia_intr_disestablish(esc->sc_pf,
288 esc->sc_ih);
289 return (EIO);
290 }
291
292 /* Initialize only chip. */
293 ncr5380_init(&esc->sc_ncr5380);
294 }
295 } else {
296 pcmcia_function_disable(esc->sc_pf);
297 pcmcia_intr_disestablish(esc->sc_pf, esc->sc_ih);
298 }
299
300 return (0);
301 }
Cache object: 2815abd4cd65a8499b198f48050d96ee
|