]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - sound/sound_core.c
ASoC: codecs: ALC5639/40: Update pll calc logic
[linux-2.6.git] / sound / sound_core.c
index 4ae07e236b36a81d87a51307a9272b50cef17528..c6e81fb928e9acda430945fe7b0bf329f5760074 100644 (file)
@@ -10,6 +10,9 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/kdev_t.h>
+#include <linux/major.h>
+#include <sound/core.h>
 
 #ifdef CONFIG_SOUND_OSS_CORE
 static int __init init_oss_soundcore(void);
@@ -26,6 +29,13 @@ MODULE_DESCRIPTION("Core sound module");
 MODULE_AUTHOR("Alan Cox");
 MODULE_LICENSE("GPL");
 
+static char *sound_devnode(struct device *dev, umode_t *mode)
+{
+       if (MAJOR(dev->devt) == SOUND_MAJOR)
+               return NULL;
+       return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev));
+}
+
 static int __init init_soundcore(void)
 {
        int rc;
@@ -40,6 +50,8 @@ static int __init init_soundcore(void)
                return PTR_ERR(sound_class);
        }
 
+       sound_class->devnode = sound_devnode;
+
        return 0;
 }
 
@@ -49,7 +61,7 @@ static void __exit cleanup_soundcore(void)
        class_destroy(sound_class);
 }
 
-module_init(init_soundcore);
+subsys_initcall(init_soundcore);
 module_exit(cleanup_soundcore);
 
 
@@ -57,7 +69,7 @@ module_exit(cleanup_soundcore);
 /*
  *     OSS sound core handling. Breaks out sound functions to submodules
  *     
- *     Author:         Alan Cox <alan.cox@linux.org>
+ *     Author:         Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     Fixes:
  *
@@ -92,11 +104,9 @@ module_exit(cleanup_soundcore);
 
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/sound.h>
-#include <linux/major.h>
 #include <linux/kmod.h>
 
 #define SOUND_STEP 16
@@ -116,6 +126,47 @@ extern int msnd_classic_init(void);
 extern int msnd_pinnacle_init(void);
 #endif
 
+/*
+ * By default, OSS sound_core claims full legacy minor range (0-255)
+ * of SOUND_MAJOR to trap open attempts to any sound minor and
+ * requests modules using custom sound-slot/service-* module aliases.
+ * The only benefit of doing this is allowing use of custom module
+ * aliases instead of the standard char-major-* ones.  This behavior
+ * prevents alternative OSS implementation and is scheduled to be
+ * removed.
+ *
+ * CONFIG_SOUND_OSS_CORE_PRECLAIM and soundcore.preclaim_oss kernel
+ * parameter are added to allow distros and developers to try and
+ * switch to alternative implementations without needing to rebuild
+ * the kernel in the meantime.  If preclaim_oss is non-zero, the
+ * kernel will behave the same as before.  All SOUND_MAJOR minors are
+ * preclaimed and the custom module aliases along with standard chrdev
+ * ones are emitted if a missing device is opened.  If preclaim_oss is
+ * zero, sound_core only grabs what's actually in use and for missing
+ * devices only the standard chrdev aliases are requested.
+ *
+ * All these clutters are scheduled to be removed along with
+ * sound-slot/service-* module aliases.  Please take a look at
+ * feature-removal-schedule.txt for details.
+ */
+#ifdef CONFIG_SOUND_OSS_CORE_PRECLAIM
+static int preclaim_oss = 1;
+#else
+static int preclaim_oss = 0;
+#endif
+
+module_param(preclaim_oss, int, 0444);
+
+static int soundcore_open(struct inode *, struct file *);
+
+static const struct file_operations soundcore_fops =
+{
+       /* We must have an owner or the module locking fails */
+       .owner  = THIS_MODULE,
+       .open   = soundcore_open,
+       .llseek = noop_llseek,
+};
+
 /*
  *     Low level list operator. Scan the ordered list, find a hole and
  *     join into it. Called with the lock asserted
@@ -208,8 +259,9 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
 
        if (!s)
                return -ENOMEM;
-               
+
        spin_lock(&sound_loader_lock);
+retry:
        r = __sound_insert_unit(s, list, fops, index, low, top);
        spin_unlock(&sound_loader_lock);
        
@@ -220,12 +272,31 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
        else
                sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);
 
-       device_create_drvdata(sound_class, dev,
-                             MKDEV(SOUND_MAJOR, s->unit_minor),
-                             NULL, s->name+6);
-       return r;
+       if (!preclaim_oss) {
+               /*
+                * Something else might have grabbed the minor.  If
+                * first free slot is requested, rescan with @low set
+                * to the next unit; otherwise, -EBUSY.
+                */
+               r = __register_chrdev(SOUND_MAJOR, s->unit_minor, 1, s->name,
+                                     &soundcore_fops);
+               if (r < 0) {
+                       spin_lock(&sound_loader_lock);
+                       __sound_remove_unit(list, s->unit_minor);
+                       if (index < 0) {
+                               low = s->unit_minor + SOUND_STEP;
+                               goto retry;
+                       }
+                       spin_unlock(&sound_loader_lock);
+                       return -EBUSY;
+               }
+       }
+
+       device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
+                     NULL, s->name+6);
+       return s->unit_minor;
 
