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