* Copyright (c) 1990 William F. Jolitz, TeleMuse
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This software is a component of "386BSD" developed by
* William F. Jolitz, TeleMuse.
* 4. Neither the name of the developer nor the name "386BSD"
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
* AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
* SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
* THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
* NOT MAKE USE OF THIS WORK.
* FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
* BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
* REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
* (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
* JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
* LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
* ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
* OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
* -------------------- ----- ----------------------
* CURRENT PATCH LEVEL: 2 00164
* -------------------- ----- ----------------------
* 06 Apr 93 Eric Haug Fixed comments and includes. [Ed: I did
* not include the unit-1 thing, that is a
* DOSism, fixed the config file instead]
* 06 Apr 93 Rodney W. Grimes A real probe routine, may even cause on
* interrupt if a printer is attached.
* 01 Jun 93 Rodney W. Grimes Made lpflag uniq now is lptflag
* Added timeout loop to lpt_port_test.
* lpt_port_test should move to a common
* Device Driver for AT parallel printer port
* Written by William Jolitz 12/18/90
#include "i386/isa/isa.h"
#include "i386/isa/isa_device.h"
#include "i386/isa/lptreg.h"
#define LPINITRDY 4 /* wait up to 4 seconds for a ready */
#define LPTOUTTIME 4 /* wait up to 4 seconds for a ready */
#define lprintf if (lptflag) printf
int lptprobe(), lptattach();
struct isa_driver lptdriver
= {
lptprobe
, lptattach
, "lpt"
#define LPTUNIT(s) (((s)>>6)&0x3)
#define LPTFLAGS(s) ((s)&0x3f)
/* default case: negative prime, negative ack, handshake strobe,
#define LP_POS_INIT 0x01 /* if we are a postive init signal */
#define LP_POS_ACK 0x02 /* if we are a positive going ack */
#define LP_NO_PRIME 0x04 /* don't prime the printer at all */
#define LP_PRIMEOPEN 0x08 /* prime on every open */
#define LP_AUTOLF 0x10 /* tell printer to do an automatic lf */
#define LP_BYPASS 0x20 /* bypass printer ready checks */
#define OPEN (1<<0) /* device is open */
#define ASLP (1<<1) /* awaiting draining of printer */
#define ERROR (1<<2) /* error was received from printer */
#define OBUSY (1<<3) /* printer is busy doing output */
#define LPTOUT (1<<4) /* timeout while not selected */
#define TOUT (1<<5) /* timeout while not selected */
#define INIT (1<<6) /* waiting to initialize for open */
* Internal routine to lptprobe to do port tests of one byte value
lpt_port_test(port
, data
, mask
)
while (temp
!= data
&& --timeout
);
lprintf("Port 0x%x\tout=%x\tin=%x\n", port
, data
, temp
);
* New lptprobe routine written by Rodney W. Grimes, 3/25/1993
* 1) You should be able to write to and read back the same value
* to the data port. Do an alternating zeros, alternating ones,
* walking zero, and walking one test to check for stuck bits.
* 2) You should be able to write to and read back the same value
* to the control port lower 5 bits, the upper 3 bits are reserved
* per the IBM PC technical reference manauls and different boards
* do different things with them. Do an alternating zeros, alternating
* ones, walking zero, and walking one test to check for stuck bits.
* Some printers drag the strobe line down when the are powered off
* so this bit has been masked out of the control port test.
* XXX Some printers may not like a fast pulse on init or strobe, I
* don't know at this point, if that becomes a problem these bits
* should be turned off in the mask byte for the control port test.
* 3) Set the data and control ports to a value of 0
port
= dvp
->id_iobase
+ lpt_data
;
data
= 0x55; /* Alternating zeros */
if (!lpt_port_test(port
, data
, mask
)) status
= 0;
data
= 0xaa; /* Alternating ones */
if (!lpt_port_test(port
, data
, mask
)) status
= 0;
for (i
= 0; i
< 8; i
++) /* Walking zero */
if (!lpt_port_test(port
, data
, mask
)) status
= 0;
for (i
= 0; i
< 8; i
++) /* Walking one */
if (!lpt_port_test(port
, data
, mask
)) status
= 0;
if (port
== dvp
->id_iobase
+ lpt_data
)
port
= dvp
->id_iobase
+ lpt_control
;
outb(dvp
->id_iobase
+lpt_data
, 0);
outb(dvp
->id_iobase
+lpt_control
, 0);
sc
= lpt_sc
+ isdp
->id_unit
;
sc
->sc_port
= isdp
->id_iobase
;
outb(sc
->sc_port
+lpt_control
, LPC_NINIT
);
* lptopen -- reset the printer, then wait until it's selected and not busy.
u_int unit
= LPTUNIT(minor(dev
));
lprintf("lp: still open\n") ;
lprintf("still open %x\n", sc
->sc_state
);
} else sc
->sc_state
|= INIT
;
sc
->sc_flags
= LPTFLAGS(minor(dev
));
lprintf("lp flags 0x%x\n", sc
->sc_flags
);
if((sc
->sc_flags
& LP_NO_PRIME
) == 0) {
if((sc
->sc_flags
& LP_PRIMEOPEN
) || sc
->sc_primed
== 0) {
outb(port
+lpt_control
, 0);
outb(port
+lpt_control
, LPC_SEL
|LPC_NINIT
);
/* wait till ready (printer running diagnostics) */
/* ran out of waiting for the printer */
if (trys
++ >= LPINITRDY
*4) {
lprintf ("status %x\n", inb(port
+lpt_status
) );
/* wait 1/4 second, give up if we get a signal */
if (tsleep (sc
, LPPRI
|PCATCH
, "lptinit", hz
/4) != EWOULDBLOCK
) {
/* is printer online and ready for output */
} while ((inb(port
+lpt_status
) & (LPS_SEL
|LPS_OUT
|LPS_NBSY
|LPS_NERR
)) !=
(LPS_SEL
|LPS_NBSY
|LPS_NERR
));
if(sc
->sc_flags
&LP_AUTOLF
) {
outb(port
+lpt_control
, LPC_SEL
|LPC_NINIT
|LPC_ENA
|LPC_AUTOL
);
sc
->sc_control
= LPC_SEL
|LPC_NINIT
|LPC_ENA
|LPC_AUTOL
;
outb(port
+lpt_control
, LPC_SEL
|LPC_NINIT
|LPC_ENA
);
sc
->sc_control
= LPC_SEL
|LPC_NINIT
|LPC_ENA
;
sc
->sc_state
= OPEN
| TOUT
;
sc
->sc_inbuf
= geteblk(BUFSIZE
);
timeout (lptout
, sc
, hz
/2);
lprintf ("T %x ", inb(sc
->sc_port
+lpt_status
));
timeout (lptout
, sc
, hz
/2);
else sc
->sc_state
&= ~TOUT
;
if (sc
->sc_state
& ERROR
)
* Avoid possible hangs do to missed interrupts
* lptclose -- close the device, free the local line buffer.
struct lpt_softc
*sc
= lpt_sc
+ LPTUNIT(minor(dev
));
while ((inb(port
+lpt_status
) & (LPS_SEL
|LPS_OUT
|LPS_NBSY
|LPS_NERR
)) !=
(LPS_SEL
|LPS_NBSY
|LPS_NERR
) || sc
->sc_xfercnt
)
/* wait 1/4 second, give up if we get a signal */
if (tsleep (sc
, LPPRI
|PCATCH
, "lpclose", hz
) != EWOULDBLOCK
)
outb(sc
->sc_port
+lpt_control
, LPC_NINIT
);
* lptwrite --copy a line from user space to a local buffer, then call
* putc to get the chars moved to the output queue.
struct lpt_softc
*sc
= lpt_sc
+ LPTUNIT(minor(dev
));
while (n
= MIN(BUFSIZE
, uio
->uio_resid
)) {
sc
->sc_cp
= sc
->sc_inbuf
->b_un
.b_addr
;
uiomove(sc
->sc_cp
, n
, uio
);
while (sc
->sc_xfercnt
> 0) {
/* if the printer is ready for a char, give it one */
if ((sc
->sc_state
& OBUSY
) == 0){
lprintf("\nC %d. ", sc
->sc_xfercnt
);
if (err
= tsleep (sc
, LPPRI
|PCATCH
, "lpwrite", 0))
* lptintr -- handle printer interrupts which occur when the printer is
* ready to accept another char.
struct lpt_softc
*sc
= lpt_sc
+ unit
;
int port
= sc
->sc_port
,sts
;
/* is printer online and ready for output */
if (((sts
=inb(port
+lpt_status
)) & (LPS_SEL
|LPS_OUT
|LPS_NBSY
|LPS_NERR
/*|LPS_NACK*/)) ==
(LPS_SEL
|LPS_NBSY
|LPS_NERR
)) {
/* is this a false interrupt ? */
if ((sc
->sc_state
& OBUSY
)
&& (sts
& LPS_NACK
) == 0) return;
sc
->sc_state
|= OBUSY
; sc
->sc_state
&= ~ERROR
;
/*lprintf("%x ", *sc->sc_cp); */
outb(port
+lpt_data
, *sc
->sc_cp
++) ; sc
->sc_xfercnt
-- ;
outb(port
+lpt_control
, sc
->sc_control
|LPC_STB
);
outb(port
+lpt_control
, sc
->sc_control
);
/* any more bytes for the printer? */
if (sc
->sc_xfercnt
> 0) return;
/* none, wake up the top half to get more */
} else sc
->sc_state
|= ERROR
;
lptioctl(dev
, cmd
, data
, flag
)
dothis
; andthis
; andthat
;
#endif /* THISISASAMPLE */