fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / char / misc.c
index a878d99..7e975f6 100644 (file)
@@ -34,7 +34,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/config.h>
 
 #include <linux/fs.h>
 #include <linux/errno.h>
@@ -44,7 +43,6 @@
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/stat.h>
 #include <linux/init.h>
 #include <linux/device.h>
@@ -63,16 +61,7 @@ static DECLARE_MUTEX(misc_sem);
 #define DYNAMIC_MINORS 64 /* like dynamic majors */
 static unsigned char misc_minors[DYNAMIC_MINORS / 8];
 
-#ifdef CONFIG_SGI_NEWPORT_GFX
-extern void gfx_register(void);
-#endif
-extern void streamable_init(void);
-extern int rtc_DP8570A_init(void);
-extern int rtc_MK48T08_init(void);
-extern int ds1286_init(void);
 extern int pmu_device_init(void);
-extern int tosh_init(void);
-extern int i8k_init(void);
 
 #ifdef CONFIG_PROC_FS
 static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
@@ -124,7 +113,7 @@ static int misc_seq_open(struct inode *inode, struct file *file)
        return seq_open(file, &misc_seq_ops);
 }
 
-static struct file_operations misc_proc_fops = {
+static const struct file_operations misc_proc_fops = {
        .owner   = THIS_MODULE,
        .open    = misc_seq_open,
        .read    = seq_read,
@@ -138,7 +127,7 @@ static int misc_open(struct inode * inode, struct file * file)
        int minor = iminor(inode);
        struct miscdevice *c;
        int err = -ENODEV;
-       struct file_operations *old_fops, *new_fops = NULL;
+       const struct file_operations *old_fops, *new_fops = NULL;
        
        down(&misc_sem);
        
@@ -180,14 +169,9 @@ fail:
        return err;
 }
 
-/* 
- * TODO for 2.7:
- *  - add a struct class_device to struct miscdevice and make all usages of
- *    them dynamic.
- */
-static struct class_simple *misc_class;
+static struct class *misc_class;
 
-static struct file_operations misc_fops = {
+static const struct file_operations misc_fops = {
        .owner          = THIS_MODULE,
        .open           = misc_open,
 };
@@ -212,10 +196,11 @@ static struct file_operations misc_fops = {
 int misc_register(struct miscdevice * misc)
 {
        struct miscdevice *c;
-       struct class_device *class;
        dev_t dev;
-       int err;
-       
+       int err = 0;
+
+       INIT_LIST_HEAD(&misc->list);
+
        down(&misc_sem);
        list_for_each_entry(c, &misc_list, list) {
                if (c->minor == misc->minor) {
@@ -229,8 +214,7 @@ int misc_register(struct miscdevice * misc)
                while (--i >= 0)
                        if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
                                break;
-               if (i<0)
-               {
+               if (i<0) {
                        up(&misc_sem);
                        return -EBUSY;
                }
@@ -239,23 +223,12 @@ int misc_register(struct miscdevice * misc)
 
        if (misc->minor < DYNAMIC_MINORS)
                misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
-       if (misc->devfs_name[0] == '\0') {
-               snprintf(misc->devfs_name, sizeof(misc->devfs_name),
-                               "misc/%s", misc->name);
-       }
        dev = MKDEV(MISC_MAJOR, misc->minor);
 
-       class = class_simple_device_add(misc_class, dev,
-                                       misc->dev, misc->name);
-       if (IS_ERR(class)) {
-               err = PTR_ERR(class);
-               goto out;
-       }
-
-       err = devfs_mk_cdev(dev, S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP, 
-                           misc->devfs_name);
-       if (err) {
-               class_simple_device_remove(dev);
+       misc->this_device = device_create(misc_class, misc->parent, dev,
+                                         "%s", misc->name);
+       if (IS_ERR(misc->this_device)) {
+               err = PTR_ERR(misc->this_device);
                goto out;
        }
 
@@ -288,8 +261,7 @@ int misc_deregister(struct miscdevice * misc)
 
        down(&misc_sem);
        list_del(&misc->list);
-       class_simple_device_remove(MKDEV(MISC_MAJOR, misc->minor));
-       devfs_remove(misc->devfs_name);
+       device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
        if (i < DYNAMIC_MINORS && i>0) {
                misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
        }
@@ -309,40 +281,14 @@ static int __init misc_init(void)
        if (ent)
                ent->proc_fops = &misc_proc_fops;
 #endif
-       misc_class = class_simple_create(THIS_MODULE, "misc");
+       misc_class = class_create(THIS_MODULE, "misc");
        if (IS_ERR(misc_class))
                return PTR_ERR(misc_class);
-#ifdef CONFIG_MVME16x
-       rtc_MK48T08_init();
-#endif
-#ifdef CONFIG_BVME6000
-       rtc_DP8570A_init();
-#endif
-#ifdef CONFIG_SGI_DS1286
-       ds1286_init();
-#endif
-#ifdef CONFIG_PMAC_PBOOK
-       pmu_device_init();
-#endif
-#ifdef CONFIG_SGI_NEWPORT_GFX
-       gfx_register ();
-#endif
-#ifdef CONFIG_SGI_IP22
-       streamable_init ();
-#endif
-#ifdef CONFIG_SGI_NEWPORT_GFX
-       gfx_register ();
-#endif
-#ifdef CONFIG_TOSHIBA
-       tosh_init();
-#endif
-#ifdef CONFIG_I8K
-       i8k_init();
-#endif
+
        if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
                printk("unable to get major %d for misc devices\n",
                       MISC_MAJOR);
-               class_simple_destroy(misc_class);
+               class_destroy(misc_class);
                return -EIO;
        }
        return 0;