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