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.31 1998/08/12 18:16:38 bde 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 ointhand2_t ascintr;
193 static d_open_t ascopen;
194 static d_close_t ascclose;
195 static d_read_t ascread;
196 static d_ioctl_t ascioctl;
197 static d_poll_t ascpoll;
199 #define CDEV_MAJOR 71
201 static struct cdevsw asc_cdevsw =
202 { ascopen, ascclose, ascread, nowrite, /*71*/
203 ascioctl, nostop, nullreset, nodevtotty, /* asc */
204 ascpoll, nommap, NULL, "asc", NULL, -1 };
206 #define STATIC static
209 *** LOCALLY USED SUBROUTINES
215 *** read resolution from the scanner
218 get_resolution(struct asc_unit *scu)
223 scu->cmd_byte = ASC_STANDBY;
224 outb(ASC_CMD, scu->cmd_byte);
225 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascres", hz/10);
226 for(delay= 100; (res=inb(ASC_STAT)) & ASC_RDY_FLAG; delay--)
228 i = tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascres0", 1);
229 if ( ( i == 0 ) || ( i == EWOULDBLOCK ) )
235 lprintf("asc.get_resolution: timeout completing command\n");
238 /* ... actual read resolution... */
240 for (i=0; geomtab[i].dpi != INVALID; i++) {
241 if (geomtab[i].g_res == res) break;
243 if (geomtab[i].dpi==INVALID) {
244 scu->geometry= i; /* INVALID; */
245 lprintf("asc.get_resolution: wrong resolution\n");
247 lprintf("asc.get_resolution: %d dpi\n",geomtab[i].dpi);
250 scu->portf_byte=0; /* default */
251 if (geomtab[scu->geometry].g_res==0 && !(scu->thedev&FRMT_GRAY)) {
252 /* color scanner seems to require this */
254 /* scu->geometry++; */
256 scu->linesize = geomtab[scu->geometry].bpl;
257 scu->height = geomtab[scu->geometry].dpl; /* default... */
262 *** allocate/reallocate a buffer
263 *** Now just checks that the preallocated buffer is large enough.
267 buffer_allocate(struct asc_unit *scu)
271 size = scu->blen * scu->linesize;
273 lprintf("asc.buffer_allocate: need 0x%x bytes\n", size);
275 if ( size > MAX_BUFSIZE ) {
277 size= ( (MAX_BUFSIZE+scu->linesize-1) / scu->linesize)*scu->linesize;
278 lprintf("asc.buffer_allocate: 0x%x bytes are too much, try 0x%x\n",
283 scu->sbuf.size = size;
286 scu->sbuf.count = 0; /* available data for reading */
288 lprintf("asc.buffer_allocate: ok\n");
294 *** invoked locally to start dma. Must run in a critical section
297 dma_restart(struct asc_unit *scu)
299 unsigned char al=scu->cmd_byte;
301 if (geomtab[scu->geometry].g_res==0) {/* color */
302 isa_dmastart(B_READ, scu->sbuf.base+scu->sbuf.wptr,
303 scu->linesize + 90 /* XXX */ , scu->dma_num);
305 * looks like we have to set and then clear this
306 * bit to enable the scanner to send interrupts
308 outb( ASC_CMD, al |= 4 ); /* seems to disable interrupts */
310 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
312 outb( ASC_CMD, al &= 0xfb );
314 } else { /* normal */
315 isa_dmastart(B_READ, scu->sbuf.base+scu->sbuf.wptr,
316 scu->linesize, scu->dma_num);
317 /*** this is done in sub_20, after dmastart ? ***/
319 outb( ASC_CMD, al |= 4 );
320 outb( ASC_CMD, al |= 8 ); /* ??? seems useless */
321 outb( ASC_CMD, al &= 0xfb );
324 outb( ASC_CMD, ASC_OPERATE);
327 scu->flags |= DMA_ACTIVE;
331 *** the main functions
335 *** resets the scanner and the config bytes...
338 asc_reset(struct asc_unit *scu)
340 scu->cfg_byte = 0 ; /* clear... */
341 scu->cmd_byte = 0 ; /* clear... */
343 outb(ASC_CFG,scu->cfg_byte); /* for safety, do this here */
344 outb(ASC_CMD,scu->cmd_byte); /* probably not needed */
345 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascres", hz/10); /* sleep .1 sec */
347 scu->blen = DEFAULT_BLEN;
348 scu->btime = TIMEOUT;
349 scu->height = 0 ; /* don't know better... */
351 /**************************************************************************
354 *** read status port and check for proper configuration:
355 *** - if address group matches (status byte has reasonable value)
356 *** cannot check interrupt/dma, only clear the config byte.
359 ascprobe (struct isa_device *isdp)
361 int unit = isdp->id_unit;
362 struct asc_unit *scu = unittab + unit;
365 scu->base = isdp->id_iobase; /*** needed by the following macros ***/
366 scu->flags = FLAG_DEBUG;
368 if ( isdp->id_iobase < 0 ) {
369 lprintf("asc%d.probe: no iobase given\n", unit);
373 if ((stb=inb(ASC_PROBE)) != ASC_PROBE_VALUE) {
374 lprintf("asc%d.probe: failed, got 0x%02x instead of 0x%02x\n",
375 unit, stb, ASC_PROBE_VALUE);
381 * the new AmiScan Color board uses int 10,11,12 instead of 3,5,10
382 * respectively. This means that the driver must act accordingly.
383 * Unfortunately there is no easy way of telling which board one has,
384 * other than trying to get an interrupt and noticing that it is
385 * missing. use "option ASC_NEW_BOARD" if you have a new board.
399 switch(ffs(isdp->id_irq) - 1) {
401 scu->int_byte = ASC_CNF_IRQ3;
404 scu->int_byte = ASC_CNF_IRQ5;
407 scu->int_byte = ASC_CNF_IRQ10;
412 lprintf("asc%d.probe: warning - going interruptless\n", unit);
416 lprintf("asc%d.probe: unsupported INT %d (only 3, 5, 10)\n",
417 unit, ffs(isdp->id_irq) - 1 );
420 scu->dma_num = isdp->id_drq;
421 switch(scu->dma_num) {
423 scu->dma_byte = ASC_CNF_DMA1;
426 scu->dma_byte = ASC_CNF_DMA3;
429 lprintf("asc%d.probe: unsupported DMA %d (only 1 or 3)\n",
434 /* lprintf("asc%d.probe: ok\n", unit); */
436 scu->flags &= ~FLAG_DEBUG;
438 return PROBE_SUCCESS;
441 /**************************************************************************
444 *** finish initialization of unit structure, get geometry value (?)
448 ascattach(struct isa_device *isdp)
450 int unit = isdp->id_unit;
451 struct asc_unit *scu = unittab + unit;
453 isdp->id_ointr = ascintr;
454 scu->flags |= FLAG_DEBUG;
455 printf("asc%d: [GI1904/Trust Ami-Scan Grey/Color]\n", unit);
458 * Initialize buffer structure.
459 * XXX this must be done early to give a good chance of getting a
460 * contiguous buffer. This wastes memory.
462 scu->sbuf.base = contigmalloc((unsigned long)MAX_BUFSIZE, M_DEVBUF, M_NOWAIT,
463 0ul, 0xfffffful, 1ul, 0x10000ul);
464 if ( scu->sbuf.base == NULL )
466 lprintf("asc%d.attach: buffer allocation failed\n", unit);
467 return ATTACH_FAIL; /* XXX attach must not fail */
469 scu->sbuf.size = INVALID;
470 scu->sbuf.rptr = INVALID;
472 scu->flags |= ATTACHED;
473 /* lprintf("asc%d.attach: ok\n", unit); */
474 scu->flags &= ~FLAG_DEBUG;
476 scu->selp.si_flags=0;
477 scu->selp.si_pid=(pid_t)0;
482 devfs_add_devswf(&asc_cdevsw, unit<<6, DV_CHR, ASC_UID,
483 ASC_GID, 0666, "asc%d", unit);
485 devfs_add_devswf(&asc_cdevsw, ((unit<<6) + FRMT_PBM), DV_CHR,
486 ASC_UID, ASC_GID, 0666, "asc%dp", unit);
488 devfs_add_devswf(&asc_cdevsw, ((unit<<6) + DBUG_MASK), DV_CHR,
489 ASC_UID, ASC_GID, 0666, "asc%dd", unit);
491 devfs_add_devswf(&asc_cdevsw, ((unit<<6) + DBUG_MASK+FRMT_PBM),
492 DV_CHR, ASC_UID, ASC_GID, 0666, "asc%dpd",
495 return ATTACH_SUCCESS;
498 /**************************************************************************
501 *** the interrupt routine, at the end of DMA...
506 struct asc_unit *scu = unittab + unit;
507 int chan_bit = 0x01 << scu->dma_num;
510 /* ignore stray interrupts... */
511 if ( scu->flags & (OPEN |READING) != (OPEN | READING) ) {
512 /* must be after closing... */
513 scu->flags &= ~(OPEN | READING | DMA_ACTIVE | SLEEPING | SEL_COLL);
516 if ( (scu->flags & DMA_ACTIVE) && (inb(DMA1_READY) & chan_bit) != 0) {
517 outb( ASC_CMD, ASC_STANDBY);
518 scu->flags &= ~DMA_ACTIVE;
519 /* bounce buffers... */
520 isa_dmadone(B_READ, scu->sbuf.base+scu->sbuf.wptr,
521 scu->linesize, scu->dma_num);
522 scu->sbuf.wptr += scu->linesize;
523 if (scu->sbuf.wptr >= scu->sbuf.size) scu->sbuf.wptr=0;
524 scu->sbuf.count += scu->linesize;
525 if (scu->flags & SLEEPING) {
526 scu->flags &= ~SLEEPING;
527 wakeup((caddr_t)scu);
529 if (scu->sbuf.size - scu->sbuf.count >= scu->linesize) {
532 if (scu->selp.si_pid) {
533 selwakeup(&scu->selp);
534 scu->selp.si_pid=(pid_t)0;
535 scu->selp.si_flags = 0;
540 /**************************************************************************
543 *** set open flag, set modes according to minor number
545 *** don't switch scanner on, wait until first read or ioctls go before
549 ascopen(dev_t dev, int flags, int fmt, struct proc *p)
551 struct asc_unit *scu;
554 unit = UNIT(minor(dev)) & UNIT_MASK;
558 /* XXX lprintf isn't valid here since there is no scu. */
559 printf("asc%d.open: unconfigured unit number (max %d)\n", unit, NASC);
563 scu = unittab + unit;
564 if ( !( scu->flags & ATTACHED ) )
566 lprintf("asc%d.open: unit was not attached successfully 0x%04x\n",
571 if ( minor(dev) & DBUG_MASK )
572 scu->flags |= FLAG_DEBUG;
574 scu->flags &= ~FLAG_DEBUG;
576 switch(minor(dev) & FRMT_MASK) {
578 scu->flags |= PBM_MODE;
579 lprintf("asc%d.open: pbm mode\n", unit);
582 lprintf("asc%d.open: raw mode\n", unit);
583 scu->flags &= ~PBM_MODE;
586 lprintf("asc%d.open: gray maps are not yet supported", unit);
590 lprintf("asc%d.open: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
592 if ( scu->flags & OPEN ) {
593 lprintf("asc%d.open: already open", unit);
596 if (isa_dma_acquire(scu->dma_num))
599 scu->flags = ATTACHED | OPEN;
607 asc_startread(struct asc_unit *scu)
609 /*** from here on, things can be delayed to the first read/ioctl ***/
610 /*** this was done in sub_12... ***/
611 scu->cfg_byte= scu->cmd_byte=0; /* init scanner */
612 outb(ASC_CMD, scu->cmd_byte);
613 /*** this was done in sub_16, set scan len... ***/
614 outb(ASC_BOH, scu->portf_byte );
615 if (geomtab[scu->geometry].g_res==0) { /* color */
616 scu->cmd_byte = 0x00 ;
618 scu->cmd_byte = 0x90 ;
620 outb(ASC_CMD, scu->cmd_byte);
621 outb(ASC_LEN_L, scu->linesize & 0xff /* len_low */);
622 outb(ASC_LEN_H, (scu->linesize >>8) & 0xff /* len_high */);
623 /*** this was done in sub_21, config DMA ... ***/
624 scu->cfg_byte |= scu->dma_byte;
625 outb(ASC_CFG, scu->cfg_byte);
626 /*** sub_22: enable int on the scanner ***/
627 scu->cfg_byte |= scu->int_byte;
628 outb(ASC_CFG, scu->cfg_byte);
629 /*** sub_28: light on etc...***/
630 scu->cmd_byte = ASC_STANDBY;
631 outb(ASC_CMD, scu->cmd_byte);
632 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascstrd", hz/10); /* sleep .1 sec */
636 /**************************************************************************
639 *** turn off scanner, release the buffer
640 *** should probably terminate dma ops, release int and dma. lr 12mar95
644 ascclose(dev_t dev, int flags, int fmt, struct proc *p)
646 int unit = UNIT(minor(dev));
647 struct asc_unit *scu = unittab + unit;
649 lprintf("asc%d.close: minor %d\n",
652 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
653 lprintf("asc%d.close: unit was not attached successfully 0x%04x\n",
657 /* all this is in sub_29... */
659 outb(ASC_CFG, 0 ); /* don't save in CFG byte!!! */
660 scu->cmd_byte &= ~ASC_LIGHT_ON;
661 outb(ASC_CMD, scu->cmd_byte);/* light off */
662 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascclo", hz/2); /* sleep 1/2 sec */
663 scu->cfg_byte &= ~ scu->dma_byte ; /* disable scanner dma */
664 scu->cfg_byte &= ~ scu->int_byte ; /* disable scanner int */
665 outb(ASC_CFG, scu->cfg_byte);
666 /* --- disable dma controller ? --- */
667 isa_dma_release(scu->dma_num);
668 /* --- disable interrupts on the controller (sub_24) --- */
670 scu->sbuf.size = INVALID;
671 scu->sbuf.rptr = INVALID;
673 scu->flags &= ~(FLAG_DEBUG | OPEN | READING);
679 pbm_init(struct asc_unit *scu)
681 int width = geomtab[scu->geometry].dpl;
682 int l= sprintf(scu->sbuf.base,"P4 %d %d\n", width, scu->height);
685 scu->bcount = scu->height * width / 8 + l;
687 /* move header to end of sbuf */
688 scu->sbuf.rptr=scu->sbuf.size-l;
689 bcopy(scu->sbuf.base, scu->sbuf.base+scu->sbuf.rptr,l);
691 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
692 for(p = scu->sbuf.base + scu->sbuf.rptr; l; p++, l--)
696 /**************************************************************************
702 ascread(dev_t dev, struct uio *uio, int ioflag)
704 int unit = UNIT(minor(dev));
705 struct asc_unit *scu = unittab + unit;
710 lprintf("asc%d.read: minor %d icnt %ld\n", unit, minor(dev), scu->icnt);
712 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
713 lprintf("asc%d.read: unit was not attached successfully 0x%04x\n",
718 if ( !(scu->flags & READING) ) { /*** first read... ***/
719 /* allocate a buffer for reading data and init things */
720 if ( (res = buffer_allocate(scu)) == SUCCESS ) scu->flags |= READING;
723 if ( scu->flags & PBM_MODE ) { /* initialize for pbm mode */
728 lprintf("asc%d.read(before): "
729 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
730 unit, scu->sbuf.size, scu->sbuf.rptr,
731 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,
735 if ( scu->sbuf.count == 0 ) { /* no data avail., must wait */
736 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
737 scu->flags |= SLEEPING;
738 res = tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascread", 0);
739 scu->flags &= ~SLEEPING;
740 if ( res == 0 ) res = SUCCESS;
742 splx(sps); /* lower priority... */
743 if (scu->flags & FLAG_DEBUG)
744 tsleep((caddr_t)scu, ASCPRI | PCATCH, "ascdly",hz);
745 lprintf("asc%d.read(after): "
746 "sz 0x%x, rptr 0x%x, wptr 0x%x, cnt 0x%x bcnt 0x%x flags 0x%x icnt %ld\n",
747 unit, scu->sbuf.size, scu->sbuf.rptr,
748 scu->sbuf.wptr, scu->sbuf.count, scu->bcount,scu->flags,scu->icnt);
750 /* first, not more than available... */
751 nbytes = min( uio->uio_resid, scu->sbuf.count );
752 /* second, contiguous data... */
753 nbytes = min( nbytes, (scu->sbuf.size - scu->sbuf.rptr) );
754 /* third, one line (will remove this later, XXX) */
755 nbytes = min( nbytes, scu->linesize );
756 if ( (scu->flags & PBM_MODE) )
757 nbytes = min( nbytes, scu->bcount );
758 lprintf("asc%d.read: transferring 0x%x bytes\n", unit, nbytes);
759 if (geomtab[scu->geometry].g_res!=0) { /* BW scanner */
760 lprintf("asc%d.read: invert buffer\n",unit);
761 for(p = scu->sbuf.base + scu->sbuf.rptr, res=nbytes; res; p++, res--)
764 res = uiomove(scu->sbuf.base + scu->sbuf.rptr, nbytes, uio);
765 if ( res != SUCCESS ) {
766 lprintf("asc%d.read: uiomove failed %d", unit, res);
771 scu->sbuf.rptr += nbytes;
772 if (scu->sbuf.rptr >= scu->sbuf.size) scu->sbuf.rptr=0;
773 scu->sbuf.count -= nbytes;
774 /* having moved some data, can read mode */
775 if (!(scu->flags & DMA_ACTIVE)) dma_restart(scu);
776 splx(sps); /* lower priority... */
777 if ( scu->flags & PBM_MODE ) scu->bcount -= nbytes;
779 lprintf("asc%d.read: size 0x%x, pointer 0x%x, bcount 0x%x, ok\n",
780 unit, scu->sbuf.size, scu->sbuf.rptr, scu->bcount);
785 /**************************************************************************
791 ascioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
793 int unit = UNIT(minor(dev));
794 struct asc_unit *scu = unittab + unit;
796 lprintf("asc%d.ioctl: minor %d\n",
799 if ( unit >= NASC || !( scu->flags & ATTACHED ) ) {
800 lprintf("asc%d.ioctl: unit was not attached successfully 0x%04x\n",
808 *(int *)data=geomtab[scu->geometry].dpi;
809 lprintf("asc%d.ioctl:ASC_GRES %ddpi\n", unit, *(int *)data);
812 *(int *)data=geomtab[scu->geometry].dpl;
813 lprintf("asc%d.ioctl:ASC_GWIDTH %d\n", unit, *(int *)data);
816 *(int *)data=scu->height;
817 lprintf("asc%d.ioctl:ASC_GHEIGHT %d\n", unit, *(int *)data);
820 lprintf("asc%d.ioctl:ASC_SHEIGHT %d\n", unit, *(int *)data);
821 if ( scu->flags & READING ) {
822 lprintf("asc%d:ioctl on already reading unit\n", unit);
825 scu->height=*(int *)data;
829 *(int *)data=scu->blen;
830 lprintf("asc%d.ioctl:ASC_GBLEN %d\n", unit, *(int *)data);
833 lprintf("asc%d.ioctl:ASC_SBLEN %d\n", unit, *(int *)data);
834 if (*(int *)data * geomtab[scu->geometry].dpl / 8 > MAX_BUFSIZE)
836 lprintf("asc%d:ioctl buffer size too high\n", unit);
839 scu->blen=*(int *)data;
842 *(int *)data = scu->btime / hz;
843 lprintf("asc%d.ioctl:ASC_GBTIME %d\n", unit, *(int *)data);
846 scu->btime = *(int *)data * hz;
847 lprintf("asc%d.ioctl:ASC_SBTIME %d\n", unit, *(int *)data);
850 default: return ENOTTY;
856 ascpoll(dev_t dev, int events, struct proc *p)
858 int unit = UNIT(minor(dev));
859 struct asc_unit *scu = unittab + unit;
866 if (events & (POLLIN | POLLRDNORM))
867 if (scu->sbuf.count >0)
868 revents |= events & (POLLIN | POLLRDNORM);
870 if (!(scu->flags & DMA_ACTIVE))
873 if (scu->selp.si_pid && (p1=pfind(scu->selp.si_pid))
874 && p1->p_wchan == (caddr_t)&selwait)
875 scu->selp.si_flags = SI_COLL;
877 scu->selp.si_pid = p->p_pid;
885 static asc_devsw_installed = 0;
888 asc_drvinit(void *unused)
892 if( ! asc_devsw_installed ) {
893 dev = makedev(CDEV_MAJOR,0);
894 cdevsw_add(&dev,&asc_cdevsw,NULL);
895 asc_devsw_installed = 1;
899 SYSINIT(ascdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,asc_drvinit,NULL)
902 #endif /* NASC > 0 */