1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
--- ../alsa-kernel/core/sound.c 2006-08-08 16:09:17.000000000 +0200
+++ sound.c 2006-08-08 16:13:02.000000000 +0200
@@ -41,6 +41,9 @@
EXPORT_SYMBOL(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.");
@@ -49,6 +52,10 @@
MODULE_PARM_DESC(major, "Major # for sound driver.");
module_param(cards_limit, int, 0444);
MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards.");
+#ifdef CONFIG_DEVFS_FS
+module_param(device_mode, int, 0444);
+MODULE_PARM_DESC(device_mode, "Device file permission mask for devfs.");
+#endif
MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR);
/* this one holds the actual max. card number currently available.
@@ -61,7 +68,15 @@
static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
static DEFINE_MUTEX(sound_mutex);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
+#ifdef CONFIG_SND_HAVE_CLASS_SIMPLE
+extern struct class_simple *sound_class;
+#else
extern struct class *sound_class;
+#endif
+#else
+#define sound_class NULL
+#endif
#ifdef CONFIG_KMOD
@@ -173,7 +188,9 @@
static struct file_operations snd_fops =
{
+#ifndef LINUX_2_2
.owner = THIS_MODULE,
+#endif
.open = snd_open
};
@@ -244,7 +261,11 @@
struct device *device = NULL;
snd_assert(name, return -EINVAL);
+#ifdef CONFIG_DEVFS_FS
+ preg = kmalloc(sizeof(*preg) + strlen(name) + 1, GFP_KERNEL);
+#else
preg = kmalloc(sizeof *preg, GFP_KERNEL);
+#endif
if (preg == NULL)
return -ENOMEM;
preg->type = type;
@@ -252,6 +273,9 @@
preg->device = dev;
preg->f_ops = f_ops;
preg->private_data = private_data;
+#ifdef CONFIG_DEVFS_FS
+ strcpy((char *)(preg + 1), name);
+#endif
mutex_lock(&sound_mutex);
#ifdef CONFIG_SND_DYNAMIC_MINORS
minor = snd_find_free_minor();
@@ -266,13 +290,22 @@
return minor;
}
snd_minors[minor] = preg;
+#ifdef CONFIG_DEVFS_FS
+ if (type != SNDRV_DEVICE_TYPE_CONTROL || preg->card >= cards_limit)
+ devfs_mk_cdev(MKDEV(major, minor), S_IFCHR | device_mode,
+ "snd/%s", name);
+#endif
if (card)
device = card->dev;
+#ifdef CONFIG_SND_HAVE_CLASS_SIMPLE
+ class_simple_device_add(sound_class, MKDEV(major, minor), device, name);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
preg->class_dev = class_device_create(sound_class, NULL,
MKDEV(major, minor),
device, "%s", name);
if (preg->class_dev)
class_set_devdata(preg->class_dev, private_data);
+#endif
mutex_unlock(&sound_mutex);
return 0;
@@ -320,7 +353,17 @@
return -EINVAL;
}
+#ifdef CONFIG_DEVFS_FS
+ if (mptr->type != SNDRV_DEVICE_TYPE_CONTROL ||
+ mptr->card >= cards_limit) /* created in sound.c */
+ devfs_remove("snd/%s", (char *)(mptr + 1));
+#endif
+
+#ifdef CONFIG_SND_HAVE_CLASS_SIMPLE
+ class_simple_device_remove(MKDEV(major, minor));
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
class_device_destroy(sound_class, MKDEV(major, minor));
+#endif
kfree(snd_minors[minor]);
snd_minors[minor] = NULL;
@@ -333,6 +376,9 @@
int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
const struct class_device_attribute *attr)
{
+#if defined(CONFIG_SND_HAVE_CLASS_SIMPLE) || LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 2)
+ return -EINVAL;
+#else
int minor, ret = -EINVAL;
struct class_device *cdev;
@@ -342,7 +388,7 @@
ret = class_device_create_file(cdev, attr);
mutex_unlock(&sound_mutex);
return ret;
-
+#endif
}
EXPORT_SYMBOL(snd_add_device_sysfs_file);
@@ -428,32 +474,81 @@
* INIT PART
*/
+#ifdef CONFIG_SND_DEBUG_MEMORY
+extern void snd_memory_done(void);
+#else
+#define snd_memory_done()
+#endif
+#if defined(CONFIG_SND_DEBUG_MEMORY) && defined(CONFIG_PROC_FS)
+extern int snd_memory_info_init(void);
+extern void snd_memory_info_done(void);
+#else
+#define snd_memory_info_init()
+#define snd_memory_info_done()
+#endif
+
static int __init alsa_sound_init(void)
{
snd_major = major;
snd_ecards_limit = cards_limit;
+#ifdef CONFIG_DEVFS_FS
+ devfs_mk_dir("snd");
+#endif
if (register_chrdev(major, "alsa", &snd_fops)) {
snd_printk(KERN_ERR "unable to register native major device number %d\n", major);
+#ifdef CONFIG_DEVFS_FS
+ devfs_remove("snd");
+#endif
return -EIO;
}
if (snd_info_init() < 0) {
unregister_chrdev(major, "alsa");
+ snd_memory_done();
return -ENOMEM;
}
+ snd_memory_info_init();
snd_info_minor_register();
+#ifdef CONFIG_DEVFS_FS
+ {
+ short controlnum;
+ for (controlnum = 0; controlnum < cards_limit; controlnum++)
+ devfs_mk_cdev(MKDEV(major, controlnum<<5),
+ S_IFCHR | device_mode ,
+ "snd/controlC%d", controlnum);
+ }
+#endif
#ifndef MODULE
printk(KERN_INFO "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n");
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) && defined(CONFIG_APM)
+ pm_init();
+#endif
return 0;
}
static void __exit alsa_sound_exit(void)
{
+#ifdef CONFIG_DEVFS_FS
+ short controlnum;
+ for (controlnum = 0; controlnum < cards_limit; controlnum++)
+ devfs_remove("snd/controlC%d", controlnum);
+#endif
+
snd_info_minor_unregister();
+ snd_memory_info_done();
snd_info_done();
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) && defined(CONFIG_APM)
+ pm_done();
+#endif
if (unregister_chrdev(major, "alsa") != 0)
snd_printk(KERN_ERR "unable to unregister major device number %d\n", major);
+ snd_memory_done();
+#ifdef CONFIG_DEVFS_FS
+ devfs_remove("snd");
+#endif
}
module_init(alsa_sound_init)
module_exit(alsa_sound_exit)
+
+#include "sound.inc"
|