[MIPS] separate rbtx4927_arch_init() and rbtx4937_arch_init()
[safe/jmp/linux-2.6] / sound / sound_core.c
index 21a69e0..dcfc1d5 100644 (file)
  *     locking at some point in 2.3.x.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/sound.h>
 #include <linux/major.h>
 #include <linux/kmod.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/device.h>
 
 #define SOUND_STEP 16
@@ -53,7 +52,7 @@
 struct sound_unit
 {
        int unit_minor;
-       struct file_operations *unit_fops;
+       const struct file_operations *unit_fops;
        struct sound_unit *next;
        char name[32];
 };
@@ -73,7 +72,7 @@ EXPORT_SYMBOL(sound_class);
  *     join into it. Called with the lock asserted
  */
 
-static int __sound_insert_unit(struct sound_unit * s, struct sound_unit **list, struct file_operations *fops, int index, int low, int top)
+static int __sound_insert_unit(struct sound_unit * s, struct sound_unit **list, const struct file_operations *fops, int index, int low, int top)
 {
        int n=low;
 
@@ -153,7 +152,7 @@ static DEFINE_SPINLOCK(sound_loader_lock);
  *     list. Acquires locks as needed
  */
 
-static int sound_insert_unit(struct sound_unit **list, struct file_operations *fops, int index, int low, int top, const char *name, umode_t mode)
+static int sound_insert_unit(struct sound_unit **list, const struct file_operations *fops, int index, int low, int top, const char *name, umode_t mode, struct device *dev)
 {
        struct sound_unit *s = kmalloc(sizeof(*s), GFP_KERNEL);
        int r;
@@ -172,10 +171,8 @@ static int sound_insert_unit(struct sound_unit **list, struct file_operations *f
        else
                sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
 
-       devfs_mk_cdev(MKDEV(SOUND_MAJOR, s->unit_minor),
-                       S_IFCHR | mode, s->name);
-       class_device_create(sound_class, MKDEV(SOUND_MAJOR, s->unit_minor),
-                               NULL, s->name+6);
+       device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
+                     s->name+6);
        return r;
 
  fail:
@@ -197,8 +194,7 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
        p = __sound_remove_unit(list, unit);
        spin_unlock(&sound_loader_lock);
        if (p) {
-               devfs_remove(p->name);
-               class_device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
+               device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
                kfree(p);
        }
 }
@@ -227,16 +223,18 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
 static struct sound_unit *chains[SOUND_STEP];
 
 /**
- *     register_sound_special - register a special sound node
+ *     register_sound_special_device - register a special sound node
  *     @fops: File operations for the driver
  *     @unit: Unit number to allocate
+ *      @dev: device pointer
  *
  *     Allocate a special sound device by minor number from the sound
  *     subsystem. The allocated number is returned on succes. On failure
  *     a negative error code is returned.
  */
  
-int register_sound_special(struct file_operations *fops, int unit)
+int register_sound_special_device(const struct file_operations *fops, int unit,
+                                 struct device *dev)
 {
        const int chain = unit % SOUND_STEP;
        int max_unit = 128 + chain;
@@ -294,9 +292,16 @@ int register_sound_special(struct file_operations *fops, int unit)
                break;
        }
        return sound_insert_unit(&chains[chain], fops, -1, unit, max_unit,
-                                name, S_IRUSR | S_IWUSR);
+                                name, S_IRUSR | S_IWUSR, dev);
 }
  
+EXPORT_SYMBOL(register_sound_special_device);
+
+int register_sound_special(const struct file_operations *fops, int unit)
+{
+       return register_sound_special_device(fops, unit, NULL);
+}
+
 EXPORT_SYMBOL(register_sound_special);
 
 /**
@@ -309,10 +314,10 @@ EXPORT_SYMBOL(register_sound_special);
  *     number is returned, on failure a negative error code is returned.
  */
 
-int register_sound_mixer(struct file_operations *fops, int dev)
+int register_sound_mixer(const struct file_operations *fops, int dev)
 {
        return sound_insert_unit(&chains[0], fops, dev, 0, 128,
-                                "mixer", S_IRUSR | S_IWUSR);
+                                "mixer", S_IRUSR | S_IWUSR, NULL);
 }
 
 EXPORT_SYMBOL(register_sound_mixer);
@@ -327,10 +332,10 @@ EXPORT_SYMBOL(register_sound_mixer);
  *     number is returned, on failure a negative error code is returned.
  */
 
