aic_pcmcia.c revision 1.11 1 /* $NetBSD: aic_pcmcia.c,v 1.11 1999/09/07 19:30:10 soren Exp $ */
2
3 /*
4 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/select.h>
35 #include <sys/device.h>
36
37 #include <machine/cpu.h>
38 #include <machine/bus.h>
39 #include <machine/intr.h>
40
41 #include <dev/scsipi/scsipi_all.h>
42 #include <dev/scsipi/scsipiconf.h>
43 #include <dev/scsipi/scsi_all.h>
44
45 #include <dev/ic/aic6360var.h>
46
47 #include <dev/pcmcia/pcmciareg.h>
48 #include <dev/pcmcia/pcmciavar.h>
49 #include <dev/pcmcia/pcmciadevs.h>
50
51 int aic_pcmcia_match __P((struct device *, struct cfdata *, void *));
52 void aic_pcmcia_attach __P((struct device *, struct device *, void *));
53
54 struct aic_pcmcia_softc {
55 struct aic_softc sc_aic; /* real "aic" softc */
56
57 /* PCMCIA-specific goo. */
58 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
59 int sc_io_window; /* our i/o window */
60 struct pcmcia_function *sc_pf; /* our PCMCIA function */
61 void *sc_ih; /* interrupt handler */
62 };
63
64 struct cfattach aic_pcmcia_ca = {
65 sizeof(struct aic_pcmcia_softc), aic_pcmcia_match, aic_pcmcia_attach
66 };
67
68 int aic_pcmcia_enable __P((void *, int));
69
70 struct aic_pcmcia_product {
71 u_int32_t app_vendor; /* PCMCIA vendor ID */
72 u_int32_t app_product; /* PCMCIA product ID */
73 int app_expfunc; /* expected function number */
74 const char *app_name; /* device name */
75 } aic_pcmcia_products[] = {
76 { PCMCIA_VENDOR_ADAPTEC, PCMCIA_PRODUCT_ADAPTEC_APA1460,
77 0, PCMCIA_STR_ADAPTEC_APA1460 },
78 { PCMCIA_VENDOR_ADAPTEC, PCMCIA_PRODUCT_ADAPTEC_APA1460A,
79 0, PCMCIA_STR_ADAPTEC_APA1460A },
80 { PCMCIA_VENDOR_NEWMEDIA, PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER,
81 0, PCMCIA_STR_NEWMEDIA_BUSTOASTER },
82
83 { 0, 0,
84 0, NULL },
85 };
86
87 struct aic_pcmcia_product *aic_pcmcia_lookup __P((struct pcmcia_attach_args *));
88
89 struct aic_pcmcia_product *
90 aic_pcmcia_lookup(pa)
91 struct pcmcia_attach_args *pa;
92 {
93 struct aic_pcmcia_product *app;
94
95 for (app = aic_pcmcia_products; app->app_name != NULL; app++) {
96 if (pa->manufacturer == app->app_vendor &&
97 pa->product == app->app_product &&
98 pa->pf->number == app->app_expfunc)
99 return (app);
100 }
101 return (NULL);
102 }
103
104 int
105 aic_pcmcia_match(parent, match, aux)
106 struct device *parent;
107 struct cfdata *match;
108 void *aux;
109 {
110 struct pcmcia_attach_args *pa = aux;
111
112 if (aic_pcmcia_lookup(pa) != NULL)
113 return (1);
114 return (0);
115 }
116
117 void
118 aic_pcmcia_attach(parent, self, aux)
119 struct device *parent, *self;
120 void *aux;
121 {
122 struct aic_pcmcia_softc *psc = (void *)self;
123 struct aic_softc *sc = &psc->sc_aic;
124 struct pcmcia_attach_args *pa = aux;
125 struct pcmcia_config_entry *cfe;
126 struct pcmcia_function *pf = pa->pf;
127 struct aic_pcmcia_product *app;
128
129 psc->sc_pf = pf;
130
131 for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
132 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
133 if (cfe->num_memspace != 0 ||
134 cfe->num_iospace != 1)
135 continue;
136
137 /* The bustoaster has a default config as first
138 * entry, we don't want to use that. */
139
140 if (pa->manufacturer == PCMCIA_VENDOR_NEWMEDIA &&
141 pa->product == PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER &&
142 cfe->iospace[0].start == 0)
143 continue;
144
145 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
146 cfe->iospace[0].length, 0, &psc->sc_pcioh) == 0)
147 break;
148 }
149
150 if (cfe == 0) {
151 printf(": can't alloc i/o space\n");
152 return;
153 }
154
155 sc->sc_iot = psc->sc_pcioh.iot;
156 sc->sc_ioh = psc->sc_pcioh.ioh;
157
158 /* Enable the card. */
159 pcmcia_function_init(pf, cfe);
160 if (pcmcia_function_enable(pf)) {
161 printf(": function enable failed\n");
162 return;
163 }
164
165 /* Map in the io space */
166 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
167 &psc->sc_pcioh, &psc->sc_io_window)) {
168 printf(": can't map i/o space\n");
169 return;
170 }
171
172 if (!aic_find(sc->sc_iot, sc->sc_ioh)) {
173 printf(": unable to detect chip!\n");
174 return;
175 }
176
177 app = aic_pcmcia_lookup(pa);
178 if (app == NULL) {
179 printf("\n");
180 panic("aic_pcmcia_attach: impossible");
181 }
182
183 #if 0 /* XXX power management broken somehow. */
184 /* We can enable and disable the controller. */
185 sc->sc_adapter.scsipi_enable = aic_pcmcia_enable;
186
187 /*
188 * Disable the pcmcia function now; we will be enbled again
189 * as the SCSI code adds references to probe for children.
190 */
191 pcmcia_function_disable(pf);
192
193 printf(": %s\n", app->app_name);
194 #else
195 printf(": %s\n", app->app_name);
196
197 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_BIO,
198 aicintr, &psc->sc_aic);
199 if (psc->sc_ih == NULL) {
200 printf("%s: couldn't establish interrupt handler\n",
201 psc->sc_aic.sc_dev.dv_xname);
202 return;
203 }
204 #endif
205
206 aicattach(sc);
207 }
208
209 int
210 aic_pcmcia_enable(arg, onoff)
211 void *arg;
212 int onoff;
213 {
214 struct aic_pcmcia_softc *psc = arg;
215
216 if (onoff) {
217 /* Establish the interrupt handler. */
218 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_BIO,
219 aicintr, &psc->sc_aic);
220 if (psc->sc_ih == NULL) {
221 printf("%s: couldn't establish interrupt handler\n",
222 psc->sc_aic.sc_dev.dv_xname);
223 return (EIO);
224 }
225
226 if (pcmcia_function_enable(psc->sc_pf)) {
227 printf("%s: couldn't enable PCMCIA function\n",
228 psc->sc_aic.sc_dev.dv_xname);
229 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
230 return (EIO);
231 }
232 } else {
233 pcmcia_function_disable(psc->sc_pf);
234 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
235 }
236
237 return (0);
238 }
239