- fail:
+fail:
        kfree(s);
        return r;
 }
@@ -244,6 +315,9 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
        p = __sound_remove_unit(list, unit);
        spin_unlock(&sound_loader_lock);
        if (p) {
+               if (!preclaim_oss)
+                       __unregister_chrdev(SOUND_MAJOR, p->unit_minor, 1,
+                                           p->name);
                device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
                kfree(p);
        }
@@ -279,7 +353,7 @@ static struct sound_unit *chains[SOUND_STEP];
  *      @dev: device pointer
  *
  *     Allocate a special sound device by minor number from the sound
- *     subsystem. The allocated number is returned on succes. On failure
+ *     subsystem. The allocated number is returned on success. On failure
  *     a negative error code is returned.
  */
  
@@ -310,6 +384,9 @@ int register_sound_special_device(const struct file_operations *fops, int unit,
            case 4:
                name = "audio";
                break;
+           case 5:
+               name = "dspW";
+               break;
            case 8:
                name = "sequencer2";
                if (unit >= SOUND_STEP)
@@ -458,7 +535,7 @@ EXPORT_SYMBOL(unregister_sound_mixer);
 
 void unregister_sound_midi(int unit)
 {
-       return sound_remove_unit(&chains[2], unit);
+       sound_remove_unit(&chains[2], unit);
 }
 
 EXPORT_SYMBOL(unregister_sound_midi);
@@ -475,25 +552,12 @@ EXPORT_SYMBOL(unregister_sound_midi);
 
 void unregister_sound_dsp(int unit)
 {
-       return sound_remove_unit(&chains[3], unit);
+       sound_remove_unit(&chains[3], unit);
 }
 
 
 EXPORT_SYMBOL(unregister_sound_dsp);
 
-/*
- *     Now our file operations
- */
-
-static int soundcore_open(struct inode *, struct file *);
-
-static const struct file_operations soundcore_fops=
-{
-       /* We must have an owner or the module locking fails */
-       .owner  = THIS_MODULE,
-       .open   = soundcore_open,
-};
-
 static struct sound_unit *__look_for_unit(int chain, int unit)
 {
        struct sound_unit *s;
@@ -508,15 +572,13 @@ static struct sound_unit *__look_for_unit(int chain, int unit)
        return NULL;
 }
 
-int soundcore_open(struct inode *inode, struct file *file)
+static int soundcore_open(struct inode *inode, struct file *file)
 {
        int chain;
        int unit = iminor(inode);
        struct sound_unit *s;
        const struct file_operations *new_fops = NULL;
 
-       lock_kernel ();
-
        chain=unit&0x0F;
        if(chain==4 || chain==5)        /* dsp/audio/dsp16 */
        {
@@ -529,8 +591,9 @@ int soundcore_open(struct inode *inode, struct file *file)
        s = __look_for_unit(chain, unit);
        if (s)
                new_fops = fops_get(s->unit_fops);
-       if (!new_fops) {
+       if (preclaim_oss && !new_fops) {
                spin_unlock(&sound_loader_lock);
+
                /*
                 *  Please, don't change this order or code.
                 *  For ALSA slot means soundcard and OSS emulation code
@@ -540,6 +603,17 @@ int soundcore_open(struct inode *inode, struct file *file)
                 */
                request_module("sound-slot-%i", unit>>4);
                request_module("sound-service-%i-%i", unit>>4, chain);
+
+               /*
+                * sound-slot/service-* module aliases are scheduled
+                * for removal in favor of the standard char-major-*
+                * module aliases.  For the time being, generate both
+                * the legacy and standard module aliases to ease
+                * transition.
+                */
+               if (request_module("char-major-%d-%d", SOUND_MAJOR, unit) > 0)
+                       request_module("char-major-%d", SOUND_MAJOR);
+
                spin_lock(&sound_loader_lock);
                s = __look_for_unit(chain, unit);
                if (s)
@@ -557,18 +631,19 @@ int soundcore_open(struct inode *inode, struct file *file)
                const struct file_operations *old_fops = file->f_op;
                file->f_op = new_fops;
                spin_unlock(&sound_loader_lock);
-               if(file->f_op->open)
+
+               if (file->f_op->open)
                        err = file->f_op->open(inode,file);
+
                if (err) {
                        fops_put(file->f_op);
                        file->f_op = fops_get(old_fops);
                }
+
                fops_put(old_fops);
-               unlock_kernel();
                return err;
        }
        spin_unlock(&sound_loader_lock);
-       unlock_kernel();
        return -ENODEV;
 }
 
@@ -583,7 +658,8 @@ static void cleanup_oss_soundcore(void)
 
 static int __init init_oss_soundcore(void)
 {
-       if (register_chrdev(SOUND_MAJOR, "sound", &soundcore_fops)==-1) {
+       if (preclaim_oss &&
+           register_chrdev(SOUND_MAJOR, "sound", &soundcore_fops) == -1) {
                printk(KERN_ERR "soundcore: sound device already in use.\n");
                return -EBUSY;
        }