2 * Generic parallel printer driver
4 * Copyright (C) 1992 by Jim Weigand and Linus Torvalds
5 * Copyright (C) 1992,1993 by Michael K. Johnson
6 * - Thanks much to Gunter Windau for pointing out to me where the error
7 * checking ought to be.
8 * Copyright (C) 1993 by Nigel Gamble (added interrupt code)
9 * Copyright (C) 1994 by Alan Cox (Modularised it)
10 * LPCAREFUL, LPABORT, LPGETSTATUS added by Chris Metcalf, metcalf@lcs.mit.edu
11 * Statistics and support for slow printers by Rob Janssen, rob@knoware.nl
12 * "lp=" command line parameters added by Grant Guenther, grant@torque.net
13 * lp_read (Status readback) support added by Carsten Gross,
14 * carsten@sol.wohnheim.uni-ulm.de
15 * Support for parport by Philip Blundell <philb@gnu.org>
16 * Parport sharing hacking by Andrea Arcangeli
17 * Fixed kernel_(to/from)_user memory copy to check for errors
18 * by Riccardo Facchetti <fizban@tin.it>
19 * 22-JAN-1998 Added support for devfs Richard Gooch <rgooch@atnf.csiro.au>
20 * Redesigned interrupt handling for handle printers with buggy handshake
21 * by Andrea Arcangeli, 11 May 1998
22 * Full efficient handling of printer with buggy irq handshake (now I have
23 * understood the meaning of the strange handshake). This is done sending new
24 * characters if the interrupt is just happened, even if the printer say to
25 * be still BUSY. This is needed at least with Epson Stylus Color. To enable
26 * the new TRUST_IRQ mode read the `LP OPTIMIZATION' section below...
27 * Fixed the irq on the rising edge of the strobe case.
28 * Obsoleted the CAREFUL flag since a printer that doesn' t work with
29 * CAREFUL will block a bit after in lp_check_status().
30 * Andrea Arcangeli, 15 Oct 1998
31 * Obsoleted and removed all the lowlevel stuff implemented in the last
32 * month to use the IEEE1284 functions (that handle the _new_ compatibilty
36 /* This driver should, in theory, work with any parallel port that has an
37 * appropriate low-level driver; all I/O is done through the parport
40 * If this driver is built into the kernel, you can configure it using the
41 * kernel command-line. For example:
43 * lp=parport1,none,parport2 (bind lp0 to parport1, disable lp1 and
44 * bind lp2 to parport2)
46 * lp=auto (assign lp devices to all ports that
47 * have printers attached, as determined
48 * by the IEEE-1284 autoprobe)
50 * lp=reset (reset the printer during
53 * lp=off (disable the printer driver entirely)
55 * If the driver is loaded as a module, similar functionality is available
56 * using module parameters. The equivalent of the above commands would be:
58 * # insmod lp.o parport=1,none,2
60 * # insmod lp.o parport=auto
62 * # insmod lp.o reset=1
65 /* COMPATIBILITY WITH OLD KERNELS
67 * Under Linux 2.0 and previous versions, lp devices were bound to ports at
68 * particular I/O addresses, as follows:
74 * The new driver, by default, binds lp devices to parport devices as it
75 * finds them. This means that if you only have one port, it will be bound
76 * to lp0 regardless of its I/O address. If you need the old behaviour, you
77 * can force it using the parameters described above.
81 * The new interrupt handling code take care of the buggy handshake
82 * of some HP and Epson printer:
84 * ACK _______________ ___________
87 * BUSY _________ _______
90 * I discovered this using the printer scanner that you can find at:
92 * ftp://e-mind.com/pub/linux/pscan/
94 * 11 May 98, Andrea Arcangeli
96 * My printer scanner run on an Epson Stylus Color show that such printer
97 * generates the irq on the _rising_ edge of the STROBE. Now lp handle
100 * 15 Oct 1998, Andrea Arcangeli
102 * The so called `buggy' handshake is really the well documented
103 * compatibility mode IEEE1284 handshake. They changed the well known
104 * Centronics handshake acking in the middle of busy expecting to not
105 * break drivers or legacy application, while they broken linux lp
106 * until I fixed it reverse engineering the protocol by hand some
109 * 14 Dec 1998, Andrea Arcangeli
111 * Copyright (C) 2000 by Tim Waugh (added LPSETTIMEOUT ioctl)
114 #include <linux/module.h>
115 #include <linux/init.h>
117 #include <linux/errno.h>
118 #include <linux/kernel.h>
119 #include <linux/major.h>
120 #include <linux/sched.h>
121 #include <linux/slab.h>
122 #include <linux/fcntl.h>
123 #include <linux/delay.h>
124 #include <linux/poll.h>
125 #include <linux/console.h>
126 #include <linux/device.h>
127 #include <linux/wait.h>
128 #include <linux/jiffies.h>
129 #include <linux/smp_lock.h>
131 #include <linux/parport.h>
133 #include <linux/lp.h>
136 #include <asm/uaccess.h>
137 #include <asm/system.h>
139 /* if you have more than 8 printers, remember to increase LP_NO */
142 static struct lp_struct lp_table
[LP_NO
];
144 static unsigned int lp_count
= 0;
145 static struct class *lp_class
;
147 #ifdef CONFIG_LP_CONSOLE
148 static struct parport
*console_registered
;
149 #endif /* CONFIG_LP_CONSOLE */
153 /* Bits used to manage claiming the parport device */
154 #define LP_PREEMPT_REQUEST 1
155 #define LP_PARPORT_CLAIMED 2
157 /* --- low-level port access ----------------------------------- */
159 #define r_dtr(x) (parport_read_data(lp_table[(x)].dev->port))
160 #define r_str(x) (parport_read_status(lp_table[(x)].dev->port))
161 #define w_ctr(x,y) do { parport_write_control(lp_table[(x)].dev->port, (y)); } while (0)
162 #define w_dtr(x,y) do { parport_write_data(lp_table[(x)].dev->port, (y)); } while (0)
164 /* Claim the parport or block trying unless we've already claimed it */
165 static void lp_claim_parport_or_block(struct lp_struct
*this_lp
)
167 if (!test_and_set_bit(LP_PARPORT_CLAIMED
, &this_lp
->bits
)) {
168 parport_claim_or_block (this_lp
->dev
);
172 /* Claim the parport or block trying unless we've already claimed it */
173 static void lp_release_parport(struct lp_struct
*this_lp
)
175 if (test_and_clear_bit(LP_PARPORT_CLAIMED
, &this_lp
->bits
)) {
176 parport_release (this_lp
->dev
);
182 static int lp_preempt(void *handle
)
184 struct lp_struct
*this_lp
= (struct lp_struct
*)handle
;
185 set_bit(LP_PREEMPT_REQUEST
, &this_lp
->bits
);
191 * Try to negotiate to a new mode; if unsuccessful negotiate to
192 * compatibility mode. Return the mode we ended up in.
194 static int lp_negotiate(struct parport
* port
, int mode
)
196 if (parport_negotiate (port
, mode
) != 0) {
197 mode
= IEEE1284_MODE_COMPAT
;
198 parport_negotiate (port
, mode
);
204 static int lp_reset(int minor
)
207 lp_claim_parport_or_block (&lp_table
[minor
]);
208 w_ctr(minor
, LP_PSELECP
);
210 w_ctr(minor
, LP_PSELECP
| LP_PINITP
);
211 retval
= r_str(minor
);
212 lp_release_parport (&lp_table
[minor
]);
216 static void lp_error (int minor
)
221 if (LP_F(minor
) & LP_ABORT
)
224 polling
= lp_table
[minor
].dev
->port
->irq
== PARPORT_IRQ_NONE
;
225 if (polling
) lp_release_parport (&lp_table
[minor
]);
226 prepare_to_wait(&lp_table
[minor
].waitq
, &wait
, TASK_INTERRUPTIBLE
);
227 schedule_timeout(LP_TIMEOUT_POLLED
);
228 finish_wait(&lp_table
[minor
].waitq
, &wait
);
229 if (polling
) lp_claim_parport_or_block (&lp_table
[minor
]);
230 else parport_yield_blocking (lp_table
[minor
].dev
);
233 static int lp_check_status(int minor
)
236 unsigned int last
= lp_table
[minor
].last_error
;
237 unsigned char status
= r_str(minor
);
238 if ((status
& LP_PERRORP
) && !(LP_F(minor
) & LP_CAREFUL
))
241 else if ((status
& LP_POUTPA
)) {
242 if (last
!= LP_POUTPA
) {
244 printk(KERN_INFO
"lp%d out of paper\n", minor
);
247 } else if (!(status
& LP_PSELECD
)) {
248 if (last
!= LP_PSELECD
) {
250 printk(KERN_INFO
"lp%d off-line\n", minor
);
253 } else if (!(status
& LP_PERRORP
)) {
254 if (last
!= LP_PERRORP
) {
256 printk(KERN_INFO
"lp%d on fire\n", minor
);
260 last
= 0; /* Come here if LP_CAREFUL is set and no
261 errors are reported. */
264 lp_table
[minor
].last_error
= last
;
272 static int lp_wait_ready(int minor
, int nonblock
)
276 /* If we're not in compatibility mode, we're ready now! */
277 if (lp_table
[minor
].current_mode
!= IEEE1284_MODE_COMPAT
) {
282 error
= lp_check_status (minor
);
283 if (error
&& (nonblock
|| (LP_F(minor
) & LP_ABORT
)))
285 if (signal_pending (current
)) {
293 static ssize_t
lp_write(struct file
* file
, const char __user
* buf
,
294 size_t count
, loff_t
*ppos
)
296 unsigned int minor
= iminor(file
->f_path
.dentry
->d_inode
);
297 struct parport
*port
= lp_table
[minor
].dev
->port
;
298 char *kbuf
= lp_table
[minor
].lp_buffer
;
301 size_t copy_size
= count
;
302 int nonblock
= ((file
->f_flags
& O_NONBLOCK
) ||
303 (LP_F(minor
) & LP_ABORT
));
306 if (time_after(jiffies
, lp_table
[minor
].lastcall
+ LP_TIME(minor
)))
307 lp_table
[minor
].runchars
= 0;
309 lp_table
[minor
].lastcall
= jiffies
;
312 /* Need to copy the data from user-space. */
313 if (copy_size
> LP_BUFFER_SIZE
)
314 copy_size
= LP_BUFFER_SIZE
;
316 if (mutex_lock_interruptible(&lp_table
[minor
].port_mutex
))
319 if (copy_from_user (kbuf
, buf
, copy_size
)) {
324 /* Claim Parport or sleep until it becomes available
326 lp_claim_parport_or_block (&lp_table
[minor
]);
327 /* Go to the proper mode. */
328 lp_table
[minor
].current_mode
= lp_negotiate (port
,
329 lp_table
[minor
].best_mode
);
331 parport_set_timeout (lp_table
[minor
].dev
,
332 (nonblock
? PARPORT_INACTIVITY_O_NONBLOCK
333 : lp_table
[minor
].timeout
));
335 if ((retv
= lp_wait_ready (minor
, nonblock
)) == 0)
337 /* Write the data. */
338 written
= parport_write (port
, kbuf
, copy_size
);
340 copy_size
-= written
;
346 if (signal_pending (current
)) {
354 /* incomplete write -> check error ! */
357 parport_negotiate (lp_table
[minor
].dev
->port
,
358 IEEE1284_MODE_COMPAT
);
359 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
361 error
= lp_wait_ready (minor
, nonblock
);
367 } else if (nonblock
) {
373 parport_yield_blocking (lp_table
[minor
].dev
);
374 lp_table
[minor
].current_mode
375 = lp_negotiate (port
,
376 lp_table
[minor
].best_mode
);
378 } else if (need_resched())
383 if (copy_size
> LP_BUFFER_SIZE
)
384 copy_size
= LP_BUFFER_SIZE
;
386 if (copy_from_user(kbuf
, buf
, copy_size
)) {
394 if (test_and_clear_bit(LP_PREEMPT_REQUEST
,
395 &lp_table
[minor
].bits
)) {
396 printk(KERN_INFO
"lp%d releasing parport\n", minor
);
397 parport_negotiate (lp_table
[minor
].dev
->port
,
398 IEEE1284_MODE_COMPAT
);
399 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
400 lp_release_parport (&lp_table
[minor
]);
403 mutex_unlock(&lp_table
[minor
].port_mutex
);
408 #ifdef CONFIG_PARPORT_1284
410 /* Status readback conforming to ieee1284 */
411 static ssize_t
lp_read(struct file
* file
, char __user
* buf
,
412 size_t count
, loff_t
*ppos
)
415 unsigned int minor
=iminor(file
->f_path
.dentry
->d_inode
);
416 struct parport
*port
= lp_table
[minor
].dev
->port
;
418 char *kbuf
= lp_table
[minor
].lp_buffer
;
419 int nonblock
= ((file
->f_flags
& O_NONBLOCK
) ||
420 (LP_F(minor
) & LP_ABORT
));
422 if (count
> LP_BUFFER_SIZE
)
423 count
= LP_BUFFER_SIZE
;
425 if (mutex_lock_interruptible(&lp_table
[minor
].port_mutex
))
428 lp_claim_parport_or_block (&lp_table
[minor
]);
430 parport_set_timeout (lp_table
[minor
].dev
,
431 (nonblock
? PARPORT_INACTIVITY_O_NONBLOCK
432 : lp_table
[minor
].timeout
));
434 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
435 if (parport_negotiate (lp_table
[minor
].dev
->port
,
436 IEEE1284_MODE_NIBBLE
)) {
441 while (retval
== 0) {
442 retval
= parport_read (port
, kbuf
, count
);
454 if (lp_table
[minor
].dev
->port
->irq
== PARPORT_IRQ_NONE
) {
455 parport_negotiate (lp_table
[minor
].dev
->port
,
456 IEEE1284_MODE_COMPAT
);
458 if (parport_negotiate (lp_table
[minor
].dev
->port
,
459 IEEE1284_MODE_NIBBLE
)) {
464 prepare_to_wait(&lp_table
[minor
].waitq
, &wait
, TASK_INTERRUPTIBLE
);
465 schedule_timeout(LP_TIMEOUT_POLLED
);
466 finish_wait(&lp_table
[minor
].waitq
, &wait
);
469 if (signal_pending (current
)) {
470 retval
= -ERESTARTSYS
;
476 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
478 lp_release_parport (&lp_table
[minor
]);
480 if (retval
> 0 && copy_to_user (buf
, kbuf
, retval
))
483 mutex_unlock(&lp_table
[minor
].port_mutex
);
488 #endif /* IEEE 1284 support */
490 static int lp_open(struct inode
* inode
, struct file
* file
)
492 unsigned int minor
= iminor(inode
);
496 if (minor
>= LP_NO
) {
500 if ((LP_F(minor
) & LP_EXIST
) == 0) {
504 if (test_and_set_bit(LP_BUSY_BIT_POS
, &LP_F(minor
))) {
508 /* If ABORTOPEN is set and the printer is offline or out of paper,
509 we may still want to open it to perform ioctl()s. Therefore we
510 have commandeered O_NONBLOCK, even though it is being used in
511 a non-standard manner. This is strictly a Linux hack, and
512 should most likely only ever be used by the tunelp application. */
513 if ((LP_F(minor
) & LP_ABORTOPEN
) && !(file
->f_flags
& O_NONBLOCK
)) {
515 lp_claim_parport_or_block (&lp_table
[minor
]);
516 status
= r_str(minor
);
517 lp_release_parport (&lp_table
[minor
]);
518 if (status
& LP_POUTPA
) {
519 printk(KERN_INFO
"lp%d out of paper\n", minor
);
520 LP_F(minor
) &= ~LP_BUSY
;
523 } else if (!(status
& LP_PSELECD
)) {
524 printk(KERN_INFO
"lp%d off-line\n", minor
);
525 LP_F(minor
) &= ~LP_BUSY
;
528 } else if (!(status
& LP_PERRORP
)) {
529 printk(KERN_ERR
"lp%d printer error\n", minor
);
530 LP_F(minor
) &= ~LP_BUSY
;
535 lp_table
[minor
].lp_buffer
= kmalloc(LP_BUFFER_SIZE
, GFP_KERNEL
);
536 if (!lp_table
[minor
].lp_buffer
) {
537 LP_F(minor
) &= ~LP_BUSY
;
541 /* Determine if the peripheral supports ECP mode */
542 lp_claim_parport_or_block (&lp_table
[minor
]);
543 if ( (lp_table
[minor
].dev
->port
->modes
& PARPORT_MODE_ECP
) &&
544 !parport_negotiate (lp_table
[minor
].dev
->port
,
545 IEEE1284_MODE_ECP
)) {
546 printk (KERN_INFO
"lp%d: ECP mode\n", minor
);
547 lp_table
[minor
].best_mode
= IEEE1284_MODE_ECP
;
549 lp_table
[minor
].best_mode
= IEEE1284_MODE_COMPAT
;
551 /* Leave peripheral in compatibility mode */
552 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
553 lp_release_parport (&lp_table
[minor
]);
554 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
560 static int lp_release(struct inode
* inode
, struct file
* file
)
562 unsigned int minor
= iminor(inode
);
564 lp_claim_parport_or_block (&lp_table
[minor
]);
565 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
566 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
567 lp_release_parport (&lp_table
[minor
]);
568 kfree(lp_table
[minor
].lp_buffer
);
569 lp_table
[minor
].lp_buffer
= NULL
;
570 LP_F(minor
) &= ~LP_BUSY
;
574 static int lp_ioctl(struct inode
*inode
, struct file
*file
,
575 unsigned int cmd
, unsigned long arg
)
577 unsigned int minor
= iminor(inode
);
580 void __user
*argp
= (void __user
*)arg
;
583 printk(KERN_DEBUG
"lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor
, cmd
, arg
);
587 if ((LP_F(minor
) & LP_EXIST
) == 0)
590 struct timeval par_timeout
;
594 LP_TIME(minor
) = arg
* HZ
/100;
597 LP_CHAR(minor
) = arg
;
601 LP_F(minor
) |= LP_ABORT
;
603 LP_F(minor
) &= ~LP_ABORT
;
607 LP_F(minor
) |= LP_ABORTOPEN
;
609 LP_F(minor
) &= ~LP_ABORTOPEN
;
613 LP_F(minor
) |= LP_CAREFUL
;
615 LP_F(minor
) &= ~LP_CAREFUL
;
618 LP_WAIT(minor
) = arg
;
624 if (copy_to_user(argp
, &LP_IRQ(minor
),
629 lp_claim_parport_or_block (&lp_table
[minor
]);
630 status
= r_str(minor
);
631 lp_release_parport (&lp_table
[minor
]);
633 if (copy_to_user(argp
, &status
, sizeof(int)))
641 if (copy_to_user(argp
, &LP_STAT(minor
),
642 sizeof(struct lp_stats
)))
644 if (capable(CAP_SYS_ADMIN
))
645 memset(&LP_STAT(minor
), 0,
646 sizeof(struct lp_stats
));
650 status
= LP_F(minor
);
651 if (copy_to_user(argp
, &status
, sizeof(int)))
656 if (copy_from_user (&par_timeout
, argp
,
657 sizeof (struct timeval
))) {
660 /* Convert to jiffies, place in lp_table */
661 if ((par_timeout
.tv_sec
< 0) ||
662 (par_timeout
.tv_usec
< 0)) {
665 to_jiffies
= DIV_ROUND_UP(par_timeout
.tv_usec
, 1000000/HZ
);
666 to_jiffies
+= par_timeout
.tv_sec
* (long) HZ
;
667 if (to_jiffies
<= 0) {
670 lp_table
[minor
].timeout
= to_jiffies
;
679 static const struct file_operations lp_fops
= {
680 .owner
= THIS_MODULE
,
684 .release
= lp_release
,
685 #ifdef CONFIG_PARPORT_1284
690 /* --- support for console on the line printer ----------------- */
692 #ifdef CONFIG_LP_CONSOLE
696 /* If the printer is out of paper, we can either lose the messages or
697 * stall until the printer is happy again. Define CONSOLE_LP_STRICT
698 * non-zero to get the latter behaviour. */
699 #define CONSOLE_LP_STRICT 1
701 /* The console must be locked when we get here. */
703 static void lp_console_write (struct console
*co
, const char *s
,
706 struct pardevice
*dev
= lp_table
[CONSOLE_LP
].dev
;
707 struct parport
*port
= dev
->port
;
710 if (parport_claim (dev
))
711 /* Nothing we can do. */
714 parport_set_timeout (dev
, 0);
716 /* Go to compatibility mode. */
717 parport_negotiate (port
, IEEE1284_MODE_COMPAT
);
720 /* Write the data, converting LF->CRLF as we go. */
721 ssize_t canwrite
= count
;
722 char *lf
= memchr (s
, '\n', count
);
727 written
= parport_write (port
, s
, canwrite
);
737 if (lf
&& canwrite
<= 0) {
738 const char *crlf
= "\r\n";
741 /* Dodge the original '\n', and put '\r\n' instead. */
745 written
= parport_write (port
, crlf
, i
);
747 i
-= written
, crlf
+= written
;
748 } while (i
> 0 && (CONSOLE_LP_STRICT
|| written
> 0));
750 } while (count
> 0 && (CONSOLE_LP_STRICT
|| written
> 0));
752 parport_release (dev
);
755 static struct console lpcons
= {
757 .write
= lp_console_write
,
758 .flags
= CON_PRINTBUFFER
,
761 #endif /* console on line printer */
763 /* --- initialisation code ------------------------------------- */
765 static int parport_nr
[LP_NO
] = { [0 ... LP_NO
-1] = LP_PARPORT_UNSPEC
};
766 static char *parport
[LP_NO
];
769 module_param_array(parport
, charp
, NULL
, 0);
770 module_param(reset
, bool, 0);
773 static int __init
lp_setup (char *str
)
775 static int parport_ptr
;
778 if (get_option(&str
, &x
)) {
780 /* disable driver on "lp=" or "lp=0" */
781 parport_nr
[0] = LP_PARPORT_OFF
;
783 printk(KERN_WARNING
"warning: 'lp=0x%x' is deprecated, ignored\n", x
);
786 } else if (!strncmp(str
, "parport", 7)) {
787 int n
= simple_strtoul(str
+7, NULL
, 10);
788 if (parport_ptr
< LP_NO
)
789 parport_nr
[parport_ptr
++] = n
;
791 printk(KERN_INFO
"lp: too many ports, %s ignored.\n",
793 } else if (!strcmp(str
, "auto")) {
794 parport_nr
[0] = LP_PARPORT_AUTO
;
795 } else if (!strcmp(str
, "none")) {
796 parport_nr
[parport_ptr
++] = LP_PARPORT_NONE
;
797 } else if (!strcmp(str
, "reset")) {
804 static int lp_register(int nr
, struct parport
*port
)
806 lp_table
[nr
].dev
= parport_register_device(port
, "lp",
807 lp_preempt
, NULL
, NULL
, 0,
808 (void *) &lp_table
[nr
]);
809 if (lp_table
[nr
].dev
== NULL
)
811 lp_table
[nr
].flags
|= LP_EXIST
;
816 device_create_drvdata(lp_class
, port
->dev
, MKDEV(LP_MAJOR
, nr
), NULL
,
819 printk(KERN_INFO
"lp%d: using %s (%s).\n", nr
, port
->name
,
820 (port
->irq
== PARPORT_IRQ_NONE
)?"polling":"interrupt-driven");
822 #ifdef CONFIG_LP_CONSOLE
824 if (port
->modes
& PARPORT_MODE_SAFEININT
) {
825 register_console(&lpcons
);
826 console_registered
= port
;
827 printk (KERN_INFO
"lp%d: console ready\n", CONSOLE_LP
);
829 printk (KERN_ERR
"lp%d: cannot run console on %s\n",
830 CONSOLE_LP
, port
->name
);
837 static void lp_attach (struct parport
*port
)
841 switch (parport_nr
[0]) {
842 case LP_PARPORT_UNSPEC
:
843 case LP_PARPORT_AUTO
:
844 if (parport_nr
[0] == LP_PARPORT_AUTO
&&
845 port
->probe_info
[0].class != PARPORT_CLASS_PRINTER
)
847 if (lp_count
== LP_NO
) {
848 printk(KERN_INFO
"lp: ignoring parallel port (max. %d)\n",LP_NO
);
851 if (!lp_register(lp_count
, port
))
856 for (i
= 0; i
< LP_NO
; i
++) {
857 if (port
->number
== parport_nr
[i
]) {
858 if (!lp_register(i
, port
))
867 static void lp_detach (struct parport
*port
)
869 /* Write this some day. */
870 #ifdef CONFIG_LP_CONSOLE
871 if (console_registered
== port
) {
872 unregister_console(&lpcons
);
873 console_registered
= NULL
;
875 #endif /* CONFIG_LP_CONSOLE */
878 static struct parport_driver lp_driver
= {
884 static int __init
lp_init (void)
888 if (parport_nr
[0] == LP_PARPORT_OFF
)
891 for (i
= 0; i
< LP_NO
; i
++) {
892 lp_table
[i
].dev
= NULL
;
893 lp_table
[i
].flags
= 0;
894 lp_table
[i
].chars
= LP_INIT_CHAR
;
895 lp_table
[i
].time
= LP_INIT_TIME
;
896 lp_table
[i
].wait
= LP_INIT_WAIT
;
897 lp_table
[i
].lp_buffer
= NULL
;
899 lp_table
[i
].lastcall
= 0;
900 lp_table
[i
].runchars
= 0;
901 memset (&lp_table
[i
].stats
, 0, sizeof (struct lp_stats
));
903 lp_table
[i
].last_error
= 0;
904 init_waitqueue_head (&lp_table
[i
].waitq
);
905 init_waitqueue_head (&lp_table
[i
].dataq
);
906 mutex_init(&lp_table
[i
].port_mutex
);
907 lp_table
[i
].timeout
= 10 * HZ
;
910 if (register_chrdev (LP_MAJOR
, "lp", &lp_fops
)) {
911 printk (KERN_ERR
"lp: unable to get major %d\n", LP_MAJOR
);
915 lp_class
= class_create(THIS_MODULE
, "printer");
916 if (IS_ERR(lp_class
)) {
917 err
= PTR_ERR(lp_class
);
921 if (parport_register_driver (&lp_driver
)) {
922 printk (KERN_ERR
"lp: unable to register with parport\n");
928 printk (KERN_INFO
"lp: driver loaded but no devices found\n");
929 #ifndef CONFIG_PARPORT_1284
930 if (parport_nr
[0] == LP_PARPORT_AUTO
)
931 printk (KERN_INFO
"lp: (is IEEE 1284 support enabled?)\n");
938 class_destroy(lp_class
);
940 unregister_chrdev(LP_MAJOR
, "lp");
944 static int __init
lp_init_module (void)
947 /* The user gave some parameters. Let's see what they were. */
948 if (!strncmp(parport
[0], "auto", 4))
949 parport_nr
[0] = LP_PARPORT_AUTO
;
952 for (n
= 0; n
< LP_NO
&& parport
[n
]; n
++) {
953 if (!strncmp(parport
[n
], "none", 4))
954 parport_nr
[n
] = LP_PARPORT_NONE
;
957 unsigned long r
= simple_strtoul(parport
[n
], &ep
, 0);
958 if (ep
!= parport
[n
])
961 printk(KERN_ERR
"lp: bad port specifier `%s'\n", parport
[n
]);
972 static void lp_cleanup_module (void)
976 parport_unregister_driver (&lp_driver
);
978 #ifdef CONFIG_LP_CONSOLE
979 unregister_console (&lpcons
);
982 unregister_chrdev(LP_MAJOR
, "lp");
983 for (offset
= 0; offset
< LP_NO
; offset
++) {
984 if (lp_table
[offset
].dev
== NULL
)
986 parport_unregister_device(lp_table
[offset
].dev
);
987 device_destroy(lp_class
, MKDEV(LP_MAJOR
, offset
));
989 class_destroy(lp_class
);
992 __setup("lp=", lp_setup
);
993 module_init(lp_init_module
);
994 module_exit(lp_cleanup_module
);
996 MODULE_ALIAS_CHARDEV_MAJOR(LP_MAJOR
);
997 MODULE_LICENSE("GPL");