atppc_isa.c revision 1.4 1 1.4 jdolecek /* $NetBSD: atppc_isa.c,v 1.4 2004/01/25 11:35:46 jdolecek 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.4 jdolecek __KERNEL_RCSID(0, "$NetBSD: atppc_isa.c,v 1.4 2004/01/25 11:35:46 jdolecek 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.1 jdolecek * Note on capabilities: capabilites may exist in the chipset but may not
57 1.1 jdolecek * 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.1 jdolecek * How can you test if the capabilites can be used? For interrupts, see if a
60 1.1 jdolecek * 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.1 jdolecek static int atppc_isa_probe __P((struct device *, struct cfdata *, void *));
80 1.1 jdolecek static void atppc_isa_attach __P((struct device *, struct device *, void *));
81 1.4 jdolecek
82 1.4 jdolecek 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.4 jdolecek static int atppc_isa_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
87 1.4 jdolecek bus_size_t);
88 1.4 jdolecek 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.1 jdolecek /*
95 1.1 jdolecek * Probe function: find parallel port controller on isa bus. Combined from
96 1.1 jdolecek * 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.1 jdolecek 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.1 jdolecek struct isa_attach_args * ia = aux;
103 1.1 jdolecek bus_space_tag_t iot = ia->ia_iot;
104 1.1 jdolecek
105 1.4 jdolecek if (ia->ia_nio < 1)
106 1.4 jdolecek return (0);
107 1.1 jdolecek
108 1.4 jdolecek /* Disallow wildcarded i/o address */
109 1.4 jdolecek if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
110 1.4 jdolecek return (0);
111 1.4 jdolecek
112 1.4 jdolecek if (bus_space_map(iot, ia->ia_io[0].ir_addr, IO_LPTSIZE, 0, &ioh))
113 1.4 jdolecek return (0);
114 1.4 jdolecek
115 1.4 jdolecek if (atppc_detect_port(iot, ioh) != 0)
116 1.4 jdolecek return (0);
117 1.4 jdolecek
118 1.4 jdolecek ia->ia_nio = 1;
119 1.4 jdolecek ia->ia_io[0].ir_size = IO_LPTSIZE;
120 1.4 jdolecek ia->ia_nirq = 1;
121 1.4 jdolecek ia->ia_ndrq = 1;
122 1.4 jdolecek ia->ia_niomem = 0;
123 1.1 jdolecek
124 1.4 jdolecek return (1);
125 1.1 jdolecek }
126 1.1 jdolecek
127 1.1 jdolecek /* Attach function: attach and configure parallel port controller on isa bus. */
128 1.1 jdolecek static void
129 1.4 jdolecek atppc_isa_attach(struct device *parent, struct device *self, void *aux)
130 1.1 jdolecek {
131 1.1 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *)self;
132 1.1 jdolecek struct atppc_softc * lsc = (struct atppc_softc *)self;
133 1.1 jdolecek struct isa_attach_args * ia = aux;
134 1.1 jdolecek
135 1.4 jdolecek printf(": AT Parallel Port\n");
136 1.4 jdolecek
137 1.1 jdolecek lsc->sc_iot = ia->ia_iot;
138 1.1 jdolecek lsc->sc_dmat = ia->ia_dmat;
139 1.1 jdolecek lsc->sc_has = 0;
140 1.1 jdolecek sc->sc_ic = ia->ia_ic;
141 1.1 jdolecek sc->sc_iobase = ia->ia_io->ir_addr;
142 1.1 jdolecek
143 1.4 jdolecek if (bus_space_map(lsc->sc_iot, sc->sc_iobase, IO_LPTSIZE, 0,
144 1.1 jdolecek &lsc->sc_ioh) != 0) {
145 1.1 jdolecek printf("%s: attempt to map bus space failed, device not "
146 1.1 jdolecek "properly attached.\n", self->dv_xname);
147 1.1 jdolecek lsc->sc_dev_ok = ATPPC_NOATTACH;
148 1.1 jdolecek return;
149 1.1 jdolecek }
150 1.4 jdolecek
151 1.4 jdolecek lsc->sc_dev_ok = ATPPC_ATTACHED;
152 1.1 jdolecek
153 1.1 jdolecek /* Assign interrupt handler */
154 1.4 jdolecek if (!(self->dv_cfdata->cf_flags & ATPPC_FLAG_DISABLE_INTR)
155 1.4 jdolecek && ia->ia_irq->ir_irq != ISACF_IRQ_DEFAULT
156 1.4 jdolecek && ia->ia_nirq >= 1) {
157 1.4 jdolecek sc->sc_irq = ia->ia_irq[0].ir_irq;
158 1.4 jdolecek } else
159 1.4 jdolecek sc->sc_irq = -1;
160 1.4 jdolecek
161 1.4 jdolecek if (sc->sc_irq > 0) {
162 1.4 jdolecek /* Establish interrupt handler. */
163 1.4 jdolecek lsc->sc_ieh = isa_intr_establish(sc->sc_ic, sc->sc_irq,
164 1.4 jdolecek IST_EDGE, IPL_ATPPC, atppcintr, &lsc->sc_dev);
165 1.4 jdolecek
166 1.4 jdolecek lsc->sc_has |= ATPPC_HAS_INTR;
167 1.1 jdolecek }
168 1.1 jdolecek
169 1.1 jdolecek /* Configure DMA */
170 1.4 jdolecek if (!(self->dv_cfdata->cf_flags & ATPPC_FLAG_DISABLE_DMA)
171 1.4 jdolecek && ia->ia_drq->ir_drq != ISACF_DRQ_DEFAULT
172 1.4 jdolecek && ia->ia_ndrq >= 1)
173 1.4 jdolecek sc->sc_drq = ia->ia_drq[0].ir_drq;
174 1.4 jdolecek else
175 1.4 jdolecek sc->sc_drq = -1;
176 1.4 jdolecek
177 1.4 jdolecek if (sc->sc_drq != -1
178 1.4 jdolecek && atppc_isadma_setup(lsc, sc->sc_ic, sc->sc_drq) == 0) {
179 1.4 jdolecek lsc->sc_has |= ATPPC_HAS_DMA;
180 1.4 jdolecek
181 1.4 jdolecek /* setup DMA hooks */
182 1.4 jdolecek lsc->sc_dma_start = atppc_isa_dma_start;
183 1.4 jdolecek lsc->sc_dma_finish = atppc_isa_dma_finish;
184 1.4 jdolecek lsc->sc_dma_abort = atppc_isa_dma_abort;
185 1.4 jdolecek lsc->sc_dma_malloc = atppc_isa_dma_malloc;
186 1.4 jdolecek lsc->sc_dma_free = atppc_isa_dma_free;
187 1.1 jdolecek }
188 1.1 jdolecek
189 1.1 jdolecek /* Run soft configuration attach */
190 1.1 jdolecek atppc_sc_attach(lsc);
191 1.1 jdolecek
192 1.1 jdolecek return;
193 1.1 jdolecek }
194 1.1 jdolecek
195 1.4 jdolecek /* Start DMA operation over ISA bus */
196 1.4 jdolecek static int
197 1.4 jdolecek atppc_isa_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
198 1.4 jdolecek u_int8_t mode)
199 1.4 jdolecek {
200 1.4 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *) lsc;
201 1.4 jdolecek
202 1.4 jdolecek return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
203 1.4 jdolecek }
204 1.4 jdolecek
205 1.4 jdolecek /* Stop DMA operation over ISA bus */
206 1.1 jdolecek static int
207 1.4 jdolecek atppc_isa_dma_finish(struct atppc_softc * lsc)
208 1.1 jdolecek {
209 1.4 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *) lsc;
210 1.4 jdolecek
211 1.4 jdolecek return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
212 1.4 jdolecek }
213 1.1 jdolecek
214 1.4 jdolecek /* Abort DMA operation over ISA bus */
215 1.4 jdolecek static int
216 1.4 jdolecek atppc_isa_dma_abort(struct atppc_softc * lsc)
217 1.4 jdolecek {
218 1.4 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *) lsc;
219 1.4 jdolecek
220 1.4 jdolecek return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
221 1.4 jdolecek }
222 1.1 jdolecek
223 1.4 jdolecek /* Allocate memory for DMA over ISA bus */
224 1.4 jdolecek static int
225 1.4 jdolecek atppc_isa_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
226 1.4 jdolecek bus_size_t size)
227 1.4 jdolecek {
228 1.4 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *) dev;
229 1.1 jdolecek
230 1.4 jdolecek return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
231 1.4 jdolecek }
232 1.1 jdolecek
233 1.4 jdolecek /* Free memory allocated by atppc_isa_dma_malloc() */
234 1.4 jdolecek static void
235 1.4 jdolecek atppc_isa_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
236 1.4 jdolecek bus_size_t size)
237 1.4 jdolecek {
238 1.4 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *) dev;
239 1.1 jdolecek
240 1.4 jdolecek return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
241 1.1 jdolecek }
242