-int register_sound_midi(struct file_operations *fops, int dev)
+int register_sound_midi(const struct file_operations *fops, int dev)
 {
        return sound_insert_unit(&chains[2], fops, dev, 2, 130,
-                                "midi", S_IRUSR | S_IWUSR);
+                                "midi", S_IRUSR | S_IWUSR, NULL);
 }
 
 EXPORT_SYMBOL(register_sound_midi);
@@ -353,34 +358,15 @@ EXPORT_SYMBOL(register_sound_midi);
  *     and will always allocate them as a matching pair - eg dsp3/audio3
  */
 
-int register_sound_dsp(struct file_operations *fops, int dev)
+int register_sound_dsp(const struct file_operations *fops, int dev)
 {
        return sound_insert_unit(&chains[3], fops, dev, 3, 131,
-                                "dsp", S_IWUSR | S_IRUSR);
+                                "dsp", S_IWUSR | S_IRUSR, NULL);
 }
 
 EXPORT_SYMBOL(register_sound_dsp);
 
 /**
- *     register_sound_synth - register a synth device
- *     @fops: File operations for the driver
- *     @dev: Unit number to allocate
- *
- *     Allocate a synth device. Unit is the number of the synth device requested.
- *     Pass -1 to request the next free synth unit. On success the allocated
- *     number is returned, on failure a negative error code is returned.
- */
-
-
-int register_sound_synth(struct file_operations *fops, int dev)
-{
-       return sound_insert_unit(&chains[9], fops, dev, 9, 137,
-                                "synth", S_IRUSR | S_IWUSR);
-}
-
-EXPORT_SYMBOL(register_sound_synth);
-
-/**
  *     unregister_sound_special - unregister a special sound device
  *     @unit: unit number to allocate
  *
@@ -445,28 +431,13 @@ void unregister_sound_dsp(int unit)
 
 EXPORT_SYMBOL(unregister_sound_dsp);
 
-/**
- *     unregister_sound_synth - unregister a synth device
- *     @unit: unit number to allocate
- *
- *     Release a sound device that was allocated with register_sound_synth().
- *     The unit passed is the return value from the register function.
- */
-
-void unregister_sound_synth(int unit)
-{
-       return sound_remove_unit(&chains[9], unit);
-}
-
-EXPORT_SYMBOL(unregister_sound_synth);
-
 /*
  *     Now our file operations
  */
 
 static int soundcore_open(struct inode *, struct file *);
 
-static struct file_operations soundcore_fops=
+static const struct file_operations soundcore_fops=
 {
        /* We must have an owner or the module locking fails */
        .owner  = THIS_MODULE,
@@ -492,7 +463,9 @@ int soundcore_open(struct inode *inode, struct file *file)
        int chain;
        int unit = iminor(inode);
        struct sound_unit *s;
-       struct file_operations *new_fops = NULL;
+       const struct file_operations *new_fops = NULL;
+
+       lock_kernel ();
 
        chain=unit&0x0F;
        if(chain==4 || chain==5)        /* dsp/audio/dsp16 */
@@ -531,7 +504,7 @@ int soundcore_open(struct inode *inode, struct file *file)
                 * switching ->f_op in the first place.
                 */
                int err = 0;
-               struct file_operations *old_fops = file->f_op;
+               const struct file_operations *old_fops = file->f_op;
                file->f_op = new_fops;
                spin_unlock(&sound_loader_lock);
                if(file->f_op->open)
@@ -541,16 +514,14 @@ int soundcore_open(struct inode *inode, struct file *file)
                        file->f_op = fops_get(old_fops);
                }
                fops_put(old_fops);
+               unlock_kernel();
                return err;
        }
        spin_unlock(&sound_loader_lock);
+       unlock_kernel();
        return -ENODEV;
 }
 
-extern int mod_firmware_load(const char *, char **);
-EXPORT_SYMBOL(mod_firmware_load);
-
-
 MODULE_DESCRIPTION("Core sound module");
 MODULE_AUTHOR("Alan Cox");
 MODULE_LICENSE("GPL");
@@ -561,7 +532,6 @@ static void __exit cleanup_soundcore(void)
        /* We have nothing to really do here - we know the lists must be
           empty */
        unregister_chrdev(SOUND_MAJOR, "sound");
-       devfs_remove("sound");
        class_destroy(sound_class);
 }
 
@@ -571,7 +541,6 @@ static int __init init_soundcore(void)
                printk(KERN_ERR "soundcore: sound device already in use.\n");
                return -EBUSY;
        }
-       devfs_mk_dir ("sound");
        sound_class = class_create(THIS_MODULE, "sound");
        if (IS_ERR(sound_class))
                return PTR_ERR(sound_class);