Merge branch 'for-linus' of git://git390.osdl.marist.edu/pub/scm/linux-2.6
[pandora-kernel.git] / sound / core / sound.c
index 7edd1fc..2827420 100644 (file)
@@ -61,9 +61,6 @@ EXPORT_SYMBOL(snd_ecards_limit);
 static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
 static DEFINE_MUTEX(sound_mutex);
 
-extern struct class *sound_class;
-
-
 #ifdef CONFIG_KMOD
 
 /**
@@ -268,7 +265,10 @@ int snd_register_device(int type, struct snd_card *card, int dev,
        snd_minors[minor] = preg;
        if (card)
                device = card->dev;
-       class_device_create(sound_class, NULL, MKDEV(major, minor), device, "%s", name);
+       preg->dev = device_create(sound_class, device, MKDEV(major, minor),
+                                 "%s", name);
+       if (preg->dev)
+               dev_set_drvdata(preg->dev, private_data);
 
        mutex_unlock(&sound_mutex);
        return 0;
@@ -276,6 +276,24 @@ int snd_register_device(int type, struct snd_card *card, int dev,
 
 EXPORT_SYMBOL(snd_register_device);
 
+/* find the matching minor record
+ * return the index of snd_minor, or -1 if not found
+ */
+static int find_snd_minor(int type, struct snd_card *card, int dev)
+{
+       int cardnum, minor;
+       struct snd_minor *mptr;
+
+       cardnum = card ? card->number : -1;
+       for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor)
+               if ((mptr = snd_minors[minor]) != NULL &&
+                   mptr->type == type &&
+                   mptr->card == cardnum &&
+                   mptr->device == dev)
+                       return minor;
+       return -1;
+}
+
 /**
  * snd_unregister_device - unregister the device on the given card
  * @type: the device type, SNDRV_DEVICE_TYPE_XXX
@@ -289,32 +307,42 @@ EXPORT_SYMBOL(snd_register_device);
  */
 int snd_unregister_device(int type, struct snd_card *card, int dev)
 {
-       int cardnum, minor;
-       struct snd_minor *mptr;
+       int minor;
 
-       cardnum = card ? card->number : -1;
        mutex_lock(&sound_mutex);
-       for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor)
-               if ((mptr = snd_minors[minor]) != NULL &&
-                   mptr->type == type &&
-                   mptr->card == cardnum &&
-                   mptr->device == dev)
-                       break;
-       if (minor == ARRAY_SIZE(snd_minors)) {
+       minor = find_snd_minor(type, card, dev);
+       if (minor < 0) {
                mutex_unlock(&sound_mutex);
                return -EINVAL;
        }
 
-       class_device_destroy(sound_class, MKDEV(major, minor));
+       device_destroy(sound_class, MKDEV(major, minor));
 
+       kfree(snd_minors[minor]);
        snd_minors[minor] = NULL;
        mutex_unlock(&sound_mutex);
-       kfree(mptr);
        return 0;
 }
 
 EXPORT_SYMBOL(snd_unregister_device);
 
+int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
+                             struct device_attribute *attr)
+{
+       int minor, ret = -EINVAL;
+       struct device *d;
+
+       mutex_lock(&sound_mutex);
+       minor = find_snd_minor(type, card, dev);
+       if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL)
+               ret = device_create_file(d, attr);
+       mutex_unlock(&sound_mutex);
+       return ret;
+
+}
+
+EXPORT_SYMBOL(snd_add_device_sysfs_file);
+
 #ifdef CONFIG_PROC_FS
 /*
  *  INFO PART
@@ -387,8 +415,7 @@ int __init snd_minor_info_init(void)
 
 int __exit snd_minor_info_done(void)
 {
-       if (snd_minor_info_entry)
-               snd_info_unregister(snd_minor_info_entry);
+       snd_info_free_entry(snd_minor_info_entry);
        return 0;
 }
 #endif /* CONFIG_PROC_FS */