Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Advanced Linux Sound Architecture |
| 3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> |
| 4 | * |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sound/driver.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/time.h> |
Takashi Iwai | 9a1a2a1 | 2005-11-22 15:46:41 +0100 | [diff] [blame] | 26 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/moduleparam.h> |
| 28 | #include <sound/core.h> |
| 29 | #include <sound/minors.h> |
| 30 | #include <sound/info.h> |
| 31 | #include <sound/version.h> |
| 32 | #include <sound/control.h> |
| 33 | #include <sound/initval.h> |
| 34 | #include <linux/kmod.h> |
| 35 | #include <linux/devfs_fs_kernel.h> |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 36 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #define SNDRV_OS_MINORS 256 |
| 39 | |
| 40 | static int major = CONFIG_SND_MAJOR; |
| 41 | int snd_major; |
| 42 | static int cards_limit = 1; |
| 43 | static int device_mode = S_IFCHR | S_IRUGO | S_IWUGO; |
| 44 | |
| 45 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
| 46 | MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards."); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | module_param(major, int, 0444); |
| 49 | MODULE_PARM_DESC(major, "Major # for sound driver."); |
| 50 | module_param(cards_limit, int, 0444); |
| 51 | MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards."); |
| 52 | #ifdef CONFIG_DEVFS_FS |
| 53 | module_param(device_mode, int, 0444); |
| 54 | MODULE_PARM_DESC(device_mode, "Device file permission mask for devfs."); |
| 55 | #endif |
| 56 | MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR); |
| 57 | |
| 58 | /* this one holds the actual max. card number currently available. |
| 59 | * as default, it's identical with cards_limit option. when more |
| 60 | * modules are loaded manually, this limit number increases, too. |
| 61 | */ |
| 62 | int snd_ecards_limit; |
| 63 | |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 64 | static struct snd_minor *snd_minors[SNDRV_OS_MINORS]; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 65 | static DEFINE_MUTEX(sound_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
gregkh@suse.de | 619e666 | 2005-03-23 09:51:41 -0800 | [diff] [blame] | 67 | extern struct class *sound_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | |
| 70 | #ifdef CONFIG_KMOD |
| 71 | |
| 72 | /** |
| 73 | * snd_request_card - try to load the card module |
| 74 | * @card: the card number |
| 75 | * |
| 76 | * Tries to load the module "snd-card-X" for the given card number |
| 77 | * via KMOD. Returns immediately if already loaded. |
| 78 | */ |
| 79 | void snd_request_card(int card) |
| 80 | { |
| 81 | int locked; |
| 82 | |
| 83 | if (! current->fs->root) |
| 84 | return; |
| 85 | read_lock(&snd_card_rwlock); |
| 86 | locked = snd_cards_lock & (1 << card); |
| 87 | read_unlock(&snd_card_rwlock); |
| 88 | if (locked) |
| 89 | return; |
| 90 | if (card < 0 || card >= cards_limit) |
| 91 | return; |
| 92 | request_module("snd-card-%i", card); |
| 93 | } |
| 94 | |
| 95 | static void snd_request_other(int minor) |
| 96 | { |
| 97 | char *str; |
| 98 | |
| 99 | if (! current->fs->root) |
| 100 | return; |
| 101 | switch (minor) { |
| 102 | case SNDRV_MINOR_SEQUENCER: str = "snd-seq"; break; |
| 103 | case SNDRV_MINOR_TIMER: str = "snd-timer"; break; |
| 104 | default: return; |
| 105 | } |
| 106 | request_module(str); |
| 107 | } |
| 108 | |
| 109 | #endif /* request_module support */ |
| 110 | |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 111 | /** |
| 112 | * snd_lookup_minor_data - get user data of a registered device |
| 113 | * @minor: the minor number |
| 114 | * @type: device type (SNDRV_DEVICE_TYPE_XXX) |
| 115 | * |
| 116 | * Checks that a minor device with the specified type is registered, and returns |
| 117 | * its user data pointer. |
| 118 | */ |
| 119 | void *snd_lookup_minor_data(unsigned int minor, int type) |
| 120 | { |
| 121 | struct snd_minor *mreg; |
| 122 | void *private_data; |
| 123 | |
Adrian Bunk | 3a63e444 | 2006-03-13 14:14:10 +0100 | [diff] [blame^] | 124 | if (minor >= ARRAY_SIZE(snd_minors)) |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 125 | return NULL; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 126 | mutex_lock(&sound_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 127 | mreg = snd_minors[minor]; |
| 128 | if (mreg && mreg->type == type) |
| 129 | private_data = mreg->private_data; |
| 130 | else |
| 131 | private_data = NULL; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 132 | mutex_unlock(&sound_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 133 | return private_data; |
| 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static int snd_open(struct inode *inode, struct file *file) |
| 137 | { |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 138 | unsigned int minor = iminor(inode); |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 139 | struct snd_minor *mptr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | struct file_operations *old_fops; |
| 141 | int err = 0; |
| 142 | |
Adrian Bunk | 3a63e444 | 2006-03-13 14:14:10 +0100 | [diff] [blame^] | 143 | if (minor >= ARRAY_SIZE(snd_minors)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return -ENODEV; |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 145 | mptr = snd_minors[minor]; |
| 146 | if (mptr == NULL) { |
| 147 | #ifdef CONFIG_KMOD |
| 148 | int dev = SNDRV_MINOR_DEVICE(minor); |
| 149 | if (dev == SNDRV_MINOR_CONTROL) { |
| 150 | /* /dev/aloadC? */ |
| 151 | int card = SNDRV_MINOR_CARD(minor); |
| 152 | if (snd_cards[card] == NULL) |
| 153 | snd_request_card(card); |
| 154 | } else if (dev == SNDRV_MINOR_GLOBAL) { |
| 155 | /* /dev/aloadSEQ */ |
| 156 | snd_request_other(minor); |
| 157 | } |
| 158 | #ifndef CONFIG_SND_DYNAMIC_MINORS |
| 159 | /* /dev/snd/{controlC?,seq} */ |
| 160 | mptr = snd_minors[minor]; |
| 161 | if (mptr == NULL) |
| 162 | #endif |
| 163 | #endif |
| 164 | return -ENODEV; |
| 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | old_fops = file->f_op; |
| 167 | file->f_op = fops_get(mptr->f_ops); |
| 168 | if (file->f_op->open) |
| 169 | err = file->f_op->open(inode, file); |
| 170 | if (err) { |
| 171 | fops_put(file->f_op); |
| 172 | file->f_op = fops_get(old_fops); |
| 173 | } |
| 174 | fops_put(old_fops); |
| 175 | return err; |
| 176 | } |
| 177 | |
| 178 | static struct file_operations snd_fops = |
| 179 | { |
| 180 | .owner = THIS_MODULE, |
| 181 | .open = snd_open |
| 182 | }; |
| 183 | |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 184 | #ifdef CONFIG_SND_DYNAMIC_MINORS |
| 185 | static int snd_find_free_minor(void) |
| 186 | { |
| 187 | int minor; |
| 188 | |
| 189 | for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) { |
| 190 | /* skip minors still used statically for autoloading devices */ |
| 191 | if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL || |
| 192 | minor == SNDRV_MINOR_SEQUENCER) |
| 193 | continue; |
| 194 | if (!snd_minors[minor]) |
| 195 | return minor; |
| 196 | } |
| 197 | return -EBUSY; |
| 198 | } |
| 199 | #else |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 200 | static int snd_kernel_minor(int type, struct snd_card *card, int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | int minor; |
| 203 | |
| 204 | switch (type) { |
| 205 | case SNDRV_DEVICE_TYPE_SEQUENCER: |
| 206 | case SNDRV_DEVICE_TYPE_TIMER: |
| 207 | minor = type; |
| 208 | break; |
| 209 | case SNDRV_DEVICE_TYPE_CONTROL: |
| 210 | snd_assert(card != NULL, return -EINVAL); |
| 211 | minor = SNDRV_MINOR(card->number, type); |
| 212 | break; |
| 213 | case SNDRV_DEVICE_TYPE_HWDEP: |
| 214 | case SNDRV_DEVICE_TYPE_RAWMIDI: |
| 215 | case SNDRV_DEVICE_TYPE_PCM_PLAYBACK: |
| 216 | case SNDRV_DEVICE_TYPE_PCM_CAPTURE: |
| 217 | snd_assert(card != NULL, return -EINVAL); |
| 218 | minor = SNDRV_MINOR(card->number, type + dev); |
| 219 | break; |
| 220 | default: |
| 221 | return -EINVAL; |
| 222 | } |
| 223 | snd_assert(minor >= 0 && minor < SNDRV_OS_MINORS, return -EINVAL); |
| 224 | return minor; |
| 225 | } |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 226 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * snd_register_device - Register the ALSA device file for the card |
| 230 | * @type: the device type, SNDRV_DEVICE_TYPE_XXX |
| 231 | * @card: the card instance |
| 232 | * @dev: the device index |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 233 | * @f_ops: the file operations |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 234 | * @private_data: user pointer for f_ops->open() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | * @name: the device file name |
| 236 | * |
| 237 | * Registers an ALSA device file for the given card. |
| 238 | * The operators have to be set in reg parameter. |
| 239 | * |
| 240 | * Retrurns zero if successful, or a negative error code on failure. |
| 241 | */ |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 242 | int snd_register_device(int type, struct snd_card *card, int dev, |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 243 | struct file_operations *f_ops, void *private_data, |
| 244 | const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 246 | int minor; |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 247 | struct snd_minor *preg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | struct device *device = NULL; |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | snd_assert(name, return -EINVAL); |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 251 | preg = kmalloc(sizeof(struct snd_minor) + strlen(name) + 1, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | if (preg == NULL) |
| 253 | return -ENOMEM; |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 254 | preg->type = type; |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 255 | preg->card = card ? card->number : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | preg->device = dev; |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 257 | preg->f_ops = f_ops; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 258 | preg->private_data = private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | strcpy(preg->name, name); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 260 | mutex_lock(&sound_mutex); |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 261 | #ifdef CONFIG_SND_DYNAMIC_MINORS |
| 262 | minor = snd_find_free_minor(); |
| 263 | #else |
| 264 | minor = snd_kernel_minor(type, card, dev); |
| 265 | if (minor >= 0 && snd_minors[minor]) |
| 266 | minor = -EBUSY; |
| 267 | #endif |
| 268 | if (minor < 0) { |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 269 | mutex_unlock(&sound_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | kfree(preg); |
Clemens Ladisch | 332682b | 2005-11-20 14:07:47 +0100 | [diff] [blame] | 271 | return minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 273 | snd_minors[minor] = preg; |
| 274 | if (type != SNDRV_DEVICE_TYPE_CONTROL || preg->card >= cards_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | devfs_mk_cdev(MKDEV(major, minor), S_IFCHR | device_mode, "snd/%s", name); |
Takashi Iwai | 3e23c65 | 2006-01-03 19:54:44 +0100 | [diff] [blame] | 276 | if (card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | device = card->dev; |
Takashi Iwai | 3e23c65 | 2006-01-03 19:54:44 +0100 | [diff] [blame] | 278 | class_device_create(sound_class, NULL, MKDEV(major, minor), device, "%s", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 280 | mutex_unlock(&sound_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * snd_unregister_device - unregister the device on the given card |
| 286 | * @type: the device type, SNDRV_DEVICE_TYPE_XXX |
| 287 | * @card: the card instance |
| 288 | * @dev: the device index |
| 289 | * |
| 290 | * Unregisters the device file already registered via |
| 291 | * snd_register_device(). |
| 292 | * |
| 293 | * Returns zero if sucecessful, or a negative error code on failure |
| 294 | */ |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 295 | int snd_unregister_device(int type, struct snd_card *card, int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 297 | int cardnum, minor; |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 298 | struct snd_minor *mptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 300 | cardnum = card ? card->number : -1; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 301 | mutex_lock(&sound_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 302 | for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) |
| 303 | if ((mptr = snd_minors[minor]) != NULL && |
| 304 | mptr->type == type && |
| 305 | mptr->card == cardnum && |
| 306 | mptr->device == dev) |
| 307 | break; |
| 308 | if (minor == ARRAY_SIZE(snd_minors)) { |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 309 | mutex_unlock(&sound_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return -EINVAL; |
| 311 | } |
| 312 | |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 313 | if (mptr->type != SNDRV_DEVICE_TYPE_CONTROL || |
| 314 | mptr->card >= cards_limit) /* created in sound.c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | devfs_remove("snd/%s", mptr->name); |
gregkh@suse.de | 619e666 | 2005-03-23 09:51:41 -0800 | [diff] [blame] | 316 | class_device_destroy(sound_class, MKDEV(major, minor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 318 | snd_minors[minor] = NULL; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 319 | mutex_unlock(&sound_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | kfree(mptr); |
| 321 | return 0; |
| 322 | } |
| 323 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 324 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | /* |
| 326 | * INFO PART |
| 327 | */ |
| 328 | |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 329 | static struct snd_info_entry *snd_minor_info_entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 331 | static const char *snd_device_type_name(int type) |
| 332 | { |
| 333 | switch (type) { |
| 334 | case SNDRV_DEVICE_TYPE_CONTROL: |
| 335 | return "control"; |
| 336 | case SNDRV_DEVICE_TYPE_HWDEP: |
| 337 | return "hardware dependent"; |
| 338 | case SNDRV_DEVICE_TYPE_RAWMIDI: |
| 339 | return "raw midi"; |
| 340 | case SNDRV_DEVICE_TYPE_PCM_PLAYBACK: |
| 341 | return "digital audio playback"; |
| 342 | case SNDRV_DEVICE_TYPE_PCM_CAPTURE: |
| 343 | return "digital audio capture"; |
| 344 | case SNDRV_DEVICE_TYPE_SEQUENCER: |
| 345 | return "sequencer"; |
| 346 | case SNDRV_DEVICE_TYPE_TIMER: |
| 347 | return "timer"; |
| 348 | default: |
| 349 | return "?"; |
| 350 | } |
| 351 | } |
| 352 | |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 353 | static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 355 | int minor; |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 356 | struct snd_minor *mptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 358 | mutex_lock(&sound_mutex); |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 359 | for (minor = 0; minor < SNDRV_OS_MINORS; ++minor) { |
| 360 | if (!(mptr = snd_minors[minor])) |
| 361 | continue; |
| 362 | if (mptr->card >= 0) { |
| 363 | if (mptr->device >= 0) |
Clemens Ladisch | d001544 | 2005-11-20 14:09:05 +0100 | [diff] [blame] | 364 | snd_iprintf(buffer, "%3i: [%2i-%2i]: %s\n", |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 365 | minor, mptr->card, mptr->device, |
| 366 | snd_device_type_name(mptr->type)); |
| 367 | else |
Clemens Ladisch | d001544 | 2005-11-20 14:09:05 +0100 | [diff] [blame] | 368 | snd_iprintf(buffer, "%3i: [%2i] : %s\n", |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 369 | minor, mptr->card, |
| 370 | snd_device_type_name(mptr->type)); |
| 371 | } else |
Clemens Ladisch | d001544 | 2005-11-20 14:09:05 +0100 | [diff] [blame] | 372 | snd_iprintf(buffer, "%3i: : %s\n", minor, |
Clemens Ladisch | 6983b72 | 2005-11-20 14:05:49 +0100 | [diff] [blame] | 373 | snd_device_type_name(mptr->type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 375 | mutex_unlock(&sound_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | int __init snd_minor_info_init(void) |
| 379 | { |
Takashi Iwai | 512bbd6 | 2005-11-17 13:51:18 +0100 | [diff] [blame] | 380 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL); |
| 383 | if (entry) { |
| 384 | entry->c.text.read_size = PAGE_SIZE; |
| 385 | entry->c.text.read = snd_minor_info_read; |
| 386 | if (snd_info_register(entry) < 0) { |
| 387 | snd_info_free_entry(entry); |
| 388 | entry = NULL; |
| 389 | } |
| 390 | } |
| 391 | snd_minor_info_entry = entry; |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | int __exit snd_minor_info_done(void) |
| 396 | { |
| 397 | if (snd_minor_info_entry) |
| 398 | snd_info_unregister(snd_minor_info_entry); |
| 399 | return 0; |
| 400 | } |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 401 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | /* |
| 404 | * INIT PART |
| 405 | */ |
| 406 | |
| 407 | static int __init alsa_sound_init(void) |
| 408 | { |
| 409 | short controlnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | snd_major = major; |
| 412 | snd_ecards_limit = cards_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | devfs_mk_dir("snd"); |
| 414 | if (register_chrdev(major, "alsa", &snd_fops)) { |
| 415 | snd_printk(KERN_ERR "unable to register native major device number %d\n", major); |
| 416 | devfs_remove("snd"); |
| 417 | return -EIO; |
| 418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (snd_info_init() < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | unregister_chrdev(major, "alsa"); |
| 421 | devfs_remove("snd"); |
| 422 | return -ENOMEM; |
| 423 | } |
| 424 | snd_info_minor_register(); |
| 425 | for (controlnum = 0; controlnum < cards_limit; controlnum++) |
| 426 | devfs_mk_cdev(MKDEV(major, controlnum<<5), S_IFCHR | device_mode, "snd/controlC%d", controlnum); |
| 427 | #ifndef MODULE |
| 428 | printk(KERN_INFO "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"); |
| 429 | #endif |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static void __exit alsa_sound_exit(void) |
| 434 | { |
| 435 | short controlnum; |
| 436 | |
| 437 | for (controlnum = 0; controlnum < cards_limit; controlnum++) |
| 438 | devfs_remove("snd/controlC%d", controlnum); |
| 439 | |
| 440 | snd_info_minor_unregister(); |
| 441 | snd_info_done(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | if (unregister_chrdev(major, "alsa") != 0) |
| 443 | snd_printk(KERN_ERR "unable to unregister major device number %d\n", major); |
| 444 | devfs_remove("snd"); |
| 445 | } |
| 446 | |
| 447 | module_init(alsa_sound_init) |
| 448 | module_exit(alsa_sound_exit) |
| 449 | |
| 450 | /* sound.c */ |
| 451 | EXPORT_SYMBOL(snd_major); |
| 452 | EXPORT_SYMBOL(snd_ecards_limit); |
| 453 | #if defined(CONFIG_KMOD) |
| 454 | EXPORT_SYMBOL(snd_request_card); |
| 455 | #endif |
| 456 | EXPORT_SYMBOL(snd_register_device); |
| 457 | EXPORT_SYMBOL(snd_unregister_device); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 458 | EXPORT_SYMBOL(snd_lookup_minor_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | #if defined(CONFIG_SND_OSSEMUL) |
| 460 | EXPORT_SYMBOL(snd_register_oss_device); |
| 461 | EXPORT_SYMBOL(snd_unregister_oss_device); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 462 | EXPORT_SYMBOL(snd_lookup_oss_minor_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | #endif |
| 464 | /* memory.c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | EXPORT_SYMBOL(copy_to_user_fromio); |
| 466 | EXPORT_SYMBOL(copy_from_user_toio); |
| 467 | /* init.c */ |
| 468 | EXPORT_SYMBOL(snd_cards); |
| 469 | #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) |
| 470 | EXPORT_SYMBOL(snd_mixer_oss_notify_callback); |
| 471 | #endif |
| 472 | EXPORT_SYMBOL(snd_card_new); |
| 473 | EXPORT_SYMBOL(snd_card_disconnect); |
| 474 | EXPORT_SYMBOL(snd_card_free); |
| 475 | EXPORT_SYMBOL(snd_card_free_in_thread); |
| 476 | EXPORT_SYMBOL(snd_card_register); |
| 477 | EXPORT_SYMBOL(snd_component_add); |
| 478 | EXPORT_SYMBOL(snd_card_file_add); |
| 479 | EXPORT_SYMBOL(snd_card_file_remove); |
| 480 | #ifdef CONFIG_PM |
| 481 | EXPORT_SYMBOL(snd_power_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | #endif |
| 483 | /* device.c */ |
| 484 | EXPORT_SYMBOL(snd_device_new); |
| 485 | EXPORT_SYMBOL(snd_device_register); |
| 486 | EXPORT_SYMBOL(snd_device_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* isadma.c */ |
Al Viro | 276bd31 | 2005-08-23 22:45:06 +0100 | [diff] [blame] | 488 | #ifdef CONFIG_ISA_DMA_API |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | EXPORT_SYMBOL(snd_dma_program); |
| 490 | EXPORT_SYMBOL(snd_dma_disable); |
| 491 | EXPORT_SYMBOL(snd_dma_pointer); |
| 492 | #endif |
| 493 | /* info.c */ |
| 494 | #ifdef CONFIG_PROC_FS |
| 495 | EXPORT_SYMBOL(snd_seq_root); |
| 496 | EXPORT_SYMBOL(snd_iprintf); |
| 497 | EXPORT_SYMBOL(snd_info_get_line); |
| 498 | EXPORT_SYMBOL(snd_info_get_str); |
| 499 | EXPORT_SYMBOL(snd_info_create_module_entry); |
| 500 | EXPORT_SYMBOL(snd_info_create_card_entry); |
| 501 | EXPORT_SYMBOL(snd_info_free_entry); |
| 502 | EXPORT_SYMBOL(snd_info_register); |
| 503 | EXPORT_SYMBOL(snd_info_unregister); |
| 504 | EXPORT_SYMBOL(snd_card_proc_new); |
| 505 | #endif |
| 506 | /* info_oss.c */ |
| 507 | #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS) |
| 508 | EXPORT_SYMBOL(snd_oss_info_register); |
| 509 | #endif |
| 510 | /* control.c */ |
| 511 | EXPORT_SYMBOL(snd_ctl_new); |
| 512 | EXPORT_SYMBOL(snd_ctl_new1); |
| 513 | EXPORT_SYMBOL(snd_ctl_free_one); |
| 514 | EXPORT_SYMBOL(snd_ctl_add); |
| 515 | EXPORT_SYMBOL(snd_ctl_remove); |
| 516 | EXPORT_SYMBOL(snd_ctl_remove_id); |
| 517 | EXPORT_SYMBOL(snd_ctl_rename_id); |
| 518 | EXPORT_SYMBOL(snd_ctl_find_numid); |
| 519 | EXPORT_SYMBOL(snd_ctl_find_id); |
| 520 | EXPORT_SYMBOL(snd_ctl_notify); |
| 521 | EXPORT_SYMBOL(snd_ctl_register_ioctl); |
| 522 | EXPORT_SYMBOL(snd_ctl_unregister_ioctl); |
| 523 | #ifdef CONFIG_COMPAT |
| 524 | EXPORT_SYMBOL(snd_ctl_register_ioctl_compat); |
| 525 | EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat); |
| 526 | #endif |
| 527 | EXPORT_SYMBOL(snd_ctl_elem_read); |
| 528 | EXPORT_SYMBOL(snd_ctl_elem_write); |
| 529 | /* misc.c */ |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 530 | EXPORT_SYMBOL(release_and_free_resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #ifdef CONFIG_SND_VERBOSE_PRINTK |
| 532 | EXPORT_SYMBOL(snd_verbose_printk); |
| 533 | #endif |
| 534 | #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK) |
| 535 | EXPORT_SYMBOL(snd_verbose_printd); |
| 536 | #endif |