Home | History | Annotate | Line # | Download | only in pcmcia
fdc_pcmcia.c revision 1.2
      1  1.2  christos /*	$NetBSD: fdc_pcmcia.c,v 1.2 1998/07/19 17:28:16 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1998 Christos Zoulas.  All rights reserved.
      5  1.1  christos  *
      6  1.1  christos  * Redistribution and use in source and binary forms, with or without
      7  1.1  christos  * modification, are permitted provided that the following conditions
      8  1.1  christos  * are met:
      9  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  christos  *    documentation and/or other materials provided with the distribution.
     14  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     15  1.1  christos  *    must display the following acknowledgement:
     16  1.1  christos  *	This product includes software developed by Christos Zoulas.
     17  1.1  christos  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  christos  *    derived from this software without specific prior written permission.
     19  1.1  christos  *
     20  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  christos  */
     31  1.1  christos 
     32  1.1  christos #include <sys/param.h>
     33  1.1  christos #include <sys/systm.h>
     34  1.1  christos #include <sys/conf.h>
     35  1.1  christos #include <sys/device.h>
     36  1.2  christos #include <sys/disk.h>
     37  1.2  christos #include <sys/buf.h>
     38  1.1  christos 
     39  1.1  christos #include <machine/bus.h>
     40  1.1  christos #include <machine/conf.h>
     41  1.1  christos #include <machine/intr.h>
     42  1.1  christos 
     43  1.1  christos #include <dev/pcmcia/pcmciareg.h>
     44  1.1  christos #include <dev/pcmcia/pcmciavar.h>
     45  1.2  christos #include <dev/pcmcia/pcmciadevs.h>
     46  1.1  christos 
     47  1.2  christos #include <dev/ic/fdcreg.h>
     48  1.2  christos #include <dev/ic/fdcvar.h>
     49  1.1  christos 
     50  1.1  christos struct fdc_pcmcia_softc {
     51  1.1  christos 	struct fdc_softc sc_fdc;		/* real "fdc" softc */
     52  1.1  christos 
     53  1.1  christos 	/* PCMCIA-specific goo. */
     54  1.1  christos 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     55  1.1  christos 	int sc_io_window;			/* our i/o window */
     56  1.1  christos 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     57  1.1  christos };
     58  1.1  christos 
     59  1.1  christos int fdc_pcmcia_probe __P((struct device *, struct cfdata *, void *));
     60  1.1  christos void fdc_pcmcia_attach __P((struct device *, struct device *, void *));
     61  1.1  christos static void fdc_conf __P((struct fdc_softc *));
     62  1.1  christos 
     63  1.1  christos struct cfattach fdc_pcmcia_ca = {
     64  1.1  christos 	sizeof(struct fdc_pcmcia_softc), fdc_pcmcia_probe, fdc_pcmcia_attach
     65  1.1  christos };
     66  1.1  christos 
     67  1.1  christos static void
     68  1.1  christos fdc_conf(fdc)
     69  1.1  christos 	struct fdc_softc *fdc;
     70  1.1  christos {
     71  1.1  christos 	bus_space_tag_t iot = fdc->sc_iot;
     72  1.1  christos 	bus_space_handle_t ioh = fdc->sc_ioh;
     73  1.1  christos 	int n;
     74  1.1  christos 
     75  1.1  christos 	/* Figure out what we have */
     76  1.1  christos 	if (out_fdc_cmd(iot, ioh, FDC_CMD_VERSION) == -1 ||
     77  1.1  christos 	    (n = fdcresult(fdc, 1)) != 1)
     78  1.1  christos 		return;
     79  1.1  christos 
     80  1.1  christos 	/* Nec765 or equivalent */
     81  1.1  christos 	if (FDC_ST0(fdc->sc_status[0]) == FDC_ST0_INVL)
     82  1.1  christos 		return;
     83  1.1  christos 
     84  1.1  christos #if 0
     85  1.1  christos 	/* ns8477 check */
     86  1.1  christos 	if (out_fdc_cmd(iot, ioh, FDC_CMD_NSC) == -1 ||
     87  1.1  christos 	    (n = fdcresult(fdc, 1)) != 1) {
     88  1.1  christos 		printf("NSC command failed\n");
     89  1.1  christos 		return;
     90  1.1  christos 	}
     91  1.1  christos 	else
     92  1.1  christos 		printf("Version %x\n", fdc->sc_status[0]);
     93  1.1  christos #endif
     94  1.1  christos 
     95  1.1  christos 	if (out_fdc_cmd(iot, ioh, FDC_CMD_DUMPREG) == -1 ||
     96  1.1  christos 	    (n = fdcresult(fdc, -1)) == -1)
     97  1.1  christos 		return;
     98  1.1  christos 
     99  1.1  christos 	/*
    100  1.1  christos          * Expect 10 bytes of status; one means that it did not
    101  1.1  christos 	 * understand the command
    102  1.1  christos 	 */
    103  1.1  christos 	if (n == 1)
    104  1.1  christos 		return;
    105  1.1  christos 
    106  1.1  christos 	/*
    107  1.1  christos 	 * Configure controller to use FIFO and 8 bytes of FIFO threshold
    108  1.1  christos 	 */
    109  1.1  christos 	(void)out_fdc_cmd(iot, ioh, FDC_CMD_CONFIGURE);
    110  1.1  christos 	(void)out_fdc(iot, ioh, 0x00);	/* doc says 0 */
    111  1.1  christos 	(void)out_fdc(iot, ioh, 8);	/* FIFO is active low. */
    112  1.1  christos 	(void)out_fdc(iot, ioh, fdc->sc_status[9]); /* same comp */
    113  1.1  christos 	/* No result phase */
    114  1.1  christos 
    115  1.1  christos 	/* Lock this configuration */
    116  1.1  christos 	if (out_fdc_cmd(iot, ioh, FDC_CMD_LOCK(FDC_CMD_FLAGS_LOCK)) == -1 ||
    117  1.1  christos 	    fdcresult(fdc, 1) != 1)
    118  1.1  christos 		return;
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos int
    122  1.1  christos fdc_pcmcia_probe(parent, match, aux)
    123  1.1  christos 	struct device *parent;
    124  1.1  christos 	struct cfdata *match;
    125  1.1  christos 	void *aux;
    126  1.1  christos {
    127  1.1  christos 	struct pcmcia_attach_args *pa = aux;
    128  1.1  christos 	struct pcmcia_card *card = pa->card;
    129  1.2  christos 	char *cis[4] = PCMCIA_CIS_YEDATA_EXTERNAL_FDD;
    130  1.1  christos 
    131  1.1  christos 	/* For this card the manufacturer and product are -1 */
    132  1.2  christos 	if (strcmp(cis[0], card->cis1_info[0]) == 0 &&
    133  1.2  christos 	    strcmp(cis[1], card->cis1_info[1]) == 0)
    134  1.1  christos 		return 1;
    135  1.1  christos 
    136  1.1  christos 	return 0;
    137  1.1  christos }
    138  1.1  christos 
    139  1.1  christos 
    140  1.1  christos void
    141  1.1  christos fdc_pcmcia_attach(parent, self, aux)
    142  1.1  christos 	struct device *parent, *self;
    143  1.1  christos 	void *aux;
    144  1.1  christos {
    145  1.1  christos 	struct fdc_pcmcia_softc *psc = (void *)self;
    146  1.1  christos 	struct fdc_softc *fdc = &psc->sc_fdc;
    147  1.1  christos 	struct pcmcia_attach_args *pa = aux;
    148  1.1  christos 	struct pcmcia_config_entry *cfe;
    149  1.1  christos 	struct pcmcia_function *pf = pa->pf;
    150  1.1  christos 	struct fdc_attach_args fa;
    151  1.1  christos 
    152  1.1  christos 	psc->sc_pf = pf;
    153  1.1  christos 
    154  1.1  christos 	for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
    155  1.1  christos 	    cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    156  1.1  christos 		if (cfe->num_memspace != 0 ||
    157  1.1  christos 		    cfe->num_iospace != 1)
    158  1.1  christos 			continue;
    159  1.1  christos 
    160  1.1  christos 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    161  1.1  christos 		    cfe->iospace[0].length, cfe->iospace[0].length,
    162  1.1  christos 		    &psc->sc_pcioh) == 0)
    163  1.1  christos 			break;
    164  1.1  christos 	}
    165  1.1  christos 
    166  1.1  christos 	if (cfe == 0) {
    167  1.1  christos 		printf(": can't alloc i/o space\n");
    168  1.1  christos 		return;
    169  1.1  christos 	}
    170  1.1  christos 
    171  1.1  christos 	/* Enable the card. */
    172  1.1  christos 	pcmcia_function_init(pf, cfe);
    173  1.1  christos 	if (pcmcia_function_enable(pf)) {
    174  1.1  christos 		printf(": function enable failed\n");
    175  1.1  christos 		return;
    176  1.1  christos 	}
    177  1.1  christos 
    178  1.1  christos 	/* Map in the io space */
    179  1.1  christos 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
    180  1.1  christos 	    &psc->sc_pcioh, &psc->sc_io_window)) {
    181  1.1  christos 		printf(": can't map i/o space\n");
    182  1.1  christos 		return;
    183  1.1  christos 	}
    184  1.1  christos 
    185  1.1  christos 	fdc->sc_iot = psc->sc_pcioh.iot;
    186  1.1  christos 	fdc->sc_ioh = psc->sc_pcioh.ioh;
    187  1.2  christos 
    188  1.1  christos 	fdc->sc_flags = 0;
    189  1.1  christos 	fdc->sc_state = DEVIDLE;
    190  1.1  christos 	TAILQ_INIT(&fdc->sc_drives);
    191  1.1  christos 
    192  1.1  christos 	if (!fdcfind(fdc->sc_iot, fdc->sc_ioh, 1))
    193  1.1  christos 		printf(": coundn't find fdc\n%s", fdc->sc_dev.dv_xname);
    194  1.1  christos 
    195  1.2  christos 	printf(": %s\n", PCMCIA_STR_YEDATA_EXTERNAL_FDD);
    196  1.1  christos 
    197  1.1  christos 	fdc_conf(fdc);
    198  1.1  christos 
    199  1.1  christos 	/* Establish the interrupt handler. */
    200  1.1  christos 	fdc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, fdchwintr, fdc);
    201  1.1  christos 	if (fdc->sc_ih == NULL)
    202  1.1  christos 		printf("%s: couldn't establish interrupt\n",
    203  1.1  christos 		    fdc->sc_dev.dv_xname);
    204  1.1  christos 
    205  1.1  christos 	/* physical limit: four drives per controller. */
    206  1.1  christos 	for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
    207  1.1  christos 		if (fa.fa_drive < 2)
    208  1.1  christos 			fa.fa_deftype = &fd_types[0];
    209  1.1  christos 		else
    210  1.1  christos 			fa.fa_deftype = NULL;		/* unknown */
    211  1.1  christos 		(void)config_found(self, (void *)&fa, fdprint);
    212  1.1  christos 	}
    213  1.1  christos }
    214