1 /* asc.c - device driver for hand scanners
3 * Current version supports:
5 * - AmiScan (Mustek) Color and BW hand scanners (GI1904 chipset)
7 * Copyright (c) 1995 Gunther Schadow. All rights reserved.
8 * Copyright (c) 1995,1996,1997 Luigi Rizzo. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 Gunther Schadow
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * $FreeBSD: src/sys/i386/isa/asc.c,v 1.42.2.2 2001/03/01 03:22:39 jlemon Exp $
38 * $DragonFly: src/sys/platform/pc32/isa/asc.c,v 1.21 2008/08/02 01:14:43 dillon Exp $
42 #include <sys/param.h>
43 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/event.h>
51 #include <sys/thread2.h>
54 #include <machine/asc_ioctl.h>
56 #include <bus/isa/isa.h>
57 #include <bus/isa/isa_device.h>
58 #include <bus/isa/isavar.h>
62 *** CONSTANTS & DEFINES
67 #define PROBE_SUCCESS IO_ASCSIZE
69 #define ATTACH_SUCCESS 1
74 #define DMA1_READY 0x08
77 # define lprintf if(scu->flags & FLAG_DEBUG) kprintf
79 # define lprintf (void)
82 #define TIMEOUT (hz*15) /* timeout while reading a buffer - default value */
85 *** LAYOUT OF THE MINOR NUMBER
88 #define UNIT_MASK 0xc0 /* unit asc0 .. asc3 */
89 #define UNIT(x) (x >> 6)
90 #define DBUG_MASK 0x20
91 #define FRMT_MASK 0x18 /* output format */
92 #define FRMT_RAW 0x00 /* output bits as read from scanner */
93 #define FRMT_GRAY 0x1 /* output gray mode for color scanner */
94 #define FRMT_PBM 0x08 /* output pbm format */
98 *** THE GEMOMETRY TABLE
101 #define GREY_LINE 826 /* 825, or 826 , or 550 ??? */
102 static const struct asc_geom {
103 int dpi; /* dots per inch */
104 int dpl; /* dots per line */
105 int bpl; /* bytes per line */
106 int g_res; /* get resolution value (ASC_STAT) */
108 { 800, 3312, 414, ASC_RES_800},
109 { 700, 2896, 362, ASC_RES_700},
110 { 600, 2480, 310, ASC_RES_600},
111 { 500, 1656, 258, ASC_RES_500},
112 { 400, 1656, 207, ASC_RES_400},
113 { 300, 1240, 155, ASC_RES_300},
114 { 200, 832, 104, ASC_RES_200},
115 { 100, 416, 52, ASC_RES_100},
116 { 200, 3*GREY_LINE, 3*GREY_LINE, 0 /* returned by color scanner */},
117 { 200, GREY_LINE, GREY_LINE, 0 /* color scanner, grey mode */},
118 { INVALID, 416, 52, INVALID } /* terminator */
122 *** THE TABLE OF UNITS
128 size_t wptr; /* only changed in ascintr */
134 long thedev; /* XXX */
135 int base; /* base address */
136 int dma_num; /* dma number */
137 char dma_byte; /* mask of byte for setting DMA value */
138 char int_byte; /* mask of byte for setting int value */
139 char cfg_byte; /* mirror of byte written to config reg (ASC_CFG). */
140 char cmd_byte; /* mirror of byte written to cmd port (ASC_CMD)*/
143 #define ATTACHED 0x01
146 #define DMA_ACTIVE 0x08
147 #define SLEEPING 0x10
148 #define SEL_COLL 0x20
149 #define PBM_MODE 0x40
150 #define FLAG_DEBUG 0x80
151 int geometry; /* resolution as geomtab index */
152 int linesize; /* length of one scan line (from geom.table) */
153 int blen; /* length of buffer in lines */
154 int btime; /* timeout of buffer in seconds/hz */
156 long icnt; /* interrupt count XXX for debugging */
158 int height; /* height, for pnm modes */
159 size_t bcount; /* bytes to read, for pnm modes */
162 static struct asc_unit unittab[NASC];
164 /*** I could not find a reasonable buffer size limit other than by
165 *** experiments. MAXPHYS is obviously too much, while DEV_BSIZE and
166 *** PAGE_SIZE are really too small. There must be something wrong
167 *** with isa_dmastart/isa_dmarangecheck HELP!!!
169 *** Note, must be DEFAULT_BLEN * samples_per_line <= MAX_BUFSIZE
171 #define MAX_BUFSIZE 0xb000 /* XXX was 0x3000 */
172 #define DEFAULT_BLEN 16
175 *** THE PER-DRIVER RECORD FOR ISA.C
177 static int ascprobe (struct isa_device *isdp);
178 static int ascattach(struct isa_device *isdp);
179 struct isa_driver ascdriver = { ascprobe, ascattach, "asc" };
181 static void ascintr(void *);
183 static d_open_t ascopen;
184 static d_close_t ascclose;
185 static d_read_t ascread;
186 static d_ioctl_t ascioctl;
187 static d_kqfilter_t asckqfilter;
189 static void ascfilter_detach(struct knote *kn);
190 static int ascfilter(struct knote *kn, long hint);
192 #define CDEV_MAJOR 71
194 static struct dev_ops asc_ops = {
195 { "asc", CDEV_MAJOR, 0 },
200 .d_kqfilter = asckqfilter
203 #define STATIC static
206 *** LOCALLY USED SUBROUTINES
212 *** read resolution from the scanner
215 get_resolution(struct asc_unit *scu)
220 scu->cmd_byte = ASC_STANDBY;
221 outb(ASC_CMD, scu->cmd_byte);
222 tsleep((caddr_t)scu, PCATCH, "ascres", hz/10);
223 for(delay= 100; (res=inb(ASC_STAT)) & ASC_RDY_FLAG; delay--)
225 i = tsleep((caddr_t)scu, PCATCH, "ascres0", 1);
226 if ( ( i == 0 ) || ( i == EWOULDBLOCK ) )
232 lprintf("asc.get_resolution: timeout completing command\n");
235 /* ... actual read resolution... */
237 for (i=0; geomtab[i].dpi != INVALID; i++) {
238 if (geomtab[i].g_res == res) break;
240 if (geomtab[i].dpi==INVALID) {
241 scu->geometry= i; /* INVALID; */
242 lprintf("asc.get_resolution: wrong resolution\n");
244 lprintf("asc.get_resolution: %d dpi\n",geomtab[i].dpi);
247 scu->portf_byte=0; /* default */
248 if (geomtab[scu->geometry].g_res==0 && !(scu->thedev&FRMT_GRAY)) {
249 /* color scanner seems to require this */
251 /* scu->geometry++; */
253 scu->linesize = geomtab[scu->geometry].bpl;
254 scu->height = geomtab[scu->geometry].dpl; /* default... */
259 *** allocate/reallocate a buffer
260 *** Now just checks that the preallocated buffer is large enough.
264 buffer_allocate(struct asc_unit *scu)
268 size = scu->blen * scu->linesize;
270 lprintf("asc.buffer_allocate: need 0x%x bytes\n", size);
272 if ( size > MAX_BUFSIZE ) {
274 size= ( (MAX_BUFSIZE+scu->linesize-1) / scu->linesize)*scu->linesize;
275 lprintf("asc.buffer_allocate: 0x%x bytes are too much, try 0x%x\n",
280 scu->sbuf.size = size;
283 scu->sbuf.count = 0; /* available data for reading */
285 lprintf("asc.buffer_allocate: ok\n");
291 *** invoked locally to start dma. Must run in a critical section
294 dma_restart(struct asc_unit *scu)
296 unsigned char al=scu->cmd_byte;
298 if (geomtab[scu->geometry].g_res==0) {/* color */
299 isa_dmastart(BUF_CMD_READ, scu->sbuf.base+scu->sbuf.wptr,
300 scu->linesize + 90 /* XXX */ , scu->dma_num);
302 * looks like we have to set and then clear this
303 * bit to enable the scanner to send interrupts
305 outb( ASC_CMD, al |= 4 ); /* seems to disable interrupts */
307 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
309 outb( ASC_CMD, al &= 0xfb );
311 } else { /* normal */
312 isa_dmastart(BUF_CMD_READ, scu->sbuf.base+scu->sbuf.wptr,
313 scu->linesize, scu->dma_num);
314 /*** this is done in sub_20, after dmastart ? ***/
316 outb( ASC_CMD, al |= 4 );
317 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
318 outb( ASC_CMD, al &= 0xfb );
321 outb( ASC_CMD, ASC_OPERATE);
324 scu->flags |= DMA_ACTIVE;
328 *** the main functions
332 *** resets the scanner and the config bytes...
335 asc_reset(struct asc_unit *scu)
337 scu->cfg_byte = 0 ; /* clear... */
338 scu->cmd_byte = 0 ; /* clear... */
340 outb(ASC_CFG,scu->cfg_byte); /* for safety, do this here */
341 outb(ASC_CMD,scu->cmd_byte); /* probably not needed */
342 tsleep((caddr_t)scu, PCATCH, "ascres", hz/10); /* sleep .1 sec */
344 scu->blen = DEFAULT_BLEN;
345 scu->btime = TIMEOUT;
346 scu->height = 0 ; /* don't know better... */
348 /**************************************************************************
351 *** read status port and check for proper configuration:
352 *** - if address group matches (status byte has reasonable value)
353 *** cannot check interrupt/dma, only clear the config byte.
356 ascprobe (struct isa_device *isdp)
358 int unit = isdp->id_unit;
359 struct asc_unit *scu = unittab + unit;
362 scu->base = isdp->id_iobase; /*** needed by the following macros ***/
363 scu->flags = FLAG_DEBUG;
365 if ( isdp->id_iobase < 0 ) {
366 lprintf("asc%d.probe: no iobase given\n", unit);
370 if ((stb=inb(ASC_PROBE)) != ASC_PROBE_VALUE) {
371 lprintf("asc%d.probe: failed, got 0x%02x instead of 0x%02x\n",
372 unit, stb, ASC_PROBE_VALUE);
378 * the new AmiScan Color board uses int 10,11,12 instead of 3,5,10
379 * respectively. This means that the driver must act accordingly.
380 * Unfortunately there is no easy way of telling which board one has,
381 * other than trying to get an interrupt and noticing that it is
382 * missing. use "option ASC_NEW_BOARD" if you have a new board.
396 switch(ffs(isdp->id_irq) - 1) {
398 scu->int_byte = ASC_CNF_IRQ3;
401 scu->int_byte = ASC_CNF_IRQ5;
404 scu->int_byte = ASC_CNF_IRQ10;
409 lprintf("asc%d.probe: warning - going interruptless\n", unit);
413 lprintf("asc%d.probe: unsupported INT %d (only 3, 5, 10)\n",
414 unit, ffs(isdp->id_irq) - 1 );
417 scu->dma_num = isdp->id_drq;
418 switch(scu->dma_num) {
420 scu->dma_byte = ASC_CNF_DMA1;
423 scu->dma_byte = ASC_CNF_DMA3;
426 lprintf("asc%d.probe: unsupported DMA %d (only 1 or 3)\n",
431 /* lprintf("asc%d.probe: ok\n", unit); */
433 scu->flags &= ~FLAG_DEBUG;
435 return PROBE_SUCCESS;
438 /**************************************************************************
441 *** finish initialization of unit structure, get geometry value (?)
445 ascattach(struct isa_device *isdp)
447 int unit = isdp->id_unit;
448 struct asc_unit *scu = unittab + unit;
450 isdp->id_intr = (inthand2_t *)ascintr;
451 scu->flags |= FLAG_DEBUG;
452 kprintf("asc%d: [GI1904/Trust Ami-Scan Grey/Color]\n", unit);
455 * Initialize buffer structure.
456 * XXX this must be done early to give a good chance of getting a
457 * contiguous buffer. This wastes memory.
459 scu->sbuf.base = contigmalloc((unsigned long)MAX_BUFSIZE, M_DEVBUF, M_NOWAIT,
460 0ul, 0xfffffful, 1ul, 0x10000ul);
461 if ( scu->sbuf.base == NULL )
463 lprintf("asc%d.attach: buffer allocation failed\n", unit);
464 return ATTACH_FAIL; /* XXX attach must not fail */
466 scu->sbuf.size = INVALID;
467 scu->sbuf.rptr = INVALID;
469 scu->flags |= ATTACHED;
470 /* lprintf("asc%d.attach: ok\n", unit); */
471 scu->flags &= ~FLAG_DEBUG;
475 make_dev(&asc_ops, unit<<6, ASC_UID, ASC_GID, 0666, "asc%d", unit);
476 make_dev(&asc_ops, ((unit<<6) + FRMT_PBM),
477 ASC_UID, ASC_GID, 0666, "asc%dp", unit);
478 make_dev(&asc_ops, ((unit<<6) + DBUG_MASK),
479 ASC_UID, ASC_GID, 0666, "asc%dd", unit);
480 make_dev(&asc_ops, ((unit<<6) + DBUG_MASK+FRMT_PBM),
481 ASC_UID, ASC_GID, 0666, "asc%dpd", unit);
482 return ATTACH_SUCCESS;
485 /**************************************************************************
488 *** the interrupt routine, at the end of DMA...
494 struct asc_unit *scu = unittab + unit;
495 int chan_bit = 0x01 << scu->dma_num;
498 /* ignore stray interrupts... */
499 if ((scu->flags & (OPEN |READING)) != (OPEN | READING) ) {
500 /* must be after closing... */
501 scu->flags &= ~(OPEN | READING | DMA_ACTIVE | SLEEPING | SEL_COLL);
504 if ( (scu->flags & DMA_ACTIVE) && (inb(DMA1_READY) & chan_bit) != 0) {
505 outb( ASC_CMD, ASC_STANDBY);
506 scu->flags &= ~DMA_ACTIVE;
507 /* bounce buffers... */
508 isa_dmadone(BUF_CMD_READ, scu->sbuf.base+scu->sbuf.wptr,
509 scu->linesize, scu->dma_num);
510 scu->sbuf.wptr += scu->linesize;
511 if (scu->sbuf.wptr >= scu->sbuf.size) scu->sbuf.wptr=0;
512 scu->sbuf.count += scu->linesize;
513 if (scu->flags & SLEEPING) {
514 scu->flags &= ~SLEEPING;
515 wakeup((caddr_t)scu);
517 if (scu->sbuf.size - scu->sbuf.count >= scu->linesize) {
520 KNOTE(&scu->kqp.ki_note, 0);
524 /**************************************************************************
527 *** set open flag, set modes according to minor number
529 *** don't switch scanner on, wait until first read or ioctls go before
533 ascopen(struct dev_open_args *ap)
535 cdev_t dev = ap->a_head.a_dev;
536 struct asc_unit *scu;
539 unit = UNIT(minor(dev)) & UNIT_MASK;
543 /* XXX lprintf isn't valid here since there is no scu. */
544 kprintf("asc%d.open: unconfigured unit number (max %d)\n", unit, NASC);
548 scu = unittab + unit;
549 if ( !( scu->flags & ATTACHED ) )
551 lprintf("asc%d.open: unit was not attached successfully 0x%04x\n",
556 if ( minor(dev) & DBUG_MASK )
557 scu->flags |= FLAG_DEBUG;
559 scu->flags &= ~FLAG_DEBUG;
561 switch(minor(dev) & FRMT_MASK) {
563 scu->flags |= PBM_MODE;
564 lprintf("asc%d.open: pbm mode\n", unit);
567 lprintf("asc%d.open: raw mode\n", unit);
568 scu->flags &= ~PBM_MODE;
571 lprintf("asc%d.open: gray maps are not yet supported", unit);
575 lprintf("asc%d.open: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
577 if ( scu->flags & OPEN ) {
578 lprintf("asc%d.open: already open", unit);
581 if (isa_dma_acquire(scu->dma_num))
584 scu->flags = ATTACHED | OPEN;
592 asc_startread(struct asc_unit *scu)
594 /*** from here on, things can be delayed to the first read/ioctl ***/
595 /*** this was done in sub_12... ***/
596 scu->cfg_byte= scu->cmd_byte=0; /* init scanner */
597 outb(ASC_CMD, scu->cmd_byte);
598 /*** this was done in sub_16, set scan len... ***/
599 outb(ASC_BOH, scu->portf_byte );
600 if (geomtab[scu->geometry].g_res==0) { /* color */
601 scu->cmd_byte = 0x00 ;
603 scu->cmd_byte = 0x90 ;
605 outb(ASC_CMD, scu->cmd_byte);
606 outb(ASC_LEN_L, scu->linesize & 0xff /* len_low */);
607 outb(ASC_LEN_H, (scu->linesize >>8) & 0xff /* len_high */);
608 /*** this was done in sub_21, config DMA ... ***/
609 scu->cfg_byte |= scu->dma_byte;
610 outb(ASC_CFG, scu->cfg_byte);
611 /*** sub_22: enable int on the scanner ***/
612 scu->cfg_byte |= scu->int_byte;
613 outb(ASC_CFG, scu->cfg_byte);
614 /*** sub_28: light on etc...***/
615 scu->cmd_byte = ASC_STANDBY;
616 outb(ASC_CMD, scu->cmd_byte);
617 tsleep((caddr_t)scu, PCATCH, "ascstrd", hz/10); /* sleep .1 sec */
621 /**************************************************************************
624 *** turn off scanner, release the buffer
625 *** should probably terminate dma ops, release int and dma. lr 12mar95
629 ascclose(struct dev_close_args *ap)
631 cdev_t dev = ap->a_head.a_dev;
632 int unit = UNIT(minor(dev));
633 struct asc_unit *scu = unittab + unit;
635 lprintf("asc%d.close: minor %d\n",
638 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
639 lprintf("asc%d.close: unit was not attached successfully 0x%04x\n",
643 /* all this is in sub_29... */
645 outb(ASC_CFG, 0 ); /* don't save in CFG byte!!! */
646 scu->cmd_byte &= ~ASC_LIGHT_ON;
647 outb(ASC_CMD, scu->cmd_byte);/* light off */
648 tsleep((caddr_t)scu, PCATCH, "ascclo", hz/2); /* sleep 1/2 sec */
649 scu->cfg_byte &= ~ scu->dma_byte ; /* disable scanner dma */
650 scu->cfg_byte &= ~ scu->int_byte ; /* disable scanner int */
651 outb(ASC_CFG, scu->cfg_byte);
652 /* --- disable dma controller ? --- */
653 isa_dma_release(scu->dma_num);
654 /* --- disable interrupts on the controller (sub_24) --- */
656 scu->sbuf.size = INVALID;
657 scu->sbuf.rptr = INVALID;
659 scu->flags &= ~(FLAG_DEBUG | OPEN | READING);
665 pbm_init(struct asc_unit *scu)
667 int width = geomtab[scu->geometry].dpl;
668 int l= ksprintf(scu->sbuf.base,"P4 %d %d\n", width, scu->height);
671 scu->bcount = scu->height * width / 8 + l;
673 /* move header to end of sbuf */
674 scu->sbuf.rptr=scu->sbuf.size-l;
675 bcopy(scu->sbuf.base, scu->sbuf.base+scu->sbuf.rptr,l);
677 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
678 for(p = scu->sbuf.base + scu->sbuf.rptr; l; p++, l--)
682 /**************************************************************************
688 ascread(struct dev_read_args *ap)
690 cdev_t dev = ap->a_head.a_dev;
691 struct uio *uio = ap->a_uio;
692 int unit = UNIT(minor(dev));
693 struct asc_unit *scu = unittab + unit;
698 lprintf("asc%d.read: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
700 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
701 lprintf("asc%d.read: unit was not attached successfully 0x%04x\n",
706 if ( !(scu->flags & READING) ) { /*** first read... ***/
707 /* allocate a buffer for reading data and init things */
708 if ( (res = buffer_allocate(scu)) == SUCCESS ) scu->flags |= READING;
711 if ( scu->flags & PBM_MODE ) { /* initialize for pbm mode */
716 lprintf("asc%d.read(before): "
717 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
718 unit, scu->sbuf.size, scu->sbuf.rptr,
719 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,
723 if ( scu->sbuf.count == 0 ) { /* no data avail., must wait */
724 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
725 scu->flags |= SLEEPING;
726 res = tsleep((caddr_t)scu, PCATCH, "ascread", 0);
727 scu->flags &= ~SLEEPING;
728 if ( res == 0 ) res = SUCCESS;
731 if (scu->flags & FLAG_DEBUG)
732 tsleep((caddr_t)scu, PCATCH, "ascdly",hz);
733 lprintf("asc%d.read(after): "
734 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
735 unit, scu->sbuf.size, scu->sbuf.rptr,
736 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,scu->icnt);
738 /* first, not more than available... */
739 nbytes = szmin(uio->uio_resid, scu->sbuf.count);
740 /* second, contiguous data... */
741 nbytes = szmin( nbytes, (scu->sbuf.size - scu->sbuf.rptr) );
742 /* third, one line (will remove this later, XXX) */
743 nbytes = szmin( nbytes, scu->linesize );
744 if ( (scu->flags & PBM_MODE) )
745 nbytes = szmin( nbytes, scu->bcount );
746 lprintf("asc%d.read: transferring 0x%x bytes\n", unit, nbytes);
747 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
748 lprintf("asc%d.read: invert buffer\n",unit);
749 for(p = scu->sbuf.base + scu->sbuf.rptr, res=nbytes; res; p++, res--)
752 res = uiomove(scu->sbuf.base + scu->sbuf.rptr, nbytes, uio);
753 if ( res != SUCCESS ) {
754 lprintf("asc%d.read: uiomove failed %d", unit, res);
759 scu->sbuf.rptr += nbytes;
760 if (scu->sbuf.rptr >= scu->sbuf.size) scu->sbuf.rptr=0;
761 scu->sbuf.count -= nbytes;
762 /* having moved some data, can read mode */
763 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
765 if ( scu->flags & PBM_MODE ) scu->bcount -= nbytes;
767 lprintf("asc%d.read: size 0x%x, pointer 0x%x, bcount 0x%x, ok\n",
768 unit, scu->sbuf.size, scu->sbuf.rptr, scu->bcount);
773 /**************************************************************************
779 ascioctl(struct dev_ioctl_args *ap)
781 cdev_t dev = ap->a_head.a_dev;
782 caddr_t data = ap->a_data;
783 int unit = UNIT(minor(dev));
784 struct asc_unit *scu = unittab + unit;
786 lprintf("asc%d.ioctl: minor %d\n",
789 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
790 lprintf("asc%d.ioctl: unit was not attached successfully 0x%04x\n",
798 *(int *)data=geomtab[scu->geometry].dpi;
799 lprintf("asc%d.ioctl:ASC_GRES %ddpi\n", unit, *(int *)data);
802 *(int *)data=geomtab[scu->geometry].dpl;
803 lprintf("asc%d.ioctl:ASC_GWIDTH %d\n", unit, *(int *)data);
806 *(int *)data=scu->height;
807 lprintf("asc%d.ioctl:ASC_GHEIGHT %d\n", unit, *(int *)data);
810 lprintf("asc%d.ioctl:ASC_SHEIGHT %d\n", unit, *(int *)data);
811 if ( scu->flags & READING ) {
812 lprintf("asc%d:ioctl on already reading unit\n", unit);
815 scu->height=*(int *)data;
819 *(int *)data=scu->blen;
820 lprintf("asc%d.ioctl:ASC_GBLEN %d\n", unit, *(int *)data);
823 lprintf("asc%d.ioctl:ASC_SBLEN %d\n", unit, *(int *)data);
824 if (*(int *)data * geomtab[scu->geometry].dpl / 8 > MAX_BUFSIZE)
826 lprintf("asc%d:ioctl buffer size too high\n", unit);
829 scu->blen=*(int *)data;
832 *(int *)data = scu->btime / hz;
833 lprintf("asc%d.ioctl:ASC_GBTIME %d\n", unit, *(int *)data);
836 scu->btime = *(int *)data * hz;
837 lprintf("asc%d.ioctl:ASC_SBTIME %d\n", unit, *(int *)data);
840 default: return ENOTTY;
845 static struct filterops ascfiltops =
846 { FILTEROP_ISFD, NULL, ascfilter_detach, ascfilter };
849 asckqfilter(struct dev_kqfilter_args *ap)
851 cdev_t dev = ap->a_head.a_dev;
852 int unit = UNIT(minor(dev));
853 struct asc_unit *scu = unittab + unit;
854 struct knote *kn = ap->a_kn;
859 switch (kn->kn_filter) {
861 kn->kn_fop = &ascfiltops;
862 kn->kn_hook = (caddr_t)scu;
865 ap->a_result = EOPNOTSUPP;
869 klist = &scu->kqp.ki_note;
870 knote_insert(klist, kn);
876 ascfilter_detach(struct knote *kn)
878 struct asc_unit *scu = (struct asc_unit *)kn->kn_hook;
881 klist = &scu->kqp.ki_note;
882 knote_remove(klist, kn);
886 ascfilter(struct knote *kn, long hint)
888 struct asc_unit *scu = (struct asc_unit *)kn->kn_hook;
892 if (scu->sbuf.count >0)
895 if (!(scu->flags & DMA_ACTIVE))