Home | History | Annotate | Line # | Download | only in jazz
      1  1.15    dyoung /*	$NetBSD: fdc_jazzio.c,v 1.15 2011/07/01 19:25:41 dyoung 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  *
     21   1.1      soda  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22   1.1      soda  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23   1.1      soda  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24   1.1      soda  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25   1.1      soda  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26   1.1      soda  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27   1.1      soda  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28   1.1      soda  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29   1.1      soda  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30   1.1      soda  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31   1.1      soda  * POSSIBILITY OF SUCH DAMAGE.
     32   1.1      soda  */
     33   1.1      soda 
     34   1.1      soda /*-
     35   1.1      soda  * Copyright (c) 1990 The Regents of the University of California.
     36   1.1      soda  * All rights reserved.
     37   1.1      soda  *
     38   1.1      soda  * This code is derived from software contributed to Berkeley by
     39   1.1      soda  * Don Ahn.
     40   1.1      soda  *
     41   1.1      soda  * Redistribution and use in source and binary forms, with or without
     42   1.1      soda  * modification, are permitted provided that the following conditions
     43   1.1      soda  * are met:
     44   1.1      soda  * 1. Redistributions of source code must retain the above copyright
     45   1.1      soda  *    notice, this list of conditions and the following disclaimer.
     46   1.1      soda  * 2. Redistributions in binary form must reproduce the above copyright
     47   1.1      soda  *    notice, this list of conditions and the following disclaimer in the
     48   1.1      soda  *    documentation and/or other materials provided with the distribution.
     49   1.9       agc  * 3. Neither the name of the University nor the names of its contributors
     50   1.1      soda  *    may be used to endorse or promote products derived from this software
     51   1.1      soda  *    without specific prior written permission.
     52   1.1      soda  *
     53   1.1      soda  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54   1.1      soda  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55   1.1      soda  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56   1.1      soda  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57   1.1      soda  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58   1.1      soda  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59   1.1      soda  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60   1.1      soda  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61   1.1      soda  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62   1.1      soda  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63   1.1      soda  * SUCH DAMAGE.
     64   1.1      soda  *
     65   1.1      soda  *	@(#)fd.c	7.4 (Berkeley) 5/25/91
     66   1.1      soda  */
     67   1.8     lukem 
     68   1.8     lukem #include <sys/cdefs.h>
     69  1.15    dyoung __KERNEL_RCSID(0, "$NetBSD: fdc_jazzio.c,v 1.15 2011/07/01 19:25:41 dyoung Exp $");
     70   1.1      soda 
     71   1.1      soda #include <sys/param.h>
     72   1.1      soda #include <sys/systm.h>
     73   1.1      soda #include <sys/callout.h>
     74   1.1      soda #include <sys/device.h>
     75   1.1      soda 
     76   1.1      soda #include <machine/autoconf.h>
     77  1.15    dyoung #include <sys/bus.h>
     78   1.1      soda 
     79   1.1      soda #include <arc/jazz/jazzdmatlbreg.h>
     80   1.1      soda #include <arc/jazz/fdreg.h>
     81   1.1      soda #include <arc/jazz/fdcvar.h>
     82   1.1      soda #include <arc/jazz/jazziovar.h>
     83   1.1      soda #include <arc/jazz/dma.h>
     84   1.1      soda 
     85   1.1      soda /* controller driver configuration */
     86  1.14   tsutsui static int fdc_jazzio_probe(device_t, cfdata_t, void *);
     87  1.14   tsutsui static void fdc_jazzio_attach(device_t, device_t, void *);
     88   1.1      soda 
     89   1.1      soda /* MD DMA hook functions */
     90  1.14   tsutsui static void fdc_jazzio_dma_start(struct fdc_softc *, void *, size_t, int);
     91  1.14   tsutsui static void fdc_jazzio_dma_abort(struct fdc_softc *);
     92  1.14   tsutsui static void fdc_jazzio_dma_done(struct fdc_softc *);
     93   1.1      soda 
     94   1.1      soda /* software state, per controller */
     95   1.1      soda struct fdc_jazzio_softc {
     96   1.1      soda 	struct fdc_softc sc_fdc;	/* base fdc device */
     97   1.1      soda 
     98   1.1      soda 	bus_space_handle_t sc_baseioh;	/* base I/O handle */
     99   1.7       wiz 	bus_space_handle_t sc_dmaioh;	/* DMA I/O handle */
    100   1.6   tsutsui 
    101   1.7       wiz 	bus_dma_tag_t sc_dmat;		/* bus_dma tag */
    102   1.7       wiz 	bus_dmamap_t sc_dmamap;		/* bus_dma map */
    103   1.6   tsutsui 	int sc_datain;			/* data direction */
    104   1.1      soda };
    105   1.1      soda 
    106  1.14   tsutsui CFATTACH_DECL_NEW(fdc_jazzio, sizeof(struct fdc_jazzio_softc),
    107   1.4   thorpej     fdc_jazzio_probe, fdc_jazzio_attach, NULL, NULL);
    108   1.1      soda 
    109   1.1      soda #define FDC_NPORT 6
    110   1.1      soda #define FDC_OFFSET 2 /* Should we use bus_space_subregion() or not? */
    111   1.1      soda 
    112  1.14   tsutsui static int
    113  1.14   tsutsui fdc_jazzio_probe(device_t parent, cfdata_t cf, void *aux)
    114   1.1      soda {
    115   1.1      soda 	struct jazzio_attach_args *ja = aux;
    116   1.1      soda 	bus_space_tag_t iot;
    117   1.1      soda 	bus_space_handle_t base_ioh, ioh;
    118   1.1      soda 	int rv;
    119   1.1      soda 
    120   1.5   tsutsui 	if (strcmp(ja->ja_name, "I82077") != 0)
    121   1.1      soda 		return 0;
    122   1.1      soda 
    123   1.1      soda 	iot = ja->ja_bust;
    124   1.1      soda 	rv = 0;
    125   1.1      soda 
    126   1.1      soda 	/* Map the I/O space. */
    127   1.1      soda 	if (bus_space_map(iot, ja->ja_addr,
    128   1.1      soda 	    FDC_OFFSET + FDC_NPORT, 0, &base_ioh))
    129   1.1      soda 		return 0;
    130   1.1      soda 
    131   1.1      soda 	if (bus_space_subregion(iot, base_ioh, FDC_OFFSET, FDC_NPORT, &ioh))
    132   1.1      soda 		goto out;
    133   1.1      soda 
    134   1.1      soda 	/* reset */
    135   1.1      soda 	bus_space_write_1(iot, ioh, FDOUT, 0);
    136   1.1      soda 	delay(100);
    137   1.1      soda 	bus_space_write_1(iot, ioh, FDOUT, FDO_FRST);
    138   1.1      soda 
    139   1.1      soda 	/* see if it can handle a command */
    140   1.1      soda 	if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
    141   1.1      soda 		goto out;
    142   1.1      soda 	out_fdc(iot, ioh, 0xdf); /* XXX */
    143   1.1      soda 	out_fdc(iot, ioh, 2); /* XXX */
    144   1.1      soda 
    145   1.1      soda 	rv = 1;
    146   1.1      soda 
    147   1.1      soda  out:
    148   1.1      soda 	bus_space_unmap(iot, base_ioh, FDC_OFFSET + FDC_NPORT);
    149   1.1      soda 	return rv;
    150   1.1      soda }
    151   1.1      soda 
    152  1.14   tsutsui static void
    153  1.14   tsutsui fdc_jazzio_attach(device_t parent, device_t self, void *aux)
    154   1.1      soda {
    155  1.14   tsutsui 	struct fdc_jazzio_softc *jsc = device_private(self);
    156   1.1      soda 	struct fdc_softc *fdc = &jsc->sc_fdc;
    157   1.1      soda 	struct jazzio_attach_args *ja = aux;
    158   1.1      soda 
    159  1.14   tsutsui 	fdc->sc_dev = self;
    160   1.1      soda 	fdc->sc_iot = ja->ja_bust;
    161   1.1      soda 
    162   1.6   tsutsui 	fdc->sc_maxiosize = MAXPHYS;
    163   1.1      soda 	fdc->sc_dma_start = fdc_jazzio_dma_start;
    164   1.1      soda 	fdc->sc_dma_abort = fdc_jazzio_dma_abort;
    165   1.1      soda 	fdc->sc_dma_done = fdc_jazzio_dma_done;
    166   1.1      soda 
    167   1.6   tsutsui 	jsc->sc_dmat = ja->ja_dmat;
    168   1.1      soda 
    169   1.1      soda 	if (bus_space_map(fdc->sc_iot, ja->ja_addr,
    170   1.1      soda 	    FDC_OFFSET + FDC_NPORT, 0, &jsc->sc_baseioh)) {
    171  1.14   tsutsui 		aprint_error(": unable to map I/O space\n");
    172   1.1      soda 		return;
    173   1.1      soda 	}
    174   1.1      soda 
    175   1.1      soda 	if (bus_space_subregion(fdc->sc_iot, jsc->sc_baseioh,
    176   1.1      soda 	    FDC_OFFSET, FDC_NPORT, &fdc->sc_ioh)) {
    177  1.14   tsutsui 		aprint_error(": unable to subregion I/O space\n");
    178   1.6   tsutsui 		goto out_unmap1;
    179   1.6   tsutsui 	}
    180   1.6   tsutsui 
    181   1.6   tsutsui 	if (bus_space_map(fdc->sc_iot, jazzio_conf->jc_fdcdmareg,
    182   1.6   tsutsui 	    R4030_DMA_RANGE, 0, &jsc->sc_dmaioh)) {
    183  1.14   tsutsui 		aprint_error(": unable to map DMA I/O space\n");
    184   1.6   tsutsui 		goto out_unmap1;
    185   1.6   tsutsui 	}
    186   1.6   tsutsui 
    187   1.6   tsutsui 	if (bus_dmamap_create(jsc->sc_dmat, MAXPHYS, 1, MAXPHYS, 0,
    188   1.6   tsutsui 	    BUS_DMA_ALLOCNOW|BUS_DMA_NOWAIT, &jsc->sc_dmamap)) {
    189  1.14   tsutsui 		aprint_error(": unable to create DMA map\n");
    190   1.6   tsutsui 		goto out_unmap2;
    191   1.1      soda 	}
    192   1.1      soda 
    193  1.14   tsutsui 	aprint_normal("\n");
    194   1.1      soda 
    195   1.1      soda 	jazzio_intr_establish(ja->ja_intr, fdcintr, fdc);
    196   1.1      soda 
    197   1.1      soda 	fdcattach(fdc);
    198   1.6   tsutsui 	return;
    199   1.6   tsutsui 
    200   1.6   tsutsui  out_unmap2:
    201   1.6   tsutsui 	bus_space_unmap(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_RANGE);
    202   1.6   tsutsui  out_unmap1:
    203   1.6   tsutsui 	bus_space_unmap(fdc->sc_iot, jsc->sc_baseioh, FDC_OFFSET + FDC_NPORT);
    204   1.1      soda }
    205   1.1      soda 
    206  1.14   tsutsui static void
    207  1.12  christos fdc_jazzio_dma_start(struct fdc_softc *fdc, void *addr, size_t size,
    208  1.10   tsutsui     int datain)
    209   1.1      soda {
    210  1.14   tsutsui 	struct fdc_jazzio_softc *jsc = (struct fdc_jazzio_softc *)fdc;
    211   1.1      soda 
    212   1.6   tsutsui 	/* halt DMA */
    213   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_ENAB, 0);
    214   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_MODE, 0);
    215   1.6   tsutsui 
    216   1.6   tsutsui 	jsc->sc_datain = datain;
    217   1.6   tsutsui 
    218   1.6   tsutsui 	bus_dmamap_load(jsc->sc_dmat, jsc->sc_dmamap, addr, size, NULL,
    219   1.6   tsutsui 	    BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
    220   1.6   tsutsui 	    (datain ? BUS_DMA_READ : BUS_DMA_WRITE));
    221   1.6   tsutsui 	bus_dmamap_sync(jsc->sc_dmat, jsc->sc_dmamap,
    222   1.6   tsutsui 	    0, jsc->sc_dmamap->dm_mapsize,
    223   1.6   tsutsui 	    datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    224   1.6   tsutsui 
    225   1.6   tsutsui 	/* load new transfer parameters */
    226   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh,
    227   1.6   tsutsui 	    R4030_DMA_ADDR, jsc->sc_dmamap->dm_segs[0].ds_addr);
    228   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh,
    229   1.6   tsutsui 	    R4030_DMA_COUNT, jsc->sc_dmamap->dm_segs[0].ds_len);
    230   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh,
    231   1.6   tsutsui 	    R4030_DMA_MODE, R4030_DMA_MODE_160NS | R4030_DMA_MODE_8);
    232   1.6   tsutsui 
    233   1.6   tsutsui 	/* start DMA */
    234   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh,
    235   1.6   tsutsui 	    R4030_DMA_ENAB, R4030_DMA_ENAB_RUN |
    236   1.6   tsutsui 	    (datain ? R4030_DMA_ENAB_READ : R4030_DMA_ENAB_WRITE));
    237   1.1      soda }
    238   1.1      soda 
    239  1.14   tsutsui static void
    240  1.10   tsutsui fdc_jazzio_dma_abort(struct fdc_softc *fdc)
    241   1.1      soda {
    242  1.14   tsutsui 	struct fdc_jazzio_softc *jsc = (struct fdc_jazzio_softc *)fdc;
    243   1.1      soda 
    244   1.6   tsutsui 	/* halt DMA */
    245   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_ENAB, 0);
    246   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_MODE, 0);
    247   1.1      soda }
    248   1.1      soda 
    249  1.14   tsutsui static void
    250  1.10   tsutsui fdc_jazzio_dma_done(struct fdc_softc *fdc)
    251   1.1      soda {
    252  1.14   tsutsui 	struct fdc_jazzio_softc *jsc = (struct fdc_jazzio_softc *)fdc;
    253   1.1      soda 
    254   1.6   tsutsui 	/* halt DMA */
    255   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_COUNT, 0);
    256   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_ENAB, 0);
    257   1.6   tsutsui 	bus_space_write_4(fdc->sc_iot, jsc->sc_dmaioh, R4030_DMA_MODE, 0);
    258   1.6   tsutsui 
    259   1.6   tsutsui 	bus_dmamap_sync(jsc->sc_dmat, jsc->sc_dmamap,
    260   1.6   tsutsui 	    0, jsc->sc_dmamap->dm_mapsize,
    261   1.6   tsutsui 	    jsc->sc_datain ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    262   1.6   tsutsui 	bus_dmamap_unload(jsc->sc_dmat, jsc->sc_dmamap);
    263   1.1      soda }
    264