wdc_pcmcia.c revision 1.42 1 1.42 bouyer /* $NetBSD: wdc_pcmcia.c,v 1.42 2001/04/25 17:53:37 bouyer Exp $ */
2 1.1 matt
3 1.8 mycroft /*-
4 1.8 mycroft * Copyright (c) 1998 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.1 matt
39 1.1 matt #include <sys/param.h>
40 1.30 enami #include <sys/device.h>
41 1.30 enami #include <sys/malloc.h>
42 1.1 matt #include <sys/systm.h>
43 1.1 matt
44 1.30 enami #include <machine/bus.h>
45 1.1 matt #include <machine/intr.h>
46 1.1 matt
47 1.14 enami #include <dev/pcmcia/pcmciareg.h>
48 1.1 matt #include <dev/pcmcia/pcmciavar.h>
49 1.9 kenh #include <dev/pcmcia/pcmciadevs.h>
50 1.9 kenh
51 1.12 bouyer #include <dev/ata/atavar.h>
52 1.1 matt #include <dev/ic/wdcvar.h>
53 1.1 matt
54 1.1 matt #define WDC_PCMCIA_REG_NPORTS 8
55 1.9 kenh #define WDC_PCMCIA_AUXREG_OFFSET (WDC_PCMCIA_REG_NPORTS + 6)
56 1.2 mycroft #define WDC_PCMCIA_AUXREG_NPORTS 2
57 1.1 matt
58 1.1 matt struct wdc_pcmcia_softc {
59 1.1 matt struct wdc_softc sc_wdcdev;
60 1.16 drochner struct channel_softc *wdc_chanptr;
61 1.12 bouyer struct channel_softc wdc_channel;
62 1.1 matt struct pcmcia_io_handle sc_pioh;
63 1.1 matt struct pcmcia_io_handle sc_auxpioh;
64 1.41 uch struct pcmcia_mem_handle sc_pmembaseh;
65 1.41 uch struct pcmcia_mem_handle sc_pmemh;
66 1.41 uch struct pcmcia_mem_handle sc_auxpmemh;
67 1.41 uch int sc_memwindow;
68 1.1 matt int sc_iowindow;
69 1.1 matt int sc_auxiowindow;
70 1.1 matt void *sc_ih;
71 1.15 thorpej struct pcmcia_function *sc_pf;
72 1.22 enami int sc_flags;
73 1.22 enami #define WDC_PCMCIA_ATTACH 0x0001
74 1.41 uch #define WDC_PCMCIA_MEMMODE 0x0002
75 1.1 matt };
76 1.1 matt
77 1.1 matt static int wdc_pcmcia_match __P((struct device *, struct cfdata *, void *));
78 1.1 matt static void wdc_pcmcia_attach __P((struct device *, struct device *, void *));
79 1.21 enami static int wdc_pcmcia_detach __P((struct device *, int));
80 1.1 matt
81 1.1 matt struct cfattach wdc_pcmcia_ca = {
82 1.21 enami sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach,
83 1.21 enami wdc_pcmcia_detach, wdcactivate
84 1.1 matt };
85 1.1 matt
86 1.40 jdolecek const struct wdc_pcmcia_product {
87 1.9 kenh u_int32_t wpp_vendor; /* vendor ID */
88 1.9 kenh u_int32_t wpp_product; /* product ID */
89 1.9 kenh int wpp_quirk_flag; /* Quirk flags */
90 1.9 kenh #define WDC_PCMCIA_NO_EXTRA_RESETS 0x02 /* Only reset ctrl once */
91 1.9 kenh const char *wpp_cis_info[4]; /* XXX necessary? */
92 1.9 kenh const char *wpp_name; /* product name */
93 1.9 kenh } wdc_pcmcia_products[] = {
94 1.9 kenh
95 1.9 kenh { /* PCMCIA_VENDOR_DIGITAL XXX */ 0x0100,
96 1.9 kenh PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
97 1.9 kenh 0, { NULL, "Digital Mobile Media CD-ROM", NULL, NULL },
98 1.9 kenh PCMCIA_STR_DIGITAL_MOBILE_MEDIA_CDROM },
99 1.19 abs
100 1.19 abs { PCMCIA_VENDOR_IBM,
101 1.24 soren PCMCIA_PRODUCT_IBM_PORTABLE_CDROM,
102 1.19 abs 0, { NULL, "PCMCIA Portable CD-ROM Drive", NULL, NULL },
103 1.24 soren PCMCIA_STR_IBM_PORTABLE_CDROM },
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.9 kenh PCMCIA_CIS_TEAC_IDECARDII,
110 1.9 kenh PCMCIA_STR_TEAC_IDECARDII },
111 1.26 augustss
112 1.27 enami /*
113 1.27 enami * EXP IDE/ATAPI DVD Card use with some DVD players.
114 1.27 enami * Does not have a vendor ID or product ID.
115 1.27 enami */
116 1.26 augustss { -1,
117 1.26 augustss -1,
118 1.26 augustss 0,
119 1.26 augustss PCMCIA_CIS_EXP_EXPMULTIMEDIA,
120 1.26 augustss PCMCIA_STR_EXP_EXPMULTIMEDIA },
121 1.23 takemura
122 1.36 abs /* Mobile Dock 2, neither vendor ID nor product ID */
123 1.23 takemura { -1, -1, 0,
124 1.23 takemura { "SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", NULL, NULL},
125 1.23 takemura "SHUTTLE TECHNOLOGY IDE/ATAPI Adapter"
126 1.34 abs },
127 1.34 abs
128 1.36 abs /* Toshiba Portege 3110 CD, neither vendor ID nor product ID */
129 1.34 abs { -1, -1, 0,
130 1.34 abs { "FREECOM", "PCCARD-IDE", NULL, NULL},
131 1.34 abs "FREECOM PCCARD-IDE"
132 1.36 abs },
133 1.36 abs
134 1.36 abs /* Random CD-ROM, (badged AMACOM), neither vendor ID nor product ID */
135 1.36 abs { -1, -1, 0,
136 1.36 abs { "PCMCIA", "CD-ROM", NULL, NULL},
137 1.36 abs "PCMCIA CD-ROM"
138 1.37 haya },
139 1.37 haya
140 1.37 haya /* IO DATA CBIDE2, with neither vendor ID nor product ID */
141 1.37 haya { -1, -1, 0,
142 1.37 haya PCMCIA_CIS_IODATA_CBIDE2,
143 1.37 haya PCMCIA_STR_IODATA_CBIDE2
144 1.38 sato },
145 1.38 sato
146 1.38 sato /*
147 1.38 sato * Novac PCMCIA-IDE Card for HD530P IDE Box,
148 1.38 sato * with neither vendor ID nor product ID
149 1.38 sato */
150 1.38 sato { -1, -1, 0,
151 1.38 sato { "PCMCIA", "PnPIDE", NULL, NULL},
152 1.38 sato "Novac PCCARD-IDE"
153 1.23 takemura },
154 1.9 kenh
155 1.9 kenh { 0, 0, 0, { NULL, NULL, NULL, NULL}, NULL }
156 1.9 kenh };
157 1.9 kenh
158 1.40 jdolecek const struct wdc_pcmcia_product *
159 1.9 kenh wdc_pcmcia_lookup __P((struct pcmcia_attach_args *));
160 1.9 kenh
161 1.42 bouyer int wdc_pcmcia_enable __P((struct device *, int));
162 1.14 enami
163 1.40 jdolecek const struct wdc_pcmcia_product *
164 1.9 kenh wdc_pcmcia_lookup(pa)
165 1.9 kenh struct pcmcia_attach_args *pa;
166 1.9 kenh {
167 1.40 jdolecek const struct wdc_pcmcia_product *wpp;
168 1.9 kenh int i, cis_match;
169 1.9 kenh
170 1.9 kenh for (wpp = wdc_pcmcia_products; wpp->wpp_name != NULL; wpp++)
171 1.9 kenh if ((wpp->wpp_vendor == -1 ||
172 1.9 kenh pa->manufacturer == wpp->wpp_vendor) &&
173 1.9 kenh (wpp->wpp_product == -1 ||
174 1.9 kenh pa->product == wpp->wpp_product)) {
175 1.9 kenh cis_match = 1;
176 1.9 kenh for (i = 0; i < 4; i++) {
177 1.9 kenh if (!(wpp->wpp_cis_info[i] == NULL ||
178 1.9 kenh (pa->card->cis1_info[i] != NULL &&
179 1.9 kenh strcmp(pa->card->cis1_info[i],
180 1.9 kenh wpp->wpp_cis_info[i]) == 0)))
181 1.9 kenh cis_match = 0;
182 1.9 kenh }
183 1.9 kenh if (cis_match)
184 1.13 enami return (wpp);
185 1.9 kenh }
186 1.9 kenh
187 1.9 kenh return (NULL);
188 1.9 kenh }
189 1.9 kenh
190 1.1 matt static int
191 1.2 mycroft wdc_pcmcia_match(parent, match, aux)
192 1.2 mycroft struct device *parent;
193 1.2 mycroft struct cfdata *match;
194 1.2 mycroft void *aux;
195 1.1 matt {
196 1.1 matt struct pcmcia_attach_args *pa = aux;
197 1.35 haya
198 1.35 haya if (pa->pf->function == PCMCIA_FUNCTION_DISK &&
199 1.35 haya pa->pf->pf_funce_disk_interface == PCMCIA_TPLFE_DDI_PCCARD_ATA) {
200 1.35 haya return 10;
201 1.35 haya }
202 1.1 matt
203 1.9 kenh if (wdc_pcmcia_lookup(pa) != NULL)
204 1.9 kenh return (1);
205 1.14 enami
206 1.9 kenh return (0);
207 1.1 matt }
208 1.1 matt
209 1.1 matt static void
210 1.2 mycroft wdc_pcmcia_attach(parent, self, aux)
211 1.2 mycroft struct device *parent;
212 1.2 mycroft struct device *self;
213 1.2 mycroft void *aux;
214 1.1 matt {
215 1.1 matt struct wdc_pcmcia_softc *sc = (void *)self;
216 1.1 matt struct pcmcia_attach_args *pa = aux;
217 1.5 enami struct pcmcia_config_entry *cfe;
218 1.40 jdolecek const struct wdc_pcmcia_product *wpp;
219 1.41 uch bus_addr_t offset;
220 1.14 enami int quirks;
221 1.1 matt
222 1.15 thorpej sc->sc_pf = pa->pf;
223 1.15 thorpej
224 1.5 enami for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
225 1.5 enami cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
226 1.9 kenh if (cfe->num_iospace != 1 && cfe->num_iospace != 2)
227 1.9 kenh continue;
228 1.9 kenh
229 1.1 matt if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
230 1.9 kenh cfe->iospace[0].length,
231 1.9 kenh cfe->iospace[0].start == 0 ? cfe->iospace[0].length : 0,
232 1.9 kenh &sc->sc_pioh))
233 1.1 matt continue;
234 1.9 kenh
235 1.9 kenh if (cfe->num_iospace == 2) {
236 1.1 matt if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
237 1.9 kenh cfe->iospace[1].length, 0, &sc->sc_auxpioh))
238 1.1 matt break;
239 1.9 kenh } else /* num_iospace == 1 */ {
240 1.1 matt sc->sc_auxpioh.iot = sc->sc_pioh.iot;
241 1.9 kenh if (!bus_space_subregion(sc->sc_pioh.iot,
242 1.9 kenh sc->sc_pioh.ioh, WDC_PCMCIA_AUXREG_OFFSET,
243 1.9 kenh WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpioh.ioh))
244 1.1 matt break;
245 1.1 matt }
246 1.11 thorpej pcmcia_io_free(pa->pf, &sc->sc_pioh);
247 1.1 matt }
248 1.1 matt
249 1.41 uch /*
250 1.41 uch * Compact Falsh memory mapped mode
251 1.41 uch * CF+ and CompactFlash Spec. Rev 1.4, 6.1.3 Memory Mapped Addressing.
252 1.41 uch * http://www.compactflash.org/cfspc1_4.pdf
253 1.41 uch */
254 1.41 uch if (cfe == NULL) {
255 1.41 uch SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
256 1.41 uch if (cfe->iftype != PCMCIA_IFTYPE_MEMORY)
257 1.41 uch continue;
258 1.41 uch if (pcmcia_mem_alloc(pa->pf, cfe->memspace[0].length,
259 1.41 uch &sc->sc_pmembaseh) == 0) {
260 1.41 uch sc->sc_flags |= WDC_PCMCIA_MEMMODE;
261 1.41 uch break;
262 1.41 uch }
263 1.41 uch }
264 1.41 uch }
265 1.41 uch
266 1.1 matt if (cfe == NULL) {
267 1.6 enami printf(": can't handle card info\n");
268 1.29 enami goto no_config_entry;
269 1.1 matt }
270 1.1 matt
271 1.1 matt /* Enable the card. */
272 1.1 matt pcmcia_function_init(pa->pf, cfe);
273 1.1 matt if (pcmcia_function_enable(pa->pf)) {
274 1.5 enami printf(": function enable failed\n");
275 1.29 enami goto enable_failed;
276 1.1 matt }
277 1.1 matt
278 1.9 kenh wpp = wdc_pcmcia_lookup(pa);
279 1.14 enami if (wpp != NULL)
280 1.14 enami quirks = wpp->wpp_quirk_flag;
281 1.14 enami else
282 1.14 enami quirks = 0;
283 1.9 kenh
284 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
285 1.41 uch if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_COMMON, 0,
286 1.41 uch sc->sc_pmembaseh.size, &sc->sc_pmembaseh, &offset,
287 1.41 uch &sc->sc_memwindow)) {
288 1.41 uch printf(": can't map memory space\n");
289 1.41 uch goto map_failed;
290 1.41 uch }
291 1.9 kenh
292 1.41 uch sc->sc_pmemh.memt = sc->sc_pmembaseh.memt;
293 1.41 uch if (offset == 0) {
294 1.41 uch sc->sc_pmemh.memh = sc->sc_pmembaseh.memh;
295 1.41 uch } else {
296 1.41 uch if (bus_space_subregion(sc->sc_pmemh.memt,
297 1.41 uch sc->sc_pmembaseh.memh, offset,
298 1.41 uch WDC_PCMCIA_REG_NPORTS, &sc->sc_pmemh.memh))
299 1.41 uch goto mapaux_failed;
300 1.41 uch }
301 1.41 uch
302 1.41 uch sc->sc_auxpmemh.memt = sc->sc_pmemh.memt;
303 1.41 uch if (bus_space_subregion(sc->sc_pmemh.memt,
304 1.41 uch sc->sc_pmemh.memh, WDC_PCMCIA_AUXREG_OFFSET,
305 1.41 uch WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpmemh.memh))
306 1.41 uch goto mapaux_failed;
307 1.41 uch
308 1.41 uch printf(" memory mapped mode");
309 1.41 uch } else {
310 1.41 uch if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
311 1.41 uch sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowindow)) {
312 1.41 uch printf(": can't map first I/O space\n");
313 1.41 uch goto map_failed;
314 1.41 uch }
315 1.41 uch }
316 1.41 uch
317 1.41 uch if (cfe->num_iospace <= 1 || sc->sc_flags & WDC_PCMCIA_MEMMODE)
318 1.25 sommerfe sc->sc_auxiowindow = -1;
319 1.25 sommerfe else if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
320 1.9 kenh sc->sc_auxpioh.size, &sc->sc_auxpioh, &sc->sc_auxiowindow)) {
321 1.27 enami printf(": can't map second I/O space\n");
322 1.41 uch goto mapaux_failed;
323 1.25 sommerfe }
324 1.5 enami
325 1.25 sommerfe if ((wpp != NULL) && (wpp->wpp_name != NULL))
326 1.25 sommerfe printf(": %s", wpp->wpp_name);
327 1.25 sommerfe
328 1.5 enami printf("\n");
329 1.9 kenh
330 1.41 uch sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
331 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
332 1.41 uch sc->wdc_channel.cmd_iot = sc->sc_pmemh.memt;
333 1.41 uch sc->wdc_channel.cmd_ioh = sc->sc_pmemh.memh;
334 1.41 uch sc->wdc_channel.ctl_iot = sc->sc_auxpmemh.memt;
335 1.41 uch sc->wdc_channel.ctl_ioh = sc->sc_auxpmemh.memh;
336 1.41 uch } else {
337 1.41 uch sc->wdc_channel.cmd_iot = sc->sc_pioh.iot;
338 1.41 uch sc->wdc_channel.cmd_ioh = sc->sc_pioh.ioh;
339 1.41 uch sc->wdc_channel.ctl_iot = sc->sc_auxpioh.iot;
340 1.41 uch sc->wdc_channel.ctl_ioh = sc->sc_auxpioh.ioh;
341 1.41 uch sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
342 1.41 uch }
343 1.12 bouyer sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
344 1.12 bouyer sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
345 1.39 takemura sc->sc_wdcdev.cap |= WDC_CAPABILITY_SINGLE_DRIVE;
346 1.18 bouyer sc->sc_wdcdev.PIO_cap = 0;
347 1.16 drochner sc->wdc_chanptr = &sc->wdc_channel;
348 1.16 drochner sc->sc_wdcdev.channels = &sc->wdc_chanptr;
349 1.12 bouyer sc->sc_wdcdev.nchannels = 1;
350 1.12 bouyer sc->wdc_channel.channel = 0;
351 1.12 bouyer sc->wdc_channel.wdc = &sc->sc_wdcdev;
352 1.12 bouyer sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
353 1.12 bouyer M_DEVBUF, M_NOWAIT);
354 1.12 bouyer if (sc->wdc_channel.ch_queue == NULL) {
355 1.20 enami printf("%s: can't allocate memory for command queue\n",
356 1.13 enami sc->sc_wdcdev.sc_dev.dv_xname);
357 1.29 enami goto ch_queue_alloc_failed;
358 1.12 bouyer }
359 1.14 enami if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
360 1.12 bouyer sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
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.22 enami sc->sc_flags |= WDC_PCMCIA_ATTACH;
367 1.30 enami wdcattach(&sc->wdc_channel); /* should return an error XXX */
368 1.22 enami sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
369 1.29 enami return;
370 1.29 enami
371 1.29 enami ch_queue_alloc_failed:
372 1.29 enami /* Unmap our aux i/o window. */
373 1.41 uch if (!(sc->sc_flags & WDC_PCMCIA_MEMMODE) && (sc->sc_auxiowindow != -1))
374 1.29 enami pcmcia_io_unmap(sc->sc_pf, sc->sc_auxiowindow);
375 1.29 enami
376 1.41 uch mapaux_failed:
377 1.29 enami /* Unmap our i/o window. */
378 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE)
379 1.41 uch pcmcia_mem_unmap(sc->sc_pf, sc->sc_memwindow);
380 1.41 uch else
381 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
382 1.29 enami
383 1.41 uch map_failed:
384 1.29 enami /* Disable the function */
385 1.29 enami pcmcia_function_disable(sc->sc_pf);
386 1.29 enami
387 1.29 enami enable_failed:
388 1.29 enami /* Unmap our i/o space. */
389 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
390 1.41 uch pcmcia_mem_free(sc->sc_pf, &sc->sc_pmembaseh);
391 1.41 uch } else {
392 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
393 1.41 uch if (cfe->num_iospace == 2)
394 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
395 1.41 uch }
396 1.29 enami no_config_entry:
397 1.29 enami sc->sc_iowindow = -1;
398 1.21 enami }
399 1.21 enami
400 1.21 enami int
401 1.21 enami wdc_pcmcia_detach(self, flags)
402 1.21 enami struct device *self;
403 1.21 enami int flags;
404 1.21 enami {
405 1.21 enami struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
406 1.21 enami int error;
407 1.29 enami
408 1.29 enami if (sc->sc_iowindow == -1)
409 1.29 enami /* Nothing to detach */
410 1.29 enami return (0);
411 1.21 enami
412 1.21 enami if ((error = wdcdetach(self, flags)) != 0)
413 1.21 enami return (error);
414 1.21 enami
415 1.25 sommerfe if (sc->wdc_channel.ch_queue != NULL)
416 1.25 sommerfe free(sc->wdc_channel.ch_queue, M_DEVBUF);
417 1.21 enami
418 1.21 enami /* Unmap our i/o window and i/o space. */
419 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
420 1.41 uch pcmcia_mem_unmap(sc->sc_pf, sc->sc_memwindow);
421 1.41 uch pcmcia_mem_free(sc->sc_pf, &sc->sc_pmembaseh);
422 1.41 uch } else {
423 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
424 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
425 1.41 uch if (sc->sc_auxiowindow != -1) {
426 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_auxiowindow);
427 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
428 1.41 uch }
429 1.21 enami }
430 1.21 enami
431 1.21 enami return (0);
432 1.15 thorpej }
433 1.15 thorpej
434 1.15 thorpej int
435 1.42 bouyer wdc_pcmcia_enable(self, onoff)
436 1.42 bouyer struct device *self;
437 1.15 thorpej int onoff;
438 1.15 thorpej {
439 1.42 bouyer struct wdc_pcmcia_softc *sc = (void *)self;
440 1.15 thorpej
441 1.15 thorpej if (onoff) {
442 1.27 enami /* See the comment in aic_pcmcia_enable */
443 1.22 enami if ((sc->sc_flags & WDC_PCMCIA_ATTACH) == 0) {
444 1.31 enami /* Establish the interrupt handler. */
445 1.31 enami sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_BIO,
446 1.31 enami wdcintr, &sc->wdc_channel);
447 1.31 enami if (sc->sc_ih == NULL) {
448 1.31 enami printf("%s: "
449 1.31 enami "couldn't establish interrupt handler\n",
450 1.31 enami sc->sc_wdcdev.sc_dev.dv_xname);
451 1.31 enami return (EIO);
452 1.31 enami }
453 1.31 enami
454 1.22 enami if (pcmcia_function_enable(sc->sc_pf)) {
455 1.22 enami printf("%s: couldn't enable PCMCIA function\n",
456 1.22 enami sc->sc_wdcdev.sc_dev.dv_xname);
457 1.22 enami pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
458 1.22 enami return (EIO);
459 1.22 enami }
460 1.22 enami wdcreset(&sc->wdc_channel, VERBOSE);
461 1.15 thorpej }
462 1.15 thorpej } else {
463 1.15 thorpej pcmcia_function_disable(sc->sc_pf);
464 1.31 enami if ((sc->sc_flags & WDC_PCMCIA_ATTACH) == 0)
465 1.31 enami pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
466 1.15 thorpej }
467 1.15 thorpej
468 1.15 thorpej return (0);
469 1.1 matt }
470