Home | History | Annotate | Line # | Download | only in pcmcia
wdc_pcmcia.c revision 1.72
      1  1.72   mycroft /*	$NetBSD: wdc_pcmcia.c,v 1.72 2004/08/10 02:56:42 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.72   mycroft __KERNEL_RCSID(0, "$NetBSD: wdc_pcmcia.c,v 1.72 2004/08/10 02:56:42 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_pmemh;
     70  1.41       uch 	struct pcmcia_mem_handle sc_auxpmemh;
     71   1.1      matt 	void *sc_ih;
     72  1.15   thorpej 	struct pcmcia_function *sc_pf;
     73  1.22     enami 	int sc_flags;
     74  1.63    briggs #define WDC_PCMCIA_ATTACH	0x0001
     75  1.72   mycroft #define WDC_PCMCIA_ATTACHED	0x0002
     76   1.1      matt };
     77   1.1      matt 
     78   1.1      matt static int wdc_pcmcia_match	__P((struct device *, struct cfdata *, void *));
     79  1.72   mycroft static int wdc_pcmcia_validate_config __P((struct pcmcia_config_entry *));
     80   1.1      matt static void wdc_pcmcia_attach	__P((struct device *, struct device *, void *));
     81  1.21     enami static int wdc_pcmcia_detach	__P((struct device *, int));
     82   1.1      matt 
     83  1.51   thorpej CFATTACH_DECL(wdc_pcmcia, sizeof(struct wdc_pcmcia_softc),
     84  1.52   thorpej     wdc_pcmcia_match, wdc_pcmcia_attach, wdc_pcmcia_detach, wdcactivate);
     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 } wdc_pcmcia_products[] = {
     93   1.9      kenh 
     94   1.9      kenh 	{ /* PCMCIA_VENDOR_DIGITAL XXX */ 0x0100,
     95   1.9      kenh 	  PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
     96  1.69   mycroft 	  0, {NULL, "Digital Mobile Media CD-ROM", NULL, NULL} },
     97  1.19       abs 
     98  1.19       abs 	{ PCMCIA_VENDOR_IBM,
     99  1.24     soren 	  PCMCIA_PRODUCT_IBM_PORTABLE_CDROM,
    100  1.69   mycroft 	  0, {NULL, "PCMCIA Portable CD-ROM Drive", NULL, NULL} },
    101   1.9      kenh 
    102   1.9      kenh 	/* The TEAC IDE/Card II is used on the Sony Vaio */
    103   1.9      kenh 	{ PCMCIA_VENDOR_TEAC,
    104   1.9      kenh 	  PCMCIA_PRODUCT_TEAC_IDECARDII,
    105   1.9      kenh 	  WDC_PCMCIA_NO_EXTRA_RESETS,
    106  1.69   mycroft 	  PCMCIA_CIS_TEAC_IDECARDII },
    107  1.43  christos 
    108  1.43  christos 	/*
    109  1.43  christos 	 * A fujitsu rebranded panasonic drive that reports
    110  1.43  christos 	 * itself as function "scsi", disk interface 0
    111  1.43  christos 	 */
    112  1.43  christos 	{ PCMCIA_VENDOR_PANASONIC,
    113  1.43  christos 	  PCMCIA_PRODUCT_PANASONIC_KXLC005,
    114  1.43  christos 	  0,
    115  1.69   mycroft 	  PCMCIA_CIS_PANASONIC_KXLC005 },
    116  1.26  augustss 
    117  1.27     enami 	/*
    118  1.27     enami 	 * EXP IDE/ATAPI DVD Card use with some DVD players.
    119  1.27     enami 	 * Does not have a vendor ID or product ID.
    120  1.27     enami 	 */
    121  1.69   mycroft 	{ -1, -1, 0,
    122  1.69   mycroft 	  PCMCIA_CIS_EXP_EXPMULTIMEDIA },
    123  1.23  takemura 
    124  1.36       abs 	/* Mobile Dock 2, neither vendor ID nor product ID */
    125  1.23  takemura 	{ -1, -1, 0,
    126  1.69   mycroft 	  {"SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", NULL, NULL} },
    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.69   mycroft 	  {"FREECOM", "PCCARD-IDE", NULL, NULL} },
    131  1.36       abs 
    132  1.36       abs 	/* Random CD-ROM, (badged AMACOM), neither vendor ID nor product ID */
    133  1.36       abs 	{ -1, -1, 0,
    134  1.69   mycroft 	  {"PCMCIA", "CD-ROM", NULL, NULL} },
    135  1.37      haya 
    136  1.37      haya 	/* IO DATA CBIDE2, with neither vendor ID nor product ID */
    137  1.37      haya 	{ -1, -1, 0,
    138  1.69   mycroft 	  PCMCIA_CIS_IODATA_CBIDE2 },
    139  1.54    ichiro 
    140  1.54    ichiro 	/* TOSHIBA PA2673U(IODATA_CBIDE2 OEM), */
    141  1.54    ichiro 	/*  with neither vendor ID nor product ID */
    142  1.54    ichiro 	{ -1, -1, 0,
    143  1.69   mycroft 	  PCMCIA_CIS_TOSHIBA_CBIDE2 },
    144  1.38      sato 
    145  1.38      sato 	/*
    146  1.38      sato 	 * Novac PCMCIA-IDE Card for HD530P IDE Box,
    147  1.38      sato 	 * with neither vendor ID nor product ID
    148  1.38      sato 	 */
    149  1.38      sato 	{ -1, -1, 0,
    150  1.69   mycroft 	  {"PCMCIA", "PnPIDE", NULL, NULL} },
    151   1.9      kenh };
    152   1.9      kenh 
    153  1.40  jdolecek const struct wdc_pcmcia_product *
    154   1.9      kenh 	wdc_pcmcia_lookup __P((struct pcmcia_attach_args *));
    155   1.9      kenh 
    156  1.42    bouyer int	wdc_pcmcia_enable __P((struct device *, int));
    157  1.14     enami 
    158  1.40  jdolecek const struct wdc_pcmcia_product *
    159   1.9      kenh wdc_pcmcia_lookup(pa)
    160   1.9      kenh 	struct pcmcia_attach_args *pa;
    161   1.9      kenh {
    162  1.40  jdolecek 	const struct wdc_pcmcia_product *wpp;
    163   1.9      kenh 	int i, cis_match;
    164  1.69   mycroft 	int n;
    165   1.9      kenh 
    166  1.69   mycroft 	for (wpp = wdc_pcmcia_products,
    167  1.69   mycroft 	    n = sizeof(wdc_pcmcia_products) / sizeof(wdc_pcmcia_products[0]);
    168  1.69   mycroft 	    n; wpp++, n--) {
    169   1.9      kenh 		if ((wpp->wpp_vendor == -1 ||
    170   1.9      kenh 		     pa->manufacturer == wpp->wpp_vendor) &&
    171   1.9      kenh 		    (wpp->wpp_product == -1 ||
    172   1.9      kenh 		     pa->product == wpp->wpp_product)) {
    173   1.9      kenh 			cis_match = 1;
    174   1.9      kenh 			for (i = 0; i < 4; i++) {
    175   1.9      kenh 				if (!(wpp->wpp_cis_info[i] == NULL ||
    176   1.9      kenh 				      (pa->card->cis1_info[i] != NULL &&
    177   1.9      kenh 				       strcmp(pa->card->cis1_info[i],
    178   1.9      kenh 					      wpp->wpp_cis_info[i]) == 0)))
    179   1.9      kenh 					cis_match = 0;
    180   1.9      kenh 			}
    181   1.9      kenh 			if (cis_match)
    182  1.13     enami 				return (wpp);
    183   1.9      kenh 		}
    184  1.69   mycroft 	}
    185   1.9      kenh 
    186   1.9      kenh 	return (NULL);
    187   1.9      kenh }
    188   1.9      kenh 
    189   1.1      matt static int
    190   1.2   mycroft wdc_pcmcia_match(parent, match, aux)
    191   1.2   mycroft 	struct device *parent;
    192   1.2   mycroft 	struct cfdata *match;
    193   1.2   mycroft 	void *aux;
    194   1.1      matt {
    195   1.1      matt 	struct pcmcia_attach_args *pa = aux;
    196  1.35      haya 
    197  1.35      haya 	if (pa->pf->function == PCMCIA_FUNCTION_DISK &&
    198  1.35      haya 	    pa->pf->pf_funce_disk_interface == PCMCIA_TPLFE_DDI_PCCARD_ATA) {
    199  1.35      haya 		return 10;
    200  1.35      haya 	}
    201   1.1      matt 
    202   1.9      kenh 	if (wdc_pcmcia_lookup(pa) != NULL)
    203   1.9      kenh 		return (1);
    204  1.14     enami 
    205   1.9      kenh 	return (0);
    206   1.1      matt }
    207   1.1      matt 
    208  1.72   mycroft static int
    209  1.72   mycroft wdc_pcmcia_validate_config(cfe)
    210  1.72   mycroft 	struct pcmcia_config_entry *cfe;
    211  1.72   mycroft {
    212  1.72   mycroft 	switch (cfe->iftype) {
    213  1.72   mycroft #if 0
    214  1.72   mycroft 	case PCMCIA_IFTYPE_MEMORY:
    215  1.72   mycroft 		if (cfe->num_iospace != 0 ||
    216  1.72   mycroft 		    cfe->num_memspace != 1)
    217  1.72   mycroft 			return (EINVAL);
    218  1.72   mycroft 		break;
    219  1.72   mycroft #endif
    220  1.72   mycroft 	case PCMCIA_IFTYPE_IO:
    221  1.72   mycroft 		if (cfe->num_iospace < 1 || cfe->num_iospace > 2)
    222  1.72   mycroft 			return (EINVAL);
    223  1.72   mycroft 		cfe->num_memspace = 0;
    224  1.72   mycroft 		break;
    225  1.72   mycroft 	default:
    226  1.72   mycroft 		return (EINVAL);
    227  1.72   mycroft 	}
    228  1.72   mycroft 	return (0);
    229  1.72   mycroft }
    230  1.72   mycroft 
    231   1.1      matt static void
    232   1.2   mycroft wdc_pcmcia_attach(parent, self, aux)
    233   1.2   mycroft 	struct device *parent;
    234   1.2   mycroft 	struct device *self;
    235   1.2   mycroft 	void *aux;
    236   1.1      matt {
    237   1.1      matt 	struct wdc_pcmcia_softc *sc = (void *)self;
    238   1.1      matt 	struct pcmcia_attach_args *pa = aux;
    239   1.5     enami 	struct pcmcia_config_entry *cfe;
    240  1.40  jdolecek 	const struct wdc_pcmcia_product *wpp;
    241  1.72   mycroft 	bus_size_t offset;
    242  1.64      fvdl 	int quirks, i;
    243  1.72   mycroft 	int error;
    244   1.1      matt 
    245  1.69   mycroft 	aprint_normal("\n");
    246  1.15   thorpej 	sc->sc_pf = pa->pf;
    247  1.15   thorpej 
    248  1.72   mycroft 	/*XXXmem16|common*/
    249  1.72   mycroft 	error = pcmcia_function_configure(pa->pf, wdc_pcmcia_validate_config);
    250  1.72   mycroft 	if (error) {
    251  1.72   mycroft 		aprint_error("%s: configure failed, error=%d\n", self->dv_xname,
    252  1.72   mycroft 		    error);
    253  1.72   mycroft 		return;
    254   1.1      matt 	}
    255   1.1      matt 
    256  1.72   mycroft 	cfe = pa->pf->cfe;
    257  1.72   mycroft 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
    258  1.72   mycroft 	if (cfe->iftype == PCMCIA_IFTYPE_MEMORY) {
    259  1.72   mycroft 		sc->sc_pmemh.memt = cfe->memspace[0].handle.memt;
    260  1.72   mycroft 		sc->sc_pmemh.memh = cfe->memspace[0].handle.memh;
    261  1.72   mycroft 		offset = cfe->memspace[0].offset;
    262  1.41       uch 
    263  1.41       uch 		sc->sc_auxpmemh.memt = sc->sc_pmemh.memt;
    264  1.41       uch 		if (bus_space_subregion(sc->sc_pmemh.memt,
    265  1.72   mycroft 		    sc->sc_pmemh.memh, WDC_PCMCIA_AUXREG_OFFSET + offset,
    266  1.41       uch 		    WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpmemh.memh))
    267  1.72   mycroft 			goto fail;
    268  1.41       uch 
    269  1.69   mycroft 		aprint_normal("%s: memory mapped mode\n", self->dv_xname);
    270  1.72   mycroft 		sc->wdc_channel.cmd_iot = sc->sc_pmemh.memt;
    271  1.72   mycroft 		sc->wdc_channel.cmd_baseioh = sc->sc_pmemh.memh;
    272  1.72   mycroft 		sc->wdc_channel.ctl_iot = sc->sc_auxpmemh.memt;
    273  1.72   mycroft 		sc->wdc_channel.ctl_ioh = sc->sc_auxpmemh.memh;
    274  1.41       uch 	} else {
    275  1.72   mycroft 		sc->sc_pioh.iot = cfe->iospace[0].handle.iot;
    276  1.72   mycroft 		sc->sc_pioh.ioh = cfe->iospace[0].handle.ioh;
    277  1.72   mycroft 		offset = 0;
    278  1.72   mycroft 
    279  1.72   mycroft 		if (cfe->num_iospace == 1) {
    280  1.72   mycroft 			sc->sc_auxpioh.iot = sc->sc_pioh.iot;
    281  1.72   mycroft 			if (bus_space_subregion(sc->sc_pioh.iot,
    282  1.72   mycroft 			    sc->sc_pioh.ioh, WDC_PCMCIA_AUXREG_OFFSET,
    283  1.72   mycroft 			    WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpioh.ioh))
    284  1.72   mycroft 				goto fail;
    285  1.72   mycroft 		} else {
    286  1.72   mycroft 			sc->sc_auxpioh.iot = cfe->iospace[1].handle.iot;
    287  1.72   mycroft 			sc->sc_auxpioh.ioh = cfe->iospace[1].handle.ioh;
    288  1.72   mycroft 		}
    289  1.41       uch 
    290  1.72   mycroft 		aprint_normal("%s: i/o mapped mode\n", self->dv_xname);
    291  1.72   mycroft 		sc->wdc_channel.cmd_iot = sc->sc_pioh.iot;
    292  1.72   mycroft 		sc->wdc_channel.cmd_baseioh = sc->sc_pioh.ioh;
    293  1.72   mycroft 		sc->wdc_channel.ctl_iot = sc->sc_auxpioh.iot;
    294  1.72   mycroft 		sc->wdc_channel.ctl_ioh = sc->sc_auxpioh.ioh;
    295  1.72   mycroft 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
    296  1.25  sommerfe 	}
    297   1.5     enami 
    298  1.71   mycroft 	if (wdc_pcmcia_enable(self, 1)) {
    299  1.71   mycroft 		aprint_error("%s: enable failed\n", self->dv_xname);
    300  1.72   mycroft 		goto fail;
    301  1.71   mycroft 	}
    302  1.71   mycroft 
    303  1.71   mycroft 	wpp = wdc_pcmcia_lookup(pa);
    304  1.71   mycroft 	if (wpp != NULL)
    305  1.71   mycroft 		quirks = wpp->wpp_quirk_flag;
    306  1.71   mycroft 	else
    307  1.71   mycroft 		quirks = 0;
    308  1.71   mycroft 
    309  1.64      fvdl 	for (i = 0; i < WDC_PCMCIA_REG_NPORTS; i++) {
    310  1.64      fvdl 		if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    311  1.64      fvdl 		    sc->wdc_channel.cmd_baseioh,
    312  1.64      fvdl 		    offset + i, i == 0 ? 4 : 1,
    313  1.64      fvdl 		    &sc->wdc_channel.cmd_iohs[i]) != 0) {
    314  1.69   mycroft 			aprint_error("%s: can't subregion I/O space\n",
    315  1.69   mycroft 			    self->dv_xname);
    316  1.72   mycroft 			goto fail2;
    317  1.64      fvdl 		}
    318  1.64      fvdl 	}
    319  1.68   thorpej 	wdc_init_shadow_regs(&sc->wdc_channel);
    320  1.12    bouyer 	sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
    321  1.64      fvdl 	sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_iohs[0];
    322  1.18    bouyer 	sc->sc_wdcdev.PIO_cap = 0;
    323  1.53      matt 	sc->wdc_chanlist[0] = &sc->wdc_channel;
    324  1.53      matt 	sc->sc_wdcdev.channels = sc->wdc_chanlist;
    325  1.12    bouyer 	sc->sc_wdcdev.nchannels = 1;
    326  1.67   thorpej 	sc->wdc_channel.ch_channel = 0;
    327  1.67   thorpej 	sc->wdc_channel.ch_wdc = &sc->sc_wdcdev;
    328  1.53      matt 	sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
    329  1.56   mycroft #if 0
    330  1.14     enami 	if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
    331  1.12    bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
    332  1.56   mycroft #endif
    333  1.15   thorpej 
    334  1.15   thorpej 	/* We can enable and disable the controller. */
    335  1.42    bouyer 	sc->sc_wdcdev.sc_atapi_adapter._generic.adapt_enable =
    336  1.32    bouyer 	    wdc_pcmcia_enable;
    337  1.15   thorpej 
    338  1.63    briggs 	sc->sc_flags |= WDC_PCMCIA_ATTACH;
    339  1.60    bouyer 	wdcattach(&sc->wdc_channel);
    340  1.72   mycroft 	sc->sc_flags |= WDC_PCMCIA_ATTACHED;
    341  1.29     enami 	return;
    342  1.29     enami 
    343  1.72   mycroft fail2:
    344  1.72   mycroft 	wdc_pcmcia_enable(self, 0);
    345  1.72   mycroft fail:
    346  1.72   mycroft 	pcmcia_function_unconfigure(pa->pf);
    347  1.21     enami }
    348  1.21     enami 
    349  1.21     enami int
    350  1.21     enami wdc_pcmcia_detach(self, flags)
    351  1.21     enami 	struct device *self;
    352  1.21     enami 	int flags;
    353  1.21     enami {
    354  1.21     enami 	struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
    355  1.21     enami 	int error;
    356  1.29     enami 
    357  1.72   mycroft 	if ((sc->sc_flags & WDC_PCMCIA_ATTACHED) == 0)
    358  1.29     enami 		return (0);
    359  1.21     enami 
    360  1.21     enami 	if ((error = wdcdetach(self, flags)) != 0)
    361  1.21     enami 		return (error);
    362  1.21     enami 
    363  1.72   mycroft 	pcmcia_function_unconfigure(sc->sc_pf);
    364  1.61    briggs 
    365  1.21     enami 	return (0);
    366  1.15   thorpej }
    367  1.15   thorpej 
    368  1.15   thorpej int
    369  1.42    bouyer wdc_pcmcia_enable(self, onoff)
    370  1.42    bouyer 	struct device *self;
    371  1.15   thorpej 	int onoff;
    372  1.15   thorpej {
    373  1.42    bouyer 	struct wdc_pcmcia_softc *sc = (void *)self;
    374  1.15   thorpej 
    375  1.15   thorpej 	if (onoff) {
    376  1.63    briggs 		/*
    377  1.63    briggs 		 * If the WDC_PCMCIA_ATTACH flag is set, we've already
    378  1.63    briggs 		 * enabled the card in the attach routine, so don't
    379  1.63    briggs 		 * re-enable it here (to save power cycle time).  Clear
    380  1.63    briggs 		 * the flag, though, so that the next disable/enable
    381  1.63    briggs 		 * will do the right thing.
    382  1.63    briggs 		 */
    383  1.63    briggs 		if (sc->sc_flags & WDC_PCMCIA_ATTACH) {
    384  1.63    briggs 			sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
    385  1.63    briggs 		} else {
    386  1.71   mycroft 			/* Establish the interrupt handler. */
    387  1.71   mycroft 			sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_BIO,
    388  1.71   mycroft 			    wdcintr, &sc->wdc_channel);
    389  1.71   mycroft 			if (sc->sc_ih == NULL) {
    390  1.71   mycroft 				printf("%s: couldn't establish interrupt handler\n",
    391  1.71   mycroft 				    sc->sc_wdcdev.sc_dev.dv_xname);
    392  1.71   mycroft 				return (EIO);
    393  1.71   mycroft 			}
    394  1.71   mycroft 
    395  1.63    briggs 			if (pcmcia_function_enable(sc->sc_pf)) {
    396  1.63    briggs 				printf("%s: couldn't enable PCMCIA function\n",
    397  1.63    briggs 				    sc->sc_wdcdev.sc_dev.dv_xname);
    398  1.63    briggs 				pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    399  1.63    briggs 				return (EIO);
    400  1.63    briggs 			}
    401  1.15   thorpej 		}
    402  1.15   thorpej 	} else {
    403  1.15   thorpej 		pcmcia_function_disable(sc->sc_pf);
    404  1.56   mycroft 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    405  1.72   mycroft 		sc->sc_ih = 0;
    406  1.15   thorpej 	}
    407  1.15   thorpej 
    408  1.15   thorpej 	return (0);
    409   1.1      matt }
    410