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 <Philip.Blundell@pobox.com>
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 * Redesigned interrupt handling for handle printers with buggy handshake
20 * by Andrea Arcangeli, 11 May 1998
21 * Full efficient handling of printer with buggy irq handshake (now I have
22 * understood the meaning of the strange handshake). This is done sending new
23 * characters if the interrupt is just happened, even if the printer say to
24 * be still BUSY. This is needed at least with Epson Stylus Color. To enable
25 * the new TRUST_IRQ mode read the `LP OPTIMIZATION' section below...
26 * Fixed the irq on the rising edge of the strobe case.
27 * Obsoleted the CAREFUL flag since a printer that doesn' t work with
28 * CAREFUL will block a bit after in lp_check_status().
29 * Andrea Arcangeli, 15 Oct 1998
30 * Obsoleted and removed all the lowlevel stuff implemented in the last
31 * month to use the IEEE1284 functions (that handle the _new_ compatibilty
35 /* This driver should, in theory, work with any parallel port that has an
36 * appropriate low-level driver; all I/O is done through the parport
39 * If this driver is built into the kernel, you can configure it using the
40 * kernel command-line. For example:
42 * lp=parport1,none,parport2 (bind lp0 to parport1, disable lp1 and
43 * bind lp2 to parport2)
45 * lp=auto (assign lp devices to all ports that
46 * have printers attached, as determined
47 * by the IEEE-1284 autoprobe)
49 * lp=reset (reset the printer during
52 * lp=off (disable the printer driver entirely)
54 * If the driver is loaded as a module, similar functionality is available
55 * using module parameters. The equivalent of the above commands would be:
57 * # insmod lp.o parport=1,none,2
59 * # insmod lp.o parport=auto
61 * # insmod lp.o reset=1
64 /* COMPATIBILITY WITH OLD KERNELS
66 * Under Linux 2.0 and previous versions, lp devices were bound to ports at
67 * particular I/O addresses, as follows:
73 * The new driver, by default, binds lp devices to parport devices as it
74 * finds them. This means that if you only have one port, it will be bound
75 * to lp0 regardless of its I/O address. If you need the old behaviour, you
76 * can force it using the parameters described above.
80 * The new interrupt handling code take care of the buggy handshake
81 * of some HP and Epson printer:
83 * ACK _______________ ___________
86 * BUSY _________ _______
89 * I discovered this using the printer scanner that you can find at:
91 * ftp://e-mind.com/pub/linux/pscan/
93 * 11 May 98, Andrea Arcangeli
95 * My printer scanner run on an Epson Stylus Color show that such printer
96 * generates the irq on the _rising_ edge of the STROBE. Now lp handle
99 * 15 Oct 1998, Andrea Arcangeli
101 * The so called `buggy' handshake is really the well documented
102 * compatibility mode IEEE1284 handshake. They changed the well known
103 * Centronics handshake acking in the middle of busy expecting to not
104 * break drivers or legacy application, while they broken linux lp
105 * until I fixed it reverse engineering the protocol by hand some
108 * 14 Dec 1998, Andrea Arcangeli
111 #include <linux/module.h>
112 #include <linux/init.h>
114 #include <linux/config.h>
115 #include <linux/errno.h>
116 #include <linux/kernel.h>
117 #include <linux/major.h>
118 #include <linux/sched.h>
119 #include <linux/malloc.h>
120 #include <linux/fcntl.h>
121 #include <linux/delay.h>
122 #include <linux/poll.h>
123 #include <linux/console.h>
125 #include <linux/parport.h>
127 #include <linux/lp.h>
130 #include <asm/uaccess.h>
131 #include <asm/system.h>
133 /* if you have more than 3 printers, remember to increase LP_NO */
136 struct lp_struct lp_table
[LP_NO
];
138 static unsigned int lp_count
= 0;
140 /* Test if printer is ready */
141 #define LP_READY(status) ((status) & LP_PBUSY)
142 /* Test if the printer is not acking the strobe */
143 #define LP_NO_ACKING(status) ((status) & LP_PACK)
144 /* Test if the printer has error conditions */
145 #define LP_NO_ERROR(status) ((status) & LP_PERRORP)
149 /* If you want to see if you can get lp_poll working, define this. */
152 /* --- parport support ----------------------------------------- */
154 static int lp_preempt(void *handle
)
156 struct lp_struct
*lps
= (struct lp_struct
*)handle
;
158 if (!(lps
->flags
& LP_PORT_BUSY
)) {
159 /* Let the port go. */
160 clear_bit (LP_HAVE_PORT_BIT
, &lps
->flags
);
164 if (!(lps
->flags
& LP_PORT_BUSY
)) {
165 /* Let the port go. */
166 clear_bit (LP_HAVE_PORT_BIT
, &lps
->flags
);
170 /* Don't actually release the port now */
174 static void lp_check_data (struct lp_struct
*lp
)
176 #if !defined(CONFIG_PARPORT_1284) || !defined (SUPPORT_POLL)
179 struct pardevice
*dev
= lp
->dev
;
180 if (!(lp
->flags
& LP_NO_REVERSE
)) {
181 int err
= parport_negotiate (dev
->port
, IEEE1284_MODE_NIBBLE
);
183 lp
->flags
|= LP_NO_REVERSE
;
185 unsigned char s
= parport_read_status (dev
->port
);
186 if (s
& PARPORT_STATUS_ERROR
)
187 lp
->flags
&= ~LP_DATA_AVAIL
;
189 lp
->flags
|= LP_DATA_AVAIL
;
190 if (waitqueue_active (&lp
->dataq
))
191 wake_up_interruptible (&lp
->dataq
);
195 #endif /* IEEE 1284 support */
198 static void lp_parport_release (int minor
)
200 lp_check_data (&lp_table
[minor
]);
201 if (test_and_clear_bit (LP_HAVE_PORT_BIT
, &lp_table
[minor
].flags
))
202 parport_release (lp_table
[minor
].dev
);
204 lp_table
[minor
].flags
&= ~LP_PORT_BUSY
;
207 static void lp_parport_claim (int minor
)
209 if (!test_and_set_bit (LP_HAVE_PORT_BIT
, &lp_table
[minor
].flags
))
210 parport_claim_or_block (lp_table
[minor
].dev
);
212 lp_table
[minor
].flags
|= LP_PORT_BUSY
;
215 /* --- low-level port access ----------------------------------- */
217 #define r_dtr(x) (parport_read_data(lp_table[(x)].dev->port))
218 #define r_str(x) (parport_read_status(lp_table[(x)].dev->port))
219 #define w_ctr(x,y) do { parport_write_control(lp_table[(x)].dev->port, (y)); } while (0)
220 #define w_dtr(x,y) do { parport_write_data(lp_table[(x)].dev->port, (y)); } while (0)
222 static int lp_reset(int minor
)
225 lp_parport_claim (minor
);
226 w_ctr(minor
, LP_PSELECP
);
228 w_ctr(minor
, LP_PSELECP
| LP_PINITP
);
229 retval
= r_str(minor
);
230 lp_parport_release (minor
);
234 static void lp_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
236 struct lp_struct
*lp_dev
= (struct lp_struct
*) dev_id
;
237 if (!(lp_dev
->flags
& LP_PORT_BUSY
))
238 /* We must have the port since we got an interrupt. */
239 lp_check_data (lp_dev
);
240 if (waitqueue_active (&lp_dev
->waitq
))
241 wake_up_interruptible (&lp_dev
->waitq
);
244 static void lp_wakeup (void *handle
)
246 struct lp_struct
*lp_dev
= handle
;
248 if (lp_dev
->flags
& LP_PORT_BUSY
)
251 /* Grab the port if it can help (i.e. reverse mode is possible). */
252 if (!(lp_dev
->flags
& LP_NO_REVERSE
)) {
253 parport_claim (lp_dev
->dev
);
254 set_bit (LP_HAVE_PORT_BIT
, &lp_dev
->flags
);
255 lp_check_data (lp_dev
);
256 if (waitqueue_active (&lp_dev
->waitq
))
257 wake_up_interruptible (&lp_dev
->waitq
);
261 static void lp_error (int minor
)
265 if (LP_F(minor
) & LP_ABORT
)
268 polling
= lp_table
[minor
].dev
->port
->irq
== PARPORT_IRQ_NONE
;
269 if (polling
) lp_parport_release (minor
);
270 interruptible_sleep_on_timeout (&lp_table
[minor
].waitq
,
272 if (polling
) lp_parport_claim (minor
);
273 else parport_yield_blocking (lp_table
[minor
].dev
);
276 static int lp_check_status(int minor
)
279 unsigned int last
= lp_table
[minor
].last_error
;
280 unsigned char status
= r_str(minor
);
281 if (status
& LP_PERRORP
)
284 else if ((status
& LP_POUTPA
)) {
285 if (last
!= LP_POUTPA
) {
287 printk(KERN_INFO
"lp%d out of paper\n", minor
);
290 } else if (!(status
& LP_PSELECD
)) {
291 if (last
!= LP_PSELECD
) {
293 printk(KERN_INFO
"lp%d off-line\n", minor
);
297 if (last
!= LP_PERRORP
) {
299 printk(KERN_INFO
"lp%d on fire\n", minor
);
304 lp_table
[minor
].last_error
= last
;
312 static ssize_t
lp_write(struct file
* file
, const char * buf
,
313 size_t count
, loff_t
*ppos
)
315 unsigned int minor
= MINOR(file
->f_dentry
->d_inode
->i_rdev
);
316 struct parport
*port
= lp_table
[minor
].dev
->port
;
317 char *kbuf
= lp_table
[minor
].lp_buffer
;
320 size_t copy_size
= count
;
323 if (jiffies
-lp_table
[minor
].lastcall
> LP_TIME(minor
))
324 lp_table
[minor
].runchars
= 0;
326 lp_table
[minor
].lastcall
= jiffies
;
329 /* Need to copy the data from user-space. */
330 if (copy_size
> LP_BUFFER_SIZE
)
331 copy_size
= LP_BUFFER_SIZE
;
333 if (copy_from_user (kbuf
, buf
, copy_size
))
336 /* Claim Parport or sleep until it becomes available
338 lp_parport_claim (minor
);
340 /* Go to compatibility mode. */
341 parport_negotiate (port
, IEEE1284_MODE_COMPAT
);
344 /* Wait until lp_read has finished. */
345 if (down_interruptible (&lp_table
[minor
].port_mutex
))
348 /* Write the data. */
349 written
= parport_write (port
, kbuf
, copy_size
);
351 copy_size
-= written
;
357 up (&lp_table
[minor
].port_mutex
);
359 if (signal_pending (current
)) {
367 /* incomplete write -> check error ! */
368 int error
= lp_check_status (minor
);
370 if (LP_F(minor
) & LP_ABORT
) {
376 parport_yield_blocking (lp_table
[minor
].dev
);
377 } else if (current
->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 lp_parport_release (minor
);
398 static long long lp_lseek(struct file
* file
, long long offset
, int origin
)
403 #ifdef CONFIG_PARPORT_1284
405 /* Status readback conforming to ieee1284 */
406 static ssize_t
lp_read(struct file
* file
, char * buf
,
407 size_t count
, loff_t
*ppos
)
409 unsigned int minor
=MINOR(file
->f_dentry
->d_inode
->i_rdev
);
410 struct parport
*port
= lp_table
[minor
].dev
->port
;
412 char *kbuf
= lp_table
[minor
].lp_buffer
;
414 if (count
> LP_BUFFER_SIZE
)
415 count
= LP_BUFFER_SIZE
;
417 lp_parport_claim (minor
);
419 if (!down_interruptible (&lp_table
[minor
].port_mutex
)) {
421 retval
= parport_read (port
, kbuf
, count
);
426 if (file
->f_flags
& O_NONBLOCK
)
429 /* Wait for an interrupt. */
430 interruptible_sleep_on_timeout (&lp_table
[minor
].waitq
,
433 if (signal_pending (current
)) {
439 up (&lp_table
[minor
].port_mutex
);
442 lp_parport_release (minor
);
444 if (retval
> 0 && copy_to_user (buf
, kbuf
, retval
))
450 #endif /* IEEE 1284 support */
452 static int lp_open(struct inode
* inode
, struct file
* file
)
454 unsigned int minor
= MINOR(inode
->i_rdev
);
458 if ((LP_F(minor
) & LP_EXIST
) == 0)
460 if (test_and_set_bit(LP_BUSY_BIT_POS
, &LP_F(minor
)))
465 /* If ABORTOPEN is set and the printer is offline or out of paper,
466 we may still want to open it to perform ioctl()s. Therefore we
467 have commandeered O_NONBLOCK, even though it is being used in
468 a non-standard manner. This is strictly a Linux hack, and
469 should most likely only ever be used by the tunelp application. */
470 if ((LP_F(minor
) & LP_ABORTOPEN
) && !(file
->f_flags
& O_NONBLOCK
)) {
472 lp_parport_claim (minor
);
473 status
= r_str(minor
);
474 lp_parport_release (minor
);
475 if (status
& LP_POUTPA
) {
476 printk(KERN_INFO
"lp%d out of paper\n", minor
);
478 LP_F(minor
) &= ~LP_BUSY
;
480 } else if (!(status
& LP_PSELECD
)) {
481 printk(KERN_INFO
"lp%d off-line\n", minor
);
483 LP_F(minor
) &= ~LP_BUSY
;
485 } else if (!(status
& LP_PERRORP
)) {
486 printk(KERN_ERR
"lp%d printer error\n", minor
);
488 LP_F(minor
) &= ~LP_BUSY
;
492 lp_table
[minor
].lp_buffer
= (char *) kmalloc(LP_BUFFER_SIZE
, GFP_KERNEL
);
493 if (!lp_table
[minor
].lp_buffer
) {
495 LP_F(minor
) &= ~LP_BUSY
;
501 static int lp_release(struct inode
* inode
, struct file
* file
)
503 unsigned int minor
= MINOR(inode
->i_rdev
);
505 kfree_s(lp_table
[minor
].lp_buffer
, LP_BUFFER_SIZE
);
506 lp_table
[minor
].lp_buffer
= NULL
;
508 LP_F(minor
) &= ~LP_BUSY
;
512 static int lp_ioctl(struct inode
*inode
, struct file
*file
,
513 unsigned int cmd
, unsigned long arg
)
515 unsigned int minor
= MINOR(inode
->i_rdev
);
520 printk(KERN_DEBUG
"lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor
, cmd
, arg
);
524 if ((LP_F(minor
) & LP_EXIST
) == 0)
528 LP_TIME(minor
) = arg
* HZ
/100;
531 LP_CHAR(minor
) = arg
;
535 LP_F(minor
) |= LP_ABORT
;
537 LP_F(minor
) &= ~LP_ABORT
;
541 LP_F(minor
) |= LP_ABORTOPEN
;
543 LP_F(minor
) &= ~LP_ABORTOPEN
;
548 LP_F(minor
) |= LP_CAREFUL
;
550 LP_F(minor
) &= ~LP_CAREFUL
;
554 LP_WAIT(minor
) = arg
;
560 if (copy_to_user((int *) arg
, &LP_IRQ(minor
),
565 lp_parport_claim(minor
);
566 status
= r_str(minor
);
567 lp_parport_release(minor
);
569 if (copy_to_user((int *) arg
, &status
, sizeof(int)))
577 if (copy_to_user((int *) arg
, &LP_STAT(minor
),
578 sizeof(struct lp_stats
)))
581 memset(&LP_STAT(minor
), 0,
582 sizeof(struct lp_stats
));
586 status
= LP_F(minor
);
587 if (copy_to_user((int *) arg
, &status
, sizeof(int)))
596 #ifdef CONFIG_PARPORT_1284
597 static unsigned int lp_poll (struct file
*filp
, struct poll_table_struct
*wait
)
599 unsigned int minor
= MINOR (filp
->f_dentry
->d_inode
->i_rdev
);
600 unsigned int mask
= POLLOUT
| POLLWRNORM
; /* always writable */
602 poll_wait (filp
, &lp_table
[minor
].dataq
, wait
);
604 if (lp_table
[minor
].flags
& LP_DATA_AVAIL
)
605 mask
|= POLLIN
| POLLRDNORM
;
609 #endif /* IEEE 1284 support */
611 static struct file_operations lp_fops
= {
613 #ifdef CONFIG_PARPORT_1284
619 NULL
, /* lp_readdir */
620 #ifdef CONFIG_PARPORT_1284
632 /* --- support for console on the line printer ----------------- */
634 #ifdef CONFIG_LP_CONSOLE
638 /* If the printer is out of paper, we can either lose the messages or
639 * stall until the printer is happy again. Define CONSOLE_LP_STRICT
640 * non-zero to get the latter behaviour. */
641 #define CONSOLE_LP_STRICT 1
643 static void lp_console_write (struct console
*co
, const char *s
,
646 struct pardevice
*dev
= lp_table
[CONSOLE_LP
].dev
;
647 struct parport
*port
= dev
->port
;
651 if (!(lp_table
[CONSOLE_LP
].flags
& (1<<LP_HAVE_PORT_BIT
))) {
652 if (parport_claim (dev
))
653 /* Nothing we can do. */
655 set_bit (LP_HAVE_PORT_BIT
, &lp_table
[CONSOLE_LP
].flags
);
658 old_to
= parport_set_timeout (dev
, 0);
660 /* Go to compatibility mode. */
661 parport_negotiate (port
, IEEE1284_MODE_COMPAT
);
664 /* Write the data. */
665 written
= parport_write (port
, s
, count
);
670 } while (count
> 0 && (CONSOLE_LP_STRICT
|| written
> 0));
672 parport_set_timeout (dev
, old_to
);
675 static kdev_t
lp_console_device (struct console
*c
)
677 return MKDEV(LP_MAJOR
, CONSOLE_LP
);
680 static struct console lpcons
= {
694 #endif /* console on line printer */
696 /* --- initialisation code ------------------------------------- */
700 static int parport_nr
[LP_NO
] = { [0 ... LP_NO
-1] = LP_PARPORT_UNSPEC
};
701 static char *parport
[LP_NO
] = { NULL
, };
702 static int reset
= 0;
704 MODULE_PARM(parport
, "1-" __MODULE_STRING(LP_NO
) "s");
705 MODULE_PARM(reset
, "i");
709 static int parport_nr
[LP_NO
] = { [0 ... LP_NO
-1] = LP_PARPORT_UNSPEC
};
710 static int reset
= 0;
712 static int parport_ptr
= 0;
714 __initfunc(void lp_setup(char *str
, int *ints
))
717 if (ints
[0] == 0 || ints
[1] == 0) {
718 /* disable driver on "lp=" or "lp=0" */
719 parport_nr
[0] = LP_PARPORT_OFF
;
721 printk(KERN_WARNING
"warning: 'lp=0x%x' is deprecated, ignored\n", ints
[1]);
723 } else if (!strncmp(str
, "parport", 7)) {
724 int n
= simple_strtoul(str
+7, NULL
, 10);
725 if (parport_ptr
< LP_NO
)
726 parport_nr
[parport_ptr
++] = n
;
728 printk(KERN_INFO
"lp: too many ports, %s ignored.\n",
730 } else if (!strcmp(str
, "auto")) {
731 parport_nr
[0] = LP_PARPORT_AUTO
;
732 } else if (!strcmp(str
, "none")) {
733 parport_nr
[parport_ptr
++] = LP_PARPORT_NONE
;
734 } else if (!strcmp(str
, "reset")) {
741 static int lp_register(int nr
, struct parport
*port
)
743 lp_table
[nr
].dev
= parport_register_device(port
, "lp",
744 lp_preempt
, lp_wakeup
,
747 (void *) &lp_table
[nr
]);
748 if (lp_table
[nr
].dev
== NULL
)
750 lp_table
[nr
].flags
|= LP_EXIST
;
755 printk(KERN_INFO
"lp%d: using %s (%s).\n", nr
, port
->name
,
756 (port
->irq
== PARPORT_IRQ_NONE
)?"polling":"interrupt-driven");
761 static void lp_attach (struct parport
*port
)
765 switch (parport_nr
[0])
767 case LP_PARPORT_UNSPEC
:
768 case LP_PARPORT_AUTO
:
769 if (parport_nr
[0] == LP_PARPORT_AUTO
&&
770 port
->probe_info
[0].class != PARPORT_CLASS_PRINTER
)
773 if (!lp_register(lp_count
, port
))
774 if (++lp_count
== LP_NO
)
780 for (i
= 0; i
< LP_NO
; i
++) {
781 if (port
->number
== parport_nr
[i
]) {
782 if (!lp_register(i
, port
))
791 static void lp_detach (struct parport
*port
)
793 /* Write this some day. */
796 static struct parport_driver lp_driver
= {
803 int __init
lp_init (void)
807 if (parport_nr
[0] == LP_PARPORT_OFF
)
810 for (i
= 0; i
< LP_NO
; i
++) {
811 lp_table
[i
].dev
= NULL
;
812 lp_table
[i
].flags
= 0;
813 lp_table
[i
].chars
= LP_INIT_CHAR
;
814 lp_table
[i
].time
= LP_INIT_TIME
;
815 lp_table
[i
].wait
= LP_INIT_WAIT
;
816 lp_table
[i
].lp_buffer
= NULL
;
818 lp_table
[i
].lastcall
= 0;
819 lp_table
[i
].runchars
= 0;
820 memset (&lp_table
[i
].stats
, 0, sizeof (struct lp_stats
));
822 lp_table
[i
].last_error
= 0;
823 init_waitqueue_head (&lp_table
[i
].waitq
);
824 init_waitqueue_head (&lp_table
[i
].dataq
);
825 init_MUTEX (&lp_table
[i
].port_mutex
);
828 if (register_chrdev (LP_MAJOR
, "lp", &lp_fops
)) {
829 printk ("lp: unable to get major %d\n", LP_MAJOR
);
833 if (parport_register_driver (&lp_driver
)) {
834 printk ("lp: unable to register with parport\n");
839 printk (KERN_INFO
"lp: driver loaded but no devices found\n");
840 #ifndef CONFIG_PARPORT_12843
841 if (parport_nr
[0] == LP_PARPORT_AUTO
)
842 printk (KERN_INFO
"lp: (is IEEE 1284.3 support enabled?)\n");
845 #ifdef CONFIG_LP_CONSOLE
847 register_console (&lpcons
);
848 printk (KERN_INFO
"lp%d: console ready\n", CONSOLE_LP
);
856 int init_module(void)
859 /* The user gave some parameters. Let's see what they were. */
860 if (!strncmp(parport
[0], "auto", 4))
861 parport_nr
[0] = LP_PARPORT_AUTO
;
864 for (n
= 0; n
< LP_NO
&& parport
[n
]; n
++) {
865 if (!strncmp(parport
[n
], "none", 4))
866 parport_nr
[n
] = LP_PARPORT_NONE
;
869 unsigned long r
= simple_strtoul(parport
[n
], &ep
, 0);
870 if (ep
!= parport
[n
])
873 printk(KERN_ERR
"lp: bad port specifier `%s'\n", parport
[n
]);
884 void cleanup_module(void)
888 parport_unregister_driver (&lp_driver
);
890 #ifdef CONFIG_LP_CONSOLE
891 unregister_console (&lpcons
);
894 unregister_chrdev(LP_MAJOR
, "lp");
895 for (offset
= 0; offset
< LP_NO
; offset
++) {
896 if (lp_table
[offset
].dev
== NULL
)
898 if (lp_table
[offset
].flags
& (1<<LP_HAVE_PORT_BIT
))
899 parport_release (lp_table
[offset
].dev
);
900 parport_unregister_device(lp_table
[offset
].dev
);