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