Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isapnp / atppc_isapnp.c
blobb07f53e049b4f8160f606e2711ebb701a8ea1e82
1 /* $NetBSD: atppc_isapnp.c,v 1.10 2008/04/16 09:39:01 cegger Exp $ */
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jaromir Dolecek.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: atppc_isapnp.c,v 1.10 2008/04/16 09:39:01 cegger Exp $");
35 #include "opt_atppc.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/syslog.h>
42 #include <sys/device.h>
43 #include <sys/proc.h>
44 #include <sys/termios.h>
46 #include <sys/bus.h>
48 #include <dev/isa/isavar.h>
49 #include <dev/isa/isadmavar.h>
51 #include <dev/isapnp/isapnpreg.h>
52 #include <dev/isapnp/isapnpvar.h>
53 #include <dev/isapnp/isapnpdevs.h>
55 #include <dev/ic/atppcvar.h>
56 #include <dev/isa/atppc_isadma.h>
58 static int atppc_isapnp_match(device_t, cfdata_t, void *);
59 static void atppc_isapnp_attach(device_t, device_t, void *);
61 struct atppc_isapnp_softc {
62 struct atppc_softc sc_atppc;
64 isa_chipset_tag_t sc_ic;
65 int sc_drq;
68 CFATTACH_DECL_NEW(atppc_isapnp, sizeof(struct atppc_isapnp_softc),
69 atppc_isapnp_match, atppc_isapnp_attach, NULL, NULL);
71 static int atppc_isapnp_dma_start(struct atppc_softc *, void *, u_int,
72 u_int8_t);
73 static int atppc_isapnp_dma_finish(struct atppc_softc *);
74 static int atppc_isapnp_dma_abort(struct atppc_softc *);
75 static int atppc_isapnp_dma_malloc(device_t, void **, bus_addr_t *,
76 bus_size_t);
77 static void atppc_isapnp_dma_free(device_t, void **, bus_addr_t *,
78 bus_size_t);
80 * atppc_isapnp_match: autoconf(9) match routine
82 static int
83 atppc_isapnp_match(device_t parent, cfdata_t match, void *aux)
85 int pri, variant;
87 pri = isapnp_devmatch(aux, &isapnp_atppc_devinfo, &variant);
88 if (pri && variant > 0)
89 pri = 0;
90 return (pri);
93 static void
94 atppc_isapnp_attach(device_t parent, device_t self, void *aux)
96 struct atppc_softc *sc = device_private(self);
97 struct atppc_isapnp_softc *asc = device_private(self);
98 struct isapnp_attach_args *ipa = aux;
100 sc->sc_dev_ok = ATPPC_NOATTACH;
102 printf(": AT Parallel Port\n");
104 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
105 aprint_error_dev(sc->sc_dev, "error in region allocation\n");
106 return;
109 /* Attach */
110 sc->sc_dev = self;
111 sc->sc_iot = ipa->ipa_iot;
112 sc->sc_ioh = ipa->ipa_io[0].h;
113 sc->sc_has = 0;
114 asc->sc_ic = ipa->ipa_ic;
115 asc->sc_drq = -1; /* Initialized below */
117 sc->sc_dev_ok = ATPPC_ATTACHED;
119 sc->sc_ieh = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
120 ipa->ipa_irq[0].type, IPL_TTY, atppcintr, sc);
121 sc->sc_has |= ATPPC_HAS_INTR;
123 /* setup DMA hooks */
124 if (ipa->ipa_ndrq > 0
125 && atppc_isadma_setup(sc, asc->sc_ic, ipa->ipa_drq[0].num) == 0) {
126 asc->sc_drq = ipa->ipa_drq[0].num;
127 sc->sc_has |= ATPPC_HAS_DMA;
128 sc->sc_dma_start = atppc_isapnp_dma_start;
129 sc->sc_dma_finish = atppc_isapnp_dma_finish;
130 sc->sc_dma_abort = atppc_isapnp_dma_abort;
131 sc->sc_dma_malloc = atppc_isapnp_dma_malloc;
132 sc->sc_dma_free = atppc_isapnp_dma_free;
135 /* Run soft configuration attach */
136 atppc_sc_attach(sc);
139 /* Start DMA operation over ISA bus */
140 static int
141 atppc_isapnp_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
142 u_int8_t mode)
144 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
146 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
149 /* Stop DMA operation over ISA bus */
150 static int
151 atppc_isapnp_dma_finish(struct atppc_softc * lsc)
153 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
155 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
158 /* Abort DMA operation over ISA bus */
160 atppc_isapnp_dma_abort(struct atppc_softc * lsc)
162 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
164 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
167 /* Allocate memory for DMA over ISA bus */
169 atppc_isapnp_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr,
170 bus_size_t size)
172 struct atppc_isapnp_softc * sc = device_private(dev);
174 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
177 /* Free memory allocated by atppc_isa_dma_malloc() */
178 void
179 atppc_isapnp_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr,
180 bus_size_t size)
182 struct atppc_isapnp_softc * sc = device_private(dev);
184 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);