fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / char / tipar.c
index 0c5ba9d..47fb20f 100644 (file)
@@ -42,7 +42,6 @@
  */
 #undef DEBUG                           /* change to #define to get debugging
                                         * output - for pr_debug() */
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/errno.h>
@@ -56,7 +55,6 @@
 #include <linux/ioport.h>
 #include <asm/io.h>
 #include <linux/bitops.h>
-#include <linux/devfs_fs_kernel.h>     /* DevFs support */
 #include <linux/parport.h>             /* Our code depend on parport */
 #include <linux/device.h>
 
@@ -90,7 +88,7 @@ static int timeout = TIMAXTIME;       /* timeout in tenth of seconds     */
 static unsigned int tp_count;  /* tipar count */
 static unsigned long opened;   /* opened devices */
 
-static struct class_simple *tipar_class;
+static struct class *tipar_class;
 
 /* --- macros for parport access -------------------------------------- */
 
@@ -226,14 +224,16 @@ probe_ti_parallel(int minor)
 {
        int i;
        int seq[] = { 0x00, 0x20, 0x10, 0x30 };
+       int data;
 
        for (i = 3; i >= 0; i--) {
                outbyte(3, minor);
                outbyte(i, minor);
                udelay(delay);
+               data = inbyte(minor) & 0x30;
                pr_debug("tipar: Probing -> %i: 0x%02x 0x%02x\n", i,
-                       data & 0x30, seq[i]);
-               if ((inbyte(minor) & 0x30) != seq[i]) {
+                       data, seq[i]);
+               if (data != seq[i]) {
                        outbyte(3, minor);
                        return -1;
                }
@@ -250,12 +250,17 @@ tipar_open(struct inode *inode, struct file *file)
 {
        unsigned int minor = iminor(inode) - TIPAR_MINOR;
 
-       if (minor > tp_count - 1)
+       if (tp_count == 0 || minor > tp_count - 1)
                return -ENXIO;
 
        if (test_and_set_bit(minor, &opened))
                return -EBUSY;
 
+       if (!table[minor].dev) {
+               printk(KERN_ERR "%s: NULL device for minor %u\n",
+                               __FUNCTION__, minor);
+               return -ENXIO;
+       }
        parport_claim_or_block(table[minor].dev);
        init_ti_parallel(minor);
        parport_release(table[minor].dev);
@@ -280,7 +285,7 @@ static ssize_t
 tipar_write (struct file *file, const char __user *buf, size_t count,
                loff_t * ppos)
 {
-       unsigned int minor = iminor(file->f_dentry->d_inode) - TIPAR_MINOR;
+       unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
        ssize_t n;
 
        parport_claim_or_block(table[minor].dev);
@@ -308,7 +313,7 @@ static ssize_t
 tipar_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
 {
        int b = 0;
-       unsigned int minor = iminor(file->f_dentry->d_inode) - TIPAR_MINOR;
+       unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
        ssize_t retval = 0;
        ssize_t n = 0;
 
@@ -378,7 +383,7 @@ tipar_ioctl(struct inode *inode, struct file *file,
 
 /* ----- kernel module registering ------------------------------------ */
 
-static struct file_operations tipar_fops = {
+static const struct file_operations tipar_fops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .read = tipar_read,
@@ -396,7 +401,7 @@ static struct file_operations tipar_fops = {
 static int __init
 tipar_setup(char *str)
 {
-       int ints[2];
+       int ints[3];
 
        str = get_options(str, ARRAY_SIZE(ints), ints);
 
@@ -436,14 +441,8 @@ tipar_register(int nr, struct parport *port)
                goto out;
        }
 
-       class_simple_device_add(tipar_class, MKDEV(TIPAR_MAJOR,
+       class_device_create(tipar_class, NULL, MKDEV(TIPAR_MAJOR,
                        TIPAR_MINOR + nr), NULL, "par%d", nr);
-       /* Use devfs, tree: /dev/ticables/par/[0..2] */
-       err = devfs_mk_cdev(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr),
-                       S_IFCHR | S_IRUGO | S_IWUGO,
-                       "ticables/par/%d", nr);
-       if (err)
-               goto out_class;
 
        /* Display informations */
        pr_info("tipar%d: using %s (%s)\n", nr, port->name, (port->irq ==
@@ -455,11 +454,7 @@ tipar_register(int nr, struct parport *port)
                pr_info("tipar%d: link cable not found\n", nr);
 
        err = 0;
-       goto out;
 
-out_class:
-       class_simple_device_remove(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr));
-       class_simple_destroy(tipar_class);
 out:
        return err;
 }
@@ -502,10 +497,7 @@ tipar_init_module(void)
                goto out;
        }
 
-       /* Use devfs with tree: /dev/ticables/par/[0..2] */
-       devfs_mk_dir("ticables/par");
-
-       tipar_class = class_simple_create(THIS_MODULE, "ticables");
+       tipar_class = class_create(THIS_MODULE, "ticables");
        if (IS_ERR(tipar_class)) {
                err = PTR_ERR(tipar_class);
                goto out_chrdev;
@@ -513,12 +505,15 @@ tipar_init_module(void)
        if (parport_register_driver(&tipar_driver)) {
                printk(KERN_ERR "tipar: unable to register with parport\n");
                err = -EIO;
-               goto out;
+               goto out_class;
        }
 
        err = 0;
        goto out;
 
+out_class:
+       class_destroy(tipar_class);
+
 out_chrdev:
        unregister_chrdev(TIPAR_MAJOR, "tipar");
 out:
@@ -539,11 +534,9 @@ tipar_cleanup_module(void)
                if (table[i].dev == NULL)
                        continue;
                parport_unregister_device(table[i].dev);
-               class_simple_device_remove(MKDEV(TIPAR_MAJOR, i));
-               devfs_remove("ticables/par/%d", i);
+               class_device_destroy(tipar_class, MKDEV(TIPAR_MAJOR, i));
        }
-       class_simple_destroy(tipar_class);
-       devfs_remove("ticables/par");
+       class_destroy(tipar_class);
 
        pr_info("tipar: module unloaded\n");
 }