1 /* $NetBSD: atppc_ofisa.c,v 1.1 2004/01/28 18:47:13 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jaromir Dolecek.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: atppc_ofisa.c,v 1.1 2004/01/28 18:47:13 jdolecek Exp $");
41
42 #include "opt_atppc.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/ioctl.h>
48 #include <sys/syslog.h>
49 #include <sys/device.h>
50 #include <sys/proc.h>
51 #include <sys/termios.h>
52
53 #include <machine/bus.h>
54
55 #include <dev/ofw/openfirm.h>
56 #include <dev/isa/isavar.h>
57 #include <dev/ofisa/ofisavar.h>
58
59 #include <dev/ic/atppcvar.h>
60 #include <dev/isa/atppc_isadma.h>
61
62 static int atppc_ofisa_match(struct device *, struct cfdata *, void *);
63 static void atppc_ofisa_attach(struct device *, struct device *, void *);
64
65 struct atppc_ofisa_softc {
66 struct atppc_softc sc_atppc;
67
68 isa_chipset_tag_t sc_ic;
69 int sc_drq;
70 };
71
72 CFATTACH_DECL(atppc_ofisa, sizeof(struct atppc_ofisa_softc), atppc_ofisa_match,
73 atppc_ofisa_attach, NULL, NULL);
74
75 static int atppc_ofisa_dma_start(struct atppc_softc *, void *, u_int,
76 u_int8_t);
77 static int atppc_ofisa_dma_finish(struct atppc_softc *);
78 static int atppc_ofisa_dma_abort(struct atppc_softc *);
79 static int atppc_ofisa_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
80 bus_size_t);
81 static void atppc_ofisa_dma_free(struct device *, caddr_t *, bus_addr_t *,
82 bus_size_t);
83 /*
84 * atppc_ofisa_match: autoconf(9) match routine
85 */
86 static int
87 atppc_ofisa_match(struct device *parent, struct cfdata *match, void *aux)
88 {
89 struct ofisa_attach_args *aa = aux;
90 static const char *const compatible_strings[] = { "pnpPNP,401", NULL };
91 int rv = 0;
92
93 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
94 rv = 5;
95 #ifdef _LPT_OFISA_MD_MATCH
96 if (!rv)
97 rv = lpt_ofisa_md_match(parent, match, aux);
98 #endif
99 return (rv);
100 }
101
102 static void
103 atppc_ofisa_attach(struct device *parent, struct device *self, void *aux)
104 {
105 struct atppc_softc *sc = (struct atppc_softc *) self;
106 struct atppc_ofisa_softc *asc = (struct atppc_ofisa_softc *)self;
107 struct ofisa_attach_args *aa = aux;
108 struct ofisa_reg_desc reg;
109 struct ofisa_intr_desc intr;
110 struct ofisa_dma_desc dma;
111 int n;
112
113 sc->sc_dev_ok = ATPPC_NOATTACH;
114
115 printf(": AT Parallel Port\n");
116
117 /* find our I/O space */
118 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1);
119 #ifdef _LPT_OFISA_MD_REG_FIXUP
120 n = lpt_ofisa_md_reg_fixup(parent, self, aux, ®, 1, n);
121 #endif
122 if (n != 1) {
123 printf("%s: unable to find i/o register resource\n",
124 sc->sc_dev.dv_xname);
125 return;
126 }
127
128 /* find our IRQ */
129 n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
130 #ifdef _LPT_OFISA_MD_INTR_FIXUP
131 n = lpt_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
132 #endif
133 if (n != 1) {
134 printf("%s: unable to find irq resource\n",
135 sc->sc_dev.dv_xname);
136 return;
137 }
138
139 /* find our DRQ */
140 if (ofisa_dma_get(aa->oba.oba_phandle, &dma, 1) != 1) {
141 printf("%s: unable to find DMA data\n",
142 sc->sc_dev.dv_xname);
143 return;
144 }
145 asc->sc_drq = dma.drq;
146
147 /* Attach */
148 sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
149 sc->sc_has = 0;
150 asc->sc_ic = aa->ic;
151
152 sc->sc_dev_ok = ATPPC_ATTACHED;
153
154 if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0,
155 &sc->sc_ioh) != 0) {
156 printf("%s: attempt to map bus space failed, device not "
157 "properly attached.\n", self->dv_xname);
158 return;
159 }
160
161 sc->sc_ieh = isa_intr_establish(aa->ic, intr.irq, intr.share,
162 IPL_TTY, atppcintr, sc);
163 sc->sc_has |= ATPPC_HAS_INTR;
164
165 /* setup DMA hooks */
166 if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
167 sc->sc_has |= ATPPC_HAS_DMA;
168 sc->sc_dma_start = atppc_ofisa_dma_start;
169 sc->sc_dma_finish = atppc_ofisa_dma_finish;
170 sc->sc_dma_abort = atppc_ofisa_dma_abort;
171 sc->sc_dma_malloc = atppc_ofisa_dma_malloc;
172 sc->sc_dma_free = atppc_ofisa_dma_free;
173 }
174
175 /* Run soft configuration attach */
176 atppc_sc_attach(sc);
177 }
178
179 /* Start DMA operation over ISA bus */
180 static int
181 atppc_ofisa_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
182 u_int8_t mode)
183 {
184 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) lsc;
185
186 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
187 }
188
189 /* Stop DMA operation over ISA bus */
190 static int
191 atppc_ofisa_dma_finish(struct atppc_softc * lsc)
192 {
193 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) lsc;
194
195 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
196 }
197
198 /* Abort DMA operation over ISA bus */
199 int
200 atppc_ofisa_dma_abort(struct atppc_softc * lsc)
201 {
202 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) lsc;
203
204 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
205 }
206
207 /* Allocate memory for DMA over ISA bus */
208 int
209 atppc_ofisa_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
210 bus_size_t size)
211 {
212 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) dev;
213
214 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
215 }
216
217 /* Free memory allocated by atppc_isa_dma_malloc() */
218 void
219 atppc_ofisa_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
220 bus_size_t size)
221 {
222 struct atppc_ofisa_softc * sc = (struct atppc_ofisa_softc *) dev;
223
224 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
225 }
Cache object: eabdf647f07516092958c476d5c1b86f
|