wdc_pcmcia.c revision 1.67 1 1.67 thorpej /* $NetBSD: wdc_pcmcia.c,v 1.67 2004/01/03 22:56:53 thorpej 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.67 thorpej __KERNEL_RCSID(0, "$NetBSD: wdc_pcmcia.c,v 1.67 2004/01/03 22:56:53 thorpej 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 const char *wpp_name; /* product name */
96 1.9 kenh } wdc_pcmcia_products[] = {
97 1.9 kenh
98 1.9 kenh { /* PCMCIA_VENDOR_DIGITAL XXX */ 0x0100,
99 1.9 kenh PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
100 1.9 kenh 0, { NULL, "Digital Mobile Media CD-ROM", NULL, NULL },
101 1.9 kenh PCMCIA_STR_DIGITAL_MOBILE_MEDIA_CDROM },
102 1.19 abs
103 1.19 abs { PCMCIA_VENDOR_IBM,
104 1.24 soren PCMCIA_PRODUCT_IBM_PORTABLE_CDROM,
105 1.19 abs 0, { NULL, "PCMCIA Portable CD-ROM Drive", NULL, NULL },
106 1.24 soren PCMCIA_STR_IBM_PORTABLE_CDROM },
107 1.9 kenh
108 1.9 kenh /* The TEAC IDE/Card II is used on the Sony Vaio */
109 1.9 kenh { PCMCIA_VENDOR_TEAC,
110 1.9 kenh PCMCIA_PRODUCT_TEAC_IDECARDII,
111 1.9 kenh WDC_PCMCIA_NO_EXTRA_RESETS,
112 1.9 kenh PCMCIA_CIS_TEAC_IDECARDII,
113 1.9 kenh PCMCIA_STR_TEAC_IDECARDII },
114 1.43 christos
115 1.43 christos /*
116 1.43 christos * A fujitsu rebranded panasonic drive that reports
117 1.43 christos * itself as function "scsi", disk interface 0
118 1.43 christos */
119 1.43 christos { PCMCIA_VENDOR_PANASONIC,
120 1.43 christos PCMCIA_PRODUCT_PANASONIC_KXLC005,
121 1.43 christos 0,
122 1.43 christos PCMCIA_CIS_PANASONIC_KXLC005,
123 1.43 christos PCMCIA_STR_PANASONIC_KXLC005 },
124 1.26 augustss
125 1.27 enami /*
126 1.27 enami * EXP IDE/ATAPI DVD Card use with some DVD players.
127 1.27 enami * Does not have a vendor ID or product ID.
128 1.27 enami */
129 1.26 augustss { -1,
130 1.26 augustss -1,
131 1.26 augustss 0,
132 1.26 augustss PCMCIA_CIS_EXP_EXPMULTIMEDIA,
133 1.26 augustss PCMCIA_STR_EXP_EXPMULTIMEDIA },
134 1.23 takemura
135 1.36 abs /* Mobile Dock 2, neither vendor ID nor product ID */
136 1.23 takemura { -1, -1, 0,
137 1.23 takemura { "SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", NULL, NULL},
138 1.23 takemura "SHUTTLE TECHNOLOGY IDE/ATAPI Adapter"
139 1.34 abs },
140 1.34 abs
141 1.36 abs /* Toshiba Portege 3110 CD, neither vendor ID nor product ID */
142 1.34 abs { -1, -1, 0,
143 1.34 abs { "FREECOM", "PCCARD-IDE", NULL, NULL},
144 1.34 abs "FREECOM PCCARD-IDE"
145 1.36 abs },
146 1.36 abs
147 1.36 abs /* Random CD-ROM, (badged AMACOM), neither vendor ID nor product ID */
148 1.36 abs { -1, -1, 0,
149 1.36 abs { "PCMCIA", "CD-ROM", NULL, NULL},
150 1.36 abs "PCMCIA CD-ROM"
151 1.37 haya },
152 1.37 haya
153 1.37 haya /* IO DATA CBIDE2, with neither vendor ID nor product ID */
154 1.37 haya { -1, -1, 0,
155 1.37 haya PCMCIA_CIS_IODATA_CBIDE2,
156 1.37 haya PCMCIA_STR_IODATA_CBIDE2
157 1.54 ichiro },
158 1.54 ichiro
159 1.54 ichiro /* TOSHIBA PA2673U(IODATA_CBIDE2 OEM), */
160 1.54 ichiro /* with neither vendor ID nor product ID */
161 1.54 ichiro { -1, -1, 0,
162 1.54 ichiro PCMCIA_CIS_TOSHIBA_CBIDE2,
163 1.54 ichiro PCMCIA_STR_TOSHIBA_CBIDE2
164 1.38 sato },
165 1.38 sato
166 1.38 sato /*
167 1.38 sato * Novac PCMCIA-IDE Card for HD530P IDE Box,
168 1.38 sato * with neither vendor ID nor product ID
169 1.38 sato */
170 1.38 sato { -1, -1, 0,
171 1.38 sato { "PCMCIA", "PnPIDE", NULL, NULL},
172 1.38 sato "Novac PCCARD-IDE"
173 1.23 takemura },
174 1.9 kenh
175 1.9 kenh { 0, 0, 0, { NULL, NULL, NULL, NULL}, NULL }
176 1.9 kenh };
177 1.9 kenh
178 1.40 jdolecek const struct wdc_pcmcia_product *
179 1.9 kenh wdc_pcmcia_lookup __P((struct pcmcia_attach_args *));
180 1.9 kenh
181 1.42 bouyer int wdc_pcmcia_enable __P((struct device *, int));
182 1.14 enami
183 1.40 jdolecek const struct wdc_pcmcia_product *
184 1.9 kenh wdc_pcmcia_lookup(pa)
185 1.9 kenh struct pcmcia_attach_args *pa;
186 1.9 kenh {
187 1.40 jdolecek const struct wdc_pcmcia_product *wpp;
188 1.9 kenh int i, cis_match;
189 1.9 kenh
190 1.9 kenh for (wpp = wdc_pcmcia_products; wpp->wpp_name != NULL; wpp++)
191 1.9 kenh if ((wpp->wpp_vendor == -1 ||
192 1.9 kenh pa->manufacturer == wpp->wpp_vendor) &&
193 1.9 kenh (wpp->wpp_product == -1 ||
194 1.9 kenh pa->product == wpp->wpp_product)) {
195 1.9 kenh cis_match = 1;
196 1.9 kenh for (i = 0; i < 4; i++) {
197 1.9 kenh if (!(wpp->wpp_cis_info[i] == NULL ||
198 1.9 kenh (pa->card->cis1_info[i] != NULL &&
199 1.9 kenh strcmp(pa->card->cis1_info[i],
200 1.9 kenh wpp->wpp_cis_info[i]) == 0)))
201 1.9 kenh cis_match = 0;
202 1.9 kenh }
203 1.9 kenh if (cis_match)
204 1.13 enami return (wpp);
205 1.9 kenh }
206 1.9 kenh
207 1.9 kenh return (NULL);
208 1.9 kenh }
209 1.9 kenh
210 1.1 matt static int
211 1.2 mycroft wdc_pcmcia_match(parent, match, aux)
212 1.2 mycroft struct device *parent;
213 1.2 mycroft struct cfdata *match;
214 1.2 mycroft void *aux;
215 1.1 matt {
216 1.1 matt struct pcmcia_attach_args *pa = aux;
217 1.35 haya
218 1.35 haya if (pa->pf->function == PCMCIA_FUNCTION_DISK &&
219 1.35 haya pa->pf->pf_funce_disk_interface == PCMCIA_TPLFE_DDI_PCCARD_ATA) {
220 1.35 haya return 10;
221 1.35 haya }
222 1.1 matt
223 1.9 kenh if (wdc_pcmcia_lookup(pa) != NULL)
224 1.9 kenh return (1);
225 1.14 enami
226 1.9 kenh return (0);
227 1.1 matt }
228 1.1 matt
229 1.1 matt static void
230 1.2 mycroft wdc_pcmcia_attach(parent, self, aux)
231 1.2 mycroft struct device *parent;
232 1.2 mycroft struct device *self;
233 1.2 mycroft void *aux;
234 1.1 matt {
235 1.1 matt struct wdc_pcmcia_softc *sc = (void *)self;
236 1.1 matt struct pcmcia_attach_args *pa = aux;
237 1.5 enami struct pcmcia_config_entry *cfe;
238 1.40 jdolecek const struct wdc_pcmcia_product *wpp;
239 1.64 fvdl bus_size_t offset = 0;
240 1.64 fvdl int quirks, i;
241 1.1 matt
242 1.15 thorpej sc->sc_pf = pa->pf;
243 1.15 thorpej
244 1.49 lukem SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
245 1.9 kenh if (cfe->num_iospace != 1 && cfe->num_iospace != 2)
246 1.9 kenh continue;
247 1.9 kenh
248 1.1 matt if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
249 1.9 kenh cfe->iospace[0].length,
250 1.9 kenh cfe->iospace[0].start == 0 ? cfe->iospace[0].length : 0,
251 1.9 kenh &sc->sc_pioh))
252 1.1 matt continue;
253 1.9 kenh
254 1.9 kenh if (cfe->num_iospace == 2) {
255 1.1 matt if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
256 1.9 kenh cfe->iospace[1].length, 0, &sc->sc_auxpioh))
257 1.1 matt break;
258 1.9 kenh } else /* num_iospace == 1 */ {
259 1.1 matt sc->sc_auxpioh.iot = sc->sc_pioh.iot;
260 1.9 kenh if (!bus_space_subregion(sc->sc_pioh.iot,
261 1.9 kenh sc->sc_pioh.ioh, WDC_PCMCIA_AUXREG_OFFSET,
262 1.9 kenh WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpioh.ioh))
263 1.1 matt break;
264 1.1 matt }
265 1.11 thorpej pcmcia_io_free(pa->pf, &sc->sc_pioh);
266 1.1 matt }
267 1.1 matt
268 1.41 uch /*
269 1.46 simonb * Compact Flash memory mapped mode
270 1.41 uch * CF+ and CompactFlash Spec. Rev 1.4, 6.1.3 Memory Mapped Addressing.
271 1.41 uch * http://www.compactflash.org/cfspc1_4.pdf
272 1.41 uch */
273 1.41 uch if (cfe == NULL) {
274 1.41 uch SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
275 1.41 uch if (cfe->iftype != PCMCIA_IFTYPE_MEMORY)
276 1.41 uch continue;
277 1.41 uch if (pcmcia_mem_alloc(pa->pf, cfe->memspace[0].length,
278 1.41 uch &sc->sc_pmembaseh) == 0) {
279 1.41 uch sc->sc_flags |= WDC_PCMCIA_MEMMODE;
280 1.41 uch break;
281 1.41 uch }
282 1.41 uch }
283 1.41 uch }
284 1.41 uch
285 1.1 matt if (cfe == NULL) {
286 1.6 enami printf(": can't handle card info\n");
287 1.29 enami goto no_config_entry;
288 1.1 matt }
289 1.1 matt
290 1.1 matt /* Enable the card. */
291 1.1 matt pcmcia_function_init(pa->pf, cfe);
292 1.1 matt if (pcmcia_function_enable(pa->pf)) {
293 1.5 enami printf(": function enable failed\n");
294 1.29 enami goto enable_failed;
295 1.1 matt }
296 1.1 matt
297 1.9 kenh wpp = wdc_pcmcia_lookup(pa);
298 1.14 enami if (wpp != NULL)
299 1.14 enami quirks = wpp->wpp_quirk_flag;
300 1.14 enami else
301 1.14 enami quirks = 0;
302 1.9 kenh
303 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
304 1.41 uch if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_COMMON, 0,
305 1.41 uch sc->sc_pmembaseh.size, &sc->sc_pmembaseh, &offset,
306 1.41 uch &sc->sc_memwindow)) {
307 1.41 uch printf(": can't map memory space\n");
308 1.41 uch goto map_failed;
309 1.41 uch }
310 1.9 kenh
311 1.41 uch sc->sc_pmemh.memt = sc->sc_pmembaseh.memt;
312 1.64 fvdl sc->sc_pmemh.memh = sc->sc_pmembaseh.memh;
313 1.41 uch
314 1.41 uch sc->sc_auxpmemh.memt = sc->sc_pmemh.memt;
315 1.41 uch if (bus_space_subregion(sc->sc_pmemh.memt,
316 1.64 fvdl sc->sc_pmembaseh.memh, WDC_PCMCIA_AUXREG_OFFSET + offset,
317 1.41 uch WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpmemh.memh))
318 1.41 uch goto mapaux_failed;
319 1.41 uch
320 1.41 uch printf(" memory mapped mode");
321 1.41 uch } else {
322 1.41 uch if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
323 1.41 uch sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowindow)) {
324 1.41 uch printf(": can't map first I/O space\n");
325 1.41 uch goto map_failed;
326 1.41 uch }
327 1.41 uch }
328 1.41 uch
329 1.41 uch if (cfe->num_iospace <= 1 || sc->sc_flags & WDC_PCMCIA_MEMMODE)
330 1.25 sommerfe sc->sc_auxiowindow = -1;
331 1.25 sommerfe else if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
332 1.9 kenh sc->sc_auxpioh.size, &sc->sc_auxpioh, &sc->sc_auxiowindow)) {
333 1.27 enami printf(": can't map second I/O space\n");
334 1.41 uch goto mapaux_failed;
335 1.25 sommerfe }
336 1.5 enami
337 1.25 sommerfe if ((wpp != NULL) && (wpp->wpp_name != NULL))
338 1.25 sommerfe printf(": %s", wpp->wpp_name);
339 1.25 sommerfe
340 1.5 enami printf("\n");
341 1.9 kenh
342 1.41 uch sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
343 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
344 1.41 uch sc->wdc_channel.cmd_iot = sc->sc_pmemh.memt;
345 1.64 fvdl sc->wdc_channel.cmd_baseioh = sc->sc_pmemh.memh;
346 1.41 uch sc->wdc_channel.ctl_iot = sc->sc_auxpmemh.memt;
347 1.41 uch sc->wdc_channel.ctl_ioh = sc->sc_auxpmemh.memh;
348 1.41 uch } else {
349 1.41 uch sc->wdc_channel.cmd_iot = sc->sc_pioh.iot;
350 1.64 fvdl sc->wdc_channel.cmd_baseioh = sc->sc_pioh.ioh;
351 1.41 uch sc->wdc_channel.ctl_iot = sc->sc_auxpioh.iot;
352 1.41 uch sc->wdc_channel.ctl_ioh = sc->sc_auxpioh.ioh;
353 1.41 uch sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
354 1.41 uch }
355 1.64 fvdl for (i = 0; i < WDC_PCMCIA_REG_NPORTS; i++) {
356 1.64 fvdl if (bus_space_subregion(sc->wdc_channel.cmd_iot,
357 1.64 fvdl sc->wdc_channel.cmd_baseioh,
358 1.64 fvdl offset + i, i == 0 ? 4 : 1,
359 1.64 fvdl &sc->wdc_channel.cmd_iohs[i]) != 0) {
360 1.64 fvdl printf(": can't subregion I/O space\n");
361 1.64 fvdl goto mapaux_failed;
362 1.64 fvdl }
363 1.64 fvdl }
364 1.12 bouyer sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
365 1.64 fvdl sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_iohs[0];
366 1.18 bouyer sc->sc_wdcdev.PIO_cap = 0;
367 1.53 matt sc->wdc_chanlist[0] = &sc->wdc_channel;
368 1.53 matt sc->sc_wdcdev.channels = sc->wdc_chanlist;
369 1.12 bouyer sc->sc_wdcdev.nchannels = 1;
370 1.67 thorpej sc->wdc_channel.ch_channel = 0;
371 1.67 thorpej sc->wdc_channel.ch_wdc = &sc->sc_wdcdev;
372 1.53 matt sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
373 1.56 mycroft #if 0
374 1.14 enami if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
375 1.12 bouyer sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
376 1.56 mycroft #endif
377 1.15 thorpej
378 1.15 thorpej /* We can enable and disable the controller. */
379 1.42 bouyer sc->sc_wdcdev.sc_atapi_adapter._generic.adapt_enable =
380 1.32 bouyer wdc_pcmcia_enable;
381 1.15 thorpej
382 1.63 briggs sc->sc_flags |= WDC_PCMCIA_ATTACH;
383 1.60 bouyer wdcattach(&sc->wdc_channel);
384 1.62 briggs
385 1.29 enami return;
386 1.29 enami
387 1.41 uch mapaux_failed:
388 1.29 enami /* Unmap our i/o window. */
389 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE)
390 1.41 uch pcmcia_mem_unmap(sc->sc_pf, sc->sc_memwindow);
391 1.41 uch else
392 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
393 1.29 enami
394 1.41 uch map_failed:
395 1.29 enami /* Disable the function */
396 1.29 enami pcmcia_function_disable(sc->sc_pf);
397 1.29 enami
398 1.29 enami enable_failed:
399 1.29 enami /* Unmap our i/o space. */
400 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
401 1.41 uch pcmcia_mem_free(sc->sc_pf, &sc->sc_pmembaseh);
402 1.41 uch } else {
403 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
404 1.41 uch if (cfe->num_iospace == 2)
405 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
406 1.41 uch }
407 1.29 enami no_config_entry:
408 1.29 enami sc->sc_iowindow = -1;
409 1.21 enami }
410 1.21 enami
411 1.21 enami int
412 1.21 enami wdc_pcmcia_detach(self, flags)
413 1.21 enami struct device *self;
414 1.21 enami int flags;
415 1.21 enami {
416 1.21 enami struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
417 1.21 enami int error;
418 1.29 enami
419 1.29 enami if (sc->sc_iowindow == -1)
420 1.29 enami /* Nothing to detach */
421 1.29 enami return (0);
422 1.21 enami
423 1.63 briggs /*
424 1.63 briggs * If the WDC_PCMCIA_ATTACH flag is still set, then we didn't get
425 1.63 briggs * a chance * enable/disable the card in the wdc/atabus layer, so
426 1.63 briggs * we still need to disable the function here.
427 1.63 briggs */
428 1.63 briggs if (sc->sc_flags & WDC_PCMCIA_ATTACH) {
429 1.63 briggs sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
430 1.63 briggs pcmcia_function_disable(sc->sc_pf);
431 1.63 briggs }
432 1.63 briggs
433 1.21 enami if ((error = wdcdetach(self, flags)) != 0)
434 1.21 enami return (error);
435 1.21 enami
436 1.21 enami /* Unmap our i/o window and i/o space. */
437 1.41 uch if (sc->sc_flags & WDC_PCMCIA_MEMMODE) {
438 1.41 uch pcmcia_mem_unmap(sc->sc_pf, sc->sc_memwindow);
439 1.41 uch pcmcia_mem_free(sc->sc_pf, &sc->sc_pmembaseh);
440 1.41 uch } else {
441 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
442 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
443 1.41 uch if (sc->sc_auxiowindow != -1) {
444 1.41 uch pcmcia_io_unmap(sc->sc_pf, sc->sc_auxiowindow);
445 1.41 uch pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
446 1.41 uch }
447 1.21 enami }
448 1.61 briggs
449 1.21 enami return (0);
450 1.15 thorpej }
451 1.15 thorpej
452 1.15 thorpej int
453 1.42 bouyer wdc_pcmcia_enable(self, onoff)
454 1.42 bouyer struct device *self;
455 1.15 thorpej int onoff;
456 1.15 thorpej {
457 1.42 bouyer struct wdc_pcmcia_softc *sc = (void *)self;
458 1.15 thorpej
459 1.15 thorpej if (onoff) {
460 1.56 mycroft /* Establish the interrupt handler. */
461 1.56 mycroft sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_BIO,
462 1.56 mycroft wdcintr, &sc->wdc_channel);
463 1.56 mycroft if (sc->sc_ih == NULL) {
464 1.56 mycroft printf("%s: couldn't establish interrupt handler\n",
465 1.56 mycroft sc->sc_wdcdev.sc_dev.dv_xname);
466 1.56 mycroft return (EIO);
467 1.56 mycroft }
468 1.56 mycroft
469 1.63 briggs /*
470 1.63 briggs * If the WDC_PCMCIA_ATTACH flag is set, we've already
471 1.63 briggs * enabled the card in the attach routine, so don't
472 1.63 briggs * re-enable it here (to save power cycle time). Clear
473 1.63 briggs * the flag, though, so that the next disable/enable
474 1.63 briggs * will do the right thing.
475 1.63 briggs */
476 1.63 briggs if (sc->sc_flags & WDC_PCMCIA_ATTACH) {
477 1.63 briggs sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
478 1.63 briggs } else {
479 1.63 briggs if (pcmcia_function_enable(sc->sc_pf)) {
480 1.63 briggs printf("%s: couldn't enable PCMCIA function\n",
481 1.63 briggs sc->sc_wdcdev.sc_dev.dv_xname);
482 1.63 briggs pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
483 1.63 briggs return (EIO);
484 1.63 briggs }
485 1.15 thorpej }
486 1.15 thorpej } else {
487 1.15 thorpej pcmcia_function_disable(sc->sc_pf);
488 1.56 mycroft pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
489 1.15 thorpej }
490 1.15 thorpej
491 1.15 thorpej return (0);
492 1.1 matt }
493