Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / ofisa / atppc_ofisa.c
blob759928fa3ea6abd5806c76da72b5fdddfdbd7280
1 /* $NetBSD: atppc_ofisa.c,v 1.9 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_ofisa.c,v 1.9 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/ofw/openfirm.h>
49 #include <dev/isa/isavar.h>
50 #include <dev/ofisa/ofisavar.h>
52 #include <dev/ic/atppcvar.h>
53 #include <dev/isa/atppc_isadma.h>
55 static int atppc_ofisa_match(device_t, cfdata_t, void *);
56 static void atppc_ofisa_attach(device_t, device_t, void *);
58 struct atppc_ofisa_softc {
59 struct atppc_softc sc_atppc;
61 isa_chipset_tag_t sc_ic;
62 int sc_drq;
65 CFATTACH_DECL_NEW(atppc_ofisa, sizeof(struct atppc_ofisa_softc), atppc_ofisa_match,
66 atppc_ofisa_attach, NULL, NULL);
68 static int atppc_ofisa_dma_start(struct atppc_softc *, void *, u_int,
69 u_int8_t);
70 static int atppc_ofisa_dma_finish(struct atppc_softc *);
71 static int atppc_ofisa_dma_abort(struct atppc_softc *);
72 static int atppc_ofisa_dma_malloc(device_t, void **, bus_addr_t *,
73 bus_size_t);
74 static void atppc_ofisa_dma_free(device_t, void **, bus_addr_t *,
75 bus_size_t);
77 * atppc_ofisa_match: autoconf(9) match routine
79 static int
80 atppc_ofisa_match(device_t parent, cfdata_t match, void *aux)
82 struct ofisa_attach_args *aa = aux;
83 static const char *const compatible_strings[] = { "pnpPNP,401", NULL };
84 int rv = 0;
86 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
87 rv = 5;
88 #ifdef _LPT_OFISA_MD_MATCH
89 if (!rv)
90 rv = lpt_ofisa_md_match(parent, match, aux);
91 #endif
92 return (rv);
95 static void
96 atppc_ofisa_attach(device_t parent, device_t self, void *aux)
98 struct atppc_softc *sc = device_private(self);
99 struct atppc_ofisa_softc *asc = device_private(self);
100 struct ofisa_attach_args *aa = aux;
101 struct ofisa_reg_desc reg;
102 struct ofisa_intr_desc intr;
103 struct ofisa_dma_desc dma;
104 int n;
106 sc->sc_dev_ok = ATPPC_NOATTACH;
108 printf(": AT Parallel Port\n");
110 /* find our I/O space */
111 n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
112 #ifdef _LPT_OFISA_MD_REG_FIXUP
113 n = lpt_ofisa_md_reg_fixup(parent, self, aux, &reg, 1, n);
114 #endif
115 if (n != 1) {
116 aprint_error_dev(sc->sc_dev, "unable to find i/o register resource\n");
117 return;
120 /* find our IRQ */
121 n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
122 #ifdef _LPT_OFISA_MD_INTR_FIXUP
123 n = lpt_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
124 #endif
125 if (n != 1) {
126 aprint_error_dev(sc->sc_dev, "unable to find irq resource\n");
127 return;
130 /* find our DRQ */
131 if (ofisa_dma_get(aa->oba.oba_phandle, &dma, 1) != 1) {
132 aprint_error_dev(sc->sc_dev, "unable to find DMA data\n");
133 return;
135 asc->sc_drq = dma.drq;
137 /* Attach */
138 sc->sc_dev = self;
139 sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
140 sc->sc_has = 0;
141 asc->sc_ic = aa->ic;
143 sc->sc_dev_ok = ATPPC_ATTACHED;
145 if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0,
146 &sc->sc_ioh) != 0) {
147 aprint_error_dev(self, "attempt to map bus space failed, device not "
148 "properly attached.\n");
149 return;
152 sc->sc_ieh = isa_intr_establish(aa->ic, intr.irq, intr.share,
153 IPL_TTY, atppcintr, sc);
154 sc->sc_has |= ATPPC_HAS_INTR;
156 /* setup DMA hooks */
157 if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
158 sc->sc_has |= ATPPC_HAS_DMA;
159 sc->sc_dma_start = atppc_ofisa_dma_start;
160 sc->sc_dma_finish = atppc_ofisa_dma_finish;
161 sc->sc_dma_abort = atppc_ofisa_dma_abort;
162 sc->sc_dma_malloc = atppc_ofisa_dma_malloc;
163 sc->sc_dma_free = atppc_ofisa_dma_free;
166 /* Run soft configuration attach */
167 atppc_sc_attach(sc);
170 /* Start DMA operation over ISA bus */
171 static int
172 atppc_ofisa_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
173 u_int8_t mode)
175 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) lsc;
177 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
180 /* Stop DMA operation over ISA bus */
181 static int
182 atppc_ofisa_dma_finish(struct atppc_softc * lsc)
184 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) lsc;
186 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
189 /* Abort DMA operation over ISA bus */
191 atppc_ofisa_dma_abort(struct atppc_softc * lsc)
193 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) lsc;
195 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
198 /* Allocate memory for DMA over ISA bus */
200 atppc_ofisa_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr,
201 bus_size_t size)
203 struct atppc_ofisa_softc * sc = device_private(dev);
205 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
208 /* Free memory allocated by atppc_isa_dma_malloc() */
209 void
210 atppc_ofisa_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr,
211 bus_size_t size)
213 struct atppc_ofisa_softc * sc = device_private(dev);
215 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);