Home | History | Annotate | Line # | Download | only in isa
atppc_isa.c revision 1.7
      1  1.7     perry /* $NetBSD: atppc_isa.c,v 1.7 2005/02/04 02:10:40 perry Exp $ */
      2  1.2     bjh21 
      3  1.1  jdolecek /*-
      4  1.1  jdolecek  * Copyright (c) 2001 Alcove - Nicolas Souchu
      5  1.1  jdolecek  * All rights reserved.
      6  1.1  jdolecek  *
      7  1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
      8  1.1  jdolecek  * modification, are permitted provided that the following conditions
      9  1.1  jdolecek  * are met:
     10  1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     15  1.1  jdolecek  *
     16  1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.1  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.1  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  jdolecek  * SUCH DAMAGE.
     27  1.1  jdolecek  *
     28  1.3     bjh21  * FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp
     29  1.1  jdolecek  *
     30  1.1  jdolecek  */
     31  1.1  jdolecek 
     32  1.3     bjh21 #include <sys/cdefs.h>
     33  1.7     perry __KERNEL_RCSID(0, "$NetBSD: atppc_isa.c,v 1.7 2005/02/04 02:10:40 perry Exp $");
     34  1.3     bjh21 
     35  1.1  jdolecek #include "opt_atppc.h"
     36  1.1  jdolecek 
     37  1.1  jdolecek #include <sys/param.h>
     38  1.1  jdolecek #include <sys/systm.h>
     39  1.1  jdolecek #include <sys/kernel.h>
     40  1.1  jdolecek #include <sys/malloc.h>
     41  1.1  jdolecek #include <sys/device.h>
     42  1.1  jdolecek 
     43  1.1  jdolecek #include <machine/intr.h>
     44  1.1  jdolecek #include <machine/bus.h>
     45  1.1  jdolecek 
     46  1.1  jdolecek #include <dev/isa/isareg.h>
     47  1.1  jdolecek #include <dev/isa/isavar.h>
     48  1.1  jdolecek #include <dev/isa/isadmavar.h>
     49  1.1  jdolecek 
     50  1.1  jdolecek #include <dev/ic/atppcreg.h>
     51  1.1  jdolecek #include <dev/ic/atppcvar.h>
     52  1.4  jdolecek #include <dev/isa/atppc_isadma.h>
     53  1.1  jdolecek 
     54  1.1  jdolecek /*
     55  1.1  jdolecek  * ISA bus attach code for atppc driver.
     56  1.5  drochner  * Note on capabilities: capabilites may exist in the chipset but may not
     57  1.5  drochner  * necessarily be useable. I.e. you may specify an IRQ in the autoconfig, but
     58  1.1  jdolecek  * will the port actually have an IRQ assigned to it at the hardware level?
     59  1.5  drochner  * How can you test if the capabilites can be used? For interrupts, see if a
     60  1.5  drochner  * handler exists (sc_intr != NULL). For DMA, see if the sc_dma_start() and
     61  1.1  jdolecek  * sc_dma_finish() function pointers are not NULL.
     62  1.1  jdolecek  */
     63  1.1  jdolecek 
     64  1.4  jdolecek /* Configuration data for atppc on isa bus. */
     65  1.4  jdolecek struct atppc_isa_softc {
     66  1.4  jdolecek 	/* Machine independent device data */
     67  1.4  jdolecek 	struct atppc_softc sc_atppc;
     68  1.4  jdolecek 
     69  1.4  jdolecek 	/* IRQ/DRQ/IO Port assignments on ISA bus */
     70  1.4  jdolecek 	int sc_irq;
     71  1.4  jdolecek 	int sc_drq;
     72  1.4  jdolecek 	int sc_iobase;
     73  1.4  jdolecek 
     74  1.4  jdolecek 	/* ISA chipset tag */
     75  1.4  jdolecek 	isa_chipset_tag_t sc_ic;
     76  1.4  jdolecek };
     77  1.4  jdolecek 
     78  1.4  jdolecek /* Probe and attach functions for a atppc device on the ISA bus. */
     79  1.7     perry static int atppc_isa_probe(struct device *, struct cfdata *, void *);
     80  1.7     perry static void atppc_isa_attach(struct device *, struct device *, void *);
     81  1.4  jdolecek 
     82  1.5  drochner static int atppc_isa_dma_start(struct atppc_softc *, void *, u_int,
     83  1.4  jdolecek 	u_int8_t);
     84  1.4  jdolecek static int atppc_isa_dma_finish(struct atppc_softc *);
     85  1.4  jdolecek static int atppc_isa_dma_abort(struct atppc_softc *);
     86  1.5  drochner static int atppc_isa_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
     87  1.4  jdolecek 	bus_size_t);
     88  1.5  drochner static void atppc_isa_dma_free(struct device *, caddr_t *, bus_addr_t *,
     89  1.4  jdolecek 	bus_size_t);
     90  1.1  jdolecek 
     91  1.1  jdolecek CFATTACH_DECL(atppc_isa, sizeof(struct atppc_isa_softc), atppc_isa_probe,
     92  1.4  jdolecek 	atppc_isa_attach, NULL, NULL);
     93  1.1  jdolecek 
     94  1.5  drochner /*
     95  1.5  drochner  * Probe function: find parallel port controller on isa bus. Combined from
     96  1.5  drochner  * lpt_isa_probe() in lpt.c and atppc_detect_port() from FreeBSD's ppc.c.
     97  1.1  jdolecek  */
     98  1.1  jdolecek static int
     99  1.5  drochner atppc_isa_probe(struct device *parent, struct cfdata *cf, void *aux)
    100  1.1  jdolecek {
    101  1.1  jdolecek 	bus_space_handle_t ioh;
    102  1.5  drochner 	struct isa_attach_args *ia = aux;
    103  1.1  jdolecek 	bus_space_tag_t iot = ia->ia_iot;
    104  1.5  drochner 	int rval = 0;
    105  1.1  jdolecek 
    106  1.4  jdolecek 	if (ia->ia_nio < 1)
    107  1.4  jdolecek 		return (0);
    108  1.1  jdolecek 
    109  1.4  jdolecek 	/* Disallow wildcarded i/o address */
    110  1.6  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    111  1.4  jdolecek 		return (0);
    112  1.4  jdolecek 
    113  1.4  jdolecek 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, IO_LPTSIZE, 0, &ioh))
    114  1.4  jdolecek 		return (0);
    115  1.4  jdolecek 
    116  1.5  drochner 	if (atppc_detect_port(iot, ioh) == 0)
    117  1.5  drochner 		rval = 1;
    118  1.4  jdolecek 
    119  1.5  drochner 	bus_space_unmap(iot, ioh, IO_LPTSIZE);
    120  1.1  jdolecek 
    121  1.5  drochner 	if (rval) {
    122  1.5  drochner 		ia->ia_nio = 1;
    123  1.5  drochner 		ia->ia_io[0].ir_size = IO_LPTSIZE;
    124  1.5  drochner 		ia->ia_nirq = 1;
    125  1.5  drochner 		ia->ia_ndrq = 1;
    126  1.5  drochner 		ia->ia_niomem = 0;
    127  1.5  drochner 	}
    128  1.5  drochner 	return (rval);
    129  1.1  jdolecek }
    130  1.1  jdolecek 
    131  1.1  jdolecek /* Attach function: attach and configure parallel port controller on isa bus. */
    132  1.5  drochner static void
    133  1.4  jdolecek atppc_isa_attach(struct device *parent, struct device *self, void *aux)
    134  1.1  jdolecek {
    135  1.5  drochner 	struct atppc_isa_softc *sc = (struct atppc_isa_softc *)self;
    136  1.5  drochner 	struct atppc_softc *lsc = &sc->sc_atppc;
    137  1.5  drochner 	struct isa_attach_args *ia = aux;
    138  1.1  jdolecek 
    139  1.4  jdolecek 	printf(": AT Parallel Port\n");
    140  1.4  jdolecek 
    141  1.1  jdolecek 	lsc->sc_iot = ia->ia_iot;
    142  1.5  drochner 	lsc->sc_dmat = ia->ia_dmat;
    143  1.1  jdolecek 	lsc->sc_has = 0;
    144  1.1  jdolecek 	sc->sc_ic = ia->ia_ic;
    145  1.1  jdolecek 	sc->sc_iobase = ia->ia_io->ir_addr;
    146  1.1  jdolecek 
    147  1.5  drochner 	if (bus_space_map(lsc->sc_iot, sc->sc_iobase, IO_LPTSIZE, 0,
    148  1.1  jdolecek 		&lsc->sc_ioh) != 0) {
    149  1.1  jdolecek 		printf("%s: attempt to map bus space failed, device not "
    150  1.1  jdolecek 			"properly attached.\n", self->dv_xname);
    151  1.1  jdolecek 		lsc->sc_dev_ok = ATPPC_NOATTACH;
    152  1.1  jdolecek 		return;
    153  1.1  jdolecek 	}
    154  1.4  jdolecek 
    155  1.4  jdolecek 	lsc->sc_dev_ok = ATPPC_ATTACHED;
    156  1.1  jdolecek 
    157  1.1  jdolecek 	/* Assign interrupt handler */
    158  1.4  jdolecek 	if (!(self->dv_cfdata->cf_flags & ATPPC_FLAG_DISABLE_INTR)
    159  1.6  drochner 	   && ia->ia_irq->ir_irq != ISA_UNKNOWN_IRQ
    160  1.4  jdolecek 	   && ia->ia_nirq >= 1) {
    161  1.4  jdolecek 		sc->sc_irq = ia->ia_irq[0].ir_irq;
    162  1.4  jdolecek 	} else
    163  1.4  jdolecek 		sc->sc_irq = -1;
    164  1.4  jdolecek 
    165  1.4  jdolecek 	if (sc->sc_irq > 0) {
    166  1.4  jdolecek 		/* Establish interrupt handler. */
    167  1.4  jdolecek 		lsc->sc_ieh = isa_intr_establish(sc->sc_ic, sc->sc_irq,
    168  1.4  jdolecek 			IST_EDGE, IPL_ATPPC, atppcintr, &lsc->sc_dev);
    169  1.4  jdolecek 
    170  1.4  jdolecek 		lsc->sc_has |= ATPPC_HAS_INTR;
    171  1.1  jdolecek 	}
    172  1.1  jdolecek 
    173  1.1  jdolecek 	/* Configure DMA */
    174  1.4  jdolecek 	if (!(self->dv_cfdata->cf_flags & ATPPC_FLAG_DISABLE_DMA)
    175  1.6  drochner 	    && ia->ia_drq->ir_drq != ISA_UNKNOWN_DRQ
    176  1.4  jdolecek 	    && ia->ia_ndrq >= 1)
    177  1.4  jdolecek 		sc->sc_drq = ia->ia_drq[0].ir_drq;
    178  1.4  jdolecek 	else
    179  1.4  jdolecek 		sc->sc_drq = -1;
    180  1.4  jdolecek 
    181  1.4  jdolecek 	if (sc->sc_drq != -1
    182  1.4  jdolecek 	    && atppc_isadma_setup(lsc, sc->sc_ic, sc->sc_drq) == 0) {
    183  1.4  jdolecek 		lsc->sc_has |= ATPPC_HAS_DMA;
    184  1.4  jdolecek 
    185  1.4  jdolecek 		/* setup DMA hooks */
    186  1.4  jdolecek 		lsc->sc_dma_start = atppc_isa_dma_start;
    187  1.4  jdolecek 		lsc->sc_dma_finish = atppc_isa_dma_finish;
    188  1.4  jdolecek 		lsc->sc_dma_abort = atppc_isa_dma_abort;
    189  1.4  jdolecek 		lsc->sc_dma_malloc = atppc_isa_dma_malloc;
    190  1.4  jdolecek 		lsc->sc_dma_free = atppc_isa_dma_free;
    191  1.1  jdolecek 	}
    192  1.1  jdolecek 
    193  1.1  jdolecek 	/* Run soft configuration attach */
    194  1.1  jdolecek 	atppc_sc_attach(lsc);
    195  1.1  jdolecek 
    196  1.1  jdolecek 	return;
    197  1.1  jdolecek }
    198  1.1  jdolecek 
    199  1.4  jdolecek /* Start DMA operation over ISA bus */
    200  1.5  drochner static int
    201  1.4  jdolecek atppc_isa_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
    202  1.4  jdolecek 	u_int8_t mode)
    203  1.4  jdolecek {
    204  1.5  drochner 	struct atppc_isa_softc *sc = (struct atppc_isa_softc *)lsc;
    205  1.5  drochner 
    206  1.4  jdolecek 	return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
    207  1.4  jdolecek }
    208  1.4  jdolecek 
    209  1.4  jdolecek /* Stop DMA operation over ISA bus */
    210  1.5  drochner static int
    211  1.5  drochner atppc_isa_dma_finish(struct atppc_softc *lsc)
    212  1.1  jdolecek {
    213  1.5  drochner 	struct atppc_isa_softc *sc = (struct atppc_isa_softc *)lsc;
    214  1.5  drochner 
    215  1.4  jdolecek 	return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
    216  1.4  jdolecek }
    217  1.1  jdolecek 
    218  1.4  jdolecek /* Abort DMA operation over ISA bus */
    219  1.5  drochner static int
    220  1.5  drochner atppc_isa_dma_abort(struct atppc_softc *lsc)
    221  1.4  jdolecek {
    222  1.5  drochner 	struct atppc_isa_softc *sc = (struct atppc_isa_softc *)lsc;
    223  1.5  drochner 
    224  1.4  jdolecek 	return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
    225  1.4  jdolecek }
    226  1.1  jdolecek 
    227  1.5  drochner /* Allocate memory for DMA over ISA bus */
    228  1.4  jdolecek static int
    229  1.5  drochner atppc_isa_dma_malloc(struct device *dev, caddr_t *buf, bus_addr_t *bus_addr,
    230  1.4  jdolecek 	bus_size_t size)
    231  1.4  jdolecek {
    232  1.5  drochner 	struct atppc_isa_softc *sc = (struct atppc_isa_softc *)dev;
    233  1.1  jdolecek 
    234  1.4  jdolecek 	return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
    235  1.4  jdolecek }
    236  1.1  jdolecek 
    237  1.5  drochner /* Free memory allocated by atppc_isa_dma_malloc() */
    238  1.5  drochner static void
    239  1.5  drochner atppc_isa_dma_free(struct device *dev, caddr_t *buf, bus_addr_t *bus_addr,
    240  1.4  jdolecek 	bus_size_t size)
    241  1.4  jdolecek {
    242  1.5  drochner 	struct atppc_isa_softc *sc = (struct atppc_isa_softc *)dev;
    243  1.1  jdolecek 
    244  1.4  jdolecek 	return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
    245  1.1  jdolecek }
    246