Upload Tizen:Base source
[framework/base/util-linux-ng.git] / sys-utils / lp.h
1 /* Line printer stuff mostly follows the original Centronics printers. See
2    IEEE Std.1284-1994 Standard Signaling Method for a Bi-directional Parallel
3    Peripheral Interface for Personal Computers for 5 modes of data transfer. */
4
5 /* Parallel port registers: data (0x3bc, 0x378, 0x278), status=data+1, control=data+2 */
6
7 /* Parallel port status register (read only):
8 bit 7: NBSY     (1: ready, 0: busy or error or off-line)
9 bit 6: NACK     (if NBSY=1, then 1; if NBSY=0 then 1: sending data, 0: ready with data)
10 bit 5:  PAP     (1: out-of-paper)
11 bit 4: OFON     (1: on-line)
12 bit 3: NFEH     (1: OK, 0: printer error)
13 bits 2-0: 07
14
15 On out-of-paper: PAP=1, OFON=0, NFEH=1.
16
17 "When reading the busy status, read twice in a row and use the value
18 obtained from the second read. This improves the reliability on some
19 parallel ports when the busy line may not be connected and is floating."
20 "On some Okidata printers when the busy signal switches from high to low,
21 the printer sends a 50 ns glitch on the paper out signal line. Before
22 declaring a paper out condition, check the status again."
23 (The Undocumented PC, F. van Gilluwe, p. 711)
24 */
25
26 /* Parallel port control register (read/write):
27 bit 4:  IRQ     (1: we want an interrupt when NACK goes from 1 to 0)
28 bit 3:  DSL     (1: activate printer)
29 bit 2: NINI     (0: initialise printer)
30 bit 1:  ALF     (1: printer performs automatic linefeed after each line)
31 bit 0:  STR     (0->1: generate a Strobe pulse: transport data to printer)
32 */
33
34 /* Parallel port timing:
35    1. wait for NBSY=1
36    2. outb(data byte, data port)
37    3. wait for at least 0.5us
38    4. read control port, OR with STR=0x1, output to control port - purpose:
39       generate strobe pulse; this will make the busy line go high
40    5. wait for at least 0.5us
41    6. read control port, AND with !STR, output to control port
42    7. wait for at least 0.5us
43    8. in a loop: read status register until NACK bit is 0 or NBSY=1
44       (the printer will keep NACK=0 for at least 0.5us, then NACK=NBSY=1).
45 */
46
47
48 /* lp ioctls */
49 #define LPCHAR   0x0601  /* specify the number of times we ask for the status
50                             (waiting for ready) before giving up with a timeout
51                             The duration may mainly depend on the timing of an inb. */
52 #define LPTIME   0x0602  /* time to sleep after each timeout (in units of 0.01 sec) */
53 #define LPABORT  0x0604  /* call with TRUE arg to abort on error,
54                             FALSE to retry.  Default is retry.  */
55 #define LPSETIRQ 0x0605  /* call with new IRQ number,
56                             or 0 for polling (no IRQ) */
57 #define LPGETIRQ 0x0606  /* get the current IRQ number */
58 #define LPWAIT   0x0608  /* #of loops to wait before taking strobe high */
59 #define LPCAREFUL   0x0609  /* call with TRUE arg to require out-of-paper, off-
60                             line, and error indicators good on all writes,
61                             FALSE to ignore them.  Default is ignore. */
62 #define LPABORTOPEN 0x060a  /* call with TRUE arg to abort open() on error,
63                             FALSE to ignore error.  Default is ignore.  */
64 #define LPGETSTATUS 0x060b  /* return LP_S(minor) */
65 #define LPRESET     0x060c  /* reset printer */
66 #define LPGETFLAGS  0x060e  /* get status flags */
67
68 #define LPSTRICT    0x060f  /* enable/disable strict compliance (2.0.36) */
69                             /* Strict: wait until !READY before taking strobe low;
70                                this may be bad for the Epson Stylus 800.
71                                Not strict: wait a constant time as given by LPWAIT */
72 #define LPTRUSTIRQ  0x060f  /* set/unset the LP_TRUST_IRQ flag (2.1.131) */
73
74 /* 
75  * bit defines for 8255 status port
76  * base + 1
77  * accessed with LP_S(minor), which gets the byte...
78  */
79 #define LP_PBUSY        0x80  /* inverted input, active high */
80 #define LP_PACK         0x40  /* unchanged input, active low */
81 #define LP_POUTPA       0x20  /* unchanged input, active high */
82 #define LP_PSELECD      0x10  /* unchanged input, active high */
83 #define LP_PERRORP      0x08  /* unchanged input, active low */