Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[linux/fpc-iii.git] / drivers / char / ppdev.c
blobbee6c47b45bdd162e33e50e32171667dd6df8df8
1 /*
2 * linux/drivers/char/ppdev.c
4 * This is the code behind /dev/parport* -- it allows a user-space
5 * application to use the parport subsystem.
7 * Copyright (C) 1998-2000, 2002 Tim Waugh <tim@cyberelk.net>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * A /dev/parportx device node represents an arbitrary device
15 * on port 'x'. The following operations are possible:
17 * open do nothing, set up default IEEE 1284 protocol to be COMPAT
18 * close release port and unregister device (if necessary)
19 * ioctl
20 * EXCL register device exclusively (may fail)
21 * CLAIM (register device first time) parport_claim_or_block
22 * RELEASE parport_release
23 * SETMODE set the IEEE 1284 protocol to use for read/write
24 * SETPHASE set the IEEE 1284 phase of a particular mode. Not to be
25 * confused with ioctl(fd, SETPHASER, &stun). ;-)
26 * DATADIR data_forward / data_reverse
27 * WDATA write_data
28 * RDATA read_data
29 * WCONTROL write_control
30 * RCONTROL read_control
31 * FCONTROL frob_control
32 * RSTATUS read_status
33 * NEGOT parport_negotiate
34 * YIELD parport_yield_blocking
35 * WCTLONIRQ on interrupt, set control lines
36 * CLRIRQ clear (and return) interrupt count
37 * SETTIME sets device timeout (struct timeval)
38 * GETTIME gets device timeout (struct timeval)
39 * GETMODES gets hardware supported modes (unsigned int)
40 * GETMODE gets the current IEEE1284 mode
41 * GETPHASE gets the current IEEE1284 phase
42 * GETFLAGS gets current (user-visible) flags
43 * SETFLAGS sets current (user-visible) flags
44 * read/write read or write in current IEEE 1284 protocol
45 * select wait for interrupt (in readfds)
47 * Changes:
48 * Added SETTIME/GETTIME ioctl, Fred Barnes, 1999.
50 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 2000/08/25
51 * - On error, copy_from_user and copy_to_user do not return -EFAULT,
52 * They return the positive number of bytes *not* copied due to address
53 * space errors.
55 * Added GETMODES/GETMODE/GETPHASE ioctls, Fred Barnes <frmb2@ukc.ac.uk>, 03/01/2001.
56 * Added GETFLAGS/SETFLAGS ioctls, Fred Barnes, 04/2001
59 #include <linux/module.h>
60 #include <linux/init.h>
61 #include <linux/sched.h>
62 #include <linux/device.h>
63 #include <linux/devfs_fs_kernel.h>
64 #include <linux/ioctl.h>
65 #include <linux/parport.h>
66 #include <linux/ctype.h>
67 #include <linux/poll.h>
68 #include <linux/major.h>
69 #include <linux/ppdev.h>
70 #include <linux/smp_lock.h>
71 #include <linux/device.h>
72 #include <asm/uaccess.h>
74 #define PP_VERSION "ppdev: user-space parallel port driver"
75 #define CHRDEV "ppdev"
77 struct pp_struct {
78 struct pardevice * pdev;
79 wait_queue_head_t irq_wait;
80 atomic_t irqc;
81 unsigned int flags;
82 int irqresponse;
83 unsigned char irqctl;
84 struct ieee1284_info state;
85 struct ieee1284_info saved_state;
86 long default_inactivity;
89 /* pp_struct.flags bitfields */
90 #define PP_CLAIMED (1<<0)
91 #define PP_EXCL (1<<1)
93 /* Other constants */
94 #define PP_INTERRUPT_TIMEOUT (10 * HZ) /* 10s */
95 #define PP_BUFFER_SIZE 1024
96 #define PARDEVICE_MAX 8
98 /* ROUND_UP macro from fs/select.c */
99 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
101 static inline void pp_enable_irq (struct pp_struct *pp)
103 struct parport *port = pp->pdev->port;
104 port->ops->enable_irq (port);
107 static ssize_t pp_read (struct file * file, char __user * buf, size_t count,
108 loff_t * ppos)
110 unsigned int minor = iminor(file->f_dentry->d_inode);
111 struct pp_struct *pp = file->private_data;
112 char * kbuffer;
113 ssize_t bytes_read = 0;
114 struct parport *pport;
115 int mode;
117 if (!(pp->flags & PP_CLAIMED)) {
118 /* Don't have the port claimed */
119 printk (KERN_DEBUG CHRDEV "%x: claim the port first\n",
120 minor);
121 return -EINVAL;
124 /* Trivial case. */
125 if (count == 0)
126 return 0;
128 kbuffer = kmalloc(min_t(size_t, count, PP_BUFFER_SIZE), GFP_KERNEL);
129 if (!kbuffer) {
130 return -ENOMEM;
132 pport = pp->pdev->port;
133 mode = pport->ieee1284.mode & ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
135 parport_set_timeout (pp->pdev,
136 (file->f_flags & O_NONBLOCK) ?
137 PARPORT_INACTIVITY_O_NONBLOCK :
138 pp->default_inactivity);
140 while (bytes_read == 0) {
141 ssize_t need = min_t(unsigned long, count, PP_BUFFER_SIZE);
143 if (mode == IEEE1284_MODE_EPP) {
144 /* various specials for EPP mode */
145 int flags = 0;
146 size_t (*fn)(struct parport *, void *, size_t, int);
148 if (pp->flags & PP_W91284PIC) {
149 flags |= PARPORT_W91284PIC;
151 if (pp->flags & PP_FASTREAD) {
152 flags |= PARPORT_EPP_FAST;
154 if (pport->ieee1284.mode & IEEE1284_ADDR) {
155 fn = pport->ops->epp_read_addr;
156 } else {
157 fn = pport->ops->epp_read_data;
159 bytes_read = (*fn)(pport, kbuffer, need, flags);
160 } else {
161 bytes_read = parport_read (pport, kbuffer, need);
164 if (bytes_read != 0)
165 break;
167 if (file->f_flags & O_NONBLOCK) {
168 bytes_read = -EAGAIN;
169 break;
172 if (signal_pending (current)) {
173 bytes_read = -ERESTARTSYS;
174 break;
177 cond_resched();
180 parport_set_timeout (pp->pdev, pp->default_inactivity);
182 if (bytes_read > 0 && copy_to_user (buf, kbuffer, bytes_read))
183 bytes_read = -EFAULT;
185 kfree (kbuffer);
186 pp_enable_irq (pp);
187 return bytes_read;
190 static ssize_t pp_write (struct file * file, const char __user * buf,
191 size_t count, loff_t * ppos)
193 unsigned int minor = iminor(file->f_dentry->d_inode);
194 struct pp_struct *pp = file->private_data;
195 char * kbuffer;
196 ssize_t bytes_written = 0;
197 ssize_t wrote;
198 int mode;
199 struct parport *pport;
201 if (!(pp->flags & PP_CLAIMED)) {
202 /* Don't have the port claimed */
203 printk (KERN_DEBUG CHRDEV "%x: claim the port first\n",
204 minor);
205 return -EINVAL;
208 kbuffer = kmalloc(min_t(size_t, count, PP_BUFFER_SIZE), GFP_KERNEL);
209 if (!kbuffer) {
210 return -ENOMEM;
212 pport = pp->pdev->port;
213 mode = pport->ieee1284.mode & ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
215 parport_set_timeout (pp->pdev,
216 (file->f_flags & O_NONBLOCK) ?
217 PARPORT_INACTIVITY_O_NONBLOCK :
218 pp->default_inactivity);
220 while (bytes_written < count) {
221 ssize_t n = min_t(unsigned long, count - bytes_written, PP_BUFFER_SIZE);
223 if (copy_from_user (kbuffer, buf + bytes_written, n)) {
224 bytes_written = -EFAULT;
225 break;
228 if ((pp->flags & PP_FASTWRITE) && (mode == IEEE1284_MODE_EPP)) {
229 /* do a fast EPP write */
230 if (pport->ieee1284.mode & IEEE1284_ADDR) {
231 wrote = pport->ops->epp_write_addr (pport,
232 kbuffer, n, PARPORT_EPP_FAST);
233 } else {
234 wrote = pport->ops->epp_write_data (pport,
235 kbuffer, n, PARPORT_EPP_FAST);
237 } else {
238 wrote = parport_write (pp->pdev->port, kbuffer, n);
241 if (wrote <= 0) {
242 if (!bytes_written) {
243 bytes_written = wrote;
245 break;
248 bytes_written += wrote;
250 if (file->f_flags & O_NONBLOCK) {
251 if (!bytes_written)
252 bytes_written = -EAGAIN;
253 break;
256 if (signal_pending (current)) {
257 if (!bytes_written) {
258 bytes_written = -EINTR;
260 break;
263 cond_resched();
266 parport_set_timeout (pp->pdev, pp->default_inactivity);
268 kfree (kbuffer);
269 pp_enable_irq (pp);
270 return bytes_written;
273 static void pp_irq (int irq, void * private, struct pt_regs * unused)
275 struct pp_struct * pp = (struct pp_struct *) private;
277 if (pp->irqresponse) {
278 parport_write_control (pp->pdev->port, pp->irqctl);
279 pp->irqresponse = 0;
282 atomic_inc (&pp->irqc);
283 wake_up_interruptible (&pp->irq_wait);
286 static int register_device (int minor, struct pp_struct *pp)
288 struct parport *port;
289 struct pardevice * pdev = NULL;
290 char *name;
291 int fl;
293 name = kmalloc (strlen (CHRDEV) + 3, GFP_KERNEL);
294 if (name == NULL)
295 return -ENOMEM;
297 sprintf (name, CHRDEV "%x", minor);
299 port = parport_find_number (minor);
300 if (!port) {
301 printk (KERN_WARNING "%s: no associated port!\n", name);
302 kfree (name);
303 return -ENXIO;
306 fl = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
307 pdev = parport_register_device (port, name, NULL,
308 NULL, pp_irq, fl, pp);
309 parport_put_port (port);
311 if (!pdev) {
312 printk (KERN_WARNING "%s: failed to register device!\n", name);
313 kfree (name);
314 return -ENXIO;
317 pp->pdev = pdev;
318 printk (KERN_DEBUG "%s: registered pardevice\n", name);
319 return 0;
322 static enum ieee1284_phase init_phase (int mode)
324 switch (mode & ~(IEEE1284_DEVICEID
325 | IEEE1284_ADDR)) {
326 case IEEE1284_MODE_NIBBLE:
327 case IEEE1284_MODE_BYTE:
328 return IEEE1284_PH_REV_IDLE;
330 return IEEE1284_PH_FWD_IDLE;
333 static int pp_ioctl(struct inode *inode, struct file *file,
334 unsigned int cmd, unsigned long arg)
336 unsigned int minor = iminor(inode);
337 struct pp_struct *pp = file->private_data;
338 struct parport * port;
339 void __user *argp = (void __user *)arg;
341 /* First handle the cases that don't take arguments. */
342 switch (cmd) {
343 case PPCLAIM:
345 struct ieee1284_info *info;
346 int ret;
348 if (pp->flags & PP_CLAIMED) {
349 printk (KERN_DEBUG CHRDEV
350 "%x: you've already got it!\n", minor);
351 return -EINVAL;
354 /* Deferred device registration. */
355 if (!pp->pdev) {
356 int err = register_device (minor, pp);
357 if (err) {
358 return err;
362 ret = parport_claim_or_block (pp->pdev);
363 if (ret < 0)
364 return ret;
366 pp->flags |= PP_CLAIMED;
368 /* For interrupt-reporting to work, we need to be
369 * informed of each interrupt. */
370 pp_enable_irq (pp);
372 /* We may need to fix up the state machine. */
373 info = &pp->pdev->port->ieee1284;
374 pp->saved_state.mode = info->mode;
375 pp->saved_state.phase = info->phase;
376 info->mode = pp->state.mode;
377 info->phase = pp->state.phase;
378 pp->default_inactivity = parport_set_timeout (pp->pdev, 0);
379 parport_set_timeout (pp->pdev, pp->default_inactivity);
381 return 0;
383 case PPEXCL:
384 if (pp->pdev) {
385 printk (KERN_DEBUG CHRDEV "%x: too late for PPEXCL; "
386 "already registered\n", minor);
387 if (pp->flags & PP_EXCL)
388 /* But it's not really an error. */
389 return 0;
390 /* There's no chance of making the driver happy. */
391 return -EINVAL;
394 /* Just remember to register the device exclusively
395 * when we finally do the registration. */
396 pp->flags |= PP_EXCL;
397 return 0;
398 case PPSETMODE:
400 int mode;
401 if (copy_from_user (&mode, argp, sizeof (mode)))
402 return -EFAULT;
403 /* FIXME: validate mode */
404 pp->state.mode = mode;
405 pp->state.phase = init_phase (mode);
407 if (pp->flags & PP_CLAIMED) {
408 pp->pdev->port->ieee1284.mode = mode;
409 pp->pdev->port->ieee1284.phase = pp->state.phase;
412 return 0;
414 case PPGETMODE:
416 int mode;
418 if (pp->flags & PP_CLAIMED) {
419 mode = pp->pdev->port->ieee1284.mode;
420 } else {
421 mode = pp->state.mode;
423 if (copy_to_user (argp, &mode, sizeof (mode))) {
424 return -EFAULT;
426 return 0;
428 case PPSETPHASE:
430 int phase;
431 if (copy_from_user (&phase, argp, sizeof (phase))) {
432 return -EFAULT;
434 /* FIXME: validate phase */
435 pp->state.phase = phase;
437 if (pp->flags & PP_CLAIMED) {
438 pp->pdev->port->ieee1284.phase = phase;
441 return 0;
443 case PPGETPHASE:
445 int phase;
447 if (pp->flags & PP_CLAIMED) {
448 phase = pp->pdev->port->ieee1284.phase;
449 } else {
450 phase = pp->state.phase;
452 if (copy_to_user (argp, &phase, sizeof (phase))) {
453 return -EFAULT;
455 return 0;
457 case PPGETMODES:
459 unsigned int modes;
461 port = parport_find_number (minor);
462 if (!port)
463 return -ENODEV;
465 modes = port->modes;
466 if (copy_to_user (argp, &modes, sizeof (modes))) {
467 return -EFAULT;
469 return 0;
471 case PPSETFLAGS:
473 int uflags;
475 if (copy_from_user (&uflags, argp, sizeof (uflags))) {
476 return -EFAULT;
478 pp->flags &= ~PP_FLAGMASK;
479 pp->flags |= (uflags & PP_FLAGMASK);
480 return 0;
482 case PPGETFLAGS:
484 int uflags;
486 uflags = pp->flags & PP_FLAGMASK;
487 if (copy_to_user (argp, &uflags, sizeof (uflags))) {
488 return -EFAULT;
490 return 0;
492 } /* end switch() */
494 /* Everything else requires the port to be claimed, so check
495 * that now. */
496 if ((pp->flags & PP_CLAIMED) == 0) {
497 printk (KERN_DEBUG CHRDEV "%x: claim the port first\n",
498 minor);
499 return -EINVAL;
502 port = pp->pdev->port;
503 switch (cmd) {
504 struct ieee1284_info *info;
505 unsigned char reg;
506 unsigned char mask;
507 int mode;
508 int ret;
509 struct timeval par_timeout;
510 long to_jiffies;
512 case PPRSTATUS:
513 reg = parport_read_status (port);
514 if (copy_to_user (argp, &reg, sizeof (reg)))
515 return -EFAULT;
516 return 0;
517 case PPRDATA:
518 reg = parport_read_data (port);
519 if (copy_to_user (argp, &reg, sizeof (reg)))
520 return -EFAULT;
521 return 0;
522 case PPRCONTROL:
523 reg = parport_read_control (port);
524 if (copy_to_user (argp, &reg, sizeof (reg)))
525 return -EFAULT;
526 return 0;
527 case PPYIELD:
528 parport_yield_blocking (pp->pdev);
529 return 0;
531 case PPRELEASE:
532 /* Save the state machine's state. */
533 info = &pp->pdev->port->ieee1284;
534 pp->state.mode = info->mode;
535 pp->state.phase = info->phase;
536 info->mode = pp->saved_state.mode;
537 info->phase = pp->saved_state.phase;
538 parport_release (pp->pdev);
539 pp->flags &= ~PP_CLAIMED;
540 return 0;
542 case PPWCONTROL:
543 if (copy_from_user (&reg, argp, sizeof (reg)))
544 return -EFAULT;
545 parport_write_control (port, reg);
546 return 0;
548 case PPWDATA:
549 if (copy_from_user (&reg, argp, sizeof (reg)))
550 return -EFAULT;
551 parport_write_data (port, reg);
552 return 0;
554 case PPFCONTROL:
555 if (copy_from_user (&mask, argp,
556 sizeof (mask)))
557 return -EFAULT;
558 if (copy_from_user (&reg, 1 + (unsigned char __user *) arg,
559 sizeof (reg)))
560 return -EFAULT;
561 parport_frob_control (port, mask, reg);
562 return 0;
564 case PPDATADIR:
565 if (copy_from_user (&mode, argp, sizeof (mode)))
566 return -EFAULT;
567 if (mode)
568 port->ops->data_reverse (port);
569 else
570 port->ops->data_forward (port);
571 return 0;
573 case PPNEGOT:
574 if (copy_from_user (&mode, argp, sizeof (mode)))
575 return -EFAULT;
576 switch ((ret = parport_negotiate (port, mode))) {
577 case 0: break;
578 case -1: /* handshake failed, peripheral not IEEE 1284 */
579 ret = -EIO;
580 break;
581 case 1: /* handshake succeeded, peripheral rejected mode */
582 ret = -ENXIO;
583 break;
585 pp_enable_irq (pp);
586 return ret;
588 case PPWCTLONIRQ:
589 if (copy_from_user (&reg, argp, sizeof (reg)))
590 return -EFAULT;
592 /* Remember what to set the control lines to, for next
593 * time we get an interrupt. */
594 pp->irqctl = reg;
595 pp->irqresponse = 1;
596 return 0;
598 case PPCLRIRQ:
599 ret = atomic_read (&pp->irqc);
600 if (copy_to_user (argp, &ret, sizeof (ret)))
601 return -EFAULT;
602 atomic_sub (ret, &pp->irqc);
603 return 0;
605 case PPSETTIME:
606 if (copy_from_user (&par_timeout, argp, sizeof(struct timeval))) {
607 return -EFAULT;
609 /* Convert to jiffies, place in pp->pdev->timeout */
610 if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) {
611 return -EINVAL;
613 to_jiffies = ROUND_UP(par_timeout.tv_usec, 1000000/HZ);
614 to_jiffies += par_timeout.tv_sec * (long)HZ;
615 if (to_jiffies <= 0) {
616 return -EINVAL;
618 pp->pdev->timeout = to_jiffies;
619 return 0;
621 case PPGETTIME:
622 to_jiffies = pp->pdev->timeout;
623 par_timeout.tv_sec = to_jiffies / HZ;
624 par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ);
625 if (copy_to_user (argp, &par_timeout, sizeof(struct timeval)))
626 return -EFAULT;
627 return 0;
629 default:
630 printk (KERN_DEBUG CHRDEV "%x: What? (cmd=0x%x)\n", minor,
631 cmd);
632 return -EINVAL;
635 /* Keep the compiler happy */
636 return 0;
639 static int pp_open (struct inode * inode, struct file * file)
641 unsigned int minor = iminor(inode);
642 struct pp_struct *pp;
644 if (minor >= PARPORT_MAX)
645 return -ENXIO;
647 pp = kmalloc (sizeof (struct pp_struct), GFP_KERNEL);
648 if (!pp)
649 return -ENOMEM;
651 pp->state.mode = IEEE1284_MODE_COMPAT;
652 pp->state.phase = init_phase (pp->state.mode);
653 pp->flags = 0;
654 pp->irqresponse = 0;
655 atomic_set (&pp->irqc, 0);
656 init_waitqueue_head (&pp->irq_wait);
658 /* Defer the actual device registration until the first claim.
659 * That way, we know whether or not the driver wants to have
660 * exclusive access to the port (PPEXCL).
662 pp->pdev = NULL;
663 file->private_data = pp;
665 return 0;
668 static int pp_release (struct inode * inode, struct file * file)
670 unsigned int minor = iminor(inode);
671 struct pp_struct *pp = file->private_data;
672 int compat_negot;
674 compat_negot = 0;
675 if (!(pp->flags & PP_CLAIMED) && pp->pdev &&
676 (pp->state.mode != IEEE1284_MODE_COMPAT)) {
677 struct ieee1284_info *info;
679 /* parport released, but not in compatibility mode */
680 parport_claim_or_block (pp->pdev);
681 pp->flags |= PP_CLAIMED;
682 info = &pp->pdev->port->ieee1284;
683 pp->saved_state.mode = info->mode;
684 pp->saved_state.phase = info->phase;
685 info->mode = pp->state.mode;
686 info->phase = pp->state.phase;
687 compat_negot = 1;
688 } else if ((pp->flags & PP_CLAIMED) && pp->pdev &&
689 (pp->pdev->port->ieee1284.mode != IEEE1284_MODE_COMPAT)) {
690 compat_negot = 2;
692 if (compat_negot) {
693 parport_negotiate (pp->pdev->port, IEEE1284_MODE_COMPAT);
694 printk (KERN_DEBUG CHRDEV
695 "%x: negotiated back to compatibility mode because "
696 "user-space forgot\n", minor);
699 if (pp->flags & PP_CLAIMED) {
700 struct ieee1284_info *info;
702 info = &pp->pdev->port->ieee1284;
703 pp->state.mode = info->mode;
704 pp->state.phase = info->phase;
705 info->mode = pp->saved_state.mode;
706 info->phase = pp->saved_state.phase;
707 parport_release (pp->pdev);
708 if (compat_negot != 1) {
709 printk (KERN_DEBUG CHRDEV "%x: released pardevice "
710 "because user-space forgot\n", minor);
714 if (pp->pdev) {
715 const char *name = pp->pdev->name;
716 parport_unregister_device (pp->pdev);
717 kfree (name);
718 pp->pdev = NULL;
719 printk (KERN_DEBUG CHRDEV "%x: unregistered pardevice\n",
720 minor);
723 kfree (pp);
725 return 0;
728 /* No kernel lock held - fine */
729 static unsigned int pp_poll (struct file * file, poll_table * wait)
731 struct pp_struct *pp = file->private_data;
732 unsigned int mask = 0;
734 poll_wait (file, &pp->irq_wait, wait);
735 if (atomic_read (&pp->irqc))
736 mask |= POLLIN | POLLRDNORM;
738 return mask;
741 static struct class *ppdev_class;
743 static struct file_operations pp_fops = {
744 .owner = THIS_MODULE,
745 .llseek = no_llseek,
746 .read = pp_read,
747 .write = pp_write,
748 .poll = pp_poll,
749 .ioctl = pp_ioctl,
750 .open = pp_open,
751 .release = pp_release,
754 static void pp_attach(struct parport *port)
756 class_device_create(ppdev_class, NULL, MKDEV(PP_MAJOR, port->number),
757 NULL, "parport%d", port->number);
760 static void pp_detach(struct parport *port)
762 class_device_destroy(ppdev_class, MKDEV(PP_MAJOR, port->number));
765 static struct parport_driver pp_driver = {
766 .name = CHRDEV,
767 .attach = pp_attach,
768 .detach = pp_detach,
771 static int __init ppdev_init (void)
773 int i, err = 0;
775 if (register_chrdev (PP_MAJOR, CHRDEV, &pp_fops)) {
776 printk (KERN_WARNING CHRDEV ": unable to get major %d\n",
777 PP_MAJOR);
778 return -EIO;
780 ppdev_class = class_create(THIS_MODULE, CHRDEV);
781 if (IS_ERR(ppdev_class)) {
782 err = PTR_ERR(ppdev_class);
783 goto out_chrdev;
785 devfs_mk_dir("parports");
786 for (i = 0; i < PARPORT_MAX; i++) {
787 devfs_mk_cdev(MKDEV(PP_MAJOR, i),
788 S_IFCHR | S_IRUGO | S_IWUGO, "parports/%d", i);
790 if (parport_register_driver(&pp_driver)) {
791 printk (KERN_WARNING CHRDEV ": unable to register with parport\n");
792 goto out_class;
795 printk (KERN_INFO PP_VERSION "\n");
796 goto out;
798 out_class:
799 for (i = 0; i < PARPORT_MAX; i++)
800 devfs_remove("parports/%d", i);
801 devfs_remove("parports");
802 class_destroy(ppdev_class);
803 out_chrdev:
804 unregister_chrdev(PP_MAJOR, CHRDEV);
805 out:
806 return err;
809 static void __exit ppdev_cleanup (void)
811 int i;
812 /* Clean up all parport stuff */
813 for (i = 0; i < PARPORT_MAX; i++)
814 devfs_remove("parports/%d", i);
815 parport_unregister_driver(&pp_driver);
816 devfs_remove("parports");
817 class_destroy(ppdev_class);
818 unregister_chrdev (PP_MAJOR, CHRDEV);
821 module_init(ppdev_init);
822 module_exit(ppdev_cleanup);
824 MODULE_LICENSE("GPL");
825 MODULE_ALIAS_CHARDEV_MAJOR(PP_MAJOR);