2 * Copyright (c) 1990 William F. Jolitz, TeleMuse
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This software is a component of "386BSD" developed by
16 * William F. Jolitz, TeleMuse.
17 * 4. Neither the name of the developer nor the name "386BSD"
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
22 * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
23 * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
24 * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
25 * NOT MAKE USE OF THIS WORK.
27 * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
28 * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
29 * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
30 * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
31 * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
32 * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
33 * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
34 * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
36 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * from: unknown origin, 386BSD 0.1
49 * From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
50 * From Id: nlpt.c,v 1.14 1999/02/08 13:55:43 des Exp
51 * $Id: lpt.c,v 1.5 1999/05/31 11:24:56 phk Exp $
55 * Device Driver for AT parallel printer port
56 * Written by William Jolitz 12/18/90
60 * Updated for ppbus by Nicolas Souchu
66 #include "opt_devfs.h"
68 #include <sys/param.h>
69 #include <sys/systm.h>
72 #include <sys/kernel.h>
74 #include <sys/syslog.h>
76 #include <sys/devfsext.h>
78 #include <sys/malloc.h>
80 #include <machine/clock.h>
81 #include <machine/lpt.h>
84 #include <dev/ppbus/ppbconf.h>
85 #include <dev/ppbus/ppb_1284.h>
86 #include <dev/ppbus/lpt.h>
93 #define lprintf(args) \
98 static int volatile lptflag = 1;
101 #define LPINITRDY 4 /* wait up to 4 seconds for a ready */
102 #define LPTOUTINITIAL 10 /* initial timeout to wait for ready 1/10 s */
103 #define LPTOUTMAX 1 /* maximal timeout 1 s */
104 #define LPPRI (PZERO+8)
106 #define BUFSTATSIZE 32
108 #define LPTUNIT(s) ((s)&0x03)
109 #define LPTFLAGS(s) ((s)&0xfc)
112 unsigned short lpt_unit;
114 struct ppb_device lpt_dev;
117 /* default case: negative prime, negative ack, handshake strobe,
121 #define LP_POS_INIT 0x04 /* if we are a postive init signal */
122 #define LP_POS_ACK 0x08 /* if we are a positive going ack */
123 #define LP_NO_PRIME 0x10 /* don't prime the printer at all */
124 #define LP_PRIMEOPEN 0x20 /* prime on every open */
125 #define LP_AUTOLF 0x40 /* tell printer to do an automatic lf */
126 #define LP_BYPASS 0x80 /* bypass printer ready checks */
127 struct buf *sc_inbuf;
128 struct buf *sc_statbuf;
132 u_short sc_irq ; /* IRQ status of port */
133 #define LP_HAS_IRQ 0x01 /* we have an irq available */
134 #define LP_USE_IRQ 0x02 /* we are using our irq */
135 #define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */
136 #define LP_ENABLE_EXT 0x10 /* we shall use advanced mode when possible */
137 u_char sc_backoff ; /* time to call lptout() again */
141 void *devfs_token_ctl;
146 #define MAXLPT 8 /* XXX not much better! */
147 static struct lpt_data *lptdata[MAXLPT];
149 #define LPT_NAME "lpt" /* our official name */
151 static timeout_t lptout;
152 static int lpt_port_test(struct lpt_data *sc, u_char data, u_char mask);
153 static int lpt_detect(struct lpt_data *sc);
156 * Make ourselves visible as a ppbus driver
159 static struct ppb_device *lptprobe(struct ppb_data *ppb);
160 static int lptattach(struct ppb_device *dev);
161 static void lptintr(int unit);
163 static void lpt_intr(int unit); /* without spls */
167 static struct ppb_driver lptdriver = {
168 lptprobe, lptattach, LPT_NAME
170 DATA_SET(ppbdriver_set, lptdriver);
175 #define OPEN (1<<0) /* device is open */
176 #define ASLP (1<<1) /* awaiting draining of printer */
177 #define EERROR (1<<2) /* error was received from printer */
178 #define OBUSY (1<<3) /* printer is busy doing output */
179 #define LPTOUT (1<<4) /* timeout while not selected */
180 #define TOUT (1<<5) /* timeout while not selected */
181 #define LPTINIT (1<<6) /* waiting to initialize for open */
182 #define INTERRUPTED (1<<7) /* write call was interrupted */
184 #define HAVEBUS (1<<8) /* the driver owns the bus */
187 /* status masks to interrogate printer status */
188 #define RDY_MASK (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR) /* ready ? */
189 #define LP_READY (LPS_SEL|LPS_NBSY|LPS_NERR)
191 /* Printer Ready condition - from lpa.c */
192 /* Only used in polling code */
193 #define LPS_INVERT (LPS_NBSY | LPS_NACK | LPS_SEL | LPS_NERR)
194 #define LPS_MASK (LPS_NBSY | LPS_NACK | LPS_OUT | LPS_SEL | LPS_NERR)
195 #define NOT_READY(lpt) ((ppb_rstr(&(lpt)->lpt_dev)^LPS_INVERT)&LPS_MASK)
197 #define MAX_SLEEP (hz*5) /* Timeout while waiting for device ready */
198 #define MAX_SPIN 20 /* Max delay for device ready in usecs */
201 static d_open_t lptopen;
202 static d_close_t lptclose;
203 static d_write_t lptwrite;
204 static d_read_t lptread;
205 static d_ioctl_t lptioctl;
207 #define CDEV_MAJOR 16
208 static struct cdevsw lpt_cdevsw = {
210 /* close */ lptclose,
212 /* write */ lptwrite,
213 /* ioctl */ lptioctl,
216 /* devtotty */ nodevtotty,
219 /* strategy */ nostrategy,
222 /* maj */ CDEV_MAJOR,
231 lpt_request_ppbus(struct lpt_data *sc, int how)
235 if (sc->sc_state & HAVEBUS)
238 /* we have the bus only if the request succeded */
239 if ((error = ppb_request_bus(&sc->lpt_dev, how)) == 0)
240 sc->sc_state |= HAVEBUS;
246 lpt_release_ppbus(struct lpt_data *sc)
248 ppb_release_bus(&sc->lpt_dev);
249 sc->sc_state &= ~HAVEBUS;
255 * Internal routine to lptprobe to do port tests of one byte value
258 lpt_port_test(struct lpt_data *sc, u_char data, u_char mask)
263 ppb_wdtr(&sc->lpt_dev, data);
267 temp = ppb_rdtr(&sc->lpt_dev) & mask;
269 while (temp != data && --timeout);
270 lprintf(("out=%x\tin=%x\ttout=%d\n", data, temp, timeout));
271 return (temp == data);
275 * Probe simplified by replacing multiple loops with a hardcoded
276 * test pattern - 1999/02/08 des@freebsd.org
278 * New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94
279 * Based partially on Rod Grimes' printer probe
282 * 1) If no port address was given, use the bios detected ports
283 * and autodetect what ports the printers are on.
284 * 2) Otherwise, probe the data port at the address given,
285 * using the method in Rod Grimes' port probe.
286 * (Much code ripped off directly from Rod's probe.)
288 * Comments from Rod's probe:
290 * 1) You should be able to write to and read back the same value
291 * to the data port. Do an alternating zeros, alternating ones,
292 * walking zero, and walking one test to check for stuck bits.
294 * 2) You should be able to write to and read back the same value
295 * to the control port lower 5 bits, the upper 3 bits are reserved
296 * per the IBM PC technical reference manauls and different boards
297 * do different things with them. Do an alternating zeros, alternating
298 * ones, walking zero, and walking one test to check for stuck bits.
300 * Some printers drag the strobe line down when the are powered off
301 * so this bit has been masked out of the control port test.
303 * XXX Some printers may not like a fast pulse on init or strobe, I
304 * don't know at this point, if that becomes a problem these bits
305 * should be turned off in the mask byte for the control port test.
307 * We are finally left with a mask of 0x14, due to some printers
308 * being adamant about holding other bits high ........
310 * Before probing the control port, we write a 0 to the data port -
311 * If not, some printers chuck out garbage when the strobe line
314 * 3) Set the data and control ports to a value of 0
316 * This probe routine has been tested on Epson Lx-800, HP LJ3P,
317 * Epson FX-1170 and C.Itoh 8510RM
319 * Quick exit on fail added.
322 lpt_detect(struct lpt_data *sc)
324 static u_char testbyte[18] = {
325 0x55, /* alternating zeros */
326 0xaa, /* alternating ones */
327 0xfe, 0xfd, 0xfb, 0xf7,
328 0xef, 0xdf, 0xbf, 0x7f, /* walking zero */
329 0x01, 0x02, 0x04, 0x08,
330 0x10, 0x20, 0x40, 0x80 /* walking one */
332 int i, error, status;
334 status = 1; /* assume success */
336 if ((error = lpt_request_ppbus(sc, PPB_DONTWAIT))) {
337 printf(LPT_NAME ": cannot alloc ppbus (%d)!\n", error);
342 for (i = 0; i < 18 && status; i++)
343 if (!lpt_port_test(sc, testbyte[i], 0xff)) {
349 /* write 0's to control and data ports */
350 ppb_wdtr(&sc->lpt_dev, 0);
351 ppb_wctr(&sc->lpt_dev, 0);
353 lpt_release_ppbus(sc);
361 static struct ppb_device *
362 lptprobe(struct ppb_data *ppb)
368 cdevsw_add(&lpt_cdevsw);
370 sc = (struct lpt_data *) malloc(sizeof(struct lpt_data),
373 printf(LPT_NAME ": cannot malloc!\n");
376 bzero(sc, sizeof(struct lpt_data));
381 * lpt dependent initialisation.
386 * ppbus dependent initialisation.
388 sc->lpt_dev.id_unit = sc->lpt_unit;
389 sc->lpt_dev.name = lptdriver.name;
390 sc->lpt_dev.ppb = ppb;
391 sc->lpt_dev.intr = lptintr;
394 * Now, try to detect the printer.
396 if (!lpt_detect(sc)) {
401 /* Ok, go to next device on next probe */
404 return (&sc->lpt_dev);
408 lptattach(struct ppb_device *dev)
410 struct lpt_data *sc = lptdata[dev->id_unit];
416 printf(LPT_NAME "%d: <generic printer> on ppbus %d\n",
417 dev->id_unit, dev->ppb->ppb_link->adapter_unit);
419 sc->sc_primed = 0; /* not primed yet */
421 if ((error = lpt_request_ppbus(sc, PPB_DONTWAIT))) {
422 printf(LPT_NAME ": cannot alloc ppbus (%d)!\n", error);
426 ppb_wctr(&sc->lpt_dev, LPC_NINIT);
428 /* check if we can use interrupt, should be done by ppc stuff */
429 lprintf(("oldirq %x\n", sc->sc_irq));
430 if (ppb_get_irq(&sc->lpt_dev)) {
431 sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ;
432 printf(LPT_NAME "%d: Interrupt-driven port\n", dev->id_unit);
435 lprintf((LPT_NAME "%d: Polled port\n", dev->id_unit));
437 lprintf(("irq %x\n", sc->sc_irq));
439 lpt_release_ppbus(sc);
442 sc->devfs_token = devfs_add_devswf(&lpt_cdevsw,
443 dev->id_unit, DV_CHR,
444 UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d", dev->id_unit);
445 sc->devfs_token_ctl = devfs_add_devswf(&lpt_cdevsw,
446 dev->id_unit | LP_BYPASS, DV_CHR,
447 UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d.ctl", dev->id_unit);
456 struct lpt_data *sc = arg;
459 lprintf(("T %x ", ppb_rstr(&sc->lpt_dev)));
460 if (sc->sc_state & OPEN) {
462 if (sc->sc_backoff > hz/LPTOUTMAX)
463 sc->sc_backoff = sc->sc_backoff > hz/LPTOUTMAX;
464 timeout(lptout, (caddr_t)sc, sc->sc_backoff);
466 sc->sc_state &= ~TOUT;
468 if (sc->sc_state & EERROR)
469 sc->sc_state &= ~EERROR;
472 * Avoid possible hangs do to missed interrupts
474 if (sc->sc_xfercnt) {
476 lpt_intr(sc->lpt_unit);
479 sc->sc_state &= ~OBUSY;
485 * lptopen -- reset the printer, then wait until it's selected and not busy.
486 * If LP_BYPASS flag is selected, then we do not try to select the
487 * printer -- this is just used for passing ioctls.
491 lptopen(dev_t dev, int flags, int fmt, struct proc *p)
497 u_int unit = LPTUNIT(minor(dev));
505 lprintf((LPT_NAME ": still open %x\n", sc->sc_state));
508 sc->sc_state |= LPTINIT;
510 sc->sc_flags = LPTFLAGS(minor(dev));
512 /* Check for open with BYPASS flag set. */
513 if (sc->sc_flags & LP_BYPASS) {
518 /* request the ppbus only if we don't have it already */
519 if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0)
523 lprintf((LPT_NAME " flags 0x%x\n", sc->sc_flags));
525 /* set IRQ status according to ENABLE_IRQ flag */
526 if (sc->sc_irq & LP_ENABLE_IRQ)
527 sc->sc_irq |= LP_USE_IRQ;
529 sc->sc_irq &= ~LP_USE_IRQ;
532 if ((sc->sc_flags & LP_NO_PRIME) == 0) {
533 if((sc->sc_flags & LP_PRIMEOPEN) || sc->sc_primed == 0) {
534 ppb_wctr(&sc->lpt_dev, 0);
540 ppb_wctr(&sc->lpt_dev, LPC_SEL|LPC_NINIT);
542 /* wait till ready (printer running diagnostics) */
545 /* ran out of waiting for the printer */
546 if (trys++ >= LPINITRDY*4) {
549 lprintf(("status %x\n", ppb_rstr(&sc->lpt_dev)));
551 lpt_release_ppbus(sc);
555 /* wait 1/4 second, give up if we get a signal */
556 if (tsleep((caddr_t)sc, LPPRI|PCATCH, "lptinit", hz/4) !=
561 lpt_release_ppbus(sc);
565 /* is printer online and ready for output */
566 } while ((ppb_rstr(&sc->lpt_dev) &
567 (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
568 (LPS_SEL|LPS_NBSY|LPS_NERR));
570 sc->sc_control = LPC_SEL|LPC_NINIT;
571 if (sc->sc_flags & LP_AUTOLF)
572 sc->sc_control |= LPC_AUTOL;
574 /* enable interrupt if interrupt-driven */
575 if (sc->sc_irq & LP_USE_IRQ)
576 sc->sc_control |= LPC_ENA;
578 ppb_wctr(&sc->lpt_dev, sc->sc_control);
581 sc->sc_inbuf = geteblk(BUFSIZE);
582 sc->sc_statbuf = geteblk(BUFSTATSIZE);
586 /* release the ppbus */
587 lpt_release_ppbus(sc);
589 /* only use timeout if using interrupt */
590 lprintf(("irq %x\n", sc->sc_irq));
591 if (sc->sc_irq & LP_USE_IRQ) {
592 sc->sc_state |= TOUT;
593 timeout(lptout, (caddr_t)sc,
594 (sc->sc_backoff = hz/LPTOUTINITIAL));
597 lprintf(("opened.\n"));
602 * lptclose -- close the device, free the local line buffer.
604 * Check for interrupted write call added.
608 lptclose(dev_t dev, int flags, int fmt, struct proc *p)
610 struct lpt_data *sc = lptdata[LPTUNIT(minor(dev))];
613 if(sc->sc_flags & LP_BYPASS)
616 if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0)
619 sc->sc_state &= ~OPEN;
621 /* if the last write was interrupted, don't complete it */
622 if((!(sc->sc_state & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ))
623 while ((ppb_rstr(&sc->lpt_dev) &
624 (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
625 (LPS_SEL|LPS_NBSY|LPS_NERR) || sc->sc_xfercnt)
626 /* wait 1/4 second, give up if we get a signal */
627 if (tsleep((caddr_t)sc, LPPRI|PCATCH,
628 "lpclose", hz) != EWOULDBLOCK)
631 ppb_wctr(&sc->lpt_dev, LPC_NINIT);
632 brelse(sc->sc_inbuf);
633 brelse(sc->sc_statbuf);
636 /* release the bus anyway */
637 lpt_release_ppbus(sc);
641 lprintf(("closed.\n"));
647 * Workhorse for actually spinning and writing bytes to printer
651 * This code is only used when we are polling the port
654 lpt_pushbytes(struct lpt_data *sc)
660 /* loop for every character .. */
661 while (sc->sc_xfercnt > 0) {
668 * Wait for printer ready.
669 * Loop 20 usecs testing BUSY bit, then sleep
670 * for exponentially increasing timeout. (vak)
672 for (spin = 0; NOT_READY(sc) && spin < MAX_SPIN; ++spin)
673 DELAY(1); /* XXX delay is NOT this accurate! */
674 if (spin >= MAX_SPIN) {
676 while (NOT_READY(sc)) {
678 * Now sleep, every cycle a
683 * But no more than 10 seconds. (vak)
687 err = tsleep((caddr_t)sc, LPPRI,
688 LPT_NAME "poll", tic);
689 if (err != EWOULDBLOCK) {
696 ppb_wdtr(&sc->lpt_dev, ch);
698 ppb_wctr(&sc->lpt_dev, sc->sc_control|LPC_STB);
699 ppb_wctr(&sc->lpt_dev, sc->sc_control);
706 * lptread --retrieve printer status in IEEE1284 NIBBLE mode
710 lptread(dev_t dev, struct uio *uio, int ioflag)
712 struct lpt_data *sc = lptdata[LPTUNIT(minor(dev))];
715 if ((error = ppb_1284_negociate(&sc->lpt_dev, PPB_NIBBLE, 0)))
718 /* read data in an other buffer, read/write may be simultaneous */
720 while (uio->uio_resid) {
721 if ((error = ppb_1284_read(&sc->lpt_dev, PPB_NIBBLE,
722 sc->sc_statbuf->b_data, min(BUFSTATSIZE,
723 uio->uio_resid), &len))) {
728 goto error; /* no more data */
730 if ((error = uiomove(sc->sc_statbuf->b_data, len, uio)))
735 ppb_1284_terminate(&sc->lpt_dev);
740 * lptwrite --copy a line from user space to a local buffer, then call
741 * putc to get the chars moved to the output queue.
743 * Flagging of interrupted write added.
747 lptwrite(dev_t dev, struct uio *uio, int ioflag)
751 u_int unit = LPTUNIT(minor(dev));
752 struct lpt_data *sc = lptdata[LPTUNIT(minor(dev))];
754 if(sc->sc_flags & LP_BYPASS) {
755 /* we can't do writes in bypass mode */
759 /* request the ppbus only if we don't have it already */
760 if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0)
763 sc->sc_state &= ~INTERRUPTED;
764 while ((n = min(BUFSIZE, uio->uio_resid)) != 0) {
765 sc->sc_cp = sc->sc_inbuf->b_data ;
766 uiomove(sc->sc_cp, n, uio);
769 if (sc->sc_irq & LP_ENABLE_EXT) {
770 /* try any extended mode */
771 err = ppb_write(&sc->lpt_dev, sc->sc_cp,
775 /* if not all data was sent, we could rely
776 * on polling for the last bytes */
780 sc->sc_state |= INTERRUPTED;
783 /* advanced mode not avail */
784 log(LOG_NOTICE, LPT_NAME "%d: advanced mode not avail, polling\n", unit);
789 } else while ((sc->sc_xfercnt > 0)&&(sc->sc_irq & LP_USE_IRQ)) {
791 /* if the printer is ready for a char, */
793 if ((sc->sc_state & OBUSY) == 0){
794 lprintf(("\nC %d. ", sc->sc_xfercnt));
796 lpt_intr(sc->lpt_unit);
800 if (sc->sc_state & OBUSY)
801 if ((err = tsleep((caddr_t)sc,
802 LPPRI|PCATCH, LPT_NAME "write", 0))) {
803 sc->sc_state |= INTERRUPTED;
808 /* check to see if we must do a polled write */
809 if(!(sc->sc_irq & LP_USE_IRQ) && (sc->sc_xfercnt)) {
812 err = lpt_pushbytes(sc);
819 /* we have not been interrupted, release the ppbus */
820 lpt_release_ppbus(sc);
826 * lpt_intr -- handle printer interrupts which occur when the printer is
827 * ready to accept another char.
829 * do checking for interrupted write call.
835 struct lpt_data *sc = lptdata[unit];
839 /* we must own the bus to use it */
840 if ((sc->sc_state & HAVEBUS) == 0)
844 * Is printer online and ready for output?
846 * Avoid falling back to lptout() too quickly. First spin-loop
847 * to see if the printer will become ready ``really soon now''.
849 for (i = 0; i < 100 &&
850 ((sts=ppb_rstr(&sc->lpt_dev)) & RDY_MASK) != LP_READY; i++) ;
852 if ((sts & RDY_MASK) == LP_READY) {
853 sc->sc_state = (sc->sc_state | OBUSY) & ~EERROR;
854 sc->sc_backoff = hz/LPTOUTINITIAL;
856 if (sc->sc_xfercnt) {
858 /*lprintf(("%x ", *sc->sc_cp)); */
859 ppb_wdtr(&sc->lpt_dev, *sc->sc_cp++) ;
860 ppb_wctr(&sc->lpt_dev, sc->sc_control|LPC_STB);
862 ppb_wctr(&sc->lpt_dev, sc->sc_control);
864 /* any more data for printer */
865 if(--(sc->sc_xfercnt) > 0) return;
869 * No more data waiting for printer.
870 * Wakeup is not done if write call was interrupted.
872 sc->sc_state &= ~OBUSY;
874 if(!(sc->sc_state & INTERRUPTED))
878 } else { /* check for error */
879 if(((sts & (LPS_NERR | LPS_OUT) ) != LPS_NERR) &&
880 (sc->sc_state & OPEN))
881 sc->sc_state |= EERROR;
882 /* lptout() will jump in and try to restart. */
884 lprintf(("sts %x ", sts));
890 /* call the interrupt at required spl level */
900 lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
904 u_int unit = LPTUNIT(minor(dev));
905 u_char old_sc_irq; /* old printer IRQ status */
911 if(sc->sc_irq & LP_HAS_IRQ) {
914 * If the IRQ status is changed,
915 * this will only be visible on the
918 * If interrupt status changes,
919 * this gets syslog'd.
921 old_sc_irq = sc->sc_irq;
922 switch(*(int*)data) {
924 sc->sc_irq &= (~LP_ENABLE_IRQ);
927 sc->sc_irq &= (~LP_ENABLE_EXT);
928 sc->sc_irq |= LP_ENABLE_IRQ;
931 /* classic irq based transfer and advanced
932 * modes are in conflict
934 sc->sc_irq &= (~LP_ENABLE_IRQ);
935 sc->sc_irq |= LP_ENABLE_EXT;
938 sc->sc_irq &= (~LP_ENABLE_EXT);
944 if (old_sc_irq != sc->sc_irq )
945 log(LOG_NOTICE, LPT_NAME "%d: switched to %s %s mode\n",
947 (sc->sc_irq & LP_ENABLE_IRQ)?
948 "interrupt-driven":"polled",
949 (sc->sc_irq & LP_ENABLE_EXT)?
950 "extended":"standard");
951 } else /* polled port */