blob: a9ad4379523b0f4e1c6717377cad296a44d67e96 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Advanced Linux Sound Architecture
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/time.h>
Takashi Iwai9a1a2a12005-11-22 15:46:41 +010025#include <linux/device.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040026#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/core.h>
28#include <sound/minors.h>
29#include <sound/info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <sound/control.h>
31#include <sound/initval.h>
32#include <linux/kmod.h>
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010033#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static int major = CONFIG_SND_MAJOR;
36int snd_major;
Takashi Iwaic0d3fb32006-04-28 15:13:39 +020037EXPORT_SYMBOL(snd_major);
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static int cards_limit = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020041MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070042MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards.");
43MODULE_LICENSE("GPL");
44module_param(major, int, 0444);
45MODULE_PARM_DESC(major, "Major # for sound driver.");
46module_param(cards_limit, int, 0444);
47MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070048MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR);
49
50/* this one holds the actual max. card number currently available.
51 * as default, it's identical with cards_limit option. when more
52 * modules are loaded manually, this limit number increases, too.
53 */
54int snd_ecards_limit;
Takashi Iwaic0d3fb32006-04-28 15:13:39 +020055EXPORT_SYMBOL(snd_ecards_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Clemens Ladisch6983b722005-11-20 14:05:49 +010057static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010058static DEFINE_MUTEX(sound_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Johannes Bergee2da992008-07-09 10:28:41 +020060#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/**
63 * snd_request_card - try to load the card module
64 * @card: the card number
65 *
66 * Tries to load the module "snd-card-X" for the given card number
Johannes Bergee2da992008-07-09 10:28:41 +020067 * via request_module. Returns immediately if already loaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 */
69void snd_request_card(int card)
70{
Takashi Iwai746df942006-05-15 19:49:05 +020071 if (snd_card_locked(card))
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return;
73 if (card < 0 || card >= cards_limit)
74 return;
75 request_module("snd-card-%i", card);
76}
Takashi Iwaic0d3fb32006-04-28 15:13:39 +020077EXPORT_SYMBOL(snd_request_card);
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static void snd_request_other(int minor)
80{
81 char *str;
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 switch (minor) {
84 case SNDRV_MINOR_SEQUENCER: str = "snd-seq"; break;
85 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
86 default: return;
87 }
88 request_module(str);
89}
90
Johannes Bergee2da992008-07-09 10:28:41 +020091#endif /* modular kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Clemens Ladischf87135f2005-11-20 14:06:59 +010093/**
94 * snd_lookup_minor_data - get user data of a registered device
95 * @minor: the minor number
96 * @type: device type (SNDRV_DEVICE_TYPE_XXX)
97 *
98 * Checks that a minor device with the specified type is registered, and returns
99 * its user data pointer.
Takashi Iwaia0830db2012-10-16 13:05:59 +0200100 *
101 * This function increments the reference counter of the card instance
102 * if an associated instance with the given minor number and type is found.
103 * The caller must call snd_card_unref() appropriately later.
Yacine Belkadieb7c06e2013-03-11 22:05:14 +0100104 *
105 * Return: The user data pointer if the specified device is found. %NULL
106 * otherwise.
Clemens Ladischf87135f2005-11-20 14:06:59 +0100107 */
108void *snd_lookup_minor_data(unsigned int minor, int type)
109{
110 struct snd_minor *mreg;
111 void *private_data;
112
Adrian Bunk3a63e4442006-03-13 14:14:10 +0100113 if (minor >= ARRAY_SIZE(snd_minors))
Clemens Ladischf87135f2005-11-20 14:06:59 +0100114 return NULL;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100115 mutex_lock(&sound_mutex);
Clemens Ladischf87135f2005-11-20 14:06:59 +0100116 mreg = snd_minors[minor];
Takashi Iwaia0830db2012-10-16 13:05:59 +0200117 if (mreg && mreg->type == type) {
Clemens Ladischf87135f2005-11-20 14:06:59 +0100118 private_data = mreg->private_data;
Takashi Iwai8bb4d9c2012-11-08 14:36:18 +0100119 if (private_data && mreg->card_ptr)
Takashi Iwaif2464062014-01-29 12:13:43 +0100120 get_device(&mreg->card_ptr->card_dev);
Takashi Iwaia0830db2012-10-16 13:05:59 +0200121 } else
Clemens Ladischf87135f2005-11-20 14:06:59 +0100122 private_data = NULL;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100123 mutex_unlock(&sound_mutex);
Clemens Ladischf87135f2005-11-20 14:06:59 +0100124 return private_data;
125}
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200126EXPORT_SYMBOL(snd_lookup_minor_data);
127
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200128#ifdef CONFIG_MODULES
129static struct snd_minor *autoload_device(unsigned int minor)
130{
131 int dev;
132 mutex_unlock(&sound_mutex); /* release lock temporarily */
133 dev = SNDRV_MINOR_DEVICE(minor);
134 if (dev == SNDRV_MINOR_CONTROL) {
135 /* /dev/aloadC? */
136 int card = SNDRV_MINOR_CARD(minor);
Takashi Iwaif4fa9682019-04-16 18:18:47 +0200137 struct snd_card *ref = snd_card_ref(card);
138 if (!ref)
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200139 snd_request_card(card);
Takashi Iwaif4fa9682019-04-16 18:18:47 +0200140 else
141 snd_card_unref(ref);
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200142 } else if (dev == SNDRV_MINOR_GLOBAL) {
143 /* /dev/aloadSEQ */
144 snd_request_other(minor);
145 }
146 mutex_lock(&sound_mutex); /* reacuire lock */
147 return snd_minors[minor];
148}
149#else /* !CONFIG_MODULES */
150#define autoload_device(minor) NULL
151#endif /* CONFIG_MODULES */
152
153static int snd_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Clemens Ladisch332682b2005-11-20 14:07:47 +0100155 unsigned int minor = iminor(inode);
Takashi Iwai512bbd62005-11-17 13:51:18 +0100156 struct snd_minor *mptr = NULL;
Al Viroe84f9e52013-09-22 14:17:15 -0400157 const struct file_operations *new_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int err = 0;
159
Adrian Bunk3a63e4442006-03-13 14:14:10 +0100160 if (minor >= ARRAY_SIZE(snd_minors))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return -ENODEV;
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200162 mutex_lock(&sound_mutex);
Clemens Ladisch332682b2005-11-20 14:07:47 +0100163 mptr = snd_minors[minor];
164 if (mptr == NULL) {
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200165 mptr = autoload_device(minor);
166 if (!mptr) {
167 mutex_unlock(&sound_mutex);
Clemens Ladisch332682b2005-11-20 14:07:47 +0100168 return -ENODEV;
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200169 }
Clemens Ladisch332682b2005-11-20 14:07:47 +0100170 }
Al Viroe84f9e52013-09-22 14:17:15 -0400171 new_fops = fops_get(mptr->f_ops);
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200172 mutex_unlock(&sound_mutex);
Al Viroe84f9e52013-09-22 14:17:15 -0400173 if (!new_fops)
174 return -ENODEV;
175 replace_fops(file, new_fops);
Takashi Iwai4cf19b82010-04-07 18:52:08 +0200176
Al Viroe84f9e52013-09-22 14:17:15 -0400177 if (file->f_op->open)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 err = file->f_op->open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return err;
180}
181
Arjan van de Ven9c2e08c2007-02-12 00:55:37 -0800182static const struct file_operations snd_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
184 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200185 .open = snd_open,
186 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
Clemens Ladisch332682b2005-11-20 14:07:47 +0100189#ifdef CONFIG_SND_DYNAMIC_MINORS
Takashi Iwai38ebb702015-02-06 14:45:33 +0100190static int snd_find_free_minor(int type, struct snd_card *card, int dev)
Clemens Ladisch332682b2005-11-20 14:07:47 +0100191{
192 int minor;
193
Kay Sievers03cfe6f2010-11-23 17:43:19 +0100194 /* static minors for module auto loading */
195 if (type == SNDRV_DEVICE_TYPE_SEQUENCER)
196 return SNDRV_MINOR_SEQUENCER;
197 if (type == SNDRV_DEVICE_TYPE_TIMER)
198 return SNDRV_MINOR_TIMER;
199
Clemens Ladisch332682b2005-11-20 14:07:47 +0100200 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
Kay Sievers03cfe6f2010-11-23 17:43:19 +0100201 /* skip static minors still used for module auto loading */
202 if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL)
203 continue;
204 if (minor == SNDRV_MINOR_SEQUENCER ||
205 minor == SNDRV_MINOR_TIMER)
Clemens Ladisch332682b2005-11-20 14:07:47 +0100206 continue;
207 if (!snd_minors[minor])
208 return minor;
209 }
210 return -EBUSY;
211}
212#else
Takashi Iwai38ebb702015-02-06 14:45:33 +0100213static int snd_find_free_minor(int type, struct snd_card *card, int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 int minor;
216
217 switch (type) {
218 case SNDRV_DEVICE_TYPE_SEQUENCER:
219 case SNDRV_DEVICE_TYPE_TIMER:
220 minor = type;
221 break;
222 case SNDRV_DEVICE_TYPE_CONTROL:
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200223 if (snd_BUG_ON(!card))
224 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 minor = SNDRV_MINOR(card->number, type);
226 break;
227 case SNDRV_DEVICE_TYPE_HWDEP:
228 case SNDRV_DEVICE_TYPE_RAWMIDI:
229 case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
230 case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
Omair Mohammed Abdullah3eafc952011-12-23 10:36:36 +0530231 case SNDRV_DEVICE_TYPE_COMPRESS:
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200232 if (snd_BUG_ON(!card))
233 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 minor = SNDRV_MINOR(card->number, type + dev);
235 break;
236 default:
237 return -EINVAL;
238 }
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200239 if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
240 return -EINVAL;
Takashi Iwai38ebb702015-02-06 14:45:33 +0100241 if (snd_minors[minor])
242 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return minor;
244}
Clemens Ladisch332682b2005-11-20 14:07:47 +0100245#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247/**
Takashi Iwai40a4b262015-01-30 08:34:58 +0100248 * snd_register_device - Register the ALSA device file for the card
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
250 * @card: the card instance
251 * @dev: the device index
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100252 * @f_ops: the file operations
Clemens Ladischf87135f2005-11-20 14:06:59 +0100253 * @private_data: user pointer for f_ops->open()
Takashi Iwai40a4b262015-01-30 08:34:58 +0100254 * @device: the device to register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 *
256 * Registers an ALSA device file for the given card.
257 * The operators have to be set in reg parameter.
258 *
Yacine Belkadieb7c06e2013-03-11 22:05:14 +0100259 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 */
Takashi Iwai40a4b262015-01-30 08:34:58 +0100261int snd_register_device(int type, struct snd_card *card, int dev,
262 const struct file_operations *f_ops,
263 void *private_data, struct device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Clemens Ladisch332682b2005-11-20 14:07:47 +0100265 int minor;
Takashi Iwai92b79522015-01-29 15:53:51 +0100266 int err = 0;
Takashi Iwai512bbd62005-11-17 13:51:18 +0100267 struct snd_minor *preg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Takashi Iwai40a4b262015-01-30 08:34:58 +0100269 if (snd_BUG_ON(!device))
270 return -EINVAL;
271
Clemens Ladisch562b5902006-07-05 11:24:22 +0200272 preg = kmalloc(sizeof *preg, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (preg == NULL)
274 return -ENOMEM;
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100275 preg->type = type;
Clemens Ladisch6983b722005-11-20 14:05:49 +0100276 preg->card = card ? card->number : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 preg->device = dev;
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100278 preg->f_ops = f_ops;
Clemens Ladischf87135f2005-11-20 14:06:59 +0100279 preg->private_data = private_data;
Takashi Iwaia0830db2012-10-16 13:05:59 +0200280 preg->card_ptr = card;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100281 mutex_lock(&sound_mutex);
Takashi Iwai38ebb702015-02-06 14:45:33 +0100282 minor = snd_find_free_minor(type, card, dev);
Clemens Ladisch332682b2005-11-20 14:07:47 +0100283 if (minor < 0) {
Takashi Iwai92b79522015-01-29 15:53:51 +0100284 err = minor;
285 goto error;
Mariusz Kozlowski24690492007-10-09 10:34:06 +0200286 }
287
Takashi Iwai40a4b262015-01-30 08:34:58 +0100288 preg->dev = device;
289 device->devt = MKDEV(major, minor);
290 err = device_add(device);
Takashi Iwai92b79522015-01-29 15:53:51 +0100291 if (err < 0)
292 goto error;
293
294 snd_minors[minor] = preg;
295 error:
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100296 mutex_unlock(&sound_mutex);
Takashi Iwai92b79522015-01-29 15:53:51 +0100297 if (err < 0)
298 kfree(preg);
299 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
Takashi Iwai40a4b262015-01-30 08:34:58 +0100301EXPORT_SYMBOL(snd_register_device);
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303/**
304 * snd_unregister_device - unregister the device on the given card
Takashi Iwai40a4b262015-01-30 08:34:58 +0100305 * @dev: the device instance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 *
307 * Unregisters the device file already registered via
308 * snd_register_device().
309 *
Yacine Belkadieb7c06e2013-03-11 22:05:14 +0100310 * Return: Zero if successful, or a negative error code on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
Takashi Iwai40a4b262015-01-30 08:34:58 +0100312int snd_unregister_device(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Takashi Iwai9d19f482006-09-06 14:27:46 +0200314 int minor;
Takashi Iwai92b79522015-01-29 15:53:51 +0100315 struct snd_minor *preg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100317 mutex_lock(&sound_mutex);
Takashi Iwai40a4b262015-01-30 08:34:58 +0100318 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
319 preg = snd_minors[minor];
320 if (preg && preg->dev == dev) {
321 snd_minors[minor] = NULL;
322 device_del(dev);
323 kfree(preg);
324 break;
325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100327 mutex_unlock(&sound_mutex);
Takashi Iwai40a4b262015-01-30 08:34:58 +0100328 if (minor >= ARRAY_SIZE(snd_minors))
329 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 return 0;
331}
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200332EXPORT_SYMBOL(snd_unregister_device);
333
Jie Yangcd6a6502015-05-27 19:45:45 +0800334#ifdef CONFIG_SND_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335/*
336 * INFO PART
337 */
Clemens Ladisch2af677f2005-11-20 14:03:48 +0100338static const char *snd_device_type_name(int type)
339{
340 switch (type) {
341 case SNDRV_DEVICE_TYPE_CONTROL:
342 return "control";
343 case SNDRV_DEVICE_TYPE_HWDEP:
344 return "hardware dependent";
345 case SNDRV_DEVICE_TYPE_RAWMIDI:
346 return "raw midi";
347 case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
348 return "digital audio playback";
349 case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
350 return "digital audio capture";
351 case SNDRV_DEVICE_TYPE_SEQUENCER:
352 return "sequencer";
353 case SNDRV_DEVICE_TYPE_TIMER:
354 return "timer";
355 default:
356 return "?";
357 }
358}
359
Takashi Iwai512bbd62005-11-17 13:51:18 +0100360static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Clemens Ladisch6983b722005-11-20 14:05:49 +0100362 int minor;
Takashi Iwai512bbd62005-11-17 13:51:18 +0100363 struct snd_minor *mptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100365 mutex_lock(&sound_mutex);
Clemens Ladisch6983b722005-11-20 14:05:49 +0100366 for (minor = 0; minor < SNDRV_OS_MINORS; ++minor) {
367 if (!(mptr = snd_minors[minor]))
368 continue;
369 if (mptr->card >= 0) {
370 if (mptr->device >= 0)
Clemens Ladischd0015442005-11-20 14:09:05 +0100371 snd_iprintf(buffer, "%3i: [%2i-%2i]: %s\n",
Clemens Ladisch6983b722005-11-20 14:05:49 +0100372 minor, mptr->card, mptr->device,
373 snd_device_type_name(mptr->type));
374 else
Clemens Ladischd0015442005-11-20 14:09:05 +0100375 snd_iprintf(buffer, "%3i: [%2i] : %s\n",
Clemens Ladisch6983b722005-11-20 14:05:49 +0100376 minor, mptr->card,
377 snd_device_type_name(mptr->type));
378 } else
Clemens Ladischd0015442005-11-20 14:09:05 +0100379 snd_iprintf(buffer, "%3i: : %s\n", minor,
Clemens Ladisch6983b722005-11-20 14:05:49 +0100380 snd_device_type_name(mptr->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100382 mutex_unlock(&sound_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
385int __init snd_minor_info_init(void)
386{
Takashi Iwai512bbd62005-11-17 13:51:18 +0100387 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL);
Takashi Iwaib591b6e2015-04-22 22:29:10 +0200390 if (!entry)
391 return -ENOMEM;
392 entry->c.text.read = snd_minor_info_read;
393 return snd_info_register(entry); /* freed in error path */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
Jie Yangcd6a6502015-05-27 19:45:45 +0800395#endif /* CONFIG_SND_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397/*
398 * INIT PART
399 */
400
401static int __init alsa_sound_init(void)
402{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 snd_major = major;
404 snd_ecards_limit = cards_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (register_chrdev(major, "alsa", &snd_fops)) {
Takashi Iwaif2f93072014-02-04 18:21:03 +0100406 pr_err("ALSA core: unable to register native major device number %d\n", major);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return -EIO;
408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 if (snd_info_init() < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 unregister_chrdev(major, "alsa");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 return -ENOMEM;
412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#ifndef MODULE
Takashi Iwaif2f93072014-02-04 18:21:03 +0100414 pr_info("Advanced Linux Sound Architecture Driver Initialized.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#endif
416 return 0;
417}
418
419static void __exit alsa_sound_exit(void)
420{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 snd_info_done();
Akinobu Mita68fc4fa2007-07-19 01:47:50 -0700422 unregister_chrdev(major, "alsa");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
Thadeu Lima de Souza Cascardoc181a132010-01-12 20:20:39 -0200425subsys_initcall(alsa_sound_init);
426module_exit(alsa_sound_exit);