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>
50 #include <sys/selinfo.h>
52 #include <sys/thread2.h>
55 #include <machine/asc_ioctl.h>
57 #include <bus/isa/isa.h>
58 #include <bus/isa/isa_device.h>
59 #include <bus/isa/isavar.h>
63 *** CONSTANTS & DEFINES
68 #define PROBE_SUCCESS IO_ASCSIZE
70 #define ATTACH_SUCCESS 1
75 #define DMA1_READY 0x08
78 # define lprintf if(scu->flags & FLAG_DEBUG) kprintf
80 # define lprintf (void)
83 #define TIMEOUT (hz*15) /* timeout while reading a buffer - default value */
86 *** LAYOUT OF THE MINOR NUMBER
89 #define UNIT_MASK 0xc0 /* unit asc0 .. asc3 */
90 #define UNIT(x) (x >> 6)
91 #define DBUG_MASK 0x20
92 #define FRMT_MASK 0x18 /* output format */
93 #define FRMT_RAW 0x00 /* output bits as read from scanner */
94 #define FRMT_GRAY 0x1 /* output gray mode for color scanner */
95 #define FRMT_PBM 0x08 /* output pbm format */
99 *** THE GEMOMETRY TABLE
102 #define GREY_LINE 826 /* 825, or 826 , or 550 ??? */
103 static const struct asc_geom {
104 int dpi; /* dots per inch */
105 int dpl; /* dots per line */
106 int bpl; /* bytes per line */
107 int g_res; /* get resolution value (ASC_STAT) */
109 { 800, 3312, 414, ASC_RES_800},
110 { 700, 2896, 362, ASC_RES_700},
111 { 600, 2480, 310, ASC_RES_600},
112 { 500, 1656, 258, ASC_RES_500},
113 { 400, 1656, 207, ASC_RES_400},
114 { 300, 1240, 155, ASC_RES_300},
115 { 200, 832, 104, ASC_RES_200},
116 { 100, 416, 52, ASC_RES_100},
117 { 200, 3*GREY_LINE, 3*GREY_LINE, 0 /* returned by color scanner */},
118 { 200, GREY_LINE, GREY_LINE, 0 /* color scanner, grey mode */},
119 { INVALID, 416, 52, INVALID } /* terminator */
123 *** THE TABLE OF UNITS
129 size_t wptr; /* only changed in ascintr */
135 long thedev; /* XXX */
136 int base; /* base address */
137 int dma_num; /* dma number */
138 char dma_byte; /* mask of byte for setting DMA value */
139 char int_byte; /* mask of byte for setting int value */
140 char cfg_byte; /* mirror of byte written to config reg (ASC_CFG). */
141 char cmd_byte; /* mirror of byte written to cmd port (ASC_CMD)*/
144 #define ATTACHED 0x01
147 #define DMA_ACTIVE 0x08
148 #define SLEEPING 0x10
149 #define SEL_COLL 0x20
150 #define PBM_MODE 0x40
151 #define FLAG_DEBUG 0x80
152 int geometry; /* resolution as geomtab index */
153 int linesize; /* length of one scan line (from geom.table) */
154 int blen; /* length of buffer in lines */
155 int btime; /* timeout of buffer in seconds/hz */
157 long icnt; /* interrupt count XXX for debugging */
159 int height; /* height, for pnm modes */
160 size_t bcount; /* bytes to read, for pnm modes */
163 static struct asc_unit unittab[NASC];
165 /*** I could not find a reasonable buffer size limit other than by
166 *** experiments. MAXPHYS is obviously too much, while DEV_BSIZE and
167 *** PAGE_SIZE are really too small. There must be something wrong
168 *** with isa_dmastart/isa_dmarangecheck HELP!!!
170 *** Note, must be DEFAULT_BLEN * samples_per_line <= MAX_BUFSIZE
172 #define MAX_BUFSIZE 0xb000 /* XXX was 0x3000 */
173 #define DEFAULT_BLEN 16
176 *** THE PER-DRIVER RECORD FOR ISA.C
178 static int ascprobe (struct isa_device *isdp);
179 static int ascattach(struct isa_device *isdp);
180 struct isa_driver ascdriver = { ascprobe, ascattach, "asc" };
182 static void ascintr(void *);
184 static d_open_t ascopen;
185 static d_close_t ascclose;
186 static d_read_t ascread;
187 static d_ioctl_t ascioctl;
188 static d_poll_t ascpoll;
190 #define CDEV_MAJOR 71
192 static struct dev_ops asc_ops = {
193 { "asc", CDEV_MAJOR, 0 },
201 #define STATIC static
204 *** LOCALLY USED SUBROUTINES
210 *** read resolution from the scanner
213 get_resolution(struct asc_unit *scu)
218 scu->cmd_byte = ASC_STANDBY;
219 outb(ASC_CMD, scu->cmd_byte);
220 tsleep((caddr_t)scu, PCATCH, "ascres", hz/10);
221 for(delay= 100; (res=inb(ASC_STAT)) & ASC_RDY_FLAG; delay--)
223 i = tsleep((caddr_t)scu, PCATCH, "ascres0", 1);
224 if ( ( i == 0 ) || ( i == EWOULDBLOCK ) )
230 lprintf("asc.get_resolution: timeout completing command\n");
233 /* ... actual read resolution... */
235 for (i=0; geomtab[i].dpi != INVALID; i++) {
236 if (geomtab[i].g_res == res) break;
238 if (geomtab[i].dpi==INVALID) {
239 scu->geometry= i; /* INVALID; */
240 lprintf("asc.get_resolution: wrong resolution\n");
242 lprintf("asc.get_resolution: %d dpi\n",geomtab[i].dpi);
245 scu->portf_byte=0; /* default */
246 if (geomtab[scu->geometry].g_res==0 && !(scu->thedev&FRMT_GRAY)) {
247 /* color scanner seems to require this */
249 /* scu->geometry++; */
251 scu->linesize = geomtab[scu->geometry].bpl;
252 scu->height = geomtab[scu->geometry].dpl; /* default... */
257 *** allocate/reallocate a buffer
258 *** Now just checks that the preallocated buffer is large enough.
262 buffer_allocate(struct asc_unit *scu)
266 size = scu->blen * scu->linesize;
268 lprintf("asc.buffer_allocate: need 0x%x bytes\n", size);
270 if ( size > MAX_BUFSIZE ) {
272 size= ( (MAX_BUFSIZE+scu->linesize-1) / scu->linesize)*scu->linesize;
273 lprintf("asc.buffer_allocate: 0x%x bytes are too much, try 0x%x\n",
278 scu->sbuf.size = size;
281 scu->sbuf.count = 0; /* available data for reading */
283 lprintf("asc.buffer_allocate: ok\n");
289 *** invoked locally to start dma. Must run in a critical section
292 dma_restart(struct asc_unit *scu)
294 unsigned char al=scu->cmd_byte;
296 if (geomtab[scu->geometry].g_res==0) {/* color */
297 isa_dmastart(BUF_CMD_READ, scu->sbuf.base+scu->sbuf.wptr,
298 scu->linesize + 90 /* XXX */ , scu->dma_num);
300 * looks like we have to set and then clear this
301 * bit to enable the scanner to send interrupts
303 outb( ASC_CMD, al |= 4 ); /* seems to disable interrupts */
305 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
307 outb( ASC_CMD, al &= 0xfb );
309 } else { /* normal */
310 isa_dmastart(BUF_CMD_READ, scu->sbuf.base+scu->sbuf.wptr,
311 scu->linesize, scu->dma_num);
312 /*** this is done in sub_20, after dmastart ? ***/
314 outb( ASC_CMD, al |= 4 );
315 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
316 outb( ASC_CMD, al &= 0xfb );
319 outb( ASC_CMD, ASC_OPERATE);
322 scu->flags |= DMA_ACTIVE;
326 *** the main functions
330 *** resets the scanner and the config bytes...
333 asc_reset(struct asc_unit *scu)
335 scu->cfg_byte = 0 ; /* clear... */
336 scu->cmd_byte = 0 ; /* clear... */
338 outb(ASC_CFG,scu->cfg_byte); /* for safety, do this here */
339 outb(ASC_CMD,scu->cmd_byte); /* probably not needed */
340 tsleep((caddr_t)scu, PCATCH, "ascres", hz/10); /* sleep .1 sec */
342 scu->blen = DEFAULT_BLEN;
343 scu->btime = TIMEOUT;
344 scu->height = 0 ; /* don't know better... */
346 /**************************************************************************
349 *** read status port and check for proper configuration:
350 *** - if address group matches (status byte has reasonable value)
351 *** cannot check interrupt/dma, only clear the config byte.
354 ascprobe (struct isa_device *isdp)
356 int unit = isdp->id_unit;
357 struct asc_unit *scu = unittab + unit;
360 scu->base = isdp->id_iobase; /*** needed by the following macros ***/
361 scu->flags = FLAG_DEBUG;
363 if ( isdp->id_iobase < 0 ) {
364 lprintf("asc%d.probe: no iobase given\n", unit);
368 if ((stb=inb(ASC_PROBE)) != ASC_PROBE_VALUE) {
369 lprintf("asc%d.probe: failed, got 0x%02x instead of 0x%02x\n",
370 unit, stb, ASC_PROBE_VALUE);
376 * the new AmiScan Color board uses int 10,11,12 instead of 3,5,10
377 * respectively. This means that the driver must act accordingly.
378 * Unfortunately there is no easy way of telling which board one has,
379 * other than trying to get an interrupt and noticing that it is
380 * missing. use "option ASC_NEW_BOARD" if you have a new board.
394 switch(ffs(isdp->id_irq) - 1) {
396 scu->int_byte = ASC_CNF_IRQ3;
399 scu->int_byte = ASC_CNF_IRQ5;
402 scu->int_byte = ASC_CNF_IRQ10;
407 lprintf("asc%d.probe: warning - going interruptless\n", unit);
411 lprintf("asc%d.probe: unsupported INT %d (only 3, 5, 10)\n",
412 unit, ffs(isdp->id_irq) - 1 );
415 scu->dma_num = isdp->id_drq;
416 switch(scu->dma_num) {
418 scu->dma_byte = ASC_CNF_DMA1;
421 scu->dma_byte = ASC_CNF_DMA3;
424 lprintf("asc%d.probe: unsupported DMA %d (only 1 or 3)\n",
429 /* lprintf("asc%d.probe: ok\n", unit); */
431 scu->flags &= ~FLAG_DEBUG;
433 return PROBE_SUCCESS;
436 /**************************************************************************
439 *** finish initialization of unit structure, get geometry value (?)
443 ascattach(struct isa_device *isdp)
445 int unit = isdp->id_unit;
446 struct asc_unit *scu = unittab + unit;
448 isdp->id_intr = (inthand2_t *)ascintr;
449 scu->flags |= FLAG_DEBUG;
450 kprintf("asc%d: [GI1904/Trust Ami-Scan Grey/Color]\n", unit);
453 * Initialize buffer structure.
454 * XXX this must be done early to give a good chance of getting a
455 * contiguous buffer. This wastes memory.
457 scu->sbuf.base = contigmalloc((unsigned long)MAX_BUFSIZE, M_DEVBUF, M_NOWAIT,
458 0ul, 0xfffffful, 1ul, 0x10000ul);
459 if ( scu->sbuf.base == NULL )
461 lprintf("asc%d.attach: buffer allocation failed\n", unit);
462 return ATTACH_FAIL; /* XXX attach must not fail */
464 scu->sbuf.size = INVALID;
465 scu->sbuf.rptr = INVALID;
467 scu->flags |= ATTACHED;
468 /* lprintf("asc%d.attach: ok\n", unit); */
469 scu->flags &= ~FLAG_DEBUG;
471 scu->selp.si_flags=0;
472 scu->selp.si_pid=(pid_t)0;
475 dev_ops_add(&asc_ops, 0xc0, unit << 6);
476 make_dev(&asc_ops, unit<<6, ASC_UID, ASC_GID, 0666, "asc%d", unit);
477 make_dev(&asc_ops, ((unit<<6) + FRMT_PBM),
478 ASC_UID, ASC_GID, 0666, "asc%dp", unit);
479 make_dev(&asc_ops, ((unit<<6) + DBUG_MASK),
480 ASC_UID, ASC_GID, 0666, "asc%dd", unit);
481 make_dev(&asc_ops, ((unit<<6) + DBUG_MASK+FRMT_PBM),
482 ASC_UID, ASC_GID, 0666, "asc%dpd", unit);
483 return ATTACH_SUCCESS;
486 /**************************************************************************
489 *** the interrupt routine, at the end of DMA...
495 struct asc_unit *scu = unittab + unit;
496 int chan_bit = 0x01 << scu->dma_num;
499 /* ignore stray interrupts... */
500 if ((scu->flags & (OPEN |READING)) != (OPEN | READING) ) {
501 /* must be after closing... */
502 scu->flags &= ~(OPEN | READING | DMA_ACTIVE | SLEEPING | SEL_COLL);
505 if ( (scu->flags & DMA_ACTIVE) && (inb(DMA1_READY) & chan_bit) != 0) {
506 outb( ASC_CMD, ASC_STANDBY);
507 scu->flags &= ~DMA_ACTIVE;
508 /* bounce buffers... */
509 isa_dmadone(BUF_CMD_READ, scu->sbuf.base+scu->sbuf.wptr,
510 scu->linesize, scu->dma_num);
511 scu->sbuf.wptr += scu->linesize;
512 if (scu->sbuf.wptr >= scu->sbuf.size) scu->sbuf.wptr=0;
513 scu->sbuf.count += scu->linesize;
514 if (scu->flags & SLEEPING) {
515 scu->flags &= ~SLEEPING;
516 wakeup((caddr_t)scu);
518 if (scu->sbuf.size - scu->sbuf.count >= scu->linesize) {
521 if (scu->selp.si_pid) {
522 selwakeup(&scu->selp);
523 scu->selp.si_pid=(pid_t)0;
524 scu->selp.si_flags = 0;
529 /**************************************************************************
532 *** set open flag, set modes according to minor number
534 *** don't switch scanner on, wait until first read or ioctls go before
538 ascopen(struct dev_open_args *ap)
540 cdev_t dev = ap->a_head.a_dev;
541 struct asc_unit *scu;
544 unit = UNIT(minor(dev)) & UNIT_MASK;
548 /* XXX lprintf isn't valid here since there is no scu. */
549 kprintf("asc%d.open: unconfigured unit number (max %d)\n", unit, NASC);
553 scu = unittab + unit;
554 if ( !( scu->flags & ATTACHED ) )
556 lprintf("asc%d.open: unit was not attached successfully 0x%04x\n",
561 if ( minor(dev) & DBUG_MASK )
562 scu->flags |= FLAG_DEBUG;
564 scu->flags &= ~FLAG_DEBUG;
566 switch(minor(dev) & FRMT_MASK) {
568 scu->flags |= PBM_MODE;
569 lprintf("asc%d.open: pbm mode\n", unit);
572 lprintf("asc%d.open: raw mode\n", unit);
573 scu->flags &= ~PBM_MODE;
576 lprintf("asc%d.open: gray maps are not yet supported", unit);
580 lprintf("asc%d.open: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
582 if ( scu->flags & OPEN ) {
583 lprintf("asc%d.open: already open", unit);
586 if (isa_dma_acquire(scu->dma_num))
589 scu->flags = ATTACHED | OPEN;
597 asc_startread(struct asc_unit *scu)
599 /*** from here on, things can be delayed to the first read/ioctl ***/
600 /*** this was done in sub_12... ***/
601 scu->cfg_byte= scu->cmd_byte=0; /* init scanner */
602 outb(ASC_CMD, scu->cmd_byte);
603 /*** this was done in sub_16, set scan len... ***/
604 outb(ASC_BOH, scu->portf_byte );
605 if (geomtab[scu->geometry].g_res==0) { /* color */
606 scu->cmd_byte = 0x00 ;
608 scu->cmd_byte = 0x90 ;
610 outb(ASC_CMD, scu->cmd_byte);
611 outb(ASC_LEN_L, scu->linesize & 0xff /* len_low */);
612 outb(ASC_LEN_H, (scu->linesize >>8) & 0xff /* len_high */);
613 /*** this was done in sub_21, config DMA ... ***/
614 scu->cfg_byte |= scu->dma_byte;
615 outb(ASC_CFG, scu->cfg_byte);
616 /*** sub_22: enable int on the scanner ***/
617 scu->cfg_byte |= scu->int_byte;
618 outb(ASC_CFG, scu->cfg_byte);
619 /*** sub_28: light on etc...***/
620 scu->cmd_byte = ASC_STANDBY;
621 outb(ASC_CMD, scu->cmd_byte);
622 tsleep((caddr_t)scu, PCATCH, "ascstrd", hz/10); /* sleep .1 sec */
626 /**************************************************************************
629 *** turn off scanner, release the buffer
630 *** should probably terminate dma ops, release int and dma. lr 12mar95
634 ascclose(struct dev_close_args *ap)
636 cdev_t dev = ap->a_head.a_dev;
637 int unit = UNIT(minor(dev));
638 struct asc_unit *scu = unittab + unit;
640 lprintf("asc%d.close: minor %d\n",
643 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
644 lprintf("asc%d.close: unit was not attached successfully 0x%04x\n",
648 /* all this is in sub_29... */
650 outb(ASC_CFG, 0 ); /* don't save in CFG byte!!! */
651 scu->cmd_byte &= ~ASC_LIGHT_ON;
652 outb(ASC_CMD, scu->cmd_byte);/* light off */
653 tsleep((caddr_t)scu, PCATCH, "ascclo", hz/2); /* sleep 1/2 sec */
654 scu->cfg_byte &= ~ scu->dma_byte ; /* disable scanner dma */
655 scu->cfg_byte &= ~ scu->int_byte ; /* disable scanner int */
656 outb(ASC_CFG, scu->cfg_byte);
657 /* --- disable dma controller ? --- */
658 isa_dma_release(scu->dma_num);
659 /* --- disable interrupts on the controller (sub_24) --- */
661 scu->sbuf.size = INVALID;
662 scu->sbuf.rptr = INVALID;
664 scu->flags &= ~(FLAG_DEBUG | OPEN | READING);
670 pbm_init(struct asc_unit *scu)
672 int width = geomtab[scu->geometry].dpl;
673 int l= ksprintf(scu->sbuf.base,"P4 %d %d\n", width, scu->height);
676 scu->bcount = scu->height * width / 8 + l;
678 /* move header to end of sbuf */
679 scu->sbuf.rptr=scu->sbuf.size-l;
680 bcopy(scu->sbuf.base, scu->sbuf.base+scu->sbuf.rptr,l);
682 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
683 for(p = scu->sbuf.base + scu->sbuf.rptr; l; p++, l--)
687 /**************************************************************************
693 ascread(struct dev_read_args *ap)
695 cdev_t dev = ap->a_head.a_dev;
696 struct uio *uio = ap->a_uio;
697 int unit = UNIT(minor(dev));
698 struct asc_unit *scu = unittab + unit;
703 lprintf("asc%d.read: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
705 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
706 lprintf("asc%d.read: unit was not attached successfully 0x%04x\n",
711 if ( !(scu->flags & READING) ) { /*** first read... ***/
712 /* allocate a buffer for reading data and init things */
713 if ( (res = buffer_allocate(scu)) == SUCCESS ) scu->flags |= READING;
716 if ( scu->flags & PBM_MODE ) { /* initialize for pbm mode */
721 lprintf("asc%d.read(before): "
722 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
723 unit, scu->sbuf.size, scu->sbuf.rptr,
724 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,
728 if ( scu->sbuf.count == 0 ) { /* no data avail., must wait */
729 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
730 scu->flags |= SLEEPING;
731 res = tsleep((caddr_t)scu, PCATCH, "ascread", 0);
732 scu->flags &= ~SLEEPING;
733 if ( res == 0 ) res = SUCCESS;
736 if (scu->flags & FLAG_DEBUG)
737 tsleep((caddr_t)scu, PCATCH, "ascdly",hz);
738 lprintf("asc%d.read(after): "
739 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
740 unit, scu->sbuf.size, scu->sbuf.rptr,
741 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,scu->icnt);
743 /* first, not more than available... */
744 nbytes = min( uio->uio_resid, scu->sbuf.count );
745 /* second, contiguous data... */
746 nbytes = min( nbytes, (scu->sbuf.size - scu->sbuf.rptr) );
747 /* third, one line (will remove this later, XXX) */
748 nbytes = min( nbytes, scu->linesize );
749 if ( (scu->flags & PBM_MODE) )
750 nbytes = min( nbytes, scu->bcount );
751 lprintf("asc%d.read: transferring 0x%x bytes\n", unit, nbytes);
752 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
753 lprintf("asc%d.read: invert buffer\n",unit);
754 for(p = scu->sbuf.base + scu->sbuf.rptr, res=nbytes; res; p++, res--)
757 res = uiomove(scu->sbuf.base + scu->sbuf.rptr, nbytes, uio);
758 if ( res != SUCCESS ) {
759 lprintf("asc%d.read: uiomove failed %d", unit, res);
764 scu->sbuf.rptr += nbytes;
765 if (scu->sbuf.rptr >= scu->sbuf.size) scu->sbuf.rptr=0;
766 scu->sbuf.count -= nbytes;
767 /* having moved some data, can read mode */
768 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
770 if ( scu->flags & PBM_MODE ) scu->bcount -= nbytes;
772 lprintf("asc%d.read: size 0x%x, pointer 0x%x, bcount 0x%x, ok\n",
773 unit, scu->sbuf.size, scu->sbuf.rptr, scu->bcount);
778 /**************************************************************************
784 ascioctl(struct dev_ioctl_args *ap)
786 cdev_t dev = ap->a_head.a_dev;
787 caddr_t data = ap->a_data;
788 int unit = UNIT(minor(dev));
789 struct asc_unit *scu = unittab + unit;
791 lprintf("asc%d.ioctl: minor %d\n",
794 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
795 lprintf("asc%d.ioctl: unit was not attached successfully 0x%04x\n",
803 *(int *)data=geomtab[scu->geometry].dpi;
804 lprintf("asc%d.ioctl:ASC_GRES %ddpi\n", unit, *(int *)data);
807 *(int *)data=geomtab[scu->geometry].dpl;
808 lprintf("asc%d.ioctl:ASC_GWIDTH %d\n", unit, *(int *)data);
811 *(int *)data=scu->height;
812 lprintf("asc%d.ioctl:ASC_GHEIGHT %d\n", unit, *(int *)data);
815 lprintf("asc%d.ioctl:ASC_SHEIGHT %d\n", unit, *(int *)data);
816 if ( scu->flags & READING ) {
817 lprintf("asc%d:ioctl on already reading unit\n", unit);
820 scu->height=*(int *)data;
824 *(int *)data=scu->blen;
825 lprintf("asc%d.ioctl:ASC_GBLEN %d\n", unit, *(int *)data);
828 lprintf("asc%d.ioctl:ASC_SBLEN %d\n", unit, *(int *)data);
829 if (*(int *)data * geomtab[scu->geometry].dpl / 8 > MAX_BUFSIZE)
831 lprintf("asc%d:ioctl buffer size too high\n", unit);
834 scu->blen=*(int *)data;
837 *(int *)data = scu->btime / hz;
838 lprintf("asc%d.ioctl:ASC_GBTIME %d\n", unit, *(int *)data);
841 scu->btime = *(int *)data * hz;
842 lprintf("asc%d.ioctl:ASC_SBTIME %d\n", unit, *(int *)data);
845 default: return ENOTTY;
851 ascpoll(struct dev_poll_args *ap)
853 cdev_t dev = ap->a_head.a_dev;
854 int unit = UNIT(minor(dev));
855 struct asc_unit *scu = unittab + unit;
860 if (ap->a_events & (POLLIN | POLLRDNORM)) {
861 if (scu->sbuf.count >0)
862 revents |= ap->a_events & (POLLIN | POLLRDNORM);
864 if (!(scu->flags & DMA_ACTIVE))
867 selrecord(curthread, &scu->selp);
871 ap->a_events = revents;