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>
130 #include <linux/parport.h>
132 #include <linux/lp.h>
135 #include <asm/uaccess.h>
136 #include <asm/system.h>
138 /* if you have more than 8 printers, remember to increase LP_NO */
141 static struct lp_struct lp_table
[LP_NO
];
143 static unsigned int lp_count
= 0;
144 static struct class *lp_class
;
146 #ifdef CONFIG_LP_CONSOLE
147 static struct parport
*console_registered
;
148 #endif /* CONFIG_LP_CONSOLE */
152 /* Bits used to manage claiming the parport device */
153 #define LP_PREEMPT_REQUEST 1
154 #define LP_PARPORT_CLAIMED 2
156 /* --- low-level port access ----------------------------------- */
158 #define r_dtr(x) (parport_read_data(lp_table[(x)].dev->port))
159 #define r_str(x) (parport_read_status(lp_table[(x)].dev->port))
160 #define w_ctr(x,y) do { parport_write_control(lp_table[(x)].dev->port, (y)); } while (0)
161 #define w_dtr(x,y) do { parport_write_data(lp_table[(x)].dev->port, (y)); } while (0)
163 /* Claim the parport or block trying unless we've already claimed it */
164 static void lp_claim_parport_or_block(struct lp_struct
*this_lp
)
166 if (!test_and_set_bit(LP_PARPORT_CLAIMED
, &this_lp
->bits
)) {
167 parport_claim_or_block (this_lp
->dev
);
171 /* Claim the parport or block trying unless we've already claimed it */
172 static void lp_release_parport(struct lp_struct
*this_lp
)
174 if (test_and_clear_bit(LP_PARPORT_CLAIMED
, &this_lp
->bits
)) {
175 parport_release (this_lp
->dev
);
181 static int lp_preempt(void *handle
)
183 struct lp_struct
*this_lp
= (struct lp_struct
*)handle
;
184 set_bit(LP_PREEMPT_REQUEST
, &this_lp
->bits
);
190 * Try to negotiate to a new mode; if unsuccessful negotiate to
191 * compatibility mode. Return the mode we ended up in.
193 static int lp_negotiate(struct parport
* port
, int mode
)
195 if (parport_negotiate (port
, mode
) != 0) {
196 mode
= IEEE1284_MODE_COMPAT
;
197 parport_negotiate (port
, mode
);
203 static int lp_reset(int minor
)
206 lp_claim_parport_or_block (&lp_table
[minor
]);
207 w_ctr(minor
, LP_PSELECP
);
209 w_ctr(minor
, LP_PSELECP
| LP_PINITP
);
210 retval
= r_str(minor
);
211 lp_release_parport (&lp_table
[minor
]);
215 static void lp_error (int minor
)
220 if (LP_F(minor
) & LP_ABORT
)
223 polling
= lp_table
[minor
].dev
->port
->irq
== PARPORT_IRQ_NONE
;
224 if (polling
) lp_release_parport (&lp_table
[minor
]);
225 prepare_to_wait(&lp_table
[minor
].waitq
, &wait
, TASK_INTERRUPTIBLE
);
226 schedule_timeout(LP_TIMEOUT_POLLED
);
227 finish_wait(&lp_table
[minor
].waitq
, &wait
);
228 if (polling
) lp_claim_parport_or_block (&lp_table
[minor
]);
229 else parport_yield_blocking (lp_table
[minor
].dev
);
232 static int lp_check_status(int minor
)
235 unsigned int last
= lp_table
[minor
].last_error
;
236 unsigned char status
= r_str(minor
);
237 if ((status
& LP_PERRORP
) && !(LP_F(minor
) & LP_CAREFUL
))
240 else if ((status
& LP_POUTPA
)) {
241 if (last
!= LP_POUTPA
) {
243 printk(KERN_INFO
"lp%d out of paper\n", minor
);
246 } else if (!(status
& LP_PSELECD
)) {
247 if (last
!= LP_PSELECD
) {
249 printk(KERN_INFO
"lp%d off-line\n", minor
);
252 } else if (!(status
& LP_PERRORP
)) {
253 if (last
!= LP_PERRORP
) {
255 printk(KERN_INFO
"lp%d on fire\n", minor
);
259 last
= 0; /* Come here if LP_CAREFUL is set and no
260 errors are reported. */
263 lp_table
[minor
].last_error
= last
;
271 static int lp_wait_ready(int minor
, int nonblock
)
275 /* If we're not in compatibility mode, we're ready now! */
276 if (lp_table
[minor
].current_mode
!= IEEE1284_MODE_COMPAT
) {
281 error
= lp_check_status (minor
);
282 if (error
&& (nonblock
|| (LP_F(minor
) & LP_ABORT
)))
284 if (signal_pending (current
)) {
292 static ssize_t
lp_write(struct file
* file
, const char __user
* buf
,
293 size_t count
, loff_t
*ppos
)
295 unsigned int minor
= iminor(file
->f_path
.dentry
->d_inode
);
296 struct parport
*port
= lp_table
[minor
].dev
->port
;
297 char *kbuf
= lp_table
[minor
].lp_buffer
;
300 size_t copy_size
= count
;
301 int nonblock
= ((file
->f_flags
& O_NONBLOCK
) ||
302 (LP_F(minor
) & LP_ABORT
));
305 if (time_after(jiffies
, lp_table
[minor
].lastcall
+ LP_TIME(minor
)))
306 lp_table
[minor
].runchars
= 0;
308 lp_table
[minor
].lastcall
= jiffies
;
311 /* Need to copy the data from user-space. */
312 if (copy_size
> LP_BUFFER_SIZE
)
313 copy_size
= LP_BUFFER_SIZE
;
315 if (mutex_lock_interruptible(&lp_table
[minor
].port_mutex
))
318 if (copy_from_user (kbuf
, buf
, copy_size
)) {
323 /* Claim Parport or sleep until it becomes available
325 lp_claim_parport_or_block (&lp_table
[minor
]);
326 /* Go to the proper mode. */
327 lp_table
[minor
].current_mode
= lp_negotiate (port
,
328 lp_table
[minor
].best_mode
);
330 parport_set_timeout (lp_table
[minor
].dev
,
331 (nonblock
? PARPORT_INACTIVITY_O_NONBLOCK
332 : lp_table
[minor
].timeout
));
334 if ((retv
= lp_wait_ready (minor
, nonblock
)) == 0)
336 /* Write the data. */
337 written
= parport_write (port
, kbuf
, copy_size
);
339 copy_size
-= written
;
345 if (signal_pending (current
)) {
353 /* incomplete write -> check error ! */
356 parport_negotiate (lp_table
[minor
].dev
->port
,
357 IEEE1284_MODE_COMPAT
);
358 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
360 error
= lp_wait_ready (minor
, nonblock
);
366 } else if (nonblock
) {
372 parport_yield_blocking (lp_table
[minor
].dev
);
373 lp_table
[minor
].current_mode
374 = lp_negotiate (port
,
375 lp_table
[minor
].best_mode
);
377 } else if (need_resched())
382 if (copy_size
> LP_BUFFER_SIZE
)
383 copy_size
= LP_BUFFER_SIZE
;
385 if (copy_from_user(kbuf
, buf
, copy_size
)) {
393 if (test_and_clear_bit(LP_PREEMPT_REQUEST
,
394 &lp_table
[minor
].bits
)) {
395 printk(KERN_INFO
"lp%d releasing parport\n", minor
);
396 parport_negotiate (lp_table
[minor
].dev
->port
,
397 IEEE1284_MODE_COMPAT
);
398 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
399 lp_release_parport (&lp_table
[minor
]);
402 mutex_unlock(&lp_table
[minor
].port_mutex
);
407 #ifdef CONFIG_PARPORT_1284
409 /* Status readback conforming to ieee1284 */
410 static ssize_t
lp_read(struct file
* file
, char __user
* buf
,
411 size_t count
, loff_t
*ppos
)
414 unsigned int minor
=iminor(file
->f_path
.dentry
->d_inode
);
415 struct parport
*port
= lp_table
[minor
].dev
->port
;
417 char *kbuf
= lp_table
[minor
].lp_buffer
;
418 int nonblock
= ((file
->f_flags
& O_NONBLOCK
) ||
419 (LP_F(minor
) & LP_ABORT
));
421 if (count
> LP_BUFFER_SIZE
)
422 count
= LP_BUFFER_SIZE
;
424 if (mutex_lock_interruptible(&lp_table
[minor
].port_mutex
))
427 lp_claim_parport_or_block (&lp_table
[minor
]);
429 parport_set_timeout (lp_table
[minor
].dev
,
430 (nonblock
? PARPORT_INACTIVITY_O_NONBLOCK
431 : lp_table
[minor
].timeout
));
433 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
434 if (parport_negotiate (lp_table
[minor
].dev
->port
,
435 IEEE1284_MODE_NIBBLE
)) {
440 while (retval
== 0) {
441 retval
= parport_read (port
, kbuf
, count
);
453 if (lp_table
[minor
].dev
->port
->irq
== PARPORT_IRQ_NONE
) {
454 parport_negotiate (lp_table
[minor
].dev
->port
,
455 IEEE1284_MODE_COMPAT
);
457 if (parport_negotiate (lp_table
[minor
].dev
->port
,
458 IEEE1284_MODE_NIBBLE
)) {
463 prepare_to_wait(&lp_table
[minor
].waitq
, &wait
, TASK_INTERRUPTIBLE
);
464 schedule_timeout(LP_TIMEOUT_POLLED
);
465 finish_wait(&lp_table
[minor
].waitq
, &wait
);
468 if (signal_pending (current
)) {
469 retval
= -ERESTARTSYS
;
475 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
477 lp_release_parport (&lp_table
[minor
]);
479 if (retval
> 0 && copy_to_user (buf
, kbuf
, retval
))
482 mutex_unlock(&lp_table
[minor
].port_mutex
);
487 #endif /* IEEE 1284 support */
489 static int lp_open(struct inode
* inode
, struct file
* file
)
491 unsigned int minor
= iminor(inode
);
495 if ((LP_F(minor
) & LP_EXIST
) == 0)
497 if (test_and_set_bit(LP_BUSY_BIT_POS
, &LP_F(minor
)))
500 /* If ABORTOPEN is set and the printer is offline or out of paper,
501 we may still want to open it to perform ioctl()s. Therefore we
502 have commandeered O_NONBLOCK, even though it is being used in
503 a non-standard manner. This is strictly a Linux hack, and
504 should most likely only ever be used by the tunelp application. */
505 if ((LP_F(minor
) & LP_ABORTOPEN
) && !(file
->f_flags
& O_NONBLOCK
)) {
507 lp_claim_parport_or_block (&lp_table
[minor
]);
508 status
= r_str(minor
);
509 lp_release_parport (&lp_table
[minor
]);
510 if (status
& LP_POUTPA
) {
511 printk(KERN_INFO
"lp%d out of paper\n", minor
);
512 LP_F(minor
) &= ~LP_BUSY
;
514 } else if (!(status
& LP_PSELECD
)) {
515 printk(KERN_INFO
"lp%d off-line\n", minor
);
516 LP_F(minor
) &= ~LP_BUSY
;
518 } else if (!(status
& LP_PERRORP
)) {
519 printk(KERN_ERR
"lp%d printer error\n", minor
);
520 LP_F(minor
) &= ~LP_BUSY
;
524 lp_table
[minor
].lp_buffer
= kmalloc(LP_BUFFER_SIZE
, GFP_KERNEL
);
525 if (!lp_table
[minor
].lp_buffer
) {
526 LP_F(minor
) &= ~LP_BUSY
;
529 /* Determine if the peripheral supports ECP mode */
530 lp_claim_parport_or_block (&lp_table
[minor
]);
531 if ( (lp_table
[minor
].dev
->port
->modes
& PARPORT_MODE_ECP
) &&
532 !parport_negotiate (lp_table
[minor
].dev
->port
,
533 IEEE1284_MODE_ECP
)) {
534 printk (KERN_INFO
"lp%d: ECP mode\n", minor
);
535 lp_table
[minor
].best_mode
= IEEE1284_MODE_ECP
;
537 lp_table
[minor
].best_mode
= IEEE1284_MODE_COMPAT
;
539 /* Leave peripheral in compatibility mode */
540 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
541 lp_release_parport (&lp_table
[minor
]);
542 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
546 static int lp_release(struct inode
* inode
, struct file
* file
)
548 unsigned int minor
= iminor(inode
);
550 lp_claim_parport_or_block (&lp_table
[minor
]);
551 parport_negotiate (lp_table
[minor
].dev
->port
, IEEE1284_MODE_COMPAT
);
552 lp_table
[minor
].current_mode
= IEEE1284_MODE_COMPAT
;
553 lp_release_parport (&lp_table
[minor
]);
554 kfree(lp_table
[minor
].lp_buffer
);
555 lp_table
[minor
].lp_buffer
= NULL
;
556 LP_F(minor
) &= ~LP_BUSY
;
560 static int lp_ioctl(struct inode
*inode
, struct file
*file
,
561 unsigned int cmd
, unsigned long arg
)
563 unsigned int minor
= iminor(inode
);
566 void __user
*argp
= (void __user
*)arg
;
569 printk(KERN_DEBUG
"lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor
, cmd
, arg
);
573 if ((LP_F(minor
) & LP_EXIST
) == 0)
576 struct timeval par_timeout
;
580 LP_TIME(minor
) = arg
* HZ
/100;
583 LP_CHAR(minor
) = arg
;
587 LP_F(minor
) |= LP_ABORT
;
589 LP_F(minor
) &= ~LP_ABORT
;
593 LP_F(minor
) |= LP_ABORTOPEN
;
595 LP_F(minor
) &= ~LP_ABORTOPEN
;
599 LP_F(minor
) |= LP_CAREFUL
;
601 LP_F(minor
) &= ~LP_CAREFUL
;
604 LP_WAIT(minor
) = arg
;
610 if (copy_to_user(argp
, &LP_IRQ(minor
),
615 lp_claim_parport_or_block (&lp_table
[minor
]);
616 status
= r_str(minor
);
617 lp_release_parport (&lp_table
[minor
]);
619 if (copy_to_user(argp
, &status
, sizeof(int)))
627 if (copy_to_user(argp
, &LP_STAT(minor
),
628 sizeof(struct lp_stats
)))
630 if (capable(CAP_SYS_ADMIN
))
631 memset(&LP_STAT(minor
), 0,
632 sizeof(struct lp_stats
));
636 status
= LP_F(minor
);
637 if (copy_to_user(argp
, &status
, sizeof(int)))
642 if (copy_from_user (&par_timeout
, argp
,
643 sizeof (struct timeval
))) {
646 /* Convert to jiffies, place in lp_table */
647 if ((par_timeout
.tv_sec
< 0) ||
648 (par_timeout
.tv_usec
< 0)) {
651 to_jiffies
= DIV_ROUND_UP(par_timeout
.tv_usec
, 1000000/HZ
);
652 to_jiffies
+= par_timeout
.tv_sec
* (long) HZ
;
653 if (to_jiffies
<= 0) {
656 lp_table
[minor
].timeout
= to_jiffies
;
665 static const struct file_operations lp_fops
= {
666 .owner
= THIS_MODULE
,
670 .release
= lp_release
,
671 #ifdef CONFIG_PARPORT_1284
676 /* --- support for console on the line printer ----------------- */
678 #ifdef CONFIG_LP_CONSOLE
682 /* If the printer is out of paper, we can either lose the messages or
683 * stall until the printer is happy again. Define CONSOLE_LP_STRICT
684 * non-zero to get the latter behaviour. */
685 #define CONSOLE_LP_STRICT 1
687 /* The console must be locked when we get here. */
689 static void lp_console_write (struct console
*co
, const char *s
,
692 struct pardevice
*dev
= lp_table
[CONSOLE_LP
].dev
;
693 struct parport
*port
= dev
->port
;
696 if (parport_claim (dev
))
697 /* Nothing we can do. */
700 parport_set_timeout (dev
, 0);
702 /* Go to compatibility mode. */
703 parport_negotiate (port
, IEEE1284_MODE_COMPAT
);
706 /* Write the data, converting LF->CRLF as we go. */
707 ssize_t canwrite
= count
;
708 char *lf
= memchr (s
, '\n', count
);
713 written
= parport_write (port
, s
, canwrite
);
723 if (lf
&& canwrite
<= 0) {
724 const char *crlf
= "\r\n";
727 /* Dodge the original '\n', and put '\r\n' instead. */
731 written
= parport_write (port
, crlf
, i
);
733 i
-= written
, crlf
+= written
;
734 } while (i
> 0 && (CONSOLE_LP_STRICT
|| written
> 0));
736 } while (count
> 0 && (CONSOLE_LP_STRICT
|| written
> 0));
738 parport_release (dev
);
741 static struct console lpcons
= {
743 .write
= lp_console_write
,
744 .flags
= CON_PRINTBUFFER
,
747 #endif /* console on line printer */
749 /* --- initialisation code ------------------------------------- */
751 static int parport_nr
[LP_NO
] = { [0 ... LP_NO
-1] = LP_PARPORT_UNSPEC
};
752 static char *parport
[LP_NO
];
755 module_param_array(parport
, charp
, NULL
, 0);
756 module_param(reset
, bool, 0);
759 static int __init
lp_setup (char *str
)
761 static int parport_ptr
;
764 if (get_option(&str
, &x
)) {
766 /* disable driver on "lp=" or "lp=0" */
767 parport_nr
[0] = LP_PARPORT_OFF
;
769 printk(KERN_WARNING
"warning: 'lp=0x%x' is deprecated, ignored\n", x
);
772 } else if (!strncmp(str
, "parport", 7)) {
773 int n
= simple_strtoul(str
+7, NULL
, 10);
774 if (parport_ptr
< LP_NO
)
775 parport_nr
[parport_ptr
++] = n
;
777 printk(KERN_INFO
"lp: too many ports, %s ignored.\n",
779 } else if (!strcmp(str
, "auto")) {
780 parport_nr
[0] = LP_PARPORT_AUTO
;
781 } else if (!strcmp(str
, "none")) {
782 parport_nr
[parport_ptr
++] = LP_PARPORT_NONE
;
783 } else if (!strcmp(str
, "reset")) {
790 static int lp_register(int nr
, struct parport
*port
)
792 lp_table
[nr
].dev
= parport_register_device(port
, "lp",
793 lp_preempt
, NULL
, NULL
, 0,
794 (void *) &lp_table
[nr
]);
795 if (lp_table
[nr
].dev
== NULL
)
797 lp_table
[nr
].flags
|= LP_EXIST
;
802 device_create(lp_class
, port
->dev
, MKDEV(LP_MAJOR
, nr
), "lp%d", nr
);
804 printk(KERN_INFO
"lp%d: using %s (%s).\n", nr
, port
->name
,
805 (port
->irq
== PARPORT_IRQ_NONE
)?"polling":"interrupt-driven");
807 #ifdef CONFIG_LP_CONSOLE
809 if (port
->modes
& PARPORT_MODE_SAFEININT
) {
810 register_console(&lpcons
);
811 console_registered
= port
;
812 printk (KERN_INFO
"lp%d: console ready\n", CONSOLE_LP
);
814 printk (KERN_ERR
"lp%d: cannot run console on %s\n",
815 CONSOLE_LP
, port
->name
);
822 static void lp_attach (struct parport
*port
)
826 switch (parport_nr
[0]) {
827 case LP_PARPORT_UNSPEC
:
828 case LP_PARPORT_AUTO
:
829 if (parport_nr
[0] == LP_PARPORT_AUTO
&&
830 port
->probe_info
[0].class != PARPORT_CLASS_PRINTER
)
832 if (lp_count
== LP_NO
) {
833 printk(KERN_INFO
"lp: ignoring parallel port (max. %d)\n",LP_NO
);
836 if (!lp_register(lp_count
, port
))
841 for (i
= 0; i
< LP_NO
; i
++) {
842 if (port
->number
== parport_nr
[i
]) {
843 if (!lp_register(i
, port
))
852 static void lp_detach (struct parport
*port
)
854 /* Write this some day. */
855 #ifdef CONFIG_LP_CONSOLE
856 if (console_registered
== port
) {
857 unregister_console(&lpcons
);
858 console_registered
= NULL
;
860 #endif /* CONFIG_LP_CONSOLE */
863 static struct parport_driver lp_driver
= {
869 static int __init
lp_init (void)
873 if (parport_nr
[0] == LP_PARPORT_OFF
)
876 for (i
= 0; i
< LP_NO
; i
++) {
877 lp_table
[i
].dev
= NULL
;
878 lp_table
[i
].flags
= 0;
879 lp_table
[i
].chars
= LP_INIT_CHAR
;
880 lp_table
[i
].time
= LP_INIT_TIME
;
881 lp_table
[i
].wait
= LP_INIT_WAIT
;
882 lp_table
[i
].lp_buffer
= NULL
;
884 lp_table
[i
].lastcall
= 0;
885 lp_table
[i
].runchars
= 0;
886 memset (&lp_table
[i
].stats
, 0, sizeof (struct lp_stats
));
888 lp_table
[i
].last_error
= 0;
889 init_waitqueue_head (&lp_table
[i
].waitq
);
890 init_waitqueue_head (&lp_table
[i
].dataq
);
891 mutex_init(&lp_table
[i
].port_mutex
);
892 lp_table
[i
].timeout
= 10 * HZ
;
895 if (register_chrdev (LP_MAJOR
, "lp", &lp_fops
)) {
896 printk (KERN_ERR
"lp: unable to get major %d\n", LP_MAJOR
);
900 lp_class
= class_create(THIS_MODULE
, "printer");
901 if (IS_ERR(lp_class
)) {
902 err
= PTR_ERR(lp_class
);
906 if (parport_register_driver (&lp_driver
)) {
907 printk (KERN_ERR
"lp: unable to register with parport\n");
913 printk (KERN_INFO
"lp: driver loaded but no devices found\n");
914 #ifndef CONFIG_PARPORT_1284
915 if (parport_nr
[0] == LP_PARPORT_AUTO
)
916 printk (KERN_INFO
"lp: (is IEEE 1284 support enabled?)\n");
923 class_destroy(lp_class
);
925 unregister_chrdev(LP_MAJOR
, "lp");
929 static int __init
lp_init_module (void)
932 /* The user gave some parameters. Let's see what they were. */
933 if (!strncmp(parport
[0], "auto", 4))
934 parport_nr
[0] = LP_PARPORT_AUTO
;
937 for (n
= 0; n
< LP_NO
&& parport
[n
]; n
++) {
938 if (!strncmp(parport
[n
], "none", 4))
939 parport_nr
[n
] = LP_PARPORT_NONE
;
942 unsigned long r
= simple_strtoul(parport
[n
], &ep
, 0);
943 if (ep
!= parport
[n
])
946 printk(KERN_ERR
"lp: bad port specifier `%s'\n", parport
[n
]);
957 static void lp_cleanup_module (void)
961 parport_unregister_driver (&lp_driver
);
963 #ifdef CONFIG_LP_CONSOLE
964 unregister_console (&lpcons
);
967 unregister_chrdev(LP_MAJOR
, "lp");
968 for (offset
= 0; offset
< LP_NO
; offset
++) {
969 if (lp_table
[offset
].dev
== NULL
)
971 parport_unregister_device(lp_table
[offset
].dev
);
972 device_destroy(lp_class
, MKDEV(LP_MAJOR
, offset
));
974 class_destroy(lp_class
);
977 __setup("lp=", lp_setup
);
978 module_init(lp_init_module
);
979 module_exit(lp_cleanup_module
);
981 MODULE_ALIAS_CHARDEV_MAJOR(LP_MAJOR
);
982 MODULE_LICENSE("GPL");