wdc_pcmcia.c revision 1.69 1 1.69 mycroft /* $NetBSD: wdc_pcmcia.c,v 1.69 2004/07/07 06:43:22 mycroft Exp $ */
2 1.1 matt
3 1.8 mycroft /*-
4 1.56 mycroft * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
5 1.8 mycroft * All rights reserved.
6 1.1 matt *
7 1.8 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.8 mycroft * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt * 3. All advertising materials mentioning features or use of this software
19 1.1 matt * must display the following acknowledgement:
20 1.8 mycroft * This product includes software developed by the NetBSD
21 1.8 mycroft * Foundation, Inc. and its contributors.
22 1.8 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.8 mycroft * contributors may be used to endorse or promote products derived
24 1.8 mycroft * from this software without specific prior written permission.
25 1.1 matt *
26 1.8 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.8 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.8 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.8 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.8 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.8 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.8 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.8 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.8 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.8 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.8 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 matt */
38 1.44 lukem
39 1.44 lukem #include <sys/cdefs.h>
40 1.69 mycroft __KERNEL_RCSID(0, "$NetBSD: wdc_pcmcia.c,v 1.69 2004/07/07 06:43:22 mycroft Exp $");
41 1.1 matt
42 1.1 matt #include <sys/param.h>
43 1.30 enami #include <sys/device.h>
44 1.30 enami #include <sys/malloc.h>
45 1.1 matt #include <sys/systm.h>
46 1.1 matt
47 1.30 enami #include <machine/bus.h>
48 1.1 matt #include <machine/intr.h>
49 1.1 matt
50 1.14 enami #include <dev/pcmcia/pcmciareg.h>
51 1.1 matt #include <dev/pcmcia/pcmciavar.h>
52 1.9 kenh #include <dev/pcmcia/pcmciadevs.h>
53 1.9 kenh
54 1.64 fvdl #include <dev/ic/wdcreg.h>
55 1.12 bouyer #include <dev/ata/atavar.h>
56 1.1 matt #include <dev/ic/wdcvar.h>
57 1.1 matt
58 1.1 matt #define WDC_PCMCIA_REG_NPORTS 8
59 1.9 kenh #define WDC_PCMCIA_AUXREG_OFFSET (WDC_PCMCIA_REG_NPORTS + 6)
60 1.2 mycroft #define WDC_PCMCIA_AUXREG_NPORTS 2
61 1.1 matt
62 1.1 matt struct wdc_pcmcia_softc {
63 1.1 matt struct wdc_softc sc_wdcdev;
64 1.66 thorpej struct wdc_channel *wdc_chanlist[1];
65 1.66 thorpej struct wdc_channel wdc_channel;
66 1.65 thorpej struct ata_queue wdc_chqueue;
67 1.1 matt struct pcmcia_io_handle sc_pioh;
68 1.1 matt struct pcmcia_io_handle sc_auxpioh;
69 1.41 uch struct pcmcia_mem_handle sc_pmembaseh;
70 1.41 uch struct pcmcia_mem_handle sc_pmemh;
71 1.41 uch struct pcmcia_mem_handle sc_auxpmemh;
72 1.41 uch int sc_memwindow;
73 1.1 matt int sc_iowindow;
74 1.1 matt int sc_auxiowindow;
75 1.1 matt void *sc_ih;
76 1.15 thorpej struct pcmcia_function *sc_pf;
77 1.22 enami int sc_flags;
78 1.63 briggs #define WDC_PCMCIA_ATTACH 0x0001
79 1.41 uch #define WDC_PCMCIA_MEMMODE 0x0002
80 1.1 matt };
81 1.1 matt
82 1.1 matt static int wdc_pcmcia_match __P((struct device *, struct cfdata *, void *));
83 1.1 matt static void wdc_pcmcia_attach __P((struct device *, struct device *, void *));
84 1.21 enami static int wdc_pcmcia_detach __P((struct device *, int));
85 1.1 matt
86 1.51 thorpej CFATTACH_DECL(wdc_pcmcia, sizeof(struct wdc_pcmcia_softc),
87 1.52 thorpej wdc_pcmcia_match, wdc_pcmcia_attach, wdc_pcmcia_detach, wdcactivate);
88 1.1 matt
89 1.40 jdolecek const struct wdc_pcmcia_product {
90 1.9 kenh u_int32_t wpp_vendor; /* vendor ID */
91 1.9 kenh u_int32_t wpp_product; /* product ID */
92 1.9 kenh int wpp_quirk_flag; /* Quirk flags */
93 1.9 kenh #define WDC_PCMCIA_NO_EXTRA_RESETS 0x02 /* Only reset ctrl once */
94 1.9 kenh const char *wpp_cis_info[4]; /* XXX necessary? */
95 1.9 kenh } wdc_pcmcia_products[] = {
96 1.9 kenh
97 1.9 kenh { /* PCMCIA_VENDOR_DIGITAL XXX */ 0x0100,
98 1.9 kenh PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
99 1.69 mycroft 0, {NULL, "Digital Mobile Media CD-ROM", NULL, NULL} },
100 1.19 abs
101 1.19 abs { PCMCIA_VENDOR_IBM,
102 1.24 soren PCMCIA_PRODUCT_IBM_PORTABLE_CDROM,
103 1.69 mycroft 0, {NULL, "PCMCIA Portable CD-ROM Drive", NULL, NULL} },
104 1.9 kenh
105 1.9 kenh /* The TEAC IDE/Card II is used on the Sony Vaio */
106 1.9 kenh { PCMCIA_VENDOR_TEAC,
107 1.9 kenh PCMCIA_PRODUCT_TEAC_IDECARDII,
108 1.9 kenh WDC_PCMCIA_NO_EXTRA_RESETS,
109 1.69 mycroft PCMCIA_CIS_TEAC_IDECARDII },
110 1.43 christos
111 1.43 christos /*
112 1.43 christos * A fujitsu rebranded panasonic drive that reports
113 1.43 christos * itself as function "scsi", disk interface 0
114 1.43 christos */
115 1.43 christos { PCMCIA_VENDOR_PANASONIC,
116 1.43 christos PCMCIA_PRODUCT_PANASONIC_KXLC005,
117 1.43 christos 0,
118 1.69 mycroft PCMCIA_CIS_PANASONIC_KXLC005 },
119 1.26 augustss
120 1.27 enami /*
121 1.27 enami * EXP IDE/ATAPI DVD Card use with some DVD players.
122 1.27 enami * Does not have a vendor ID or product ID.
123 1.27 enami */
124 1.69 mycroft { -1, -1, 0,
125 1.69 mycroft PCMCIA_CIS_EXP_EXPMULTIMEDIA },
126 1.23 takemura
127 1.36 abs /* Mobile Dock 2, neither vendor ID nor product ID */
128 1.23 takemura { -1, -1, 0,
129 1.69 mycroft {"SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", NULL, NULL} },
130 1.34 abs
131 1.36 abs /* Toshiba Portege 3110 CD, neither vendor ID nor product ID */
132 1.34 abs { -1, -1, 0,
133 1.69 mycroft {"FREECOM", "PCCARD-IDE", NULL, NULL} },
134 1.36 abs
135 1.36 abs /* Random CD-ROM, (badged AMACOM), neither vendor ID nor product ID */
136 1.36 abs { -1, -1, 0,
137 1.69 mycroft {"PCMCIA", "CD-ROM", NULL, NULL} },
138 1.37 haya
139 1.37 haya /* IO DATA CBIDE2, with neither vendor ID nor product ID */
140 1.37 haya { -1, -1, 0,
141 1.69 mycroft PCMCIA_CIS_IODATA_CBIDE2 },
142 1.54 ichiro
143 1.54 ichiro /* TOSHIBA PA2673U(IODATA_CBIDE2 OEM), */
144 1.54 ichiro /* with neither vendor ID nor product ID */
145 1.54 ichiro { -1, -1, 0,
146 1.69 mycroft PCMCIA_CIS_TOSHIBA_CBIDE2 },
147 1.38 sato
148 1.38 sato /*
149 1.38 sato * Novac PCMCIA-IDE Card for HD530P IDE Box,
150 1.38 sato * with neither vendor ID nor product ID
151 1.38 sato */
152 1.38 sato { -1, -1, 0,
153 1.69 mycroft {"PCMCIA", "PnPIDE", NULL, NULL} },
154 1.9 kenh };
155 1.9 kenh
156 1.40 jdolecek const struct wdc_pcmcia_product *
157 1.9 kenh wdc_pcmcia_lookup __P((struct pcmcia_attach_args *));
158 1.9 kenh
159 1.42 bouyer int wdc_pcmcia_enable __P((struct device *, int));
160 1.14 enami
161 1.40 jdolecek const struct wdc_pcmcia_product *
162 1.9 kenh wdc_pcmcia_lookup(pa)
163 1.9 kenh struct pcmcia_attach_args *pa;
164 1.9 kenh {
165 1.40 jdolecek const struct wdc_pcmcia_product *wpp;
166 1.9 kenh int i, cis_match;
167 1.69 mycroft int n;
168 1.9 kenh
169 1.69 mycroft for (wpp = wdc_pcmcia_products,
170 1.69 mycroft n = sizeof(wdc_pcmcia_products) / sizeof(wdc_pcmcia_products[0]);
171 1.69 mycroft n; wpp++, n--) {
172 1.9 kenh if ((wpp->wpp_vendor == -1 ||
173 1.9 kenh pa->manufacturer == wpp->wpp_vendor) &&
174 1.9 kenh (wpp->wpp_product == -1 ||
175 1.9 kenh pa->product == wpp->wpp_product)) {
176 1.9 kenh cis_match = 1;
177 1.9 kenh for (i = 0; i < 4; i++) {
178 1.9 kenh if (!(wpp->wpp_cis_info[i] == NULL ||
179 1.9 kenh (pa->card->cis1_info[i] != NULL &&
180 1.9 kenh strcmp(pa->card->cis1_info[i],
181 1.9 kenh wpp->wpp_cis_info[i]) == 0)))
182 1.9 kenh cis_match = 0;
183 1.9 kenh }
184 1.9 kenh if (cis_match)
185 1.13 enami return (wpp);
186 1.9 kenh }
187 1.69 mycroft }
188 1.9 kenh
189 1.9 kenh return (NULL);
190 1.9 kenh }
191 1.9 kenh
192 1.1 matt static int
193 1.2 mycroft wdc_pcmcia_match(parent, match, aux)
194 1.2 mycroft struct device *parent;
195 1.2 mycroft struct cfdata *match;
196 1.2 mycroft void *aux;
197 1.1 matt {
198 1.1 matt struct pcmcia_attach_args *pa = aux;
199 1.35 haya
200 1.35 haya if (pa->pf->function == PCMCIA_FUNCTION_DISK &&
201 1.35 haya pa->pf->pf_funce_disk_interface == PCMCIA_TPLFE_DDI_PCCARD_ATA) {
202 1.35 haya return 10;
203 1.35 haya }
204 1.1 matt
205 1.9 kenh if (wdc_pcmcia_lookup(pa) != NULL)
206 1.9 kenh return (1);
207 1.14 enami
208 1.9 kenh return (0);
209 1.1 matt }
210 1.1 matt
211 1.1 matt static void
212 1.2 mycroft wdc_pcmcia_attach(parent, self, aux)
213 1.2 mycroft struct device *parent;
214 1.2 mycroft struct device *self;
215 1.2 mycroft void *aux;
216 1.1 matt {
217 1.1 matt struct wdc_pcmcia_softc *sc = (void *)self;
218 1.1 matt struct pcmcia_attach_args *pa = aux;
219 1.5 enami struct pcmcia_config_entry *cfe;
220 1.40 jdolecek const struct wdc_pcmcia_product *wpp;
221 1.64 fvdl bus_size_t offset = 0;
222 1.64 fvdl int quirks, i;
223 1.1 matt
224 1.69 mycroft aprint_normal("\n");
225 1.69 mycroft
226 1.15 thorpej sc->sc_pf = pa->pf;
227 1.15 thorpej
228 1.49 lukem SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
229 1.9 kenh if (cfe->num_iospace != 1 && cfe->num_iospace != 2)
230 1.9 kenh continue;
231 1.9 kenh
232 1.1 matt if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
233 1.9 kenh cfe->iospace[0].length,
234 1.9 kenh cfe->iospace[0].start == 0 ? cfe->iospace[0].length : 0,
235 1.9 kenh &sc->sc_pioh))
236 1.1 matt continue;
237 1.9 kenh
238 1.9 kenh if (cfe->num_iospace == 2) {
239 1.1 matt if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
240 1.9 kenh cfe->iospace[1].length, 0, &sc->sc_auxpioh))
241 1.1 matt break;
242 1.9 kenh } else /* num_iospace == 1 */ {
243 1.1 matt sc->sc_auxpioh.iot = sc->sc_pioh.iot;
244 1.9 kenh if (!bus_space_subregion(sc->sc_pioh.iot,
245 1.9 kenh sc->sc_pioh.ioh, WDC_PCMCIA_AUXREG_OFFSET,
246 1.9 kenh WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpioh.ioh))
247 1.1 matt break;
248 1.1 matt }
249 1.11 thorpej pcmcia_io_free(pa->pf, &sc->sc_pioh);
250 1.1 matt }
251 1.1 matt
252 1.41 uch /*
253 1.46 simonb * Compact Flash memory mapped mode
254 1.41 uch * CF+ and CompactFlash Spec. Rev 1.4, 6.1.3 Memory Mapped Addressing.
255 1.41 uch * http://www.compactflash.org/cfspc1_4.pdf
256 1.41 uch */
257 1.41 uch if (cfe == NULL) {
258 1.41 uch SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
259 1.41 uch if (cfe->iftype != PCMCIA_IFTYPE_MEMORY)
260 1.41 uch continue;
261 1.41 uch if (pcmcia_mem_alloc(pa->pf, cfe->memspace[0].length,
262 1.41 uch &sc->sc_pmembaseh) == 0) {
263 1.41 uch sc->sc_flags |= WDC_PCMCIA_MEMMODE;
264 1.41 uch break;
265 1.41 uch }
266 1.41 uch }
267 1.41 uch }
268 1.41 uch
269 1.1 matt if (cfe == NULL) {
270 1.69 mycroft aprint_error("%s: can't handle card info\n", self->dv_xname);
271 1.29 enami goto no_config_entry;
272 1.1 matt }
273 1.1 matt
274 1.1 matt /* Enable the card. */
275 1.1 matt pcmcia_function_init(pa->pf, cfe);
276 1.1 matt if (pcmcia_function_enable(pa->pf)) {
277 1.69 mycroft aprint_error("%s: function enable failed\n", self->dv_xname);
278 1.29 enami goto enable_failed;
279 1.1 matt }
280 1.1 matt
281 1.9 kenh wpp = wdc_pcmcia_lookup(pa);
282 1.14 enami if (wpp != NULL)
283 1.14 enami quirks = wpp->wpp_quirk_flag;
284 1.14 enami else
285 1.14 enami quirks = 0;
286 1.9 kenh
287 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
288 1.41 uch if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_COMMON, 0,
289 1.41 uch sc->sc_pmembaseh.size, &sc->sc_pmembaseh, &offset,
290 1.41 uch &sc->sc_memwindow)) {
291 1.69 mycroft aprint_error("%s: can't map memory space\n",
292 1.69 mycroft self->dv_xname);
293 1.41 uch goto map_failed;
294 1.41 uch }
295 1.9 kenh
296 1.41 uch sc->sc_pmemh.memt = sc->sc_pmembaseh.memt;
297 1.64 fvdl sc->sc_pmemh.memh = sc->sc_pmembaseh.memh;
298 1.41 uch
299 1.41 uch sc->sc_auxpmemh.memt = sc->sc_pmemh.memt;
300 1.41 uch if (bus_space_subregion(sc->sc_pmemh.memt,
301 1.64 fvdl sc->sc_pmembaseh.memh, WDC_PCMCIA_AUXREG_OFFSET + offset,
302 1.41 uch WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpmemh.memh))
303 1.41 uch goto mapaux_failed;
304 1.41 uch
305 1.69 mycroft aprint_normal("%s: memory mapped mode\n", self->dv_xname);
306 1.41 uch } else {
307 1.41 uch if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
308 1.41 uch sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowindow)) {
309 1.69 mycroft aprint_error("%s: can't map first I/O space\n",
310 1.69 mycroft self->dv_xname);
311 1.41 uch goto map_failed;
312 1.41 uch }
313 1.41 uch }
314 1.41 uch
315 1.41 uch if (cfe->num_iospace <= 1 || sc->sc_flags & WDC_PCMCIA_MEMMODE)
316 1.25 sommerfe sc->sc_auxiowindow = -1;
317 1.25 sommerfe else if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
318 1.9 kenh sc->sc_auxpioh.size, &sc->sc_auxpioh, &sc->sc_auxiowindow)) {
319 1.69 mycroft aprint_error("%s: can't map second I/O space\n",
320 1.69 mycroft self->dv_xname);
321 1.41 uch goto mapaux_failed;
322 1.25 sommerfe }
323 1.5 enami
324 1.41 uch sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
325 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
326 1.41 uch sc->wdc_channel.cmd_iot = sc->sc_pmemh.memt;
327 1.64 fvdl sc->wdc_channel.cmd_baseioh = sc->sc_pmemh.memh;
328 1.41 uch sc->wdc_channel.ctl_iot = sc->sc_auxpmemh.memt;
329 1.41 uch sc->wdc_channel.ctl_ioh = sc->sc_auxpmemh.memh;
330 1.41 uch } else {
331 1.41 uch sc->wdc_channel.cmd_iot = sc->sc_pioh.iot;
332 1.64 fvdl sc->wdc_channel.cmd_baseioh = sc->sc_pioh.ioh;
333 1.41 uch sc->wdc_channel.ctl_iot = sc->sc_auxpioh.iot;
334 1.41 uch sc->wdc_channel.ctl_ioh = sc->sc_auxpioh.ioh;
335 1.41 uch sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
336 1.41 uch }
337 1.64 fvdl for (i = 0; i < WDC_PCMCIA_REG_NPORTS; i++) {
338 1.64 fvdl if (bus_space_subregion(sc->wdc_channel.cmd_iot,
339 1.64 fvdl sc->wdc_channel.cmd_baseioh,
340 1.64 fvdl offset + i, i == 0 ? 4 : 1,
341 1.64 fvdl &sc->wdc_channel.cmd_iohs[i]) != 0) {
342 1.69 mycroft aprint_error("%s: can't subregion I/O space\n",
343 1.69 mycroft self->dv_xname);
344 1.64 fvdl goto mapaux_failed;
345 1.64 fvdl }
346 1.64 fvdl }
347 1.68 thorpej wdc_init_shadow_regs(&sc->wdc_channel);
348 1.12 bouyer sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
349 1.64 fvdl sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_iohs[0];
350 1.18 bouyer sc->sc_wdcdev.PIO_cap = 0;
351 1.53 matt sc->wdc_chanlist[0] = &sc->wdc_channel;
352 1.53 matt sc->sc_wdcdev.channels = sc->wdc_chanlist;
353 1.12 bouyer sc->sc_wdcdev.nchannels = 1;
354 1.67 thorpej sc->wdc_channel.ch_channel = 0;
355 1.67 thorpej sc->wdc_channel.ch_wdc = &sc->sc_wdcdev;
356 1.53 matt sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
357 1.56 mycroft #if 0
358 1.14 enami if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
359 1.12 bouyer sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
360 1.56 mycroft #endif
361 1.15 thorpej
362 1.15 thorpej /* We can enable and disable the controller. */
363 1.42 bouyer sc->sc_wdcdev.sc_atapi_adapter._generic.adapt_enable =
364 1.32 bouyer wdc_pcmcia_enable;
365 1.15 thorpej
366 1.63 briggs sc->sc_flags |= WDC_PCMCIA_ATTACH;
367 1.60 bouyer wdcattach(&sc->wdc_channel);
368 1.62 briggs
369 1.29 enami return;
370 1.29 enami
371 1.41 uch mapaux_failed:
372 1.29 enami /* Unmap our i/o window. */
373 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE)
374 1.41 uch pcmcia_mem_unmap(sc->sc_pf, sc->sc_memwindow);
375 1.41 uch else
376 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
377 1.29 enami
378 1.41 uch map_failed:
379 1.29 enami /* Disable the function */
380 1.29 enami pcmcia_function_disable(sc->sc_pf);
381 1.29 enami
382 1.29 enami enable_failed:
383 1.29 enami /* Unmap our i/o space. */
384 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
385 1.41 uch pcmcia_mem_free(sc->sc_pf, &sc->sc_pmembaseh);
386 1.41 uch } else {
387 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
388 1.41 uch if (cfe->num_iospace == 2)
389 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
390 1.41 uch }
391 1.29 enami no_config_entry:
392 1.29 enami sc->sc_iowindow = -1;
393 1.21 enami }
394 1.21 enami
395 1.21 enami int
396 1.21 enami wdc_pcmcia_detach(self, flags)
397 1.21 enami struct device *self;
398 1.21 enami int flags;
399 1.21 enami {
400 1.21 enami struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
401 1.21 enami int error;
402 1.29 enami
403 1.29 enami if (sc->sc_iowindow == -1)
404 1.29 enami /* Nothing to detach */
405 1.29 enami return (0);
406 1.21 enami
407 1.63 briggs /*
408 1.63 briggs * If the WDC_PCMCIA_ATTACH flag is still set, then we didn't get
409 1.63 briggs * a chance * enable/disable the card in the wdc/atabus layer, so
410 1.63 briggs * we still need to disable the function here.
411 1.63 briggs */
412 1.63 briggs if (sc->sc_flags & WDC_PCMCIA_ATTACH) {
413 1.63 briggs sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
414 1.63 briggs pcmcia_function_disable(sc->sc_pf);
415 1.63 briggs }
416 1.63 briggs
417 1.21 enami if ((error = wdcdetach(self, flags)) != 0)
418 1.21 enami return (error);
419 1.21 enami
420 1.21 enami /* Unmap our i/o window and i/o space. */
421 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
422 1.41 uch pcmcia_mem_unmap(sc->sc_pf, sc->sc_memwindow);
423 1.41 uch pcmcia_mem_free(sc->sc_pf, &sc->sc_pmembaseh);
424 1.41 uch } else {
425 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
426 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
427 1.41 uch if (sc->sc_auxiowindow != -1) {
428 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_auxiowindow);
429 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
430 1.41 uch }
431 1.21 enami }
432 1.61 briggs
433 1.21 enami return (0);
434 1.15 thorpej }
435 1.15 thorpej
436 1.15 thorpej int
437 1.42 bouyer wdc_pcmcia_enable(self, onoff)
438 1.42 bouyer struct device *self;
439 1.15 thorpej int onoff;
440 1.15 thorpej {
441 1.42 bouyer struct wdc_pcmcia_softc *sc = (void *)self;
442 1.15 thorpej
443 1.15 thorpej if (onoff) {
444 1.56 mycroft /* Establish the interrupt handler. */
445 1.56 mycroft sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_BIO,
446 1.56 mycroft wdcintr, &sc->wdc_channel);
447 1.56 mycroft if (sc->sc_ih == NULL) {
448 1.56 mycroft printf("%s: couldn't establish interrupt handler\n",
449 1.56 mycroft sc->sc_wdcdev.sc_dev.dv_xname);
450 1.56 mycroft return (EIO);
451 1.56 mycroft }
452 1.56 mycroft
453 1.63 briggs /*
454 1.63 briggs * If the WDC_PCMCIA_ATTACH flag is set, we've already
455 1.63 briggs * enabled the card in the attach routine, so don't
456 1.63 briggs * re-enable it here (to save power cycle time). Clear
457 1.63 briggs * the flag, though, so that the next disable/enable
458 1.63 briggs * will do the right thing.
459 1.63 briggs */
460 1.63 briggs if (sc->sc_flags & WDC_PCMCIA_ATTACH) {
461 1.63 briggs sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
462 1.63 briggs } else {
463 1.63 briggs if (pcmcia_function_enable(sc->sc_pf)) {
464 1.63 briggs printf("%s: couldn't enable PCMCIA function\n",
465 1.63 briggs sc->sc_wdcdev.sc_dev.dv_xname);
466 1.63 briggs pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
467 1.63 briggs return (EIO);
468 1.63 briggs }
469 1.15 thorpej }
470 1.15 thorpej } else {
471 1.15 thorpej pcmcia_function_disable(sc->sc_pf);
472 1.56 mycroft pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
473 1.15 thorpej }
474 1.15 thorpej
475 1.15 thorpej return (0);
476 1.1 matt }
477