blob: b75f78f2c4b8e222e46297589c5bf6ca8055d9d4 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Advanced Linux Sound Architecture
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02004 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/init.h>
8#include <linux/slab.h>
9#include <linux/time.h>
Takashi Iwai9a1a2a12005-11-22 15:46:41 +010010#include <linux/device.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040011#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <sound/core.h>
13#include <sound/minors.h>
14#include <sound/info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <sound/control.h>
16#include <sound/initval.h>
17#include <linux/kmod.h>
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010018#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static int major = CONFIG_SND_MAJOR;
21int snd_major;
Takashi Iwaic0d3fb32006-04-28 15:13:39 +020022EXPORT_SYMBOL(snd_major);
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int cards_limit = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020026MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070027MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards.");
28MODULE_LICENSE("GPL");
29module_param(major, int, 0444);
30MODULE_PARM_DESC(major, "Major # for sound driver.");
31module_param(cards_limit, int, 0444);
32MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070033MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR);
34
35/* this one holds the actual max. card number currently available.
36 * as default, it's identical with cards_limit option. when more
37 * modules are loaded manually, this limit number increases, too.
38 */
39int snd_ecards_limit;
Takashi Iwaic0d3fb32006-04-28 15:13:39 +020040EXPORT_SYMBOL(snd_ecards_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Clemens Ladisch6983b722005-11-20 14:05:49 +010042static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010043static DEFINE_MUTEX(sound_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Johannes Bergee2da992008-07-09 10:28:41 +020045#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47/**
48 * snd_request_card - try to load the card module
49 * @card: the card number
50 *
51 * Tries to load the module "snd-card-X" for the given card number
Johannes Bergee2da992008-07-09 10:28:41 +020052 * via request_module. Returns immediately if already loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 */
54void snd_request_card(int card)
55{
Takashi Iwai746df942006-05-15 19:49:05 +020056 if (snd_card_locked(card))
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 return;
58 if (card < 0 || card >= cards_limit)
59 return;
60 request_module("snd-card-%i", card);
61}
Takashi Iwaic0d3fb32006-04-28 15:13:39 +020062EXPORT_SYMBOL(snd_request_card);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void snd_request_other(int minor)
65{
66 char *str;
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 switch (minor) {
69 case SNDRV_MINOR_SEQUENCER: str = "snd-seq"; break;
70 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
71 default: return;
72 }
73 request_module(str);
74}
75
Johannes Bergee2da992008-07-09 10:28:41 +020076#endif /* modular kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Clemens Ladischf87135f2005-11-20 14:06:59 +010078/**
79 * snd_lookup_minor_data - get user data of a registered device
80 * @minor: the minor number
81 * @type: device type (SNDRV_DEVICE_TYPE_XXX)
82 *
83 * Checks that a minor device with the specified type is registered, and returns
84 * its user data pointer.
Takashi Iwaia0830db2012-10-16 13:05:59 +020085 *
86 * This function increments the reference counter of the card instance
87 * if an associated instance with the given minor number and type is found.
88 * The caller must call snd_card_unref() appropriately later.
Yacine Belkadieb7c06e2013-03-11 22:05:14 +010089 *
90 * Return: The user data pointer if the specified device is found. %NULL
91 * otherwise.
Clemens Ladischf87135f2005-11-20 14:06:59 +010092 */
93void *snd_lookup_minor_data(unsigned int minor, int type)
94{
95 struct snd_minor *mreg;
96 void *private_data;
97
Adrian Bunk3a63e4442006-03-13 14:14:10 +010098 if (minor >= ARRAY_SIZE(snd_minors))
Clemens Ladischf87135f2005-11-20 14:06:59 +010099 return NULL;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100100 mutex_lock(&sound_mutex);
Clemens Ladischf87135f2005-11-20 14:06:59 +0100101 mreg = snd_minors[minor];
Takashi Iwaia0830db2012-10-16 13:05:59 +0200102 if (mreg && mreg->type == type) {
Clemens Ladischf87135f2005-11-20 14:06:59 +0100103 private_data = mreg->private_data;
Takashi Iwai8bb4d9c2012-11-08 14:36:18 +0100104 if (private_data && mreg->card_ptr)
Takashi Iwaif2464062014-01-29 12:13:43 +0100105 get_device(&mreg->card_ptr->card_dev);
Takashi Iwaia0830db2012-10-16 13:05:59 +0200106 } else
Clemens Ladischf87135f2005-11-20 14:06:59 +0100107 private_data = NULL;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100108 mutex_unlock(&sound_mutex);
Clemens Ladischf87135f2005-11-20 14:06:59 +0100109 return private_data;
110}
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200111EXPORT_SYMBOL(snd_lookup_minor_data);
112
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200113#ifdef CONFIG_MODULES
114static struct snd_minor *autoload_device(unsigned int minor)
115{
116 int dev;
117 mutex_unlock(&sound_mutex); /* release lock temporarily */
118 dev = SNDRV_MINOR_DEVICE(minor);
119 if (dev == SNDRV_MINOR_CONTROL) {
120 /* /dev/aloadC? */
121 int card = SNDRV_MINOR_CARD(minor);
Takashi Iwaif4fa9682019-04-16 18:18:47 +0200122 struct snd_card *ref = snd_card_ref(card);
123 if (!ref)
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200124 snd_request_card(card);
Takashi Iwaif4fa9682019-04-16 18:18:47 +0200125 else
126 snd_card_unref(ref);
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200127 } else if (dev == SNDRV_MINOR_GLOBAL) {
128 /* /dev/aloadSEQ */
129 snd_request_other(minor);
130 }
131 mutex_lock(&sound_mutex); /* reacuire lock */
132 return snd_minors[minor];
133}
134#else /* !CONFIG_MODULES */
135#define autoload_device(minor) NULL
136#endif /* CONFIG_MODULES */
137
138static int snd_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Clemens Ladisch332682b2005-11-20 14:07:47 +0100140 unsigned int minor = iminor(inode);
Takashi Iwai512bbd62005-11-17 13:51:18 +0100141 struct snd_minor *mptr = NULL;
Al Viroe84f9e52013-09-22 14:17:15 -0400142 const struct file_operations *new_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 int err = 0;
144
Adrian Bunk3a63e4442006-03-13 14:14:10 +0100145 if (minor >= ARRAY_SIZE(snd_minors))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return -ENODEV;
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200147 mutex_lock(&sound_mutex);
Clemens Ladisch332682b2005-11-20 14:07:47 +0100148 mptr = snd_minors[minor];
149 if (mptr == NULL) {
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200150 mptr = autoload_device(minor);
151 if (!mptr) {
152 mutex_unlock(&sound_mutex);
Clemens Ladisch332682b2005-11-20 14:07:47 +0100153 return -ENODEV;
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200154 }
Clemens Ladisch332682b2005-11-20 14:07:47 +0100155 }
Al Viroe84f9e52013-09-22 14:17:15 -0400156 new_fops = fops_get(mptr->f_ops);
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200157 mutex_unlock(&sound_mutex);
Al Viroe84f9e52013-09-22 14:17:15 -0400158 if (!new_fops)
159 return -ENODEV;
160 replace_fops(file, new_fops);
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200161
Al Viroe84f9e52013-09-22 14:17:15 -0400162 if (file->f_op->open)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 err = file->f_op->open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return err;
165}
166
Arjan van de Ven9c2e08c2007-02-12 00:55:37 -0800167static const struct file_operations snd_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200170 .open = snd_open,
171 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
Clemens Ladisch332682b2005-11-20 14:07:47 +0100174#ifdef CONFIG_SND_DYNAMIC_MINORS
Takashi Iwai38ebb702015-02-06 14:45:33 +0100175static int snd_find_free_minor(int type, struct snd_card *card, int dev)
Clemens Ladisch332682b2005-11-20 14:07:47 +0100176{
177 int minor;
178
Kay Sievers03cfe6f2010-11-23 17:43:19 +0100179 /* static minors for module auto loading */
180 if (type == SNDRV_DEVICE_TYPE_SEQUENCER)
181 return SNDRV_MINOR_SEQUENCER;
182 if (type == SNDRV_DEVICE_TYPE_TIMER)
183 return SNDRV_MINOR_TIMER;
184
Clemens Ladisch332682b2005-11-20 14:07:47 +0100185 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
Kay Sievers03cfe6f2010-11-23 17:43:19 +0100186 /* skip static minors still used for module auto loading */
187 if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL)
188 continue;
189 if (minor == SNDRV_MINOR_SEQUENCER ||
190 minor == SNDRV_MINOR_TIMER)
Clemens Ladisch332682b2005-11-20 14:07:47 +0100191 continue;
192 if (!snd_minors[minor])
193 return minor;
194 }
195 return -EBUSY;
196}
197#else
Takashi Iwai38ebb702015-02-06 14:45:33 +0100198static int snd_find_free_minor(int type, struct snd_card *card, int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 int minor;
201
202 switch (type) {
203 case SNDRV_DEVICE_TYPE_SEQUENCER:
204 case SNDRV_DEVICE_TYPE_TIMER:
205 minor = type;
206 break;
207 case SNDRV_DEVICE_TYPE_CONTROL:
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200208 if (snd_BUG_ON(!card))
209 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 minor = SNDRV_MINOR(card->number, type);
211 break;
212 case SNDRV_DEVICE_TYPE_HWDEP:
213 case SNDRV_DEVICE_TYPE_RAWMIDI:
214 case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
215 case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
Omair Mohammed Abdullah3eafc952011-12-23 10:36:36 +0530216 case SNDRV_DEVICE_TYPE_COMPRESS:
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200217 if (snd_BUG_ON(!card))
218 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 minor = SNDRV_MINOR(card->number, type + dev);
220 break;
221 default:
222 return -EINVAL;
223 }
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200224 if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
225 return -EINVAL;
Takashi Iwai38ebb702015-02-06 14:45:33 +0100226 if (snd_minors[minor])
227 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return minor;
229}
Clemens Ladisch332682b2005-11-20 14:07:47 +0100230#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232/**
Takashi Iwai40a4b262015-01-30 08:34:58 +0100233 * snd_register_device - Register the ALSA device file for the card
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
235 * @card: the card instance
236 * @dev: the device index
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100237 * @f_ops: the file operations
Clemens Ladischf87135f2005-11-20 14:06:59 +0100238 * @private_data: user pointer for f_ops->open()
Takashi Iwai40a4b262015-01-30 08:34:58 +0100239 * @device: the device to register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 *
241 * Registers an ALSA device file for the given card.
242 * The operators have to be set in reg parameter.
243 *
Yacine Belkadieb7c06e2013-03-11 22:05:14 +0100244 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 */
Takashi Iwai40a4b262015-01-30 08:34:58 +0100246int snd_register_device(int type, struct snd_card *card, int dev,
247 const struct file_operations *f_ops,
248 void *private_data, struct device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Clemens Ladisch332682b2005-11-20 14:07:47 +0100250 int minor;
Takashi Iwai92b79522015-01-29 15:53:51 +0100251 int err = 0;
Takashi Iwai512bbd62005-11-17 13:51:18 +0100252 struct snd_minor *preg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Takashi Iwai40a4b262015-01-30 08:34:58 +0100254 if (snd_BUG_ON(!device))
255 return -EINVAL;
256
Clemens Ladisch562b5902006-07-05 11:24:22 +0200257 preg = kmalloc(sizeof *preg, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (preg == NULL)
259 return -ENOMEM;
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100260 preg->type = type;
Clemens Ladisch6983b722005-11-20 14:05:49 +0100261 preg->card = card ? card->number : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 preg->device = dev;
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100263 preg->f_ops = f_ops;
Clemens Ladischf87135f2005-11-20 14:06:59 +0100264 preg->private_data = private_data;
Takashi Iwaia0830db2012-10-16 13:05:59 +0200265 preg->card_ptr = card;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100266 mutex_lock(&sound_mutex);
Takashi Iwai38ebb702015-02-06 14:45:33 +0100267 minor = snd_find_free_minor(type, card, dev);
Clemens Ladisch332682b2005-11-20 14:07:47 +0100268 if (minor < 0) {
Takashi Iwai92b79522015-01-29 15:53:51 +0100269 err = minor;
270 goto error;
Mariusz Kozlowski24690492007-10-09 10:34:06 +0200271 }
272
Takashi Iwai40a4b262015-01-30 08:34:58 +0100273 preg->dev = device;
274 device->devt = MKDEV(major, minor);
275 err = device_add(device);
Takashi Iwai92b79522015-01-29 15:53:51 +0100276 if (err < 0)
277 goto error;
278
279 snd_minors[minor] = preg;
280 error:
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100281 mutex_unlock(&sound_mutex);
Takashi Iwai92b79522015-01-29 15:53:51 +0100282 if (err < 0)
283 kfree(preg);
284 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
Takashi Iwai40a4b262015-01-30 08:34:58 +0100286EXPORT_SYMBOL(snd_register_device);
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288/**
289 * snd_unregister_device - unregister the device on the given card
Takashi Iwai40a4b262015-01-30 08:34:58 +0100290 * @dev: the device instance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 *
292 * Unregisters the device file already registered via
293 * snd_register_device().
294 *
Yacine Belkadieb7c06e2013-03-11 22:05:14 +0100295 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 */
Takashi Iwai40a4b262015-01-30 08:34:58 +0100297int snd_unregister_device(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Takashi Iwai9d19f482006-09-06 14:27:46 +0200299 int minor;
Takashi Iwai92b79522015-01-29 15:53:51 +0100300 struct snd_minor *preg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100302 mutex_lock(&sound_mutex);
Takashi Iwai40a4b262015-01-30 08:34:58 +0100303 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
304 preg = snd_minors[minor];
305 if (preg && preg->dev == dev) {
306 snd_minors[minor] = NULL;
307 device_del(dev);
308 kfree(preg);
309 break;
310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100312 mutex_unlock(&sound_mutex);
Takashi Iwai40a4b262015-01-30 08:34:58 +0100313 if (minor >= ARRAY_SIZE(snd_minors))
314 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 return 0;
316}
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200317EXPORT_SYMBOL(snd_unregister_device);
318
Jie Yangcd6a6502015-05-27 19:45:45 +0800319#ifdef CONFIG_SND_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320/*
321 * INFO PART
322 */
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100323static const char *snd_device_type_name(int type)
324{
325 switch (type) {
326 case SNDRV_DEVICE_TYPE_CONTROL:
327 return "control";
328 case SNDRV_DEVICE_TYPE_HWDEP:
329 return "hardware dependent";
330 case SNDRV_DEVICE_TYPE_RAWMIDI:
331 return "raw midi";
332 case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
333 return "digital audio playback";
334 case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
335 return "digital audio capture";
336 case SNDRV_DEVICE_TYPE_SEQUENCER:
337 return "sequencer";
338 case SNDRV_DEVICE_TYPE_TIMER:
339 return "timer";
340 default:
341 return "?";
342 }
343}
344
Takashi Iwai512bbd62005-11-17 13:51:18 +0100345static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Clemens Ladisch6983b722005-11-20 14:05:49 +0100347 int minor;
Takashi Iwai512bbd62005-11-17 13:51:18 +0100348 struct snd_minor *mptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100350 mutex_lock(&sound_mutex);
Clemens Ladisch6983b722005-11-20 14:05:49 +0100351 for (minor = 0; minor < SNDRV_OS_MINORS; ++minor) {
352 if (!(mptr = snd_minors[minor]))
353 continue;
354 if (mptr->card >= 0) {
355 if (mptr->device >= 0)
Clemens Ladischd0015442005-11-20 14:09:05 +0100356 snd_iprintf(buffer, "%3i: [%2i-%2i]: %s\n",
Clemens Ladisch6983b722005-11-20 14:05:49 +0100357 minor, mptr->card, mptr->device,
358 snd_device_type_name(mptr->type));
359 else
Clemens Ladischd0015442005-11-20 14:09:05 +0100360 snd_iprintf(buffer, "%3i: [%2i] : %s\n",
Clemens Ladisch6983b722005-11-20 14:05:49 +0100361 minor, mptr->card,
362 snd_device_type_name(mptr->type));
363 } else
Clemens Ladischd0015442005-11-20 14:09:05 +0100364 snd_iprintf(buffer, "%3i: : %s\n", minor,
Clemens Ladisch6983b722005-11-20 14:05:49 +0100365 snd_device_type_name(mptr->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100367 mutex_unlock(&sound_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370int __init snd_minor_info_init(void)
371{
Takashi Iwai512bbd62005-11-17 13:51:18 +0100372 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL);
Takashi Iwaib591b6e2015-04-22 22:29:10 +0200375 if (!entry)
376 return -ENOMEM;
377 entry->c.text.read = snd_minor_info_read;
378 return snd_info_register(entry); /* freed in error path */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
Jie Yangcd6a6502015-05-27 19:45:45 +0800380#endif /* CONFIG_SND_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382/*
383 * INIT PART
384 */
385
386static int __init alsa_sound_init(void)
387{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 snd_major = major;
389 snd_ecards_limit = cards_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (register_chrdev(major, "alsa", &snd_fops)) {
Takashi Iwaif2f93072014-02-04 18:21:03 +0100391 pr_err("ALSA core: unable to register native major device number %d\n", major);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return -EIO;
393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (snd_info_init() < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 unregister_chrdev(major, "alsa");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 return -ENOMEM;
397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#ifndef MODULE
Takashi Iwaif2f93072014-02-04 18:21:03 +0100399 pr_info("Advanced Linux Sound Architecture Driver Initialized.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#endif
401 return 0;
402}
403
404static void __exit alsa_sound_exit(void)
405{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 snd_info_done();
Akinobu Mita68fc4fa2007-07-19 01:47:50 -0700407 unregister_chrdev(major, "alsa");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Thadeu Lima de Souza Cascardoc181a132010-01-12 20:20:39 -0200410subsys_initcall(alsa_sound_init);
411module_exit(alsa_sound_exit);