bpp.c revision 1.8 1 1.8 eeh /* $NetBSD: bpp.c,v 1.8 2000/11/01 06:17:32 eeh Exp $ */
2 1.7 eeh
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.5 pk #include <machine/intr.h>
56 1.1 pk #include <machine/autoconf.h>
57 1.5 pk #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.6 eeh #ifdef DEBUG
68 1.6 eeh #define DPRINTF(x) do { if (bppdebug) printf x ; } while (0)
69 1.6 eeh int bppdebug = 1;
70 1.6 eeh #else
71 1.6 eeh #define DPRINTF(x)
72 1.6 eeh #endif
73 1.6 eeh
74 1.1 pk #if 0
75 1.1 pk struct bpp_param {
76 1.1 pk int bpp_dss; /* data setup to strobe */
77 1.1 pk int bpp_dsw; /* data strobe width */
78 1.1 pk int bpp_outputpins; /* Select/Autofeed/Init pins */
79 1.1 pk int bpp_inputpins; /* Error/Select/Paperout pins */
80 1.1 pk };
81 1.1 pk #endif
82 1.1 pk
83 1.1 pk struct hwstate {
84 1.1 pk u_int16_t hw_hcr; /* Hardware config register */
85 1.1 pk u_int16_t hw_ocr; /* Operation config register */
86 1.1 pk u_int8_t hw_tcr; /* Transfer Control register */
87 1.1 pk u_int8_t hw_or; /* Output register */
88 1.1 pk u_int16_t hw_irq; /* IRQ; polarity bits only */
89 1.1 pk };
90 1.1 pk
91 1.1 pk struct bpp_softc {
92 1.1 pk struct lsi64854_softc sc_lsi64854; /* base device */
93 1.1 pk struct sbusdev sc_sd; /* sbus device */
94 1.1 pk
95 1.1 pk size_t sc_bufsz; /* temp buffer */
96 1.1 pk caddr_t sc_buf;
97 1.1 pk
98 1.1 pk int sc_error; /* bottom-half error */
99 1.1 pk int sc_flags;
100 1.1 pk #define BPP_OPEN 0x01 /* Device is open */
101 1.1 pk #define BPP_XCLUDE 0x02 /* Exclusive-open mode */
102 1.1 pk #define BPP_ASYNC 0x04 /* Asynchronous I/O mode */
103 1.1 pk #define BPP_LOCKED 0x08 /* DMA in progress */
104 1.1 pk #define BPP_WANT 0x10 /* Waiting for DMA */
105 1.1 pk
106 1.1 pk struct selinfo sc_rsel;
107 1.1 pk struct selinfo sc_wsel;
108 1.1 pk struct proc *sc_asyncproc; /* Process to notify if async */
109 1.1 pk
110 1.1 pk /* Hardware state */
111 1.1 pk struct hwstate sc_hwdefault;
112 1.1 pk struct hwstate sc_hwcurrent;
113 1.1 pk };
114 1.1 pk
115 1.1 pk static int bppmatch __P((struct device *, struct cfdata *, void *));
116 1.1 pk static void bppattach __P((struct device *, struct device *, void *));
117 1.1 pk static int bppintr __P((void *));
118 1.1 pk static void bpp_setparams __P((struct bpp_softc *, struct hwstate *));
119 1.1 pk
120 1.1 pk struct cfattach bpp_ca = {
121 1.1 pk sizeof(struct bpp_softc), bppmatch, bppattach
122 1.1 pk };
123 1.1 pk
124 1.1 pk extern struct cfdriver bpp_cd;
125 1.1 pk #define BPPUNIT(dev) (minor(dev))
126 1.1 pk
127 1.1 pk
128 1.1 pk int
129 1.1 pk bppmatch(parent, cf, aux)
130 1.1 pk struct device *parent;
131 1.1 pk struct cfdata *cf;
132 1.1 pk void *aux;
133 1.1 pk {
134 1.1 pk struct sbus_attach_args *sa = aux;
135 1.1 pk
136 1.1 pk return (strcmp("SUNW,bpp", sa->sa_name) == 0);
137 1.1 pk }
138 1.1 pk
139 1.1 pk void
140 1.1 pk bppattach(parent, self, aux)
141 1.1 pk struct device *parent, *self;
142 1.1 pk void *aux;
143 1.1 pk {
144 1.1 pk struct sbus_attach_args *sa = aux;
145 1.1 pk struct bpp_softc *dsc = (void *)self;
146 1.1 pk struct lsi64854_softc *sc = &dsc->sc_lsi64854;
147 1.1 pk int burst, sbusburst;
148 1.1 pk int node;
149 1.1 pk
150 1.1 pk sc->sc_bustag = sa->sa_bustag;
151 1.1 pk sc->sc_dmatag = sa->sa_dmatag;
152 1.1 pk node = sa->sa_node;
153 1.1 pk
154 1.1 pk /* Map device registers */
155 1.1 pk if (bus_space_map2(sa->sa_bustag,
156 1.1 pk sa->sa_slot,
157 1.1 pk sa->sa_offset,
158 1.1 pk sa->sa_size,
159 1.1 pk BUS_SPACE_MAP_LINEAR,
160 1.1 pk 0, &sc->sc_regs) != 0) {
161 1.1 pk printf("%s: cannot map registers\n", self->dv_xname);
162 1.1 pk return;
163 1.1 pk }
164 1.1 pk
165 1.1 pk /*
166 1.1 pk * Get transfer burst size from PROM and plug it into the
167 1.1 pk * controller registers. This is needed on the Sun4m; do
168 1.1 pk * others need it too?
169 1.1 pk */
170 1.1 pk sbusburst = ((struct sbus_softc *)parent)->sc_burst;
171 1.1 pk if (sbusburst == 0)
172 1.1 pk sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
173 1.1 pk
174 1.1 pk burst = getpropint(node, "burst-sizes", -1);
175 1.1 pk if (burst == -1)
176 1.1 pk /* take SBus burst sizes */
177 1.1 pk burst = sbusburst;
178 1.1 pk
179 1.1 pk /* Clamp at parent's burst sizes */
180 1.1 pk burst &= sbusburst;
181 1.1 pk sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
182 1.1 pk (burst & SBUS_BURST_16) ? 16 : 0;
183 1.1 pk
184 1.1 pk /* Join the Sbus device family */
185 1.1 pk dsc->sc_sd.sd_reset = (void *)0;
186 1.1 pk sbus_establish(&dsc->sc_sd, self);
187 1.1 pk
188 1.1 pk /* Initialize the DMA channel */
189 1.1 pk sc->sc_channel = L64854_CHANNEL_PP;
190 1.1 pk lsi64854_attach(sc);
191 1.1 pk
192 1.3 pk /* Establish interrupt handler */
193 1.3 pk if (sa->sa_nintr) {
194 1.3 pk sc->sc_intrchain = bppintr;
195 1.3 pk sc->sc_intrchainarg = dsc;
196 1.5 pk (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY, 0,
197 1.6 eeh bppintr, sc);
198 1.3 pk }
199 1.1 pk
200 1.1 pk /* Allocate buffer XXX - should actually use dmamap_uio() */
201 1.1 pk dsc->sc_bufsz = 1024;
202 1.1 pk dsc->sc_buf = malloc(dsc->sc_bufsz, M_DEVBUF, M_NOWAIT);
203 1.1 pk
204 1.1 pk /* XXX read default state */
205 1.1 pk {
206 1.1 pk bus_space_handle_t h = sc->sc_regs;
207 1.1 pk struct hwstate *hw = &dsc->sc_hwdefault;
208 1.6 eeh int ack_rate = sa->sa_frequency/1000000;
209 1.6 eeh
210 1.1 pk hw->hw_hcr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_HCR);
211 1.1 pk hw->hw_ocr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_OCR);
212 1.1 pk hw->hw_tcr = bus_space_read_1(sc->sc_bustag, h, L64854_REG_TCR);
213 1.1 pk hw->hw_or = bus_space_read_1(sc->sc_bustag, h, L64854_REG_OR);
214 1.6 eeh
215 1.6 eeh DPRINTF(("bpp: hcr %x ocr %x tcr %x or %x\n",
216 1.6 eeh hw->hw_hcr, hw->hw_ocr, hw->hw_tcr, hw->hw_or));
217 1.6 eeh /* Set these to sane values */
218 1.6 eeh hw->hw_hcr = ((ack_rate<<BPP_HCR_DSS_SHFT)&BPP_HCR_DSS_MASK)
219 1.6 eeh | ((ack_rate<<BPP_HCR_DSW_SHFT)&BPP_HCR_DSW_MASK);
220 1.6 eeh hw->hw_ocr |= BPP_OCR_ACK_OP;
221 1.1 pk }
222 1.1 pk }
223 1.1 pk
224 1.1 pk void
225 1.1 pk bpp_setparams(sc, hw)
226 1.1 pk struct bpp_softc *sc;
227 1.1 pk struct hwstate *hw;
228 1.1 pk {
229 1.1 pk u_int16_t irq;
230 1.1 pk bus_space_tag_t t = sc->sc_lsi64854.sc_bustag;
231 1.1 pk bus_space_handle_t h = sc->sc_lsi64854.sc_regs;
232 1.1 pk
233 1.1 pk bus_space_write_2(t, h, L64854_REG_HCR, hw->hw_hcr);
234 1.1 pk bus_space_write_2(t, h, L64854_REG_OCR, hw->hw_ocr);
235 1.1 pk bus_space_write_1(t, h, L64854_REG_TCR, hw->hw_tcr);
236 1.1 pk bus_space_write_1(t, h, L64854_REG_OR, hw->hw_or);
237 1.1 pk
238 1.1 pk /* Only change IRP settings in interrupt status register */
239 1.1 pk irq = bus_space_read_2(t, h, L64854_REG_ICR);
240 1.1 pk irq &= ~BPP_ALLIRP;
241 1.1 pk irq |= (hw->hw_irq & BPP_ALLIRP);
242 1.1 pk bus_space_write_2(t, h, L64854_REG_ICR, irq);
243 1.6 eeh DPRINTF(("bpp_setparams: hcr %x ocr %x tcr %x or %x, irq %x\n",
244 1.6 eeh hw->hw_hcr, hw->hw_ocr, hw->hw_tcr, hw->hw_or, irq));
245 1.1 pk }
246 1.1 pk
247 1.1 pk int
248 1.1 pk bppopen(dev, flags, mode, p)
249 1.1 pk dev_t dev;
250 1.1 pk int flags, mode;
251 1.1 pk struct proc *p;
252 1.1 pk {
253 1.1 pk int unit = BPPUNIT(dev);
254 1.1 pk struct bpp_softc *sc;
255 1.1 pk struct lsi64854_softc *lsi;
256 1.1 pk u_int16_t irq;
257 1.1 pk int s;
258 1.1 pk
259 1.1 pk if (unit >= bpp_cd.cd_ndevs)
260 1.1 pk return (ENXIO);
261 1.1 pk sc = bpp_cd.cd_devs[unit];
262 1.1 pk
263 1.1 pk if ((sc->sc_flags & (BPP_OPEN|BPP_XCLUDE)) == (BPP_OPEN|BPP_XCLUDE))
264 1.1 pk return (EBUSY);
265 1.1 pk
266 1.1 pk lsi = &sc->sc_lsi64854;
267 1.1 pk
268 1.1 pk /* Set default parameters */
269 1.1 pk sc->sc_hwcurrent = sc->sc_hwdefault;
270 1.1 pk s = splbpp();
271 1.1 pk bpp_setparams(sc, &sc->sc_hwdefault);
272 1.1 pk splx(s);
273 1.1 pk
274 1.1 pk /* Enable interrupts */
275 1.6 eeh irq = BPP_ERR_IRQ_EN;
276 1.1 pk irq |= sc->sc_hwdefault.hw_irq;
277 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
278 1.1 pk return (0);
279 1.1 pk }
280 1.1 pk
281 1.1 pk int
282 1.1 pk bppclose(dev, flags, mode, p)
283 1.1 pk dev_t dev;
284 1.1 pk int flags, mode;
285 1.1 pk struct proc *p;
286 1.1 pk {
287 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
288 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
289 1.1 pk u_int16_t irq;
290 1.1 pk
291 1.1 pk /* Turn off all interrupt enables */
292 1.1 pk irq = sc->sc_hwdefault.hw_irq | BPP_ALLIRQ;
293 1.1 pk irq &= ~BPP_ALLEN;
294 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
295 1.1 pk
296 1.1 pk sc->sc_asyncproc = NULL;
297 1.1 pk sc->sc_flags = 0;
298 1.1 pk return (0);
299 1.1 pk }
300 1.1 pk
301 1.1 pk int
302 1.1 pk bppread(dev, uio, flags)
303 1.1 pk dev_t dev;
304 1.1 pk struct uio *uio;
305 1.1 pk int flags;
306 1.1 pk {
307 1.1 pk
308 1.1 pk return (ENXIO);
309 1.1 pk }
310 1.1 pk
311 1.1 pk int
312 1.1 pk bppwrite(dev, uio, flags)
313 1.1 pk dev_t dev;
314 1.1 pk struct uio *uio;
315 1.1 pk int flags;
316 1.1 pk {
317 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
318 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
319 1.1 pk int error = 0;
320 1.1 pk int s;
321 1.1 pk
322 1.1 pk /*
323 1.4 pk * Wait until the DMA engine is free.
324 1.1 pk */
325 1.1 pk s = splbpp();
326 1.1 pk while ((sc->sc_flags & BPP_LOCKED) != 0) {
327 1.1 pk if ((flags & IO_NDELAY) != 0) {
328 1.1 pk splx(s);
329 1.1 pk return (EWOULDBLOCK);
330 1.1 pk }
331 1.1 pk
332 1.1 pk sc->sc_flags |= BPP_WANT;
333 1.1 pk error = tsleep(sc->sc_buf, PZERO|PCATCH, "bppwrite", 0);
334 1.1 pk if (error != 0) {
335 1.1 pk splx(s);
336 1.1 pk return (error);
337 1.1 pk }
338 1.1 pk }
339 1.1 pk sc->sc_flags |= BPP_LOCKED;
340 1.1 pk splx(s);
341 1.1 pk
342 1.1 pk /*
343 1.1 pk * Move data from user space into our private buffer
344 1.1 pk * and start DMA.
345 1.1 pk */
346 1.1 pk while (uio->uio_resid > 0) {
347 1.1 pk caddr_t bp = sc->sc_buf;
348 1.1 pk size_t len = min(sc->sc_bufsz, uio->uio_resid);
349 1.1 pk
350 1.1 pk if ((error = uiomove(bp, len, uio)) != 0)
351 1.1 pk break;
352 1.1 pk
353 1.1 pk while (len > 0) {
354 1.1 pk u_int8_t tcr;
355 1.1 pk size_t size = len;
356 1.1 pk DMA_SETUP(lsi, &bp, &len, 0, &size);
357 1.6 eeh
358 1.6 eeh #ifdef DEBUG
359 1.6 eeh if (bppdebug) {
360 1.6 eeh int i;
361 1.8 eeh printf("bpp: writing %ld : ", len);
362 1.6 eeh for (i=0; i<len; i++) printf("%c(0x%x)", bp[i], bp[i]);
363 1.6 eeh printf("\n");
364 1.6 eeh }
365 1.6 eeh #endif
366 1.1 pk
367 1.1 pk /* Clear direction control bit */
368 1.1 pk tcr = bus_space_read_1(lsi->sc_bustag, lsi->sc_regs,
369 1.1 pk L64854_REG_TCR);
370 1.1 pk tcr &= ~BPP_TCR_DIR;
371 1.2 pk bus_space_write_1(lsi->sc_bustag, lsi->sc_regs,
372 1.2 pk L64854_REG_TCR, tcr);
373 1.1 pk
374 1.1 pk /* Enable DMA */
375 1.4 pk s = splbpp();
376 1.1 pk DMA_GO(lsi);
377 1.1 pk error = tsleep(sc, PZERO|PCATCH, "bppdma", 0);
378 1.4 pk splx(s);
379 1.1 pk if (error != 0)
380 1.1 pk goto out;
381 1.1 pk
382 1.1 pk /* Bail out if bottom half reported an error */
383 1.1 pk if ((error = sc->sc_error) != 0)
384 1.1 pk goto out;
385 1.4 pk
386 1.6 eeh /*
387 1.6 eeh * lsi64854_pp_intr() does this part.
388 1.6 eeh *
389 1.6 eeh * len -= size;
390 1.6 eeh */
391 1.1 pk }
392 1.1 pk }
393 1.1 pk
394 1.1 pk out:
395 1.6 eeh DPRINTF(("bpp done %x\n", error));
396 1.1 pk s = splbpp();
397 1.1 pk sc->sc_flags &= ~BPP_LOCKED;
398 1.1 pk if ((sc->sc_flags & BPP_WANT) != 0) {
399 1.1 pk sc->sc_flags &= ~BPP_WANT;
400 1.1 pk wakeup(sc->sc_buf);
401 1.1 pk }
402 1.1 pk splx(s);
403 1.1 pk return (error);
404 1.1 pk }
405 1.1 pk
406 1.1 pk /* move to header: */
407 1.1 pk #define BPPIOCSPARAM _IOW('P', 0x1, struct hwstate)
408 1.1 pk #define BPPIOCGPARAM _IOR('P', 0x2, struct hwstate)
409 1.1 pk
410 1.1 pk int
411 1.1 pk bppioctl(dev, cmd, data, flag, p)
412 1.1 pk dev_t dev;
413 1.1 pk u_long cmd;
414 1.1 pk caddr_t data;
415 1.1 pk int flag;
416 1.1 pk struct proc *p;
417 1.1 pk {
418 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
419 1.1 pk struct hwstate *hw, *chw;
420 1.1 pk int error = 0;
421 1.1 pk int s;
422 1.1 pk
423 1.1 pk switch(cmd) {
424 1.1 pk case BPPIOCSPARAM:
425 1.1 pk chw = &sc->sc_hwcurrent;
426 1.1 pk hw = (struct hwstate *)data;
427 1.1 pk
428 1.1 pk /*
429 1.1 pk * Extract and store user-settable bits.
430 1.1 pk */
431 1.1 pk #define _bpp_set(reg,mask) do { \
432 1.1 pk chw->reg &= ~(mask); \
433 1.1 pk chw->reg |= (hw->reg & (mask)); \
434 1.1 pk } while (0)
435 1.1 pk _bpp_set(hw_hcr, BPP_HCR_DSS_MASK|BPP_HCR_DSW_MASK);
436 1.1 pk _bpp_set(hw_ocr, BPP_OCR_USER);
437 1.1 pk _bpp_set(hw_tcr, BPP_TCR_USER);
438 1.1 pk _bpp_set(hw_or, BPP_OR_USER);
439 1.1 pk _bpp_set(hw_irq, BPP_IRQ_USER);
440 1.1 pk #undef _bpp_set
441 1.1 pk
442 1.1 pk /* Apply settings */
443 1.1 pk s = splbpp();
444 1.1 pk bpp_setparams(sc, chw);
445 1.1 pk splx(s);
446 1.1 pk break;
447 1.1 pk case BPPIOCGPARAM:
448 1.1 pk *((struct hwstate *)data) = sc->sc_hwcurrent;
449 1.1 pk break;
450 1.1 pk case TIOCEXCL:
451 1.1 pk s = splbpp();
452 1.1 pk sc->sc_flags |= BPP_XCLUDE;
453 1.1 pk splx(s);
454 1.1 pk break;
455 1.1 pk case TIOCNXCL:
456 1.1 pk s = splbpp();
457 1.1 pk sc->sc_flags &= ~BPP_XCLUDE;
458 1.1 pk splx(s);
459 1.1 pk break;
460 1.1 pk case FIOASYNC:
461 1.1 pk s = splbpp();
462 1.1 pk if (*(int *)data) {
463 1.1 pk if (sc->sc_asyncproc != NULL)
464 1.1 pk error = EBUSY;
465 1.1 pk else
466 1.1 pk sc->sc_asyncproc = p;
467 1.1 pk } else
468 1.1 pk sc->sc_asyncproc = NULL;
469 1.1 pk splx(s);
470 1.1 pk break;
471 1.1 pk default:
472 1.1 pk break;
473 1.1 pk }
474 1.1 pk
475 1.1 pk return (error);
476 1.1 pk }
477 1.1 pk
478 1.1 pk int
479 1.1 pk bpppoll(dev, events, p)
480 1.1 pk dev_t dev;
481 1.1 pk int events;
482 1.1 pk struct proc *p;
483 1.1 pk {
484 1.1 pk struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
485 1.1 pk int revents = 0;
486 1.1 pk
487 1.1 pk if (events & (POLLIN | POLLRDNORM)) {
488 1.1 pk /* read is not yet implemented */
489 1.1 pk }
490 1.1 pk
491 1.1 pk if (events & (POLLOUT | POLLWRNORM)) {
492 1.1 pk if ((sc->sc_flags & BPP_LOCKED) == 0)
493 1.1 pk revents |= (POLLOUT | POLLWRNORM);
494 1.1 pk }
495 1.1 pk
496 1.1 pk if (revents == 0) {
497 1.1 pk if (events & (POLLIN | POLLRDNORM))
498 1.1 pk selrecord(p, &sc->sc_rsel);
499 1.1 pk if (events & (POLLOUT | POLLWRNORM))
500 1.1 pk selrecord(p, &sc->sc_wsel);
501 1.1 pk }
502 1.1 pk
503 1.1 pk return (revents);
504 1.1 pk }
505 1.1 pk
506 1.1 pk int
507 1.1 pk bppintr(arg)
508 1.1 pk void *arg;
509 1.1 pk {
510 1.1 pk struct bpp_softc *sc = arg;
511 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
512 1.1 pk u_int16_t irq;
513 1.1 pk
514 1.6 eeh /* First handle any possible DMA interrupts */
515 1.6 eeh if (lsi64854_pp_intr((void *)lsi) == -1)
516 1.6 eeh sc->sc_error = 1;
517 1.6 eeh
518 1.1 pk irq = bus_space_read_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR);
519 1.1 pk /* Ack all interrupts */
520 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR,
521 1.1 pk irq | BPP_ALLIRQ);
522 1.1 pk
523 1.6 eeh DPRINTF(("bpp_intr: %x\n", irq));
524 1.1 pk /* Did our device interrupt? */
525 1.1 pk if ((irq & BPP_ALLIRQ) == 0)
526 1.1 pk return (0);
527 1.1 pk
528 1.1 pk if ((sc->sc_flags & BPP_LOCKED) != 0)
529 1.1 pk wakeup(sc);
530 1.1 pk else if ((sc->sc_flags & BPP_WANT) != 0) {
531 1.1 pk sc->sc_flags &= ~BPP_WANT;
532 1.1 pk wakeup(sc->sc_buf);
533 1.1 pk } else {
534 1.1 pk selwakeup(&sc->sc_wsel);
535 1.1 pk if (sc->sc_asyncproc != NULL)
536 1.1 pk psignal(sc->sc_asyncproc, SIGIO);
537 1.1 pk }
538 1.1 pk return (1);
539 1.1 pk }
540