Home | History | Annotate | Line # | Download | only in jazz
fdc_jazzio.c revision 1.1
      1  1.1  soda /*	$NetBSD: fdc_jazzio.c,v 1.1 2001/05/22 03:22:50 soda Exp $	*/
      2  1.1  soda /*	$OpenBSD: fd.c,v 1.6 1998/10/03 21:18:57 millert Exp $	*/
      3  1.1  soda /*	NetBSD: fd.c,v 1.78 1995/07/04 07:23:09 mycroft Exp 	*/
      4  1.1  soda 
      5  1.1  soda /*-
      6  1.1  soda  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      7  1.1  soda  * All rights reserved.
      8  1.1  soda  *
      9  1.1  soda  * This code is derived from software contributed to The NetBSD Foundation
     10  1.1  soda  * by Charles M. Hannum.
     11  1.1  soda  *
     12  1.1  soda  * Redistribution and use in source and binary forms, with or without
     13  1.1  soda  * modification, are permitted provided that the following conditions
     14  1.1  soda  * are met:
     15  1.1  soda  * 1. Redistributions of source code must retain the above copyright
     16  1.1  soda  *    notice, this list of conditions and the following disclaimer.
     17  1.1  soda  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1  soda  *    notice, this list of conditions and the following disclaimer in the
     19  1.1  soda  *    documentation and/or other materials provided with the distribution.
     20  1.1  soda  * 3. All advertising materials mentioning features or use of this software
     21  1.1  soda  *    must display the following acknowledgement:
     22  1.1  soda  *        This product includes software developed by the NetBSD
     23  1.1  soda  *        Foundation, Inc. and its contributors.
     24  1.1  soda  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25  1.1  soda  *    contributors may be used to endorse or promote products derived
     26  1.1  soda  *    from this software without specific prior written permission.
     27  1.1  soda  *
     28  1.1  soda  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29  1.1  soda  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30  1.1  soda  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31  1.1  soda  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32  1.1  soda  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33  1.1  soda  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34  1.1  soda  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35  1.1  soda  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36  1.1  soda  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37  1.1  soda  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  1.1  soda  * POSSIBILITY OF SUCH DAMAGE.
     39  1.1  soda  */
     40  1.1  soda 
     41  1.1  soda /*-
     42  1.1  soda  * Copyright (c) 1990 The Regents of the University of California.
     43  1.1  soda  * All rights reserved.
     44  1.1  soda  *
     45  1.1  soda  * This code is derived from software contributed to Berkeley by
     46  1.1  soda  * Don Ahn.
     47  1.1  soda  *
     48  1.1  soda  * Redistribution and use in source and binary forms, with or without
     49  1.1  soda  * modification, are permitted provided that the following conditions
     50  1.1  soda  * are met:
     51  1.1  soda  * 1. Redistributions of source code must retain the above copyright
     52  1.1  soda  *    notice, this list of conditions and the following disclaimer.
     53  1.1  soda  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.1  soda  *    notice, this list of conditions and the following disclaimer in the
     55  1.1  soda  *    documentation and/or other materials provided with the distribution.
     56  1.1  soda  * 3. All advertising materials mentioning features or use of this software
     57  1.1  soda  *    must display the following acknowledgement:
     58  1.1  soda  *	This product includes software developed by the University of
     59  1.1  soda  *	California, Berkeley and its contributors.
     60  1.1  soda  * 4. Neither the name of the University nor the names of its contributors
     61  1.1  soda  *    may be used to endorse or promote products derived from this software
     62  1.1  soda  *    without specific prior written permission.
     63  1.1  soda  *
     64  1.1  soda  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65  1.1  soda  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66  1.1  soda  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67  1.1  soda  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68  1.1  soda  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69  1.1  soda  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70  1.1  soda  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71  1.1  soda  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72  1.1  soda  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73  1.1  soda  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74  1.1  soda  * SUCH DAMAGE.
     75  1.1  soda  *
     76  1.1  soda  *	@(#)fd.c	7.4 (Berkeley) 5/25/91
     77  1.1  soda  */
     78  1.1  soda 
     79  1.1  soda #include <sys/param.h>
     80  1.1  soda #include <sys/systm.h>
     81  1.1  soda #include <sys/callout.h>
     82  1.1  soda #include <sys/device.h>
     83  1.1  soda #include <sys/buf.h>
     84  1.1  soda #include <sys/queue.h>
     85  1.1  soda 
     86  1.1  soda #include <mips/locore.h>	/* for mips3_HitFlushDCache() */
     87  1.1  soda 
     88  1.1  soda #include <machine/autoconf.h>
     89  1.1  soda #include <machine/bus.h>
     90  1.1  soda #include <machine/cpu.h>
     91  1.1  soda 
     92  1.1  soda #include <arc/jazz/jazzdmatlbreg.h>
     93  1.1  soda #include <arc/jazz/fdreg.h>
     94  1.1  soda #include <arc/jazz/fdcvar.h>
     95  1.1  soda #include <arc/jazz/jazziovar.h>
     96  1.1  soda #include <arc/jazz/dma.h>
     97  1.1  soda 
     98  1.1  soda #include "locators.h"
     99  1.1  soda 
    100  1.1  soda /* controller driver configuration */
    101  1.1  soda int fdc_jazzio_probe(struct device *, struct cfdata *, void *);
    102  1.1  soda void fdc_jazzio_attach(struct device *, struct device *, void *);
    103  1.1  soda 
    104  1.1  soda /* MD DMA hook functions */
    105  1.1  soda void fdc_jazzio_dma_start(struct fdc_softc *, caddr_t, size_t, int);
    106  1.1  soda void fdc_jazzio_dma_abort(struct fdc_softc *);
    107  1.1  soda void fdc_jazzio_dma_done(struct fdc_softc *);
    108  1.1  soda 
    109  1.1  soda /* software state, per controller */
    110  1.1  soda struct fdc_jazzio_softc {
    111  1.1  soda 	struct fdc_softc sc_fdc;	/* base fdc device */
    112  1.1  soda 
    113  1.1  soda 	bus_space_handle_t sc_baseioh;	/* base I/O handle */
    114  1.1  soda 	struct dma_softc __dma;
    115  1.1  soda 	struct dma_softc *dma;
    116  1.1  soda };
    117  1.1  soda 
    118  1.1  soda struct cfattach fdc_jazzio_ca = {
    119  1.1  soda 	sizeof(struct fdc_jazzio_softc), fdc_jazzio_probe, fdc_jazzio_attach
    120  1.1  soda };
    121  1.1  soda 
    122  1.1  soda #define FDC_NPORT 6
    123  1.1  soda #define FDC_OFFSET 2 /* Should we use bus_space_subregion() or not? */
    124  1.1  soda 
    125  1.1  soda int
    126  1.1  soda fdc_jazzio_probe(parent, match, aux)
    127  1.1  soda 	struct device *parent;
    128  1.1  soda 	struct cfdata *match;
    129  1.1  soda 	void *aux;
    130  1.1  soda {
    131  1.1  soda 	struct jazzio_attach_args *ja = aux;
    132  1.1  soda 	bus_space_tag_t iot;
    133  1.1  soda 	bus_space_handle_t base_ioh, ioh;
    134  1.1  soda 	int rv;
    135  1.1  soda 
    136  1.1  soda 	if (strcmp(ja->ja_name, "fdc") != 0)
    137  1.1  soda 		return 0;
    138  1.1  soda 
    139  1.1  soda 	iot = ja->ja_bust;
    140  1.1  soda 	rv = 0;
    141  1.1  soda 
    142  1.1  soda 	/* Map the I/O space. */
    143  1.1  soda 	if (bus_space_map(iot, ja->ja_addr,
    144  1.1  soda 	    FDC_OFFSET + FDC_NPORT, 0, &base_ioh))
    145  1.1  soda 		return 0;
    146  1.1  soda 
    147  1.1  soda 	if (bus_space_subregion(iot, base_ioh, FDC_OFFSET, FDC_NPORT, &ioh))
    148  1.1  soda 		goto out;
    149  1.1  soda 
    150  1.1  soda 	/* reset */
    151  1.1  soda 	bus_space_write_1(iot, ioh, FDOUT, 0);
    152  1.1  soda 	delay(100);
    153  1.1  soda 	bus_space_write_1(iot, ioh, FDOUT, FDO_FRST);
    154  1.1  soda 
    155  1.1  soda 	/* see if it can handle a command */
    156  1.1  soda 	if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
    157  1.1  soda 		goto out;
    158  1.1  soda 	out_fdc(iot, ioh, 0xdf); /* XXX */
    159  1.1  soda 	out_fdc(iot, ioh, 2); /* XXX */
    160  1.1  soda 
    161  1.1  soda 	rv = 1;
    162  1.1  soda 
    163  1.1  soda  out:
    164  1.1  soda 	bus_space_unmap(iot, base_ioh, FDC_OFFSET + FDC_NPORT);
    165  1.1  soda 	return rv;
    166  1.1  soda }
    167  1.1  soda 
    168  1.1  soda void
    169  1.1  soda fdc_jazzio_attach(parent, self, aux)
    170  1.1  soda 	struct device *parent, *self;
    171  1.1  soda 	void *aux;
    172  1.1  soda {
    173  1.1  soda 	struct fdc_jazzio_softc *jsc = (struct fdc_jazzio_softc *)self;
    174  1.1  soda 	struct fdc_softc *fdc = &jsc->sc_fdc;
    175  1.1  soda 	struct jazzio_attach_args *ja = aux;
    176  1.1  soda 
    177  1.1  soda 	fdc->sc_iot = ja->ja_bust;
    178  1.1  soda 
    179  1.1  soda 	fdc->sc_maxiosize = 4096; /* XXX */
    180  1.1  soda 	fdc->sc_dma_start = fdc_jazzio_dma_start;
    181  1.1  soda 	fdc->sc_dma_abort = fdc_jazzio_dma_abort;
    182  1.1  soda 	fdc->sc_dma_done = fdc_jazzio_dma_done;
    183  1.1  soda 
    184  1.1  soda 	jsc->dma = &jsc->__dma;
    185  1.1  soda 	fdc_dma_init(jsc->dma);
    186  1.1  soda 
    187  1.1  soda 	if (bus_space_map(fdc->sc_iot, ja->ja_addr,
    188  1.1  soda 	    FDC_OFFSET + FDC_NPORT, 0, &jsc->sc_baseioh)) {
    189  1.1  soda 		printf(": unable to map I/O space\n");
    190  1.1  soda 		return;
    191  1.1  soda 	}
    192  1.1  soda 
    193  1.1  soda 	if (bus_space_subregion(fdc->sc_iot, jsc->sc_baseioh,
    194  1.1  soda 	    FDC_OFFSET, FDC_NPORT, &fdc->sc_ioh)) {
    195  1.1  soda 		printf(": unable to subregion I/O space\n");
    196  1.1  soda 		bus_space_unmap(fdc->sc_iot, jsc->sc_baseioh,
    197  1.1  soda 		    FDC_OFFSET + FDC_NPORT);
    198  1.1  soda 		return;
    199  1.1  soda 	}
    200  1.1  soda 
    201  1.1  soda 	printf("\n");
    202  1.1  soda 
    203  1.1  soda 	jazzio_intr_establish(ja->ja_intr, fdcintr, fdc);
    204  1.1  soda 
    205  1.1  soda 	fdcattach(fdc);
    206  1.1  soda }
    207  1.1  soda 
    208  1.1  soda void
    209  1.1  soda fdc_jazzio_dma_start(fdc, addr, size, datain)
    210  1.1  soda 	struct fdc_softc *fdc;
    211  1.1  soda 	caddr_t addr;
    212  1.1  soda 	size_t size;
    213  1.1  soda 	int datain;
    214  1.1  soda {
    215  1.1  soda 	struct fdc_jazzio_softc *jsc = (void *)fdc;
    216  1.1  soda 
    217  1.1  soda 	mips3_FlushDCache((vaddr_t)addr, (vsize_t)size);
    218  1.1  soda 	DMA_START(jsc->dma, addr, size, datain ? DMA_FROM_DEV : DMA_TO_DEV);
    219  1.1  soda }
    220  1.1  soda 
    221  1.1  soda void
    222  1.1  soda fdc_jazzio_dma_abort(fdc)
    223  1.1  soda 	struct fdc_softc *fdc;
    224  1.1  soda {
    225  1.1  soda 	struct fdc_jazzio_softc *jsc = (void *)fdc;
    226  1.1  soda 
    227  1.1  soda 	DMA_RESET(jsc->dma);
    228  1.1  soda }
    229  1.1  soda 
    230  1.1  soda void
    231  1.1  soda fdc_jazzio_dma_done(fdc)
    232  1.1  soda 	struct fdc_softc *fdc;
    233  1.1  soda {
    234  1.1  soda 	struct fdc_jazzio_softc *jsc = (void *)fdc;
    235  1.1  soda 
    236  1.1  soda 	DMA_END(jsc->dma);
    237  1.1  soda }
    238