Home | History | Annotate | Line # | Download | only in pcmcia
wdc_pcmcia.c revision 1.27
      1  1.27     enami /*	$NetBSD: wdc_pcmcia.c,v 1.27 2000/01/24 23:14:23 enami 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.1      matt #include <sys/systm.h>
     41   1.1      matt #include <sys/kernel.h>
     42   1.1      matt #include <sys/conf.h>
     43   1.1      matt #include <sys/file.h>
     44   1.1      matt #include <sys/stat.h>
     45   1.1      matt #include <sys/ioctl.h>
     46   1.1      matt #include <sys/buf.h>
     47   1.1      matt #include <sys/uio.h>
     48   1.1      matt #include <sys/malloc.h>
     49   1.1      matt #include <sys/device.h>
     50   1.1      matt #include <sys/disklabel.h>
     51   1.1      matt #include <sys/disk.h>
     52   1.1      matt #include <sys/syslog.h>
     53   1.1      matt #include <sys/proc.h>
     54   1.1      matt 
     55   1.1      matt #include <vm/vm.h>
     56   1.1      matt 
     57   1.1      matt #include <machine/cpu.h>
     58   1.1      matt #include <machine/intr.h>
     59   1.1      matt #include <machine/bus.h>
     60   1.1      matt 
     61  1.14     enami #include <dev/pcmcia/pcmciareg.h>
     62   1.1      matt #include <dev/pcmcia/pcmciavar.h>
     63   1.9      kenh #include <dev/pcmcia/pcmciadevs.h>
     64   1.9      kenh 
     65  1.12    bouyer #include <dev/ata/atavar.h>
     66   1.1      matt #include <dev/ic/wdcvar.h>
     67   1.1      matt 
     68   1.1      matt #define WDC_PCMCIA_REG_NPORTS      8
     69   1.9      kenh #define WDC_PCMCIA_AUXREG_OFFSET   (WDC_PCMCIA_REG_NPORTS + 6)
     70   1.2   mycroft #define WDC_PCMCIA_AUXREG_NPORTS   2
     71   1.1      matt 
     72   1.1      matt struct wdc_pcmcia_softc {
     73   1.1      matt 	struct wdc_softc sc_wdcdev;
     74  1.16  drochner 	struct channel_softc *wdc_chanptr;
     75  1.12    bouyer 	struct channel_softc wdc_channel;
     76   1.1      matt 	struct pcmcia_io_handle sc_pioh;
     77   1.1      matt 	struct pcmcia_io_handle sc_auxpioh;
     78   1.1      matt 	int sc_iowindow;
     79   1.1      matt 	int sc_auxiowindow;
     80   1.1      matt 	void *sc_ih;
     81  1.15   thorpej 	struct pcmcia_function *sc_pf;
     82  1.22     enami 	int sc_flags;
     83  1.22     enami #define	WDC_PCMCIA_ATTACH	0x0001
     84   1.1      matt };
     85   1.1      matt 
     86   1.1      matt static int wdc_pcmcia_match	__P((struct device *, struct cfdata *, void *));
     87   1.1      matt static void wdc_pcmcia_attach	__P((struct device *, struct device *, void *));
     88  1.21     enami static int wdc_pcmcia_detach	__P((struct device *, int));
     89   1.1      matt 
     90   1.1      matt struct cfattach wdc_pcmcia_ca = {
     91  1.21     enami 	sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach,
     92  1.21     enami 	wdc_pcmcia_detach, wdcactivate
     93   1.1      matt };
     94   1.1      matt 
     95   1.9      kenh struct wdc_pcmcia_product {
     96   1.9      kenh 	u_int32_t	wpp_vendor;	/* vendor ID */
     97   1.9      kenh 	u_int32_t	wpp_product;	/* product ID */
     98   1.9      kenh 	int		wpp_quirk_flag;	/* Quirk flags */
     99   1.9      kenh #define WDC_PCMCIA_FORCE_16BIT_IO	0x01 /* Don't use PCMCIA_WIDTH_AUTO */
    100   1.9      kenh #define WDC_PCMCIA_NO_EXTRA_RESETS	0x02 /* Only reset ctrl once */
    101   1.9      kenh 	const char	*wpp_cis_info[4];	/* XXX necessary? */
    102   1.9      kenh 	const char	*wpp_name;	/* product name */
    103   1.9      kenh } wdc_pcmcia_products[] = {
    104   1.9      kenh 
    105   1.9      kenh 	{ /* PCMCIA_VENDOR_DIGITAL XXX */ 0x0100,
    106   1.9      kenh 	  PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
    107   1.9      kenh 	  0, { NULL, "Digital Mobile Media CD-ROM", NULL, NULL },
    108   1.9      kenh 	  PCMCIA_STR_DIGITAL_MOBILE_MEDIA_CDROM },
    109  1.19       abs 
    110  1.19       abs 	{ PCMCIA_VENDOR_IBM,
    111  1.24     soren 	  PCMCIA_PRODUCT_IBM_PORTABLE_CDROM,
    112  1.19       abs 	  0, { NULL, "PCMCIA Portable CD-ROM Drive", NULL, NULL },
    113  1.24     soren 	  PCMCIA_STR_IBM_PORTABLE_CDROM },
    114   1.9      kenh 
    115   1.9      kenh 	{ PCMCIA_VENDOR_HAGIWARASYSCOM,
    116   1.9      kenh 	  -1,			/* XXX */
    117   1.9      kenh 	  WDC_PCMCIA_FORCE_16BIT_IO,
    118   1.9      kenh 	  { NULL, NULL, NULL, NULL },
    119  1.13     enami 	  "Hagiwara SYS-COM CompactFlash Card" },
    120   1.9      kenh 
    121   1.9      kenh 	/* The TEAC IDE/Card II is used on the Sony Vaio */
    122   1.9      kenh 	{ PCMCIA_VENDOR_TEAC,
    123   1.9      kenh 	  PCMCIA_PRODUCT_TEAC_IDECARDII,
    124   1.9      kenh 	  WDC_PCMCIA_NO_EXTRA_RESETS,
    125   1.9      kenh 	  PCMCIA_CIS_TEAC_IDECARDII,
    126   1.9      kenh 	  PCMCIA_STR_TEAC_IDECARDII },
    127  1.26  augustss 
    128  1.27     enami 	/*
    129  1.27     enami 	 * EXP IDE/ATAPI DVD Card use with some DVD players.
    130  1.27     enami 	 * Does not have a vendor ID or product ID.
    131  1.27     enami 	 */
    132  1.26  augustss 	{ -1,
    133  1.26  augustss 	  -1,
    134  1.26  augustss 	  0,
    135  1.26  augustss 	  PCMCIA_CIS_EXP_EXPMULTIMEDIA,
    136  1.26  augustss 	  PCMCIA_STR_EXP_EXPMULTIMEDIA },
    137  1.23  takemura 
    138  1.23  takemura 	/* Mobile Dock 2, which doesn't have vendor ID nor product ID */
    139  1.23  takemura 	{ -1, -1, 0,
    140  1.23  takemura 	  { "SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", NULL, NULL},
    141  1.23  takemura 	  "SHUTTLE TECHNOLOGY IDE/ATAPI Adapter"
    142  1.23  takemura 	},
    143   1.9      kenh 
    144   1.9      kenh 	{ 0, 0, 0, { NULL, NULL, NULL, NULL}, NULL }
    145   1.9      kenh };
    146   1.9      kenh 
    147  1.14     enami struct wdc_pcmcia_disk_device_interface_args {
    148  1.14     enami 	int ddi_type;		/* interface type */
    149  1.14     enami 	int ddi_reqfn;		/* function we are requesting iftype */
    150  1.14     enami 	int ddi_curfn;		/* function we are currently parsing in CIS */
    151  1.14     enami };
    152  1.14     enami 
    153  1.14     enami int	wdc_pcmcia_disk_device_interface_callback __P((struct pcmcia_tuple *,
    154  1.14     enami 	    void *));
    155  1.14     enami int	wdc_pcmcia_disk_device_interface __P((struct pcmcia_function *));
    156   1.9      kenh struct wdc_pcmcia_product *
    157   1.9      kenh 	wdc_pcmcia_lookup __P((struct pcmcia_attach_args *));
    158   1.9      kenh 
    159  1.15   thorpej int	wdc_pcmcia_enable __P((void *, int));
    160  1.15   thorpej 
    161  1.14     enami int
    162  1.14     enami wdc_pcmcia_disk_device_interface_callback(tuple, arg)
    163  1.14     enami 	struct pcmcia_tuple *tuple;
    164  1.14     enami 	void *arg;
    165  1.14     enami {
    166  1.14     enami 	struct wdc_pcmcia_disk_device_interface_args *ddi = arg;
    167  1.14     enami 
    168  1.14     enami 	switch (tuple->code) {
    169  1.14     enami 	case PCMCIA_CISTPL_FUNCID:
    170  1.14     enami 		ddi->ddi_curfn++;
    171  1.14     enami 		break;
    172  1.14     enami 
    173  1.14     enami 	case PCMCIA_CISTPL_FUNCE:
    174  1.14     enami 		if (ddi->ddi_reqfn != ddi->ddi_curfn)
    175  1.14     enami 			break;
    176  1.14     enami 
    177  1.14     enami 		/* subcode (disk device interface), data (interface type) */
    178  1.14     enami 		if (tuple->length < 2)
    179  1.14     enami 			break;
    180  1.14     enami 
    181  1.14     enami 		/* check type */
    182  1.14     enami 		if (pcmcia_tuple_read_1(tuple, 0) !=
    183  1.14     enami 		    PCMCIA_TPLFE_TYPE_DISK_DEVICE_INTERFACE)
    184  1.14     enami 			break;
    185  1.14     enami 
    186  1.14     enami 		ddi->ddi_type = pcmcia_tuple_read_1(tuple, 1);
    187  1.14     enami 		return (1);
    188  1.14     enami 	}
    189  1.14     enami 	return (0);
    190  1.14     enami }
    191  1.14     enami 
    192  1.14     enami int
    193  1.14     enami wdc_pcmcia_disk_device_interface(pf)
    194  1.14     enami 	struct pcmcia_function *pf;
    195  1.14     enami {
    196  1.14     enami 	struct wdc_pcmcia_disk_device_interface_args ddi;
    197  1.14     enami 
    198  1.14     enami 	ddi.ddi_reqfn = pf->number;
    199  1.14     enami 	ddi.ddi_curfn = -1;
    200  1.14     enami 	if (pcmcia_scan_cis((struct device *)pf->sc,
    201  1.14     enami 	    wdc_pcmcia_disk_device_interface_callback, &ddi) > 0)
    202  1.14     enami 		return (ddi.ddi_type);
    203  1.14     enami 	else
    204  1.14     enami 		return (-1);
    205  1.14     enami }
    206  1.14     enami 
    207   1.9      kenh struct wdc_pcmcia_product *
    208   1.9      kenh wdc_pcmcia_lookup(pa)
    209   1.9      kenh 	struct pcmcia_attach_args *pa;
    210   1.9      kenh {
    211   1.9      kenh 	struct wdc_pcmcia_product *wpp;
    212   1.9      kenh 	int i, cis_match;
    213   1.9      kenh 
    214   1.9      kenh 	for (wpp = wdc_pcmcia_products; wpp->wpp_name != NULL; wpp++)
    215   1.9      kenh 		if ((wpp->wpp_vendor == -1 ||
    216   1.9      kenh 		     pa->manufacturer == wpp->wpp_vendor) &&
    217   1.9      kenh 		    (wpp->wpp_product == -1 ||
    218   1.9      kenh 		     pa->product == wpp->wpp_product)) {
    219   1.9      kenh 			cis_match = 1;
    220   1.9      kenh 			for (i = 0; i < 4; i++) {
    221   1.9      kenh 				if (!(wpp->wpp_cis_info[i] == NULL ||
    222   1.9      kenh 				      (pa->card->cis1_info[i] != NULL &&
    223   1.9      kenh 				       strcmp(pa->card->cis1_info[i],
    224   1.9      kenh 					      wpp->wpp_cis_info[i]) == 0)))
    225   1.9      kenh 					cis_match = 0;
    226   1.9      kenh 			}
    227   1.9      kenh 			if (cis_match)
    228  1.13     enami 				return (wpp);
    229   1.9      kenh 		}
    230   1.9      kenh 
    231   1.9      kenh 	return (NULL);
    232   1.9      kenh }
    233   1.9      kenh 
    234   1.1      matt static int
    235   1.2   mycroft wdc_pcmcia_match(parent, match, aux)
    236   1.2   mycroft 	struct device *parent;
    237   1.2   mycroft 	struct cfdata *match;
    238   1.2   mycroft 	void *aux;
    239   1.1      matt {
    240   1.1      matt 	struct pcmcia_attach_args *pa = aux;
    241  1.14     enami 	struct pcmcia_softc *sc;
    242  1.14     enami 	int iftype;
    243   1.1      matt 
    244   1.9      kenh 	if (wdc_pcmcia_lookup(pa) != NULL)
    245   1.9      kenh 		return (1);
    246   1.3      matt 
    247  1.14     enami 	if (pa->pf->function == PCMCIA_FUNCTION_DISK) {
    248  1.14     enami 		sc = pa->pf->sc;
    249  1.14     enami 
    250  1.14     enami 		pcmcia_chip_socket_enable(sc->pct, sc->pch);
    251  1.14     enami 		iftype = wdc_pcmcia_disk_device_interface(pa->pf);
    252  1.14     enami 		pcmcia_chip_socket_disable(sc->pct, sc->pch);
    253  1.14     enami 
    254  1.14     enami 		if (iftype == PCMCIA_TPLFE_DDI_PCCARD_ATA)
    255  1.14     enami 			return (1);
    256  1.14     enami 	}
    257  1.14     enami 
    258   1.9      kenh 	return (0);
    259   1.1      matt }
    260   1.1      matt 
    261   1.1      matt static void
    262   1.2   mycroft wdc_pcmcia_attach(parent, self, aux)
    263   1.2   mycroft 	struct device *parent;
    264   1.2   mycroft 	struct device *self;
    265   1.2   mycroft 	void *aux;
    266   1.1      matt {
    267   1.1      matt 	struct wdc_pcmcia_softc *sc = (void *)self;
    268   1.1      matt 	struct pcmcia_attach_args *pa = aux;
    269   1.5     enami 	struct pcmcia_config_entry *cfe;
    270   1.9      kenh 	struct wdc_pcmcia_product *wpp;
    271  1.14     enami 	int quirks;
    272   1.1      matt 
    273  1.15   thorpej 	sc->sc_pf = pa->pf;
    274  1.15   thorpej 
    275   1.5     enami 	for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
    276   1.5     enami 	    cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    277   1.9      kenh 		if (cfe->num_iospace != 1 && cfe->num_iospace != 2)
    278   1.9      kenh 			continue;
    279   1.9      kenh 
    280   1.1      matt 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    281   1.9      kenh 		    cfe->iospace[0].length,
    282   1.9      kenh 		    cfe->iospace[0].start == 0 ? cfe->iospace[0].length : 0,
    283   1.9      kenh 		    &sc->sc_pioh))
    284   1.1      matt 			continue;
    285   1.9      kenh 
    286   1.9      kenh 		if (cfe->num_iospace == 2) {
    287   1.1      matt 			if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
    288   1.9      kenh 			    cfe->iospace[1].length, 0, &sc->sc_auxpioh))
    289   1.1      matt 				break;
    290   1.9      kenh 		} else /* num_iospace == 1 */ {
    291   1.1      matt 			sc->sc_auxpioh.iot = sc->sc_pioh.iot;
    292   1.9      kenh 			if (!bus_space_subregion(sc->sc_pioh.iot,
    293   1.9      kenh 			    sc->sc_pioh.ioh, WDC_PCMCIA_AUXREG_OFFSET,
    294   1.9      kenh 			    WDC_PCMCIA_AUXREG_NPORTS, &sc->sc_auxpioh.ioh))
    295   1.1      matt 				break;
    296   1.1      matt 		}
    297  1.11   thorpej 		pcmcia_io_free(pa->pf, &sc->sc_pioh);
    298   1.1      matt 	}
    299   1.1      matt 
    300   1.1      matt 	if (cfe == NULL) {
    301   1.6     enami 		printf(": can't handle card info\n");
    302   1.1      matt 		return;
    303   1.1      matt 	}
    304   1.1      matt 
    305   1.1      matt 	/* Enable the card. */
    306   1.1      matt 	pcmcia_function_init(pa->pf, cfe);
    307   1.1      matt 	if (pcmcia_function_enable(pa->pf)) {
    308   1.5     enami 		printf(": function enable failed\n");
    309   1.1      matt 		return;
    310   1.1      matt 	}
    311   1.1      matt 
    312   1.9      kenh 	/*
    313   1.9      kenh 	 * XXX  DEC Mobile Media CDROM is not yet tested whether it works
    314   1.9      kenh 	 * XXX  with PCMCIA_WIDTH_IO16.  HAGIWARA SYS-COM HPC-CF32 doesn't
    315   1.9      kenh 	 * XXX  work with PCMCIA_WIDTH_AUTO.
    316   1.9      kenh 	 * XXX  CANON FC-8M (SANDISK SDCFB 8M) works for both _AUTO and IO16.
    317   1.9      kenh 	 * XXX  So, here is temporary work around.
    318   1.9      kenh 	 */
    319   1.9      kenh 	wpp = wdc_pcmcia_lookup(pa);
    320  1.14     enami 	if (wpp != NULL)
    321  1.14     enami 		quirks = wpp->wpp_quirk_flag;
    322  1.14     enami 	else
    323  1.14     enami 		quirks = 0;
    324   1.9      kenh 
    325  1.14     enami 	if (pcmcia_io_map(pa->pf, quirks & WDC_PCMCIA_FORCE_16BIT_IO ?
    326  1.13     enami 	    PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_AUTO, 0,
    327  1.13     enami 	    sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowindow)) {
    328   1.5     enami 		printf(": can't map first I/O space\n");
    329   1.1      matt 		return;
    330   1.1      matt 	}
    331   1.9      kenh 
    332   1.9      kenh 	/*
    333   1.9      kenh 	 * Currently, # of iospace is 1 except DIGITAL Mobile Media CD-ROM.
    334   1.9      kenh 	 * So whether the work around like above is necessary or not
    335   1.9      kenh 	 * is unknown.  XXX.
    336   1.9      kenh 	 */
    337  1.25  sommerfe 	if (cfe->num_iospace <= 1)
    338  1.25  sommerfe 		sc->sc_auxiowindow = -1;
    339  1.25  sommerfe 	else if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
    340   1.9      kenh 	    sc->sc_auxpioh.size, &sc->sc_auxpioh, &sc->sc_auxiowindow)) {
    341  1.27     enami 		printf(": can't map second I/O space\n");
    342  1.27     enami 		return;
    343  1.25  sommerfe 	}
    344   1.5     enami 
    345  1.25  sommerfe 	if ((wpp != NULL) && (wpp->wpp_name != NULL))
    346  1.25  sommerfe 		printf(": %s", wpp->wpp_name);
    347  1.25  sommerfe 
    348   1.5     enami 	printf("\n");
    349   1.9      kenh 
    350  1.12    bouyer 	sc->wdc_channel.cmd_iot = sc->sc_pioh.iot;
    351  1.12    bouyer 	sc->wdc_channel.cmd_ioh = sc->sc_pioh.ioh;
    352  1.12    bouyer 	sc->wdc_channel.ctl_iot = sc->sc_auxpioh.iot;
    353  1.12    bouyer 	sc->wdc_channel.ctl_ioh = sc->sc_auxpioh.ioh;
    354  1.12    bouyer 	sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
    355  1.12    bouyer 	sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
    356  1.12    bouyer 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
    357  1.18    bouyer 	sc->sc_wdcdev.PIO_cap = 0;
    358  1.16  drochner 	sc->wdc_chanptr = &sc->wdc_channel;
    359  1.16  drochner 	sc->sc_wdcdev.channels = &sc->wdc_chanptr;
    360  1.12    bouyer 	sc->sc_wdcdev.nchannels = 1;
    361  1.12    bouyer 	sc->wdc_channel.channel = 0;
    362  1.12    bouyer 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
    363  1.12    bouyer 	sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
    364  1.12    bouyer 	    M_DEVBUF, M_NOWAIT);
    365  1.12    bouyer 	if (sc->wdc_channel.ch_queue == NULL) {
    366  1.20     enami 		printf("%s: can't allocate memory for command queue\n",
    367  1.13     enami 		    sc->sc_wdcdev.sc_dev.dv_xname);
    368  1.13     enami 		return;
    369  1.12    bouyer 	}
    370  1.14     enami 	if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
    371  1.12    bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
    372  1.15   thorpej 
    373  1.15   thorpej 	/* We can enable and disable the controller. */
    374  1.15   thorpej 	sc->sc_wdcdev.sc_atapi_adapter.scsipi_enable = wdc_pcmcia_enable;
    375  1.15   thorpej 
    376  1.22     enami 	sc->sc_flags |= WDC_PCMCIA_ATTACH;
    377  1.12    bouyer 	wdcattach(&sc->wdc_channel);
    378  1.22     enami 	sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
    379  1.21     enami }
    380  1.21     enami 
    381  1.21     enami int
    382  1.21     enami wdc_pcmcia_detach(self, flags)
    383  1.21     enami 	struct device *self;
    384  1.21     enami 	int flags;
    385  1.21     enami {
    386  1.21     enami 	struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
    387  1.21     enami 	int error;
    388  1.21     enami 
    389  1.21     enami 	if ((error = wdcdetach(self, flags)) != 0)
    390  1.21     enami 		return (error);
    391  1.21     enami 
    392  1.25  sommerfe 	if (sc->wdc_channel.ch_queue != NULL)
    393  1.25  sommerfe 		free(sc->wdc_channel.ch_queue, M_DEVBUF);
    394  1.21     enami 
    395  1.21     enami 	/* Unmap our i/o window and i/o space. */
    396  1.21     enami 	pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
    397  1.21     enami 	pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
    398  1.21     enami 	if (sc->sc_auxiowindow != -1) {
    399  1.21     enami 		pcmcia_io_unmap(sc->sc_pf, sc->sc_auxiowindow);
    400  1.21     enami 		pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
    401  1.21     enami 	}
    402  1.21     enami 
    403  1.21     enami 	return (0);
    404  1.15   thorpej }
    405  1.15   thorpej 
    406  1.15   thorpej int
    407  1.15   thorpej wdc_pcmcia_enable(arg, onoff)
    408  1.15   thorpej 	void *arg;
    409  1.15   thorpej 	int onoff;
    410  1.15   thorpej {
    411  1.15   thorpej 	struct wdc_pcmcia_softc *sc = arg;
    412  1.15   thorpej 
    413  1.15   thorpej 	if (onoff) {
    414  1.15   thorpej 		/* Establish the interrupt handler. */
    415  1.15   thorpej 		sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_BIO, wdcintr,
    416  1.15   thorpej 		    &sc->wdc_channel);
    417  1.15   thorpej 		if (sc->sc_ih == NULL) {
    418  1.15   thorpej 			printf("%s: couldn't establish interrupt handler\n",
    419  1.15   thorpej 			    sc->sc_wdcdev.sc_dev.dv_xname);
    420  1.15   thorpej 			return (EIO);
    421  1.15   thorpej 		}
    422  1.15   thorpej 
    423  1.27     enami 		/* See the comment in aic_pcmcia_enable */
    424  1.22     enami 		if ((sc->sc_flags & WDC_PCMCIA_ATTACH) == 0) {
    425  1.22     enami 			if (pcmcia_function_enable(sc->sc_pf)) {
    426  1.22     enami 				printf("%s: couldn't enable PCMCIA function\n",
    427  1.22     enami 				    sc->sc_wdcdev.sc_dev.dv_xname);
    428  1.22     enami 				pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    429  1.22     enami 				return (EIO);
    430  1.22     enami 			}
    431  1.22     enami 			wdcreset(&sc->wdc_channel, VERBOSE);
    432  1.15   thorpej 		}
    433  1.15   thorpej 	} else {
    434  1.15   thorpej 		pcmcia_function_disable(sc->sc_pf);
    435  1.15   thorpej 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    436  1.15   thorpej 	}
    437  1.15   thorpej 
    438  1.15   thorpej 	return (0);
    439   1.1      matt }
    440