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 * $Id: asc.c,v 1.30 1998/06/07 17:10:13 dfr Exp $
42 #include <sys/param.h>
43 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
51 #include "opt_devfs.h"
54 #include <sys/devfsext.h>
58 #include <machine/asc_ioctl.h>
60 #include <i386/isa/isa.h>
61 #include <i386/isa/isa_device.h>
62 #include <i386/isa/ascreg.h>
65 *** CONSTANTS & DEFINES
70 #define PROBE_SUCCESS IO_ASCSIZE
72 #define ATTACH_SUCCESS 1
77 #define DMA1_READY 0x08
80 # define lprintf if(scu->flags & FLAG_DEBUG) printf
82 # define lprintf (void)
85 #define TIMEOUT (hz*15) /* timeout while reading a buffer - default value */
86 #define ASCPRI PRIBIO /* priority while reading a buffer */
89 *** LAYOUT OF THE MINOR NUMBER
92 #define UNIT_MASK 0xc0 /* unit asc0 .. asc3 */
93 #define UNIT(x) (x >> 6)
94 #define DBUG_MASK 0x20
95 #define FRMT_MASK 0x18 /* output format */
96 #define FRMT_RAW 0x00 /* output bits as read from scanner */
97 #define FRMT_GRAY 0x1 /* output gray mode for color scanner */
98 #define FRMT_PBM 0x08 /* output pbm format */
102 *** THE GEMOMETRY TABLE
105 #define GREY_LINE 826 /* 825, or 826 , or 550 ??? */
106 static const struct asc_geom {
107 int dpi; /* dots per inch */
108 int dpl; /* dots per line */
109 int bpl; /* bytes per line */
110 int g_res; /* get resolution value (ASC_STAT) */
112 { 800, 3312, 414, ASC_RES_800},
113 { 700, 2896, 362, ASC_RES_700},
114 { 600, 2480, 310, ASC_RES_600},
115 { 500, 1656, 258, ASC_RES_500},
116 { 400, 1656, 207, ASC_RES_400},
117 { 300, 1240, 155, ASC_RES_300},
118 { 200, 832, 104, ASC_RES_200},
119 { 100, 416, 52, ASC_RES_100},
120 { 200, 3*GREY_LINE, 3*GREY_LINE, 0 /* returned by color scanner */},
121 { 200, GREY_LINE, GREY_LINE, 0 /* color scanner, grey mode */},
122 { INVALID, 416, 52, INVALID } /* terminator */
126 *** THE TABLE OF UNITS
132 size_t wptr; /* only changed in ascintr */
138 long thedev; /* XXX */
139 int base; /* base address */
140 int dma_num; /* dma number */
141 char dma_byte; /* mask of byte for setting DMA value */
142 char int_byte; /* mask of byte for setting int value */
143 char cfg_byte; /* mirror of byte written to config reg (ASC_CFG). */
144 char cmd_byte; /* mirror of byte written to cmd port (ASC_CMD)*/
147 #define ATTACHED 0x01
150 #define DMA_ACTIVE 0x08
151 #define SLEEPING 0x10
152 #define SEL_COLL 0x20
153 #define PBM_MODE 0x40
154 #define FLAG_DEBUG 0x80
155 int geometry; /* resolution as geomtab index */
156 int linesize; /* length of one scan line (from geom.table) */
157 int blen; /* length of buffer in lines */
158 int btime; /* timeout of buffer in seconds/hz */
160 long icnt; /* interrupt count XXX for debugging */
162 int height; /* height, for pnm modes */
163 size_t bcount; /* bytes to read, for pnm modes */
165 void *devfs_asc; /* storage for devfs tokens (handles) */
172 static struct asc_unit unittab[NASC];
174 /*** I could not find a reasonable buffer size limit other than by
175 *** experiments. MAXPHYS is obviously too much, while DEV_BSIZE and
176 *** PAGE_SIZE are really too small. There must be something wrong
177 *** with isa_dmastart/isa_dmarangecheck HELP!!!
179 *** Note, must be DEFAULT_BLEN * samples_per_line <= MAX_BUFSIZE
181 #define MAX_BUFSIZE 0xb000 /* XXX was 0x3000 */
182 #define DEFAULT_BLEN 16
185 *** THE PER-DRIVER RECORD FOR ISA.C
187 static int ascprobe (struct isa_device *isdp);
188 static int ascattach(struct isa_device *isdp);
189 struct isa_driver ascdriver = { ascprobe, ascattach, "asc" };
191 static d_open_t ascopen;
192 static d_close_t ascclose;
193 static d_read_t ascread;
194 static d_ioctl_t ascioctl;
195 static d_poll_t ascpoll;
197 #define CDEV_MAJOR 71
199 static struct cdevsw asc_cdevsw =
200 { ascopen, ascclose, ascread, nowrite, /*71*/
201 ascioctl, nostop, nullreset, nodevtotty, /* asc */
202 ascpoll, nommap, NULL, "asc", NULL, -1 };
204 #define STATIC static
207 *** LOCALLY USED SUBROUTINES
213 *** read resolution from the scanner
216 get_resolution(struct asc_unit *scu)
221 scu->cmd_byte = ASC_STANDBY;
222 outb(ASC_CMD, scu->cmd_byte);
223 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascres", hz/10);
224 for(delay= 100; (res=inb(ASC_STAT)) & ASC_RDY_FLAG; delay--)
226 i = tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascres0", 1);
227 if ( ( i == 0 ) || ( i == EWOULDBLOCK ) )
233 lprintf("asc.get_resolution: timeout completing command\n");
236 /* ... actual read resolution... */
238 for (i=0; geomtab[i].dpi != INVALID; i++) {
239 if (geomtab[i].g_res == res) break;
241 if (geomtab[i].dpi==INVALID) {
242 scu->geometry= i; /* INVALID; */
243 lprintf("asc.get_resolution: wrong resolution\n");
245 lprintf("asc.get_resolution: %d dpi\n",geomtab[i].dpi);
248 scu->portf_byte=0; /* default */
249 if (geomtab[scu->geometry].g_res==0 && !(scu->thedev&FRMT_GRAY)) {
250 /* color scanner seems to require this */
252 /* scu->geometry++; */
254 scu->linesize = geomtab[scu->geometry].bpl;
255 scu->height = geomtab[scu->geometry].dpl; /* default... */
260 *** allocate/reallocate a buffer
261 *** Now just checks that the preallocated buffer is large enough.
265 buffer_allocate(struct asc_unit *scu)
269 size = scu->blen * scu->linesize;
271 lprintf("asc.buffer_allocate: need 0x%x bytes\n", size);
273 if ( size > MAX_BUFSIZE ) {
275 size= ( (MAX_BUFSIZE+scu->linesize-1) / scu->linesize)*scu->linesize;
276 lprintf("asc.buffer_allocate: 0x%x bytes are too much, try 0x%x\n",
281 scu->sbuf.size = size;
284 scu->sbuf.count = 0; /* available data for reading */
286 lprintf("asc.buffer_allocate: ok\n");
292 *** invoked locally to start dma. Must run in a critical section
295 dma_restart(struct asc_unit *scu)
297 unsigned char al=scu->cmd_byte;
299 if (geomtab[scu->geometry].g_res==0) {/* color */
300 isa_dmastart(B_READ, scu->sbuf.base+scu->sbuf.wptr,
301 scu->linesize + 90 /* XXX */ , scu->dma_num);
303 * looks like we have to set and then clear this
304 * bit to enable the scanner to send interrupts
306 outb( ASC_CMD, al |= 4 ); /* seems to disable interrupts */
308 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
310 outb( ASC_CMD, al &= 0xfb );
312 } else { /* normal */
313 isa_dmastart(B_READ, scu->sbuf.base+scu->sbuf.wptr,
314 scu->linesize, scu->dma_num);
315 /*** this is done in sub_20, after dmastart ? ***/
317 outb( ASC_CMD, al |= 4 );
318 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
319 outb( ASC_CMD, al &= 0xfb );
322 outb( ASC_CMD, ASC_OPERATE);
325 scu->flags |= DMA_ACTIVE;
329 *** the main functions
333 *** resets the scanner and the config bytes...
336 asc_reset(struct asc_unit *scu)
338 scu->cfg_byte = 0 ; /* clear... */
339 scu->cmd_byte = 0 ; /* clear... */
341 outb(ASC_CFG,scu->cfg_byte); /* for safety, do this here */
342 outb(ASC_CMD,scu->cmd_byte); /* probably not needed */
343 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascres", hz/10); /* sleep .1 sec */
345 scu->blen = DEFAULT_BLEN;
346 scu->btime = TIMEOUT;
347 scu->height = 0 ; /* don't know better... */
349 /**************************************************************************
352 *** read status port and check for proper configuration:
353 *** - if address group matches (status byte has reasonable value)
354 *** cannot check interrupt/dma, only clear the config byte.
357 ascprobe (struct isa_device *isdp)
359 int unit = isdp->id_unit;
360 struct asc_unit *scu = unittab + unit;
363 scu->base = isdp->id_iobase; /*** needed by the following macros ***/
364 scu->flags = FLAG_DEBUG;
366 if ( isdp->id_iobase < 0 ) {
367 lprintf("asc%d.probe: no iobase given\n", unit);
371 if ((stb=inb(ASC_PROBE)) != ASC_PROBE_VALUE) {
372 lprintf("asc%d.probe: failed, got 0x%02x instead of 0x%02x\n",
373 unit, stb, ASC_PROBE_VALUE);
379 * the new AmiScan Color board uses int 10,11,12 instead of 3,5,10
380 * respectively. This means that the driver must act accordingly.
381 * Unfortunately there is no easy way of telling which board one has,
382 * other than trying to get an interrupt and noticing that it is
383 * missing. use "option ASC_NEW_BOARD" if you have a new board.
397 switch(ffs(isdp->id_irq) - 1) {
399 scu->int_byte = ASC_CNF_IRQ3;
402 scu->int_byte = ASC_CNF_IRQ5;
405 scu->int_byte = ASC_CNF_IRQ10;
410 lprintf("asc%d.probe: warning - going interruptless\n", unit);
414 lprintf("asc%d.probe: unsupported INT %d (only 3, 5, 10)\n",
415 unit, ffs(isdp->id_irq) - 1 );
418 scu->dma_num = isdp->id_drq;
419 switch(scu->dma_num) {
421 scu->dma_byte = ASC_CNF_DMA1;
424 scu->dma_byte = ASC_CNF_DMA3;
427 lprintf("asc%d.probe: unsupported DMA %d (only 1 or 3)\n",
432 /* lprintf("asc%d.probe: ok\n", unit); */
434 scu->flags &= ~FLAG_DEBUG;
436 return PROBE_SUCCESS;
439 /**************************************************************************
442 *** finish initialization of unit structure, get geometry value (?)
446 ascattach(struct isa_device *isdp)
448 int unit = isdp->id_unit;
449 struct asc_unit *scu = unittab + unit;
451 scu->flags |= FLAG_DEBUG;
452 printf("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;
473 scu->selp.si_flags=0;
474 scu->selp.si_pid=(pid_t)0;
479 devfs_add_devswf(&asc_cdevsw, unit<<6, DV_CHR, ASC_UID,
480 ASC_GID, 0666, "asc%d", unit);
482 devfs_add_devswf(&asc_cdevsw, ((unit<<6) + FRMT_PBM), DV_CHR,
483 ASC_UID, ASC_GID, 0666, "asc%dp", unit);
485 devfs_add_devswf(&asc_cdevsw, ((unit<<6) + DBUG_MASK), DV_CHR,
486 ASC_UID, ASC_GID, 0666, "asc%dd", unit);
488 devfs_add_devswf(&asc_cdevsw, ((unit<<6) + DBUG_MASK+FRMT_PBM),
489 DV_CHR, ASC_UID, ASC_GID, 0666, "asc%dpd",
492 return ATTACH_SUCCESS;
495 /**************************************************************************
498 *** the interrupt routine, at the end of DMA...
503 struct asc_unit *scu = unittab + unit;
504 int chan_bit = 0x01 << scu->dma_num;
507 /* ignore stray interrupts... */
508 if ( scu->flags & (OPEN |READING) != (OPEN | READING) ) {
509 /* must be after closing... */
510 scu->flags &= ~(OPEN | READING | DMA_ACTIVE | SLEEPING | SEL_COLL);
513 if ( (scu->flags & DMA_ACTIVE) && (inb(DMA1_READY) & chan_bit) != 0) {
514 outb( ASC_CMD, ASC_STANDBY);
515 scu->flags &= ~DMA_ACTIVE;
516 /* bounce buffers... */
517 isa_dmadone(B_READ, scu->sbuf.base+scu->sbuf.wptr,
518 scu->linesize, scu->dma_num);
519 scu->sbuf.wptr += scu->linesize;
520 if (scu->sbuf.wptr >= scu->sbuf.size) scu->sbuf.wptr=0;
521 scu->sbuf.count += scu->linesize;
522 if (scu->flags & SLEEPING) {
523 scu->flags &= ~SLEEPING;
524 wakeup((caddr_t)scu);
526 if (scu->sbuf.size - scu->sbuf.count >= scu->linesize) {
529 if (scu->selp.si_pid) {
530 selwakeup(&scu->selp);
531 scu->selp.si_pid=(pid_t)0;
532 scu->selp.si_flags = 0;
537 /**************************************************************************
540 *** set open flag, set modes according to minor number
542 *** don't switch scanner on, wait until first read or ioctls go before
546 ascopen(dev_t dev, int flags, int fmt, struct proc *p)
548 struct asc_unit *scu;
551 unit = UNIT(minor(dev)) & UNIT_MASK;
555 /* XXX lprintf isn't valid here since there is no scu. */
556 printf("asc%d.open: unconfigured unit number (max %d)\n", unit, NASC);
560 scu = unittab + unit;
561 if ( !( scu->flags & ATTACHED ) )
563 lprintf("asc%d.open: unit was not attached successfully 0x%04x\n",
568 if ( minor(dev) & DBUG_MASK )
569 scu->flags |= FLAG_DEBUG;
571 scu->flags &= ~FLAG_DEBUG;
573 switch(minor(dev) & FRMT_MASK) {
575 scu->flags |= PBM_MODE;
576 lprintf("asc%d.open: pbm mode\n", unit);
579 lprintf("asc%d.open: raw mode\n", unit);
580 scu->flags &= ~PBM_MODE;
583 lprintf("asc%d.open: gray maps are not yet supported", unit);
587 lprintf("asc%d.open: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
589 if ( scu->flags & OPEN ) {
590 lprintf("asc%d.open: already open", unit);
593 if (isa_dma_acquire(scu->dma_num))
596 scu->flags = ATTACHED | OPEN;
604 asc_startread(struct asc_unit *scu)
606 /*** from here on, things can be delayed to the first read/ioctl ***/
607 /*** this was done in sub_12... ***/
608 scu->cfg_byte= scu->cmd_byte=0; /* init scanner */
609 outb(ASC_CMD, scu->cmd_byte);
610 /*** this was done in sub_16, set scan len... ***/
611 outb(ASC_BOH, scu->portf_byte );
612 if (geomtab[scu->geometry].g_res==0) { /* color */
613 scu->cmd_byte = 0x00 ;
615 scu->cmd_byte = 0x90 ;
617 outb(ASC_CMD, scu->cmd_byte);
618 outb(ASC_LEN_L, scu->linesize & 0xff /* len_low */);
619 outb(ASC_LEN_H, (scu->linesize >>8) & 0xff /* len_high */);
620 /*** this was done in sub_21, config DMA ... ***/
621 scu->cfg_byte |= scu->dma_byte;
622 outb(ASC_CFG, scu->cfg_byte);
623 /*** sub_22: enable int on the scanner ***/
624 scu->cfg_byte |= scu->int_byte;
625 outb(ASC_CFG, scu->cfg_byte);
626 /*** sub_28: light on etc...***/
627 scu->cmd_byte = ASC_STANDBY;
628 outb(ASC_CMD, scu->cmd_byte);
629 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascstrd", hz/10); /* sleep .1 sec */
633 /**************************************************************************
636 *** turn off scanner, release the buffer
637 *** should probably terminate dma ops, release int and dma. lr 12mar95
641 ascclose(dev_t dev, int flags, int fmt, struct proc *p)
643 int unit = UNIT(minor(dev));
644 struct asc_unit *scu = unittab + unit;
646 lprintf("asc%d.close: minor %d\n",
649 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
650 lprintf("asc%d.close: unit was not attached successfully 0x%04x\n",
654 /* all this is in sub_29... */
656 outb(ASC_CFG, 0 ); /* don't save in CFG byte!!! */
657 scu->cmd_byte &= ~ASC_LIGHT_ON;
658 outb(ASC_CMD, scu->cmd_byte);/* light off */
659 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascclo", hz/2); /* sleep 1/2 sec */
660 scu->cfg_byte &= ~ scu->dma_byte ; /* disable scanner dma */
661 scu->cfg_byte &= ~ scu->int_byte ; /* disable scanner int */
662 outb(ASC_CFG, scu->cfg_byte);
663 /* --- disable dma controller ? --- */
664 isa_dma_release(scu->dma_num);
665 /* --- disable interrupts on the controller (sub_24) --- */
667 scu->sbuf.size = INVALID;
668 scu->sbuf.rptr = INVALID;
670 scu->flags &= ~(FLAG_DEBUG | OPEN | READING);
676 pbm_init(struct asc_unit *scu)
678 int width = geomtab[scu->geometry].dpl;
679 int l= sprintf(scu->sbuf.base,"P4 %d %d\n", width, scu->height);
682 scu->bcount = scu->height * width / 8 + l;
684 /* move header to end of sbuf */
685 scu->sbuf.rptr=scu->sbuf.size-l;
686 bcopy(scu->sbuf.base, scu->sbuf.base+scu->sbuf.rptr,l);
688 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
689 for(p = scu->sbuf.base + scu->sbuf.rptr; l; p++, l--)
693 /**************************************************************************
699 ascread(dev_t dev, struct uio *uio, int ioflag)
701 int unit = UNIT(minor(dev));
702 struct asc_unit *scu = unittab + unit;
707 lprintf("asc%d.read: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
709 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
710 lprintf("asc%d.read: unit was not attached successfully 0x%04x\n",
715 if ( !(scu->flags & READING) ) { /*** first read... ***/
716 /* allocate a buffer for reading data and init things */
717 if ( (res = buffer_allocate(scu)) == SUCCESS ) scu->flags |= READING;
720 if ( scu->flags & PBM_MODE ) { /* initialize for pbm mode */
725 lprintf("asc%d.read(before): "
726 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
727 unit, scu->sbuf.size, scu->sbuf.rptr,
728 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,
732 if ( scu->sbuf.count == 0 ) { /* no data avail., must wait */
733 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
734 scu->flags |= SLEEPING;
735 res = tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascread", 0);
736 scu->flags &= ~SLEEPING;
737 if ( res == 0 ) res = SUCCESS;
739 splx(sps); /* lower priority... */
740 if (scu->flags & FLAG_DEBUG)
741 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascdly",hz);
742 lprintf("asc%d.read(after): "
743 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
744 unit, scu->sbuf.size, scu->sbuf.rptr,
745 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,scu->icnt);
747 /* first, not more than available... */
748 nbytes = min( uio->uio_resid, scu->sbuf.count );
749 /* second, contiguous data... */
750 nbytes = min( nbytes, (scu->sbuf.size - scu->sbuf.rptr) );
751 /* third, one line (will remove this later, XXX) */
752 nbytes = min( nbytes, scu->linesize );
753 if ( (scu->flags & PBM_MODE) )
754 nbytes = min( nbytes, scu->bcount );
755 lprintf("asc%d.read: transferring 0x%x bytes\n", unit, nbytes);
756 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
757 lprintf("asc%d.read: invert buffer\n",unit);
758 for(p = scu->sbuf.base + scu->sbuf.rptr, res=nbytes; res; p++, res--)
761 res = uiomove(scu->sbuf.base + scu->sbuf.rptr, nbytes, uio);
762 if ( res != SUCCESS ) {
763 lprintf("asc%d.read: uiomove failed %d", unit, res);
768 scu->sbuf.rptr += nbytes;
769 if (scu->sbuf.rptr >= scu->sbuf.size) scu->sbuf.rptr=0;
770 scu->sbuf.count -= nbytes;
771 /* having moved some data, can read mode */
772 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
773 splx(sps); /* lower priority... */
774 if ( scu->flags & PBM_MODE ) scu->bcount -= nbytes;
776 lprintf("asc%d.read: size 0x%x, pointer 0x%x, bcount 0x%x, ok\n",
777 unit, scu->sbuf.size, scu->sbuf.rptr, scu->bcount);
782 /**************************************************************************
788 ascioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
790 int unit = UNIT(minor(dev));
791 struct asc_unit *scu = unittab + unit;
793 lprintf("asc%d.ioctl: minor %d\n",
796 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
797 lprintf("asc%d.ioctl: unit was not attached successfully 0x%04x\n",
805 *(int *)data=geomtab[scu->geometry].dpi;
806 lprintf("asc%d.ioctl:ASC_GRES %ddpi\n", unit, *(int *)data);
809 *(int *)data=geomtab[scu->geometry].dpl;
810 lprintf("asc%d.ioctl:ASC_GWIDTH %d\n", unit, *(int *)data);
813 *(int *)data=scu->height;
814 lprintf("asc%d.ioctl:ASC_GHEIGHT %d\n", unit, *(int *)data);
817 lprintf("asc%d.ioctl:ASC_SHEIGHT %d\n", unit, *(int *)data);
818 if ( scu->flags & READING ) {
819 lprintf("asc%d:ioctl on already reading unit\n", unit);
822 scu->height=*(int *)data;
826 *(int *)data=scu->blen;
827 lprintf("asc%d.ioctl:ASC_GBLEN %d\n", unit, *(int *)data);
830 lprintf("asc%d.ioctl:ASC_SBLEN %d\n", unit, *(int *)data);
831 if (*(int *)data * geomtab[scu->geometry].dpl / 8 > MAX_BUFSIZE)
833 lprintf("asc%d:ioctl buffer size too high\n", unit);
836 scu->blen=*(int *)data;
839 *(int *)data = scu->btime / hz;
840 lprintf("asc%d.ioctl:ASC_GBTIME %d\n", unit, *(int *)data);
843 scu->btime = *(int *)data * hz;
844 lprintf("asc%d.ioctl:ASC_SBTIME %d\n", unit, *(int *)data);
847 default: return ENOTTY;
853 ascpoll(dev_t dev, int events, struct proc *p)
855 int unit = UNIT(minor(dev));
856 struct asc_unit *scu = unittab + unit;
863 if (events & (POLLIN | POLLRDNORM))
864 if (scu->sbuf.count >0)
865 revents |= events & (POLLIN | POLLRDNORM);
867 if (!(scu->flags & DMA_ACTIVE))
870 if (scu->selp.si_pid && (p1=pfind(scu->selp.si_pid))
871 && p1->p_wchan == (caddr_t)&selwait)
872 scu->selp.si_flags = SI_COLL;
874 scu->selp.si_pid = p->p_pid;
882 static asc_devsw_installed = 0;
885 asc_drvinit(void *unused)
889 if( ! asc_devsw_installed ) {
890 dev = makedev(CDEV_MAJOR,0);
891 cdevsw_add(&dev,&asc_cdevsw,NULL);
892 asc_devsw_installed = 1;
896 SYSINIT(ascdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,asc_drvinit,NULL)
899 #endif /* NASC > 0 */