Home | History | Annotate | Line # | Download | only in pcmcia
wdc_pcmcia.c revision 1.8
      1  1.8  mycroft /*	$NetBSD: wdc_pcmcia.c,v 1.8 1998/08/15 10:10:55 mycroft 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.1     matt #include <dev/pcmcia/pcmciavar.h>
     62  1.1     matt #include <dev/isa/isavar.h>
     63  1.1     matt #include <dev/ic/wdcvar.h>
     64  1.1     matt 
     65  1.1     matt #define WDC_PCMCIA_REG_NPORTS      8
     66  1.1     matt #define WDC_PCMCIA_AUXREG_OFFSET   0x206
     67  1.2  mycroft #define WDC_PCMCIA_AUXREG_NPORTS   2
     68  1.1     matt 
     69  1.1     matt struct wdc_pcmcia_softc {
     70  1.1     matt 	struct wdc_softc sc_wdcdev;
     71  1.1     matt 	struct wdc_attachment_data sc_ad;
     72  1.1     matt 	struct pcmcia_io_handle sc_pioh;
     73  1.1     matt 	struct pcmcia_io_handle sc_auxpioh;
     74  1.1     matt 	int sc_iowindow;
     75  1.1     matt 	int sc_auxiowindow;
     76  1.1     matt 	void *sc_ih;
     77  1.1     matt };
     78  1.1     matt 
     79  1.1     matt static int wdc_pcmcia_match	__P((struct device *, struct cfdata *, void *));
     80  1.1     matt static void wdc_pcmcia_attach	__P((struct device *, struct device *, void *));
     81  1.1     matt 
     82  1.1     matt struct cfattach wdc_pcmcia_ca = {
     83  1.1     matt 	sizeof(struct wdc_pcmcia_softc), wdc_pcmcia_match, wdc_pcmcia_attach
     84  1.1     matt };
     85  1.1     matt 
     86  1.1     matt static int
     87  1.2  mycroft wdc_pcmcia_match(parent, match, aux)
     88  1.2  mycroft 	struct device *parent;
     89  1.2  mycroft 	struct cfdata *match;
     90  1.2  mycroft 	void *aux;
     91  1.1     matt {
     92  1.1     matt 	struct pcmcia_attach_args *pa = aux;
     93  1.1     matt 
     94  1.3     matt 	if (pa->card->manufacturer == 0x100 && pa->card->product == 0xd00) {
     95  1.3     matt 		if (pa->card->cis1_info[1] != NULL &&
     96  1.3     matt 		    strcmp(pa->card->cis1_info[1], "Digital Mobile Media CD-ROM") == 0)
     97  1.3     matt 			return 1;
     98  1.3     matt 	}
     99  1.3     matt 
    100  1.1     matt 
    101  1.1     matt 	return 0;
    102  1.1     matt }
    103  1.1     matt 
    104  1.1     matt static void
    105  1.2  mycroft wdc_pcmcia_attach(parent, self, aux)
    106  1.2  mycroft 	struct device *parent;
    107  1.2  mycroft 	struct device *self;
    108  1.2  mycroft 	void *aux;
    109  1.1     matt {
    110  1.1     matt 	struct wdc_pcmcia_softc *sc = (void *)self;
    111  1.1     matt 	struct pcmcia_attach_args *pa = aux;
    112  1.5    enami 	struct pcmcia_config_entry *cfe;
    113  1.1     matt 
    114  1.5    enami 	for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
    115  1.5    enami 	    cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    116  1.1     matt 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    117  1.1     matt 		    cfe->iospace[0].length, 0, &sc->sc_pioh))
    118  1.1     matt 			continue;
    119  1.1     matt 		if (cfe->num_iospace > 1) {
    120  1.1     matt 			if (!pcmcia_io_alloc(pa->pf, cfe->iospace[1].start,
    121  1.1     matt 			    cfe->iospace[1].length, 0, &sc->sc_auxpioh)) {
    122  1.1     matt 				break;
    123  1.1     matt 			}
    124  1.1     matt 		} else {
    125  1.1     matt 			sc->sc_auxpioh.iot = sc->sc_pioh.iot;
    126  1.1     matt 			if (!bus_space_subregion(sc->sc_pioh.iot, sc->sc_pioh.ioh,
    127  1.1     matt 			    WDC_PCMCIA_REG_NPORTS,
    128  1.1     matt 			    cfe->iospace[0].length - WDC_PCMCIA_REG_NPORTS,
    129  1.1     matt 			    &sc->sc_auxpioh.ioh))
    130  1.1     matt 				break;
    131  1.1     matt 		}
    132  1.1     matt 		pcmcia_chip_io_free(pa->pf->sc->pct, pa->pf->sc->pch, &sc->sc_pioh);
    133  1.1     matt 	}
    134  1.1     matt 
    135  1.1     matt 	if (cfe == NULL) {
    136  1.6    enami 		printf(": can't handle card info\n");
    137  1.1     matt 		return;
    138  1.1     matt 	}
    139  1.1     matt 
    140  1.1     matt 	sc->sc_ad.iot = sc->sc_pioh.iot;
    141  1.1     matt 	sc->sc_ad.ioh = sc->sc_pioh.ioh;
    142  1.1     matt 	sc->sc_ad.auxiot = sc->sc_auxpioh.iot;
    143  1.1     matt 	sc->sc_ad.auxioh = sc->sc_auxpioh.ioh;
    144  1.1     matt 
    145  1.1     matt 	/* Enable the card. */
    146  1.1     matt 	pcmcia_function_init(pa->pf, cfe);
    147  1.1     matt 	if (pcmcia_function_enable(pa->pf)) {
    148  1.5    enami 		printf(": function enable failed\n");
    149  1.1     matt 		return;
    150  1.1     matt 	}
    151  1.1     matt 
    152  1.1     matt 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
    153  1.1     matt 			  sc->sc_pioh.size, &sc->sc_pioh,
    154  1.1     matt 			  &sc->sc_iowindow)) {
    155  1.5    enami 		printf(": can't map first I/O space\n");
    156  1.1     matt 		return;
    157  1.1     matt 	}
    158  1.1     matt 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
    159  1.1     matt 			  sc->sc_auxpioh.size, &sc->sc_auxpioh,
    160  1.1     matt 			  &sc->sc_auxiowindow)) {
    161  1.5    enami 		printf(": can't map second I/O space\n");
    162  1.1     matt 		return;
    163  1.1     matt 	}
    164  1.5    enami 
    165  1.5    enami 	printf("\n");
    166  1.1     matt 
    167  1.1     matt 	sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, wdcintr, sc);
    168  1.1     matt 	if (sc->sc_ih == NULL) {
    169  1.1     matt 		printf("%s: couldn't establish interrupt\n", self->dv_xname);
    170  1.1     matt 		return;
    171  1.1     matt 	}
    172  1.2  mycroft 
    173  1.1     matt 	wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
    174  1.1     matt }
    175