bpp.c revision 1.2.8.1 1 1.2.8.1 bouyer /* $NetBSD: bpp.c,v 1.2.8.1 2000/11/20 11:43:04 bouyer Exp $ */
2 1.1 pk
3 1.1 pk /*-
4 1.1 pk * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Paul Kranenburg.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk * 3. All advertising materials mentioning features or use of this software
19 1.1 pk * must display the following acknowledgement:
20 1.1 pk * This product includes software developed by the NetBSD
21 1.1 pk * Foundation, Inc. and its contributors.
22 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 pk * contributors may be used to endorse or promote products derived
24 1.1 pk * from this software without specific prior written permission.
25 1.1 pk *
26 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk */
38 1.1 pk
39 1.1 pk #include <sys/param.h>
40 1.1 pk #include <sys/ioctl.h>
41 1.1 pk #include <sys/fcntl.h>
42 1.1 pk #include <sys/systm.h>
43 1.1 pk #include <sys/kernel.h>
44 1.1 pk #include <sys/vnode.h>
45 1.1 pk #include <sys/poll.h>
46 1.1 pk #include <sys/select.h>
47 1.1 pk #include <sys/malloc.h>
48 1.1 pk #include <sys/proc.h>
49 1.1 pk #include <sys/signalvar.h>
50 1.1 pk #include <sys/conf.h>
51 1.1 pk #include <sys/errno.h>
52 1.1 pk #include <sys/device.h>
53 1.1 pk
54 1.1 pk #include <machine/bus.h>
55 1.2.8.1 bouyer #include <machine/intr.h>
56 1.1 pk #include <machine/autoconf.h>
57 1.2.8.1 bouyer #include <machine/conf.h>
58 1.1 pk
59 1.1 pk #include <dev/ic/lsi64854reg.h>
60 1.1 pk #include <dev/ic/lsi64854var.h>
61 1.1 pk
62 1.1 pk #include <dev/sbus/sbusvar.h>
63 1.1 pk #include <dev/sbus/bppreg.h>
64 1.1 pk
65 1.1 pk #define splbpp() spltty() /* XXX */
66 1.1 pk
67 1.1 pk #if 0
68 1.1 pk struct bpp_param {
69 1.1 pk int bpp_dss; /* data setup to strobe */
70 1.1 pk int bpp_dsw; /* data strobe width */
71 1.1 pk int bpp_outputpins; /* Select/Autofeed/Init pins */
72 1.1 pk int bpp_inputpins; /* Error/Select/Paperout pins */
73 1.1 pk };
74 1.1 pk #endif
75 1.1 pk
76 1.1 pk struct hwstate {
77 1.1 pk u_int16_t hw_hcr; /* Hardware config register */
78 1.1 pk u_int16_t hw_ocr; /* Operation config register */
79 1.1 pk u_int8_t hw_tcr; /* Transfer Control register */
80 1.1 pk u_int8_t hw_or; /* Output register */
81 1.1 pk u_int16_t hw_irq; /* IRQ; polarity bits only */
82 1.1 pk };
83 1.1 pk
84 1.1 pk struct bpp_softc {
85 1.1 pk struct lsi64854_softc sc_lsi64854; /* base device */
86 1.1 pk struct sbusdev sc_sd; /* sbus device */
87 1.1 pk
88 1.1 pk size_t sc_bufsz; /* temp buffer */
89 1.1 pk caddr_t sc_buf;
90 1.1 pk
91 1.1 pk int sc_error; /* bottom-half error */
92 1.1 pk int sc_flags;
93 1.1 pk #define BPP_OPEN 0x01 /* Device is open */
94 1.1 pk #define BPP_XCLUDE 0x02 /* Exclusive-open mode */
95 1.1 pk #define BPP_ASYNC 0x04 /* Asynchronous I/O mode */
96 1.1 pk #define BPP_LOCKED 0x08 /* DMA in progress */
97 1.1 pk #define BPP_WANT 0x10 /* Waiting for DMA */
98 1.1 pk
99 1.1 pk struct selinfo sc_rsel;
100 1.1 pk struct selinfo sc_wsel;
101 1.1 pk struct proc *sc_asyncproc; /* Process to notify if async */
102 1.1 pk
103 1.1 pk /* Hardware state */
104 1.1 pk struct hwstate sc_hwdefault;
105 1.1 pk struct hwstate sc_hwcurrent;
106 1.1 pk };
107 1.1 pk
108 1.1 pk static int bppmatch __P((struct device *, struct cfdata *, void *));
109 1.1 pk static void bppattach __P((struct device *, struct device *, void *));
110 1.1 pk static int bppintr __P((void *));
111 1.1 pk static void bpp_setparams __P((struct bpp_softc *, struct hwstate *));
112 1.1 pk
113 1.1 pk struct cfattach bpp_ca = {
114 1.1 pk sizeof(struct bpp_softc), bppmatch, bppattach
115 1.1 pk };
116 1.1 pk
117 1.1 pk extern struct cfdriver bpp_cd;
118 1.1 pk #define BPPUNIT(dev) (minor(dev))
119 1.1 pk
120 1.1 pk
121 1.1 pk int
122 1.1 pk bppmatch(parent, cf, aux)
123 1.1 pk struct device *parent;
124 1.1 pk struct cfdata *cf;
125 1.1 pk void *aux;
126 1.1 pk {
127 1.1 pk struct sbus_attach_args *sa = aux;
128 1.1 pk
129 1.1 pk return (strcmp("SUNW,bpp", sa->sa_name) == 0);
130 1.1 pk }
131 1.1 pk
132 1.1 pk void
133 1.1 pk bppattach(parent, self, aux)
134 1.1 pk struct device *parent, *self;
135 1.1 pk void *aux;
136 1.1 pk {
137 1.1 pk struct sbus_attach_args *sa = aux;
138 1.1 pk struct bpp_softc *dsc = (void *)self;
139 1.1 pk struct lsi64854_softc *sc = &dsc->sc_lsi64854;
140 1.1 pk int burst, sbusburst;
141 1.1 pk int node;
142 1.1 pk
143 1.1 pk sc->sc_bustag = sa->sa_bustag;
144 1.1 pk sc->sc_dmatag = sa->sa_dmatag;
145 1.1 pk node = sa->sa_node;
146 1.1 pk
147 1.1 pk /* Map device registers */
148 1.1 pk if (bus_space_map2(sa->sa_bustag,
149 1.1 pk sa->sa_slot,
150 1.1 pk sa->sa_offset,
151 1.1 pk sa->sa_size,
152 1.1 pk BUS_SPACE_MAP_LINEAR,
153 1.1 pk 0, &sc->sc_regs) != 0) {
154 1.1 pk printf("%s: cannot map registers\n", self->dv_xname);
155 1.1 pk return;
156 1.1 pk }
157 1.1 pk
158 1.1 pk /*
159 1.1 pk * Get transfer burst size from PROM and plug it into the
160 1.1 pk * controller registers. This is needed on the Sun4m; do
161 1.1 pk * others need it too?
162 1.1 pk */
163 1.1 pk sbusburst = ((struct sbus_softc *)parent)->sc_burst;
164 1.1 pk if (sbusburst == 0)
165 1.1 pk sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
166 1.1 pk
167 1.1 pk burst = getpropint(node, "burst-sizes", -1);
168 1.1 pk if (burst == -1)
169 1.1 pk /* take SBus burst sizes */
170 1.1 pk burst = sbusburst;
171 1.1 pk
172 1.1 pk /* Clamp at parent's burst sizes */
173 1.1 pk burst &= sbusburst;
174 1.1 pk sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
175 1.1 pk (burst & SBUS_BURST_16) ? 16 : 0;
176 1.1 pk
177 1.1 pk /* Join the Sbus device family */
178 1.1 pk dsc->sc_sd.sd_reset = (void *)0;
179 1.1 pk sbus_establish(&dsc->sc_sd, self);
180 1.1 pk
181 1.1 pk /* Initialize the DMA channel */
182 1.1 pk sc->sc_channel = L64854_CHANNEL_PP;
183 1.1 pk lsi64854_attach(sc);
184 1.1 pk
185 1.2.8.1 bouyer /* Establish interrupt handler */
186 1.2.8.1 bouyer if (sa->sa_nintr) {
187 1.2.8.1 bouyer sc->sc_intrchain = bppintr;
188 1.2.8.1 bouyer sc->sc_intrchainarg = dsc;
189 1.2.8.1 bouyer (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY, 0,
190 1.2.8.1 bouyer lsi64854_pp_intr, sc);
191 1.2.8.1 bouyer }
192 1.1 pk
193 1.1 pk /* Allocate buffer XXX - should actually use dmamap_uio() */
194 1.1 pk dsc->sc_bufsz = 1024;
195 1.1 pk dsc->sc_buf = malloc(dsc->sc_bufsz, M_DEVBUF, M_NOWAIT);
196 1.1 pk
197 1.1 pk /* XXX read default state */
198 1.1 pk {
199 1.1 pk bus_space_handle_t h = sc->sc_regs;
200 1.1 pk struct hwstate *hw = &dsc->sc_hwdefault;
201 1.1 pk hw->hw_hcr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_HCR);
202 1.1 pk hw->hw_ocr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_OCR);
203 1.1 pk hw->hw_tcr = bus_space_read_1(sc->sc_bustag, h, L64854_REG_TCR);
204 1.1 pk hw->hw_or = bus_space_read_1(sc->sc_bustag, h, L64854_REG_OR);
205 1.1 pk }
206 1.1 pk }
207 1.1 pk
208 1.1 pk void
209 1.1 pk bpp_setparams(sc, hw)
210 1.1 pk struct bpp_softc *sc;
211 1.1 pk struct hwstate *hw;
212 1.1 pk {
213 1.1 pk u_int16_t irq;
214 1.1 pk bus_space_tag_t t = sc->sc_lsi64854.sc_bustag;
215 1.1 pk bus_space_handle_t h = sc->sc_lsi64854.sc_regs;
216 1.1 pk
217 1.1 pk bus_space_write_2(t, h, L64854_REG_HCR, hw->hw_hcr);
218 1.1 pk bus_space_write_2(t, h, L64854_REG_OCR, hw->hw_ocr);
219 1.1 pk bus_space_write_1(t, h, L64854_REG_TCR, hw->hw_tcr);
220 1.1 pk bus_space_write_1(t, h, L64854_REG_OR, hw->hw_or);
221 1.1 pk
222 1.1 pk /* Only change IRP settings in interrupt status register */
223 1.1 pk irq = bus_space_read_2(t, h, L64854_REG_ICR);
224 1.1 pk irq &= ~BPP_ALLIRP;
225 1.1 pk irq |= (hw->hw_irq & BPP_ALLIRP);
226 1.1 pk bus_space_write_2(t, h, L64854_REG_ICR, irq);
227 1.1 pk }
228 1.1 pk
229 1.1 pk int
230 1.1 pk bppopen(dev, flags, mode, p)
231 1.1 pk dev_t dev;
232 1.1 pk int flags, mode;
233 1.1 pk struct proc *p;
234 1.1 pk {
235 1.1 pk int unit = BPPUNIT(dev);
236 1.1 pk struct bpp_softc *sc;
237 1.1 pk struct lsi64854_softc *lsi;
238 1.1 pk u_int16_t irq;
239 1.1 pk int s;
240 1.1 pk
241 1.1 pk if (unit >= bpp_cd.cd_ndevs)
242 1.1 pk return (ENXIO);
243 1.1 pk sc = bpp_cd.cd_devs[unit];
244 1.1 pk
245 1.1 pk if ((sc->sc_flags & (BPP_OPEN|BPP_XCLUDE)) == (BPP_OPEN|BPP_XCLUDE))
246 1.1 pk return (EBUSY);
247 1.1 pk
248 1.1 pk lsi = &sc->sc_lsi64854;
249 1.1 pk
250 1.1 pk /* Set default parameters */
251 1.1 pk sc->sc_hwcurrent = sc->sc_hwdefault;
252 1.1 pk s = splbpp();
253 1.1 pk bpp_setparams(sc, &sc->sc_hwdefault);
254 1.1 pk splx(s);
255 1.1 pk
256 1.1 pk /* Enable interrupts */
257 1.1 pk irq = BPP_ALLEN;
258 1.1 pk irq |= sc->sc_hwdefault.hw_irq;
259 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
260 1.1 pk return (0);
261 1.1 pk }
262 1.1 pk
263 1.1 pk int
264 1.1 pk bppclose(dev, flags, mode, p)
265 1.1 pk dev_t dev;
266 1.1 pk int flags, mode;
267 1.1 pk struct proc *p;
268 1.1 pk {
269 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
270 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
271 1.1 pk u_int16_t irq;
272 1.1 pk
273 1.1 pk /* Turn off all interrupt enables */
274 1.1 pk irq = sc->sc_hwdefault.hw_irq | BPP_ALLIRQ;
275 1.1 pk irq &= ~BPP_ALLEN;
276 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
277 1.1 pk
278 1.1 pk sc->sc_asyncproc = NULL;
279 1.1 pk sc->sc_flags = 0;
280 1.1 pk return (0);
281 1.1 pk }
282 1.1 pk
283 1.1 pk int
284 1.1 pk bppread(dev, uio, flags)
285 1.1 pk dev_t dev;
286 1.1 pk struct uio *uio;
287 1.1 pk int flags;
288 1.1 pk {
289 1.1 pk
290 1.1 pk return (ENXIO);
291 1.1 pk }
292 1.1 pk
293 1.1 pk int
294 1.1 pk bppwrite(dev, uio, flags)
295 1.1 pk dev_t dev;
296 1.1 pk struct uio *uio;
297 1.1 pk int flags;
298 1.1 pk {
299 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
300 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
301 1.1 pk int error = 0;
302 1.1 pk int s;
303 1.1 pk
304 1.1 pk /*
305 1.2.8.1 bouyer * Wait until the DMA engine is free.
306 1.1 pk */
307 1.1 pk s = splbpp();
308 1.1 pk while ((sc->sc_flags & BPP_LOCKED) != 0) {
309 1.1 pk if ((flags & IO_NDELAY) != 0) {
310 1.1 pk splx(s);
311 1.1 pk return (EWOULDBLOCK);
312 1.1 pk }
313 1.1 pk
314 1.1 pk sc->sc_flags |= BPP_WANT;
315 1.1 pk error = tsleep(sc->sc_buf, PZERO|PCATCH, "bppwrite", 0);
316 1.1 pk if (error != 0) {
317 1.1 pk splx(s);
318 1.1 pk return (error);
319 1.1 pk }
320 1.1 pk }
321 1.1 pk sc->sc_flags |= BPP_LOCKED;
322 1.1 pk splx(s);
323 1.1 pk
324 1.1 pk /*
325 1.1 pk * Move data from user space into our private buffer
326 1.1 pk * and start DMA.
327 1.1 pk */
328 1.1 pk while (uio->uio_resid > 0) {
329 1.1 pk caddr_t bp = sc->sc_buf;
330 1.1 pk size_t len = min(sc->sc_bufsz, uio->uio_resid);
331 1.1 pk
332 1.1 pk if ((error = uiomove(bp, len, uio)) != 0)
333 1.1 pk break;
334 1.1 pk
335 1.1 pk while (len > 0) {
336 1.1 pk u_int8_t tcr;
337 1.1 pk size_t size = len;
338 1.1 pk DMA_SETUP(lsi, &bp, &len, 0, &size);
339 1.1 pk
340 1.1 pk /* Clear direction control bit */
341 1.1 pk tcr = bus_space_read_1(lsi->sc_bustag, lsi->sc_regs,
342 1.1 pk L64854_REG_TCR);
343 1.1 pk tcr &= ~BPP_TCR_DIR;
344 1.2 pk bus_space_write_1(lsi->sc_bustag, lsi->sc_regs,
345 1.2 pk L64854_REG_TCR, tcr);
346 1.1 pk
347 1.1 pk /* Enable DMA */
348 1.2.8.1 bouyer s = splbpp();
349 1.1 pk DMA_GO(lsi);
350 1.1 pk error = tsleep(sc, PZERO|PCATCH, "bppdma", 0);
351 1.2.8.1 bouyer splx(s);
352 1.1 pk if (error != 0)
353 1.1 pk goto out;
354 1.1 pk
355 1.1 pk /* Bail out if bottom half reported an error */
356 1.1 pk if ((error = sc->sc_error) != 0)
357 1.1 pk goto out;
358 1.2.8.1 bouyer
359 1.2.8.1 bouyer len -= size;
360 1.1 pk }
361 1.1 pk }
362 1.1 pk
363 1.1 pk out:
364 1.1 pk s = splbpp();
365 1.1 pk sc->sc_flags &= ~BPP_LOCKED;
366 1.1 pk if ((sc->sc_flags & BPP_WANT) != 0) {
367 1.1 pk sc->sc_flags &= ~BPP_WANT;
368 1.1 pk wakeup(sc->sc_buf);
369 1.1 pk }
370 1.1 pk splx(s);
371 1.1 pk return (error);
372 1.1 pk }
373 1.1 pk
374 1.1 pk /* move to header: */
375 1.1 pk #define BPPIOCSPARAM _IOW('P', 0x1, struct hwstate)
376 1.1 pk #define BPPIOCGPARAM _IOR('P', 0x2, struct hwstate)
377 1.1 pk
378 1.1 pk int
379 1.1 pk bppioctl(dev, cmd, data, flag, p)
380 1.1 pk dev_t dev;
381 1.1 pk u_long cmd;
382 1.1 pk caddr_t data;
383 1.1 pk int flag;
384 1.1 pk struct proc *p;
385 1.1 pk {
386 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
387 1.1 pk struct hwstate *hw, *chw;
388 1.1 pk int error = 0;
389 1.1 pk int s;
390 1.1 pk
391 1.1 pk switch(cmd) {
392 1.1 pk case BPPIOCSPARAM:
393 1.1 pk chw = &sc->sc_hwcurrent;
394 1.1 pk hw = (struct hwstate *)data;
395 1.1 pk
396 1.1 pk /*
397 1.1 pk * Extract and store user-settable bits.
398 1.1 pk */
399 1.1 pk #define _bpp_set(reg,mask) do { \
400 1.1 pk chw->reg &= ~(mask); \
401 1.1 pk chw->reg |= (hw->reg & (mask)); \
402 1.1 pk } while (0)
403 1.1 pk _bpp_set(hw_hcr, BPP_HCR_DSS_MASK|BPP_HCR_DSW_MASK);
404 1.1 pk _bpp_set(hw_ocr, BPP_OCR_USER);
405 1.1 pk _bpp_set(hw_tcr, BPP_TCR_USER);
406 1.1 pk _bpp_set(hw_or, BPP_OR_USER);
407 1.1 pk _bpp_set(hw_irq, BPP_IRQ_USER);
408 1.1 pk #undef _bpp_set
409 1.1 pk
410 1.1 pk /* Apply settings */
411 1.1 pk s = splbpp();
412 1.1 pk bpp_setparams(sc, chw);
413 1.1 pk splx(s);
414 1.1 pk break;
415 1.1 pk case BPPIOCGPARAM:
416 1.1 pk *((struct hwstate *)data) = sc->sc_hwcurrent;
417 1.1 pk break;
418 1.1 pk case TIOCEXCL:
419 1.1 pk s = splbpp();
420 1.1 pk sc->sc_flags |= BPP_XCLUDE;
421 1.1 pk splx(s);
422 1.1 pk break;
423 1.1 pk case TIOCNXCL:
424 1.1 pk s = splbpp();
425 1.1 pk sc->sc_flags &= ~BPP_XCLUDE;
426 1.1 pk splx(s);
427 1.1 pk break;
428 1.1 pk case FIOASYNC:
429 1.1 pk s = splbpp();
430 1.1 pk if (*(int *)data) {
431 1.1 pk if (sc->sc_asyncproc != NULL)
432 1.1 pk error = EBUSY;
433 1.1 pk else
434 1.1 pk sc->sc_asyncproc = p;
435 1.1 pk } else
436 1.1 pk sc->sc_asyncproc = NULL;
437 1.1 pk splx(s);
438 1.1 pk break;
439 1.1 pk default:
440 1.1 pk break;
441 1.1 pk }
442 1.1 pk
443 1.1 pk return (error);
444 1.1 pk }
445 1.1 pk
446 1.1 pk int
447 1.1 pk bpppoll(dev, events, p)
448 1.1 pk dev_t dev;
449 1.1 pk int events;
450 1.1 pk struct proc *p;
451 1.1 pk {
452 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
453 1.1 pk int revents = 0;
454 1.1 pk
455 1.1 pk if (events & (POLLIN | POLLRDNORM)) {
456 1.1 pk /* read is not yet implemented */
457 1.1 pk }
458 1.1 pk
459 1.1 pk if (events & (POLLOUT | POLLWRNORM)) {
460 1.1 pk if ((sc->sc_flags & BPP_LOCKED) == 0)
461 1.1 pk revents |= (POLLOUT | POLLWRNORM);
462 1.1 pk }
463 1.1 pk
464 1.1 pk if (revents == 0) {
465 1.1 pk if (events & (POLLIN | POLLRDNORM))
466 1.1 pk selrecord(p, &sc->sc_rsel);
467 1.1 pk if (events & (POLLOUT | POLLWRNORM))
468 1.1 pk selrecord(p, &sc->sc_wsel);
469 1.1 pk }
470 1.1 pk
471 1.1 pk return (revents);
472 1.1 pk }
473 1.1 pk
474 1.1 pk int
475 1.1 pk bppintr(arg)
476 1.1 pk void *arg;
477 1.1 pk {
478 1.1 pk struct bpp_softc *sc = arg;
479 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
480 1.1 pk u_int16_t irq;
481 1.1 pk
482 1.1 pk irq = bus_space_read_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR);
483 1.1 pk /* Ack all interrupts */
484 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR,
485 1.1 pk irq | BPP_ALLIRQ);
486 1.1 pk
487 1.1 pk /* Did our device interrupt? */
488 1.1 pk if ((irq & BPP_ALLIRQ) == 0)
489 1.1 pk return (0);
490 1.1 pk
491 1.1 pk if ((sc->sc_flags & BPP_LOCKED) != 0)
492 1.1 pk wakeup(sc);
493 1.1 pk else if ((sc->sc_flags & BPP_WANT) != 0) {
494 1.1 pk sc->sc_flags &= ~BPP_WANT;
495 1.1 pk wakeup(sc->sc_buf);
496 1.1 pk } else {
497 1.1 pk selwakeup(&sc->sc_wsel);
498 1.1 pk if (sc->sc_asyncproc != NULL)
499 1.1 pk psignal(sc->sc_asyncproc, SIGIO);
500 1.1 pk }
501 1.1 pk return (1);
502 1.1 pk }
503