From: Greg KH <greg@kroah.com>

Adds sysfs sound class support for all ALSA drivers

Note, this is based on a previous patch from Leann Ogasawara
<ogasawara@osdl.org>, but modified a lot by me.



---

 25-akpm/include/sound/core.h |    1 +
 25-akpm/sound/core/sound.c   |   41 +++++++++++++++++++++++------------------
 25-akpm/sound/pci/intel8x0.c |    1 +
 3 files changed, 25 insertions(+), 18 deletions(-)

diff -puN include/sound/core.h~sysfs-add-alsa-class include/sound/core.h
--- 25/include/sound/core.h~sysfs-add-alsa-class	Thu Jan  8 16:43:18 2004
+++ 25-akpm/include/sound/core.h	Thu Jan  8 16:43:18 2004
@@ -160,6 +160,7 @@ struct _snd_card {
 	int shutdown;			/* this card is going down */
 	wait_queue_head_t shutdown_sleep;
 	struct work_struct free_workq;	/* for free in workqueue */
+	struct device *dev;
 
 #ifdef CONFIG_PM
 	int (*set_power_state) (snd_card_t *card, unsigned int state);
diff -puN sound/core/sound.c~sysfs-add-alsa-class sound/core/sound.c
--- 25/sound/core/sound.c~sysfs-add-alsa-class	Thu Jan  8 16:43:18 2004
+++ 25-akpm/sound/core/sound.c	Thu Jan  8 16:43:45 2004
@@ -38,9 +38,7 @@
 static int major = CONFIG_SND_MAJOR;
 int snd_major;
 static int cards_limit = 1;
-#ifdef CONFIG_DEVFS_FS
 static int device_mode = S_IFCHR | S_IRUGO | S_IWUGO;
-#endif
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
 MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards.");
@@ -71,6 +69,7 @@ static struct list_head snd_minors_hash[
 
 static DECLARE_MUTEX(sound_mutex);
 
+extern struct class sound_class;
 #ifdef CONFIG_KMOD
 
 /**
@@ -212,6 +211,7 @@ int snd_register_device(int type, snd_ca
 {
 	int minor = snd_kernel_minor(type, card, dev);
 	snd_minor_t *preg;
+	struct device *device = NULL;
 
 	if (minor < 0)
 		return minor;
@@ -230,10 +230,15 @@ int snd_register_device(int type, snd_ca
 		return -EBUSY;
 	}
 	list_add_tail(&preg->list, &snd_minors_hash[SNDRV_MINOR_CARD(minor)]);
-#ifdef CONFIG_DEVFS_FS
-	if (strncmp(name, "controlC", 8) || card->number >= cards_limit)
-		devfs_mk_cdev(MKDEV(major, minor), S_IFCHR | device_mode, "snd/%s", name);
-#endif
+	if (strncmp(name, "controlC", 8) ||	/* created in sound.c */
+			card->number >= cards_limit) {
+		devfs_mk_cdev(MKDEV(major, minor), S_IFCHR | device_mode,
+				"snd/%s", name);
+		if (card)
+			device = card->dev;
+		simple_add_class_device(&sound_class, MKDEV(major, minor),
+				device, name);
+	}
 	up(&sound_mutex);
 	return 0;
 }
@@ -261,13 +266,13 @@ int snd_unregister_device(int type, snd_
 		up(&sound_mutex);
 		return -EINVAL;
 	}
-#ifdef CONFIG_DEVFS_FS
-	if (strncmp(mptr->name, "controlC", 8))	/* created in sound.c */
+	if (strncmp(mptr->name, "controlC", 8) || /* created in sound.c */
+			(card->number >= cards_limit)) {
 		devfs_remove("snd/%s", mptr->name);
-	else if (card->number >= cards_limit)
-		devfs_remove("snd/%s", mptr->name); /* manualy created */
-#endif
-	list_del(&mptr->list);
+		simple_remove_class_device(MKDEV(major, minor));
+	}
+
+ 	list_del(&mptr->list);
 	up(&sound_mutex);
 	kfree(mptr);
 	return 0;
@@ -332,9 +337,7 @@ int __exit snd_minor_info_done(void)
 
 static int __init alsa_sound_init(void)
 {
-#ifdef CONFIG_DEVFS_FS
 	short controlnum;
-#endif
 #ifdef CONFIG_SND_OSSEMUL
 	int err;
 #endif
@@ -368,10 +371,10 @@ static int __init alsa_sound_init(void)
 #ifdef CONFIG_SND_OSSEMUL
 	snd_info_minor_register();
 #endif
-#ifdef CONFIG_DEVFS_FS
-	for (controlnum = 0; controlnum < cards_limit; controlnum++) 
+	for (controlnum = 0; controlnum < cards_limit; controlnum++) {
 		devfs_mk_cdev(MKDEV(major, controlnum<<5), S_IFCHR | device_mode, "snd/controlC%d", controlnum);
-#endif
+		simple_add_class_device(&sound_class, MKDEV(major, controlnum<<5), NULL, "controlC%d", controlnum);
+	}
 #ifndef MODULE
 	printk(KERN_INFO "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n");
 #endif
@@ -382,8 +385,10 @@ static void __exit alsa_sound_exit(void)
 {
 	short controlnum;
 
-	for (controlnum = 0; controlnum < cards_limit; controlnum++)
+	for (controlnum = 0; controlnum < cards_limit; controlnum++) {
 		devfs_remove("snd/controlC%d", controlnum);
+		simple_remove_class_device(MKDEV(major, controlnum<<5));
+	}
 
 #ifdef CONFIG_SND_OSSEMUL
 	snd_info_minor_unregister();
diff -puN sound/pci/intel8x0.c~sysfs-add-alsa-class sound/pci/intel8x0.c
--- 25/sound/pci/intel8x0.c~sysfs-add-alsa-class	Thu Jan  8 16:43:18 2004
+++ 25-akpm/sound/pci/intel8x0.c	Thu Jan  8 16:43:18 2004
@@ -2522,6 +2522,7 @@ static int __devinit snd_intel8x0_probe(
 			break;
 		}
 	}
+	card->dev = &pci->dev;
 
 	if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip)) < 0) {
 		snd_card_free(card);

_