Home | History | Annotate | Line # | Download | only in pcmcia
wdc_pcmcia.c revision 1.1
      1  1.1  matt /*	$NetBSD: wdc_pcmcia.c,v 1.1 1998/01/19 19:49:03 matt Exp $ */
      2  1.1  matt 
      3  1.1  matt /*
      4  1.1  matt  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
      5  1.1  matt  *
      6  1.1  matt  * DMA and multi-sector PIO handling are derived from code contributed by
      7  1.1  matt  * Onno van der Linden.
      8  1.1  matt  *
      9  1.1  matt  * Atapi support added by Manuel Bouyer.
     10  1.1  matt  *
     11  1.1  matt  * Redistribution and use in source and binary forms, with or without
     12  1.1  matt  * modification, are permitted provided that the following conditions
     13  1.1  matt  * are met:
     14  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     15  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     16  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  matt  *    documentation and/or other materials provided with the distribution.
     19  1.1  matt  * 3. All advertising materials mentioning features or use of this software
     20  1.1  matt  *    must display the following acknowledgement:
     21  1.1  matt  *	This product includes software developed by Charles M. Hannum.
     22  1.1  matt  * 4. The name of the author may not be used to endorse or promote products
     23  1.1  matt  *    derived from this software without specific prior written permission.
     24  1.1  matt  *
     25  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     26  1.1  matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     27  1.1  matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  1.1  matt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     29  1.1  matt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     30  1.1  matt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     31  1.1  matt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     32  1.1  matt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     33  1.1  matt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     34  1.1  matt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  1.1  matt  */
     36  1.1  matt 
     37  1.1  matt #undef ATAPI_DEBUG_WDC
     38  1.1  matt #define WDDEBUG
     39  1.1  matt 
     40  1.1  matt #include <sys/param.h>
     41  1.1  matt #include <sys/systm.h>
     42  1.1  matt #include <sys/kernel.h>
     43  1.1  matt #include <sys/conf.h>
     44  1.1  matt #include <sys/file.h>
     45  1.1  matt #include <sys/stat.h>
     46  1.1  matt #include <sys/ioctl.h>
     47  1.1  matt #include <sys/buf.h>
     48  1.1  matt #include <sys/uio.h>
     49  1.1  matt #include <sys/malloc.h>
     50  1.1  matt #include <sys/device.h>
     51  1.1  matt #include <sys/disklabel.h>
     52  1.1  matt #include <sys/disk.h>
     53  1.1  matt #include <sys/syslog.h>
     54  1.1  matt #include <sys/proc.h>
     55  1.1  matt 
     56  1.1  matt #include <vm/vm.h>
     57  1.1  matt 
     58  1.1  matt #include <machine/cpu.h>
     59  1.1  matt #include <machine/intr.h>
     60  1.1  matt #include <machine/bus.h>
     61  1.1  matt 
     62  1.1  matt #include <dev/pcmcia/pcmciavar.h>
     63  1.1  matt #include <dev/isa/isavar.h>
     64  1.1  matt #include <dev/ic/wdcvar.h>
     65  1.1  matt 
     66  1.1  matt #define WDC_PCMCIA_REG_NPORTS      8
     67  1.1  matt #define WDC_PCMCIA_AUXREG_OFFSET   0x206
     68  1.1  matt #define WDC_PCMCIA_AUXREG_NPORTS   1
     69  1.1  matt 
     70  1.1  matt struct wdc_pcmcia_softc {
     71  1.1  matt 	struct wdc_softc sc_wdcdev;
     72  1.1  matt 	struct wdc_attachment_data sc_ad;
     73  1.1  matt 	struct pcmcia_io_handle sc_pioh;
     74  1.1  matt 	struct pcmcia_io_handle sc_auxpioh;
     75  1.1  matt 	int sc_iowindow;
     76  1.1  matt 	int sc_auxiowindow;
     77  1.1  matt 	void *sc_ih;
     78  1.1  matt };
     79  1.1  matt 
     80  1.1  matt #ifdef __BROKEN_INDIRECT_CONFIG
     81  1.1  matt static int wdc_pcmcia_match	__P((struct device *, void *, void *));
     82  1.1  matt #else
     83  1.1  matt static int wdc_pcmcia_match	__P((struct device *, struct cfdata *, void *));
     84  1.1  matt #endif
     85  1.1  matt static void wdc_pcmcia_attach	__P((struct device *, struct device *, void *));
     86  1.1  matt 
     87  1.1  matt struct cfattach wdc_pcmcia_ca = {
     88  1.1  matt 	sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach
     89  1.1  matt };
     90  1.1  matt 
     91  1.1  matt static int
     92  1.1  matt wdc_pcmcia_match(
     93  1.1  matt 	struct device *parent,
     94  1.1  matt #ifdef __BROKEN_INDIRECT_CONFIG
     95  1.1  matt 	void *match,
     96  1.1  matt #else
     97  1.1  matt 	struct cfdata *match,
     98  1.1  matt #endif
     99  1.1  matt 	void *aux)
    100  1.1  matt {
    101  1.1  matt 	struct pcmcia_attach_args *pa = aux;
    102  1.1  matt 
    103  1.1  matt 	if (pa->card->cis1_info[0] != NULL &&
    104  1.1  matt 	    strcmp(pa->card->cis1_info[0], "Digital Equipment Corporation.") == 0 &&
    105  1.1  matt 	    pa->card->cis1_info[1] != NULL &&
    106  1.1  matt 	    strcmp(pa->card->cis1_info[1], "Digital Mobile Media CD-ROM") == 0)
    107  1.1  matt 		return 1;
    108  1.1  matt 
    109  1.1  matt 	return 0;
    110  1.1  matt }
    111  1.1  matt 
    112  1.1  matt static void
    113  1.1  matt wdc_pcmcia_attach(
    114  1.1  matt 	struct device *parent,
    115  1.1  matt 	struct device *self,
    116  1.1  matt 	void *aux)
    117  1.1  matt {
    118  1.1  matt 	struct wdc_pcmcia_softc *sc = (void *)self;
    119  1.1  matt 	struct pcmcia_attach_args *pa = aux;
    120  1.1  matt 	struct pcmcia_config_entry *cfe = pa->pf->cfe_head.sqh_first;
    121  1.1  matt 
    122  1.1  matt 	bzero(&sc->sc_ad, sizeof(sc->sc_ad));
    123  1.1  matt 
    124  1.1  matt 	for (; cfe != NULL; cfe = cfe->cfe_list.sqe_next) {
    125  1.1  matt 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    126  1.1  matt 		    cfe->iospace[0].length, 0, &sc->sc_pioh))
    127  1.1  matt 			continue;
    128  1.1  matt 		if (cfe->num_iospace > 1) {
    129  1.1  matt 			if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
    130  1.1  matt 			    cfe->iospace[1].length, 0, &sc->sc_auxpioh)) {
    131  1.1  matt 				break;
    132  1.1  matt 			}
    133  1.1  matt 		} else {
    134  1.1  matt 			sc->sc_auxpioh.iot = sc->sc_pioh.iot;
    135  1.1  matt 			if (!bus_space_subregion(sc->sc_pioh.iot, sc->sc_pioh.ioh,
    136  1.1  matt 			    WDC_PCMCIA_REG_NPORTS,
    137  1.1  matt 			    cfe->iospace[0].length - WDC_PCMCIA_REG_NPORTS,
    138  1.1  matt 			    &sc->sc_auxpioh.ioh))
    139  1.1  matt 				break;
    140  1.1  matt 		}
    141  1.1  matt 		pcmcia_chip_io_free(pa->pf->sc->pct, pa->pf->sc->pch, &sc->sc_pioh);
    142  1.1  matt 	}
    143  1.1  matt 
    144  1.1  matt 	if (cfe == NULL) {
    145  1.1  matt 		printf(": can't handle card info\n");
    146  1.1  matt 		return;
    147  1.1  matt 	}
    148  1.1  matt 
    149  1.1  matt 	sc->sc_ad.iot = sc->sc_pioh.iot;
    150  1.1  matt 	sc->sc_ad.ioh = sc->sc_pioh.ioh;
    151  1.1  matt 	sc->sc_ad.auxiot = sc->sc_auxpioh.iot;
    152  1.1  matt 	sc->sc_ad.auxioh = sc->sc_auxpioh.ioh;
    153  1.1  matt 
    154  1.1  matt 	/* Enable the card. */
    155  1.1  matt 	pcmcia_function_init(pa->pf, cfe);
    156  1.1  matt 	if (pcmcia_function_enable(pa->pf)) {
    157  1.1  matt 		printf(": function enable failed\n");
    158  1.1  matt 		return;
    159  1.1  matt 	}
    160  1.1  matt 
    161  1.1  matt 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
    162  1.1  matt 			  sc->sc_pioh.size, &sc->sc_pioh,
    163  1.1  matt 			  &sc->sc_iowindow)) {
    164  1.1  matt 		printf(": can't map first I/O space\n");
    165  1.1  matt 		return;
    166  1.1  matt 	}
    167  1.1  matt 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
    168  1.1  matt 			  sc->sc_auxpioh.size, &sc->sc_auxpioh,
    169  1.1  matt 			  &sc->sc_auxiowindow)) {
    170  1.1  matt 		printf(": can't map second I/O space\n");
    171  1.1  matt 		return;
    172  1.1  matt 	}
    173  1.1  matt 
    174  1.1  matt 	printf("\n");
    175  1.1  matt 	sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, wdcintr, sc);
    176  1.1  matt 	if (sc->sc_ih == NULL) {
    177  1.1  matt 		printf("%s: couldn't establish interrupt\n", self->dv_xname);
    178  1.1  matt 		return;
    179  1.1  matt 	}
    180  1.1  matt 	wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
    181  1.1  matt }
    182