Home | History | Annotate | Line # | Download | only in pcmcia
esp_pcmcia.c revision 1.9
      1  1.9   bouyer /*	$NetBSD: esp_pcmcia.c,v 1.9 2001/04/25 17:53:37 bouyer Exp $	*/
      2  1.1  mycroft 
      3  1.1  mycroft /*-
      4  1.1  mycroft  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.1  mycroft  * All rights reserved.
      6  1.1  mycroft  *
      7  1.1  mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  mycroft  * by Charles M. Hannum.
      9  1.1  mycroft  *
     10  1.1  mycroft  * Redistribution and use in source and binary forms, with or without
     11  1.1  mycroft  * modification, are permitted provided that the following conditions
     12  1.1  mycroft  * are met:
     13  1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     14  1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     15  1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     18  1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     19  1.1  mycroft  *    must display the following acknowledgement:
     20  1.1  mycroft  *        This product includes software developed by the NetBSD
     21  1.1  mycroft  *        Foundation, Inc. and its contributors.
     22  1.1  mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  mycroft  *    contributors may be used to endorse or promote products derived
     24  1.1  mycroft  *    from this software without specific prior written permission.
     25  1.1  mycroft  *
     26  1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  mycroft  */
     38  1.1  mycroft 
     39  1.1  mycroft #include <sys/param.h>
     40  1.1  mycroft #include <sys/systm.h>
     41  1.1  mycroft #include <sys/device.h>
     42  1.1  mycroft #include <sys/buf.h>
     43  1.1  mycroft 
     44  1.1  mycroft #include <machine/bus.h>
     45  1.1  mycroft #include <machine/intr.h>
     46  1.1  mycroft 
     47  1.1  mycroft #include <dev/scsipi/scsi_all.h>
     48  1.1  mycroft #include <dev/scsipi/scsipi_all.h>
     49  1.1  mycroft #include <dev/scsipi/scsiconf.h>
     50  1.1  mycroft 
     51  1.1  mycroft #include <dev/pcmcia/pcmciareg.h>
     52  1.1  mycroft #include <dev/pcmcia/pcmciavar.h>
     53  1.1  mycroft #include <dev/pcmcia/pcmciadevs.h>
     54  1.1  mycroft 
     55  1.1  mycroft #include <dev/ic/ncr53c9xreg.h>
     56  1.1  mycroft #include <dev/ic/ncr53c9xvar.h>
     57  1.1  mycroft 
     58  1.1  mycroft struct esp_pcmcia_softc {
     59  1.1  mycroft 	struct ncr53c9x_softc	sc_ncr53c9x;	/* glue to MI code */
     60  1.1  mycroft 
     61  1.1  mycroft 	int		sc_active;		/* Pseudo-DMA state vars */
     62  1.1  mycroft 	int		sc_tc;
     63  1.1  mycroft 	int		sc_datain;
     64  1.1  mycroft 	size_t		sc_dmasize;
     65  1.1  mycroft 	size_t		sc_dmatrans;
     66  1.1  mycroft 	char		**sc_dmaaddr;
     67  1.1  mycroft 	size_t		*sc_pdmalen;
     68  1.1  mycroft 
     69  1.1  mycroft 	/* PCMCIA-specific goo. */
     70  1.1  mycroft 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     71  1.1  mycroft 	int sc_io_window;			/* our i/o window */
     72  1.1  mycroft 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     73  1.1  mycroft 	void *sc_ih;				/* interrupt handler */
     74  1.5  thorpej #ifdef ESP_PCMCIA_POLL
     75  1.5  thorpej 	struct callout sc_poll_ch;
     76  1.5  thorpej #endif
     77  1.1  mycroft 	int sc_flags;
     78  1.1  mycroft #define	ESP_PCMCIA_ATTACHED	1		/* attach completed */
     79  1.1  mycroft #define ESP_PCMCIA_ATTACHING	2		/* attach in progress */
     80  1.1  mycroft };
     81  1.1  mycroft 
     82  1.1  mycroft int	esp_pcmcia_match __P((struct device *, struct cfdata *, void *));
     83  1.1  mycroft void	esp_pcmcia_attach __P((struct device *, struct device *, void *));
     84  1.1  mycroft void	esp_pcmcia_init __P((struct esp_pcmcia_softc *));
     85  1.1  mycroft int	esp_pcmcia_detach __P((struct device *, int));
     86  1.1  mycroft int	esp_pcmcia_enable __P((void *, int));
     87  1.1  mycroft 
     88  1.1  mycroft struct cfattach esp_pcmcia_ca = {
     89  1.1  mycroft 	sizeof(struct esp_pcmcia_softc), esp_pcmcia_match, esp_pcmcia_attach,
     90  1.1  mycroft 	esp_pcmcia_detach
     91  1.1  mycroft };
     92  1.1  mycroft 
     93  1.1  mycroft /*
     94  1.1  mycroft  * Functions and the switch for the MI code.
     95  1.1  mycroft  */
     96  1.1  mycroft #ifdef ESP_PCMCIA_POLL
     97  1.1  mycroft void	esp_pcmcia_poll __P((void *));
     98  1.1  mycroft #endif
     99  1.1  mycroft u_char	esp_pcmcia_read_reg __P((struct ncr53c9x_softc *, int));
    100  1.1  mycroft void	esp_pcmcia_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    101  1.1  mycroft int	esp_pcmcia_dma_isintr __P((struct ncr53c9x_softc *));
    102  1.1  mycroft void	esp_pcmcia_dma_reset __P((struct ncr53c9x_softc *));
    103  1.1  mycroft int	esp_pcmcia_dma_intr __P((struct ncr53c9x_softc *));
    104  1.1  mycroft int	esp_pcmcia_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    105  1.1  mycroft 	    size_t *, int, size_t *));
    106  1.1  mycroft void	esp_pcmcia_dma_go __P((struct ncr53c9x_softc *));
    107  1.1  mycroft void	esp_pcmcia_dma_stop __P((struct ncr53c9x_softc *));
    108  1.1  mycroft int	esp_pcmcia_dma_isactive __P((struct ncr53c9x_softc *));
    109  1.1  mycroft 
    110  1.1  mycroft struct ncr53c9x_glue esp_pcmcia_glue = {
    111  1.1  mycroft 	esp_pcmcia_read_reg,
    112  1.1  mycroft 	esp_pcmcia_write_reg,
    113  1.1  mycroft 	esp_pcmcia_dma_isintr,
    114  1.1  mycroft 	esp_pcmcia_dma_reset,
    115  1.1  mycroft 	esp_pcmcia_dma_intr,
    116  1.1  mycroft 	esp_pcmcia_dma_setup,
    117  1.1  mycroft 	esp_pcmcia_dma_go,
    118  1.1  mycroft 	esp_pcmcia_dma_stop,
    119  1.1  mycroft 	esp_pcmcia_dma_isactive,
    120  1.1  mycroft 	NULL,			/* gl_clear_latched_intr */
    121  1.1  mycroft };
    122  1.1  mycroft 
    123  1.1  mycroft const struct pcmcia_product esp_pcmcia_products[] = {
    124  1.1  mycroft 	{ PCMCIA_STR_PANASONIC_KXLC002,		PCMCIA_VENDOR_PANASONIC,
    125  1.1  mycroft 	  PCMCIA_PRODUCT_PANASONIC_KXLC002,	0 },
    126  1.1  mycroft 
    127  1.1  mycroft 	{ NULL }
    128  1.1  mycroft };
    129  1.1  mycroft 
    130  1.1  mycroft int
    131  1.1  mycroft esp_pcmcia_match(parent, match, aux)
    132  1.1  mycroft 	struct device *parent;
    133  1.1  mycroft 	struct cfdata *match;
    134  1.1  mycroft 	void *aux;
    135  1.1  mycroft {
    136  1.1  mycroft 	struct pcmcia_attach_args *pa = aux;
    137  1.1  mycroft 
    138  1.1  mycroft 	if (pcmcia_product_lookup(pa, esp_pcmcia_products,
    139  1.1  mycroft 	    sizeof esp_pcmcia_products[0], NULL) != NULL)
    140  1.1  mycroft 		return (1);
    141  1.1  mycroft 	return (0);
    142  1.1  mycroft }
    143  1.1  mycroft 
    144  1.1  mycroft void
    145  1.1  mycroft esp_pcmcia_attach(parent, self, aux)
    146  1.1  mycroft 	struct device *parent, *self;
    147  1.1  mycroft 	void *aux;
    148  1.1  mycroft {
    149  1.1  mycroft 	struct esp_pcmcia_softc *esc = (void *)self;
    150  1.1  mycroft 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    151  1.1  mycroft 	struct pcmcia_attach_args *pa = aux;
    152  1.1  mycroft 	struct pcmcia_config_entry *cfe;
    153  1.1  mycroft 	struct pcmcia_function *pf = pa->pf;
    154  1.1  mycroft 	const struct pcmcia_product *pp;
    155  1.1  mycroft 
    156  1.1  mycroft 	esc->sc_pf = pf;
    157  1.1  mycroft 
    158  1.1  mycroft 	for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
    159  1.1  mycroft 	    cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    160  1.1  mycroft 		if (cfe->num_memspace != 0 ||
    161  1.1  mycroft 		    cfe->num_iospace != 1)
    162  1.1  mycroft 			continue;
    163  1.1  mycroft 
    164  1.1  mycroft 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    165  1.1  mycroft 		    cfe->iospace[0].length, 0, &esc->sc_pcioh) == 0)
    166  1.1  mycroft 			break;
    167  1.1  mycroft 	}
    168  1.1  mycroft 
    169  1.1  mycroft 	if (cfe == 0) {
    170  1.1  mycroft 		printf(": can't alloc i/o space\n");
    171  1.1  mycroft 		goto no_config_entry;
    172  1.1  mycroft 	}
    173  1.1  mycroft 
    174  1.1  mycroft 	/* Enable the card. */
    175  1.1  mycroft 	pcmcia_function_init(pf, cfe);
    176  1.1  mycroft 	if (pcmcia_function_enable(pf)) {
    177  1.1  mycroft 		printf(": function enable failed\n");
    178  1.1  mycroft 		goto enable_failed;
    179  1.1  mycroft 	}
    180  1.1  mycroft 
    181  1.1  mycroft 	/* Map in the I/O space */
    182  1.1  mycroft 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, esc->sc_pcioh.size,
    183  1.1  mycroft 	    &esc->sc_pcioh, &esc->sc_io_window)) {
    184  1.1  mycroft 		printf(": can't map i/o space\n");
    185  1.1  mycroft 		goto iomap_failed;
    186  1.1  mycroft 	}
    187  1.1  mycroft 
    188  1.1  mycroft 	pp = pcmcia_product_lookup(pa, esp_pcmcia_products,
    189  1.1  mycroft 	    sizeof esp_pcmcia_products[0], NULL);
    190  1.1  mycroft 	if (pp == NULL) {
    191  1.1  mycroft 		printf("\n");
    192  1.1  mycroft 		panic("esp_pcmcia_attach: impossible");
    193  1.1  mycroft 	}
    194  1.1  mycroft 
    195  1.1  mycroft 	printf(": %s\n", pp->pp_name);
    196  1.1  mycroft 
    197  1.1  mycroft 	esp_pcmcia_init(esc);
    198  1.1  mycroft 
    199  1.1  mycroft 	/*
    200  1.1  mycroft 	 *  Initialize nca board itself.
    201  1.1  mycroft 	 */
    202  1.1  mycroft 	esc->sc_flags |= ESP_PCMCIA_ATTACHING;
    203  1.9   bouyer 	sc->sc_adapter.adapt_minphys = minphys;
    204  1.9   bouyer 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    205  1.9   bouyer 	ncr53c9x_attach(sc);
    206  1.1  mycroft 	esc->sc_flags &= ~ESP_PCMCIA_ATTACHING;
    207  1.1  mycroft 	esc->sc_flags |= ESP_PCMCIA_ATTACHED;
    208  1.1  mycroft 	return;
    209  1.1  mycroft 
    210  1.1  mycroft iomap_failed:
    211  1.1  mycroft 	/* Disable the device. */
    212  1.1  mycroft 	pcmcia_function_disable(esc->sc_pf);
    213  1.1  mycroft 
    214  1.1  mycroft enable_failed:
    215  1.1  mycroft 	/* Unmap our I/O space. */
    216  1.1  mycroft 	pcmcia_io_free(esc->sc_pf, &esc->sc_pcioh);
    217  1.1  mycroft 
    218  1.1  mycroft no_config_entry:
    219  1.1  mycroft 	return;
    220  1.1  mycroft }
    221  1.1  mycroft 
    222  1.1  mycroft void
    223  1.1  mycroft esp_pcmcia_init(esc)
    224  1.1  mycroft 	struct esp_pcmcia_softc *esc;
    225  1.1  mycroft {
    226  1.1  mycroft 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    227  1.1  mycroft 	bus_space_tag_t iot = esc->sc_pcioh.iot;
    228  1.1  mycroft 	bus_space_handle_t ioh = esc->sc_pcioh.ioh;
    229  1.1  mycroft 
    230  1.1  mycroft 	/* id 7, clock 40M, parity ON, sync OFF, fast ON, slow ON */
    231  1.1  mycroft 
    232  1.1  mycroft 	sc->sc_glue = &esp_pcmcia_glue;
    233  1.1  mycroft 
    234  1.5  thorpej #ifdef ESP_PCMCIA_POLL
    235  1.5  thorpej 	callout_init(&esc->sc_poll_ch);
    236  1.5  thorpej #endif
    237  1.5  thorpej 
    238  1.1  mycroft 	sc->sc_rev = NCR_VARIANT_ESP406;
    239  1.1  mycroft 	sc->sc_id = 7;
    240  1.1  mycroft 	sc->sc_freq = 40;
    241  1.2  mycroft 	/* try -PARENB -SLOW */
    242  1.1  mycroft 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB | NCRCFG1_SLOW;
    243  1.2  mycroft 	/* try +FE */
    244  1.1  mycroft 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    245  1.2  mycroft 	/* try -IDM -FSCSI -FCLK */
    246  1.2  mycroft 	sc->sc_cfg3 = NCRESPCFG3_CDB | NCRESPCFG3_FCLK | NCRESPCFG3_IDM |
    247  1.2  mycroft 	    NCRESPCFG3_FSCSI;
    248  1.1  mycroft 	sc->sc_cfg4 = NCRCFG4_ACTNEG;
    249  1.2  mycroft 	/* try +INTP */
    250  1.1  mycroft 	sc->sc_cfg5 = NCRCFG5_CRS1 | NCRCFG5_AADDR | NCRCFG5_PTRINC;
    251  1.1  mycroft 	sc->sc_minsync = 0;
    252  1.1  mycroft 	sc->sc_maxxfer = 64 * 1024;
    253  1.1  mycroft 
    254  1.1  mycroft 	bus_space_write_1(iot, ioh, NCR_CFG5, sc->sc_cfg5);
    255  1.1  mycroft 
    256  1.1  mycroft 	bus_space_write_1(iot, ioh, NCR_PIOI, 0);
    257  1.1  mycroft 	bus_space_write_1(iot, ioh, NCR_PSTAT, 0);
    258  1.1  mycroft 	bus_space_write_1(iot, ioh, 0x09, 0x24);
    259  1.1  mycroft 
    260  1.1  mycroft 	bus_space_write_1(iot, ioh, NCR_CFG4, sc->sc_cfg4);
    261  1.1  mycroft }
    262  1.1  mycroft 
    263  1.1  mycroft int
    264  1.1  mycroft esp_pcmcia_detach(self, flags)
    265  1.1  mycroft 	struct device *self;
    266  1.1  mycroft 	int flags;
    267  1.1  mycroft {
    268  1.1  mycroft 	struct esp_pcmcia_softc *esc = (void *)self;
    269  1.1  mycroft 	int error;
    270  1.1  mycroft 
    271  1.1  mycroft 	if ((esc->sc_flags & ESP_PCMCIA_ATTACHED) == 0) {
    272  1.1  mycroft 		/* Nothing to detach. */
    273  1.1  mycroft 		return (0);
    274  1.1  mycroft 	}
    275  1.1  mycroft 
    276  1.1  mycroft 	error = ncr53c9x_detach(&esc->sc_ncr53c9x, flags);
    277  1.1  mycroft 	if (error)
    278  1.1  mycroft 		return (error);
    279  1.1  mycroft 
    280  1.1  mycroft 	/* Unmap our i/o window and i/o space. */
    281  1.1  mycroft 	pcmcia_io_unmap(esc->sc_pf, esc->sc_io_window);
    282  1.1  mycroft 	pcmcia_io_free(esc->sc_pf, &esc->sc_pcioh);
    283  1.1  mycroft 
    284  1.1  mycroft 	return (0);
    285  1.1  mycroft }
    286  1.1  mycroft 
    287  1.1  mycroft int
    288  1.1  mycroft esp_pcmcia_enable(arg, onoff)
    289  1.1  mycroft 	void *arg;
    290  1.1  mycroft 	int onoff;
    291  1.1  mycroft {
    292  1.1  mycroft 	struct esp_pcmcia_softc *esc = arg;
    293  1.1  mycroft 
    294  1.1  mycroft 	if (onoff) {
    295  1.1  mycroft #ifdef ESP_PCMCIA_POLL
    296  1.5  thorpej 		callout_reset(&esc->sc_poll_ch, 1, esp_pcmcia_poll, esc);
    297  1.1  mycroft #else
    298  1.1  mycroft 		/* Establish the interrupt handler. */
    299  1.1  mycroft 		esc->sc_ih = pcmcia_intr_establish(esc->sc_pf, IPL_BIO,
    300  1.1  mycroft 		    ncr53c9x_intr, &esc->sc_ncr53c9x);
    301  1.1  mycroft 		if (esc->sc_ih == NULL) {
    302  1.1  mycroft 			printf("%s: couldn't establish interrupt handler\n",
    303  1.1  mycroft 			    esc->sc_ncr53c9x.sc_dev.dv_xname);
    304  1.1  mycroft 			return (EIO);
    305  1.1  mycroft 		}
    306  1.1  mycroft #endif
    307  1.1  mycroft 
    308  1.1  mycroft 		/*
    309  1.1  mycroft 		 * If attach is in progress, we know that card power is
    310  1.1  mycroft 		 * enabled and chip will be initialized later.
    311  1.1  mycroft 		 * Otherwise, enable and reset now.
    312  1.1  mycroft 		 */
    313  1.1  mycroft 		if ((esc->sc_flags & ESP_PCMCIA_ATTACHING) == 0) {
    314  1.1  mycroft 			if (pcmcia_function_enable(esc->sc_pf)) {
    315  1.1  mycroft 				printf("%s: couldn't enable PCMCIA function\n",
    316  1.1  mycroft 				    esc->sc_ncr53c9x.sc_dev.dv_xname);
    317  1.1  mycroft 				pcmcia_intr_disestablish(esc->sc_pf,
    318  1.1  mycroft 				    esc->sc_ih);
    319  1.1  mycroft 				return (EIO);
    320  1.1  mycroft 			}
    321  1.1  mycroft 
    322  1.1  mycroft 			/* Initialize only chip.  */
    323  1.1  mycroft 			ncr53c9x_init(&esc->sc_ncr53c9x, 0);
    324  1.1  mycroft 		}
    325  1.1  mycroft 	} else {
    326  1.1  mycroft 		pcmcia_function_disable(esc->sc_pf);
    327  1.1  mycroft #ifdef ESP_PCMCIA_POLL
    328  1.5  thorpej 		callout_stop(&esc->sc_poll_ch);
    329  1.1  mycroft #else
    330  1.1  mycroft 		pcmcia_intr_disestablish(esc->sc_pf, esc->sc_ih);
    331  1.1  mycroft #endif
    332  1.1  mycroft 	}
    333  1.1  mycroft 
    334  1.1  mycroft 	return (0);
    335  1.1  mycroft }
    336  1.1  mycroft 
    337  1.1  mycroft #ifdef ESP_PCMCIA_POLL
    338  1.1  mycroft void
    339  1.1  mycroft esp_pcmcia_poll(arg)
    340  1.1  mycroft 	void *arg;
    341  1.1  mycroft {
    342  1.1  mycroft 	struct esp_pcmcia_softc *esc = arg;
    343  1.1  mycroft 
    344  1.1  mycroft 	(void) ncr53c9x_intr(&esc->sc_ncr53c9x);
    345  1.5  thorpej 	callout_reset(&esc->sc_poll_ch, 1, esp_pcmcia_poll, esc);
    346  1.1  mycroft }
    347  1.1  mycroft #endif
    348  1.1  mycroft 
    349  1.1  mycroft /*
    350  1.1  mycroft  * Glue functions.
    351  1.1  mycroft  */
    352  1.1  mycroft u_char
    353  1.1  mycroft esp_pcmcia_read_reg(sc, reg)
    354  1.1  mycroft 	struct ncr53c9x_softc *sc;
    355  1.1  mycroft 	int reg;
    356  1.1  mycroft {
    357  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    358  1.1  mycroft 	u_char v;
    359  1.1  mycroft 
    360  1.1  mycroft 	v = bus_space_read_1(esc->sc_pcioh.iot, esc->sc_pcioh.ioh, reg);
    361  1.1  mycroft 	return v;
    362  1.1  mycroft }
    363  1.1  mycroft 
    364  1.1  mycroft void
    365  1.1  mycroft esp_pcmcia_write_reg(sc, reg, val)
    366  1.1  mycroft 	struct ncr53c9x_softc *sc;
    367  1.1  mycroft 	int reg;
    368  1.1  mycroft 	u_char val;
    369  1.1  mycroft {
    370  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    371  1.1  mycroft 	u_char v = val;
    372  1.1  mycroft 
    373  1.1  mycroft 	if (reg == NCR_CMD && v == (NCRCMD_TRANS|NCRCMD_DMA))
    374  1.1  mycroft 		v = NCRCMD_TRANS;
    375  1.1  mycroft 	bus_space_write_1(esc->sc_pcioh.iot, esc->sc_pcioh.ioh, reg, v);
    376  1.1  mycroft }
    377  1.1  mycroft 
    378  1.1  mycroft int
    379  1.1  mycroft esp_pcmcia_dma_isintr(sc)
    380  1.1  mycroft 	struct ncr53c9x_softc *sc;
    381  1.1  mycroft {
    382  1.1  mycroft 
    383  1.1  mycroft 	return NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT;
    384  1.1  mycroft }
    385  1.1  mycroft 
    386  1.1  mycroft void
    387  1.1  mycroft esp_pcmcia_dma_reset(sc)
    388  1.1  mycroft 	struct ncr53c9x_softc *sc;
    389  1.1  mycroft {
    390  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    391  1.1  mycroft 
    392  1.1  mycroft 	esc->sc_active = 0;
    393  1.1  mycroft 	esc->sc_tc = 0;
    394  1.1  mycroft }
    395  1.1  mycroft 
    396  1.1  mycroft int
    397  1.1  mycroft esp_pcmcia_dma_intr(sc)
    398  1.1  mycroft 	struct ncr53c9x_softc *sc;
    399  1.1  mycroft {
    400  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    401  1.1  mycroft 	u_char	*p;
    402  1.1  mycroft 	u_int	espphase, espstat, espintr;
    403  1.1  mycroft 	int	cnt;
    404  1.1  mycroft 
    405  1.1  mycroft 	if (esc->sc_active == 0) {
    406  1.1  mycroft 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    407  1.1  mycroft 		return -1;
    408  1.1  mycroft 	}
    409  1.1  mycroft 
    410  1.1  mycroft 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    411  1.1  mycroft 		esc->sc_active = 0;
    412  1.1  mycroft 		return 0;
    413  1.1  mycroft 	}
    414  1.1  mycroft 
    415  1.1  mycroft 	cnt = *esc->sc_pdmalen;
    416  1.1  mycroft 	if (*esc->sc_pdmalen == 0) {
    417  1.1  mycroft 		printf("%s: data interrupt, but no count left\n",
    418  1.1  mycroft 		    sc->sc_dev.dv_xname);
    419  1.1  mycroft 	}
    420  1.1  mycroft 
    421  1.1  mycroft 	p = *esc->sc_dmaaddr;
    422  1.1  mycroft 	espphase = sc->sc_phase;
    423  1.1  mycroft 	espstat = (u_int) sc->sc_espstat;
    424  1.1  mycroft 	espintr = (u_int) sc->sc_espintr;
    425  1.1  mycroft 	do {
    426  1.1  mycroft 		if (esc->sc_datain) {
    427  1.4  mycroft 			*p++ = NCR_READ_REG(sc, NCR_FIFO);
    428  1.4  mycroft 			cnt--;
    429  1.4  mycroft 			if (espphase == DATA_IN_PHASE)
    430  1.1  mycroft 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    431  1.4  mycroft 			else
    432  1.1  mycroft 				esc->sc_active = 0;
    433  1.1  mycroft 	 	} else {
    434  1.1  mycroft 			if (espphase == DATA_OUT_PHASE ||
    435  1.1  mycroft 			    espphase == MESSAGE_OUT_PHASE) {
    436  1.1  mycroft 				NCR_WRITE_REG(sc, NCR_FIFO, *p++);
    437  1.1  mycroft 				cnt--;
    438  1.1  mycroft 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    439  1.1  mycroft 			} else
    440  1.1  mycroft 				esc->sc_active = 0;
    441  1.1  mycroft 		}
    442  1.1  mycroft 
    443  1.1  mycroft 		if (esc->sc_active) {
    444  1.3  tsutsui 			while (!(NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT));
    445  1.1  mycroft 			espstat = NCR_READ_REG(sc, NCR_STAT);
    446  1.1  mycroft 			espintr = NCR_READ_REG(sc, NCR_INTR);
    447  1.1  mycroft 			espphase = (espintr & NCRINTR_DIS)
    448  1.1  mycroft 				    ? /* Disconnected */ BUSFREE_PHASE
    449  1.1  mycroft 				    : espstat & PHASE_MASK;
    450  1.1  mycroft 		}
    451  1.1  mycroft 	} while (esc->sc_active && espintr);
    452  1.1  mycroft 	sc->sc_phase = espphase;
    453  1.1  mycroft 	sc->sc_espstat = (u_char) espstat;
    454  1.1  mycroft 	sc->sc_espintr = (u_char) espintr;
    455  1.1  mycroft 	*esc->sc_dmaaddr = p;
    456  1.1  mycroft 	*esc->sc_pdmalen = cnt;
    457  1.1  mycroft 
    458  1.1  mycroft 	if (*esc->sc_pdmalen == 0)
    459  1.1  mycroft 		esc->sc_tc = NCRSTAT_TC;
    460  1.1  mycroft 	sc->sc_espstat |= esc->sc_tc;
    461  1.1  mycroft 	return 0;
    462  1.1  mycroft }
    463  1.1  mycroft 
    464  1.1  mycroft int
    465  1.1  mycroft esp_pcmcia_dma_setup(sc, addr, len, datain, dmasize)
    466  1.1  mycroft 	struct ncr53c9x_softc *sc;
    467  1.1  mycroft 	caddr_t *addr;
    468  1.1  mycroft 	size_t *len;
    469  1.1  mycroft 	int datain;
    470  1.1  mycroft 	size_t *dmasize;
    471  1.1  mycroft {
    472  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    473  1.1  mycroft 
    474  1.1  mycroft 	esc->sc_dmaaddr = addr;
    475  1.1  mycroft 	esc->sc_pdmalen = len;
    476  1.1  mycroft 	esc->sc_datain = datain;
    477  1.1  mycroft 	esc->sc_dmasize = *dmasize;
    478  1.1  mycroft 	esc->sc_tc = 0;
    479  1.1  mycroft 
    480  1.1  mycroft 	return 0;
    481  1.1  mycroft }
    482  1.1  mycroft 
    483  1.1  mycroft void
    484  1.1  mycroft esp_pcmcia_dma_go(sc)
    485  1.1  mycroft 	struct ncr53c9x_softc *sc;
    486  1.1  mycroft {
    487  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    488  1.1  mycroft 
    489  1.1  mycroft 	esc->sc_active = 1;
    490  1.1  mycroft }
    491  1.1  mycroft 
    492  1.1  mycroft void
    493  1.1  mycroft esp_pcmcia_dma_stop(sc)
    494  1.1  mycroft 	struct ncr53c9x_softc *sc;
    495  1.1  mycroft {
    496  1.1  mycroft }
    497  1.1  mycroft 
    498  1.1  mycroft int
    499  1.1  mycroft esp_pcmcia_dma_isactive(sc)
    500  1.1  mycroft 	struct ncr53c9x_softc *sc;
    501  1.1  mycroft {
    502  1.1  mycroft 	struct esp_pcmcia_softc *esc = (struct esp_pcmcia_softc *)sc;
    503  1.1  mycroft 
    504  1.1  mycroft 	return (esc->sc_active);
    505  1.1  mycroft }
    506