]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - sound/core/pcm.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / sound / core / pcm.c
1 /*
2 * Digital Audio (PCM) abstract layer
3 * Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/time.h>
26 #include <linux/mutex.h>
27 #include <linux/device.h>
28 #include <sound/core.h>
29 #include <sound/minors.h>
30 #include <sound/pcm.h>
31 #include <sound/control.h>
32 #include <sound/info.h>
33
34 #include "pcm_local.h"
35
36 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Abramo Bagnara <abramo@alsa-project.org>");
37 MODULE_DESCRIPTION("Midlevel PCM code for ALSA.");
38 MODULE_LICENSE("GPL");
39
40 static LIST_HEAD(snd_pcm_devices);
41 static DEFINE_MUTEX(register_mutex);
42 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
43 static LIST_HEAD(snd_pcm_notify_list);
44 #endif
45
46 static int snd_pcm_free(struct snd_pcm *pcm);
47 static int snd_pcm_dev_free(struct snd_device *device);
48 static int snd_pcm_dev_register(struct snd_device *device);
49 static int snd_pcm_dev_disconnect(struct snd_device *device);
50
51 static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
52 {
53 struct snd_pcm *pcm;
54
55 list_for_each_entry(pcm, &snd_pcm_devices, list) {
56 if (pcm->card == card && pcm->device == device)
57 return pcm;
58 }
59 return NULL;
60 }
61
62 static int snd_pcm_next(struct snd_card *card, int device)
63 {
64 struct snd_pcm *pcm;
65
66 list_for_each_entry(pcm, &snd_pcm_devices, list) {
67 if (pcm->card == card && pcm->device > device)
68 return pcm->device;
69 else if (pcm->card->number > card->number)
70 return -1;
71 }
72 return -1;
73 }
74
75 static int snd_pcm_add(struct snd_pcm *newpcm)
76 {
77 struct snd_pcm *pcm;
78
79 if (newpcm->internal)
80 return 0;
81
82 list_for_each_entry(pcm, &snd_pcm_devices, list) {
83 if (pcm->card == newpcm->card && pcm->device == newpcm->device)
84 return -EBUSY;
85 if (pcm->card->number > newpcm->card->number ||
86 (pcm->card == newpcm->card &&
87 pcm->device > newpcm->device)) {
88 list_add(&newpcm->list, pcm->list.prev);
89 return 0;
90 }
91 }
92 list_add_tail(&newpcm->list, &snd_pcm_devices);
93 return 0;
94 }
95
96 static int snd_pcm_control_ioctl(struct snd_card *card,
97 struct snd_ctl_file *control,
98 unsigned int cmd, unsigned long arg)
99 {
100 switch (cmd) {
101 case SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE:
102 {
103 int device;
104
105 if (get_user(device, (int __user *)arg))
106 return -EFAULT;
107 mutex_lock(&register_mutex);
108 device = snd_pcm_next(card, device);
109 mutex_unlock(&register_mutex);
110 if (put_user(device, (int __user *)arg))
111 return -EFAULT;
112 return 0;
113 }
114 case SNDRV_CTL_IOCTL_PCM_INFO:
115 {
116 struct snd_pcm_info __user *info;
117 unsigned int device, subdevice;
118 int stream;
119 struct snd_pcm *pcm;
120 struct snd_pcm_str *pstr;
121 struct snd_pcm_substream *substream;
122 int err;
123
124 info = (struct snd_pcm_info __user *)arg;
125 if (get_user(device, &info->device))
126 return -EFAULT;
127 if (get_user(stream, &info->stream))
128 return -EFAULT;
129 if (stream < 0 || stream > 1)
130 return -EINVAL;
131 if (get_user(subdevice, &info->subdevice))
132 return -EFAULT;
133 mutex_lock(&register_mutex);
134 pcm = snd_pcm_get(card, device);
135 if (pcm == NULL) {
136 err = -ENXIO;
137 goto _error;
138 }
139 pstr = &pcm->streams[stream];
140 if (pstr->substream_count == 0) {
141 err = -ENOENT;
142 goto _error;
143 }
144 if (subdevice >= pstr->substream_count) {
145 err = -ENXIO;
146 goto _error;
147 }
148 for (substream = pstr->substream; substream;
149 substream = substream->next)
150 if (substream->number == (int)subdevice)
151 break;
152 if (substream == NULL) {
153 err = -ENXIO;
154 goto _error;
155 }
156 mutex_lock(&pcm->open_mutex);
157 err = snd_pcm_info_user(substream, info);
158 mutex_unlock(&pcm->open_mutex);
159 _error:
160 mutex_unlock(&register_mutex);
161 return err;
162 }
163 case SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE:
164 {
165 int val;
166
167 if (get_user(val, (int __user *)arg))
168 return -EFAULT;
169 control->preferred_subdevice[SND_CTL_SUBDEV_PCM] = val;
170 return 0;
171 }
172 }
173 return -ENOIOCTLCMD;
174 }
175
176 #define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v
177
178 static char *snd_pcm_format_names[] = {
179 FORMAT(S8),
180 FORMAT(U8),
181 FORMAT(S16_LE),
182 FORMAT(S16_BE),
183 FORMAT(U16_LE),
184 FORMAT(U16_BE),
185 FORMAT(S24_LE),
186 FORMAT(S24_BE),
187 FORMAT(U24_LE),
188 FORMAT(U24_BE),
189 FORMAT(S32_LE),
190 FORMAT(S32_BE),
191 FORMAT(U32_LE),
192 FORMAT(U32_BE),
193 FORMAT(FLOAT_LE),
194 FORMAT(FLOAT_BE),
195 FORMAT(FLOAT64_LE),
196 FORMAT(FLOAT64_BE),
197 FORMAT(IEC958_SUBFRAME_LE),
198 FORMAT(IEC958_SUBFRAME_BE),
199 FORMAT(MU_LAW),
200 FORMAT(A_LAW),
201 FORMAT(IMA_ADPCM),
202 FORMAT(MPEG),
203 FORMAT(GSM),
204 FORMAT(SPECIAL),
205 FORMAT(S24_3LE),
206 FORMAT(S24_3BE),
207 FORMAT(U24_3LE),
208 FORMAT(U24_3BE),
209 FORMAT(S20_3LE),
210 FORMAT(S20_3BE),
211 FORMAT(U20_3LE),
212 FORMAT(U20_3BE),
213 FORMAT(S18_3LE),
214 FORMAT(S18_3BE),
215 FORMAT(U18_3LE),
216 FORMAT(U18_3BE),
217 FORMAT(G723_24),
218 FORMAT(G723_24_1B),
219 FORMAT(G723_40),
220 FORMAT(G723_40_1B),
221 FORMAT(DSD_U8),
222 FORMAT(DSD_U16_LE),
223 FORMAT(DSD_U32_LE),
224 FORMAT(DSD_U16_BE),
225 FORMAT(DSD_U32_BE),
226 };
227
228 /**
229 * snd_pcm_format_name - Return a name string for the given PCM format
230 * @format: PCM format
231 */
232 const char *snd_pcm_format_name(snd_pcm_format_t format)
233 {
234 if ((__force unsigned int)format >= ARRAY_SIZE(snd_pcm_format_names))
235 return "Unknown";
236 return snd_pcm_format_names[(__force unsigned int)format];
237 }
238 EXPORT_SYMBOL_GPL(snd_pcm_format_name);
239
240 #ifdef CONFIG_SND_VERBOSE_PROCFS
241
242 #define STATE(v) [SNDRV_PCM_STATE_##v] = #v
243 #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
244 #define READY(v) [SNDRV_PCM_READY_##v] = #v
245 #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
246 #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
247 #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
248 #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
249 #define START(v) [SNDRV_PCM_START_##v] = #v
250 #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
251
252 static char *snd_pcm_stream_names[] = {
253 STREAM(PLAYBACK),
254 STREAM(CAPTURE),
255 };
256
257 static char *snd_pcm_state_names[] = {
258 STATE(OPEN),
259 STATE(SETUP),
260 STATE(PREPARED),
261 STATE(RUNNING),
262 STATE(XRUN),
263 STATE(DRAINING),
264 STATE(PAUSED),
265 STATE(SUSPENDED),
266 };
267
268 static char *snd_pcm_access_names[] = {
269 ACCESS(MMAP_INTERLEAVED),
270 ACCESS(MMAP_NONINTERLEAVED),
271 ACCESS(MMAP_COMPLEX),
272 ACCESS(RW_INTERLEAVED),
273 ACCESS(RW_NONINTERLEAVED),
274 };
275
276 static char *snd_pcm_subformat_names[] = {
277 SUBFORMAT(STD),
278 };
279
280 static char *snd_pcm_tstamp_mode_names[] = {
281 TSTAMP(NONE),
282 TSTAMP(ENABLE),
283 };
284
285 static const char *snd_pcm_stream_name(int stream)
286 {
287 return snd_pcm_stream_names[stream];
288 }
289
290 static const char *snd_pcm_access_name(snd_pcm_access_t access)
291 {
292 return snd_pcm_access_names[(__force int)access];
293 }
294
295 static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
296 {
297 return snd_pcm_subformat_names[(__force int)subformat];
298 }
299
300 static const char *snd_pcm_tstamp_mode_name(int mode)
301 {
302 return snd_pcm_tstamp_mode_names[mode];
303 }
304
305 static const char *snd_pcm_state_name(snd_pcm_state_t state)
306 {
307 return snd_pcm_state_names[(__force int)state];
308 }
309
310 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
311 #include <linux/soundcard.h>
312
313 static const char *snd_pcm_oss_format_name(int format)
314 {
315 switch (format) {
316 case AFMT_MU_LAW:
317 return "MU_LAW";
318 case AFMT_A_LAW:
319 return "A_LAW";
320 case AFMT_IMA_ADPCM:
321 return "IMA_ADPCM";
322 case AFMT_U8:
323 return "U8";
324 case AFMT_S16_LE:
325 return "S16_LE";
326 case AFMT_S16_BE:
327 return "S16_BE";
328 case AFMT_S8:
329 return "S8";
330 case AFMT_U16_LE:
331 return "U16_LE";
332 case AFMT_U16_BE:
333 return "U16_BE";
334 case AFMT_MPEG:
335 return "MPEG";
336 default:
337 return "unknown";
338 }
339 }
340 #endif
341
342 static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
343 struct snd_info_buffer *buffer)
344 {
345 struct snd_pcm_info *info;
346 int err;
347
348 if (! substream)
349 return;
350
351 info = kmalloc(sizeof(*info), GFP_KERNEL);
352 if (!info)
353 return;
354
355 err = snd_pcm_info(substream, info);
356 if (err < 0) {
357 snd_iprintf(buffer, "error %d\n", err);
358 kfree(info);
359 return;
360 }
361 snd_iprintf(buffer, "card: %d\n", info->card);
362 snd_iprintf(buffer, "device: %d\n", info->device);
363 snd_iprintf(buffer, "subdevice: %d\n", info->subdevice);
364 snd_iprintf(buffer, "stream: %s\n", snd_pcm_stream_name(info->stream));
365 snd_iprintf(buffer, "id: %s\n", info->id);
366 snd_iprintf(buffer, "name: %s\n", info->name);
367 snd_iprintf(buffer, "subname: %s\n", info->subname);
368 snd_iprintf(buffer, "class: %d\n", info->dev_class);
369 snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass);
370 snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count);
371 snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail);
372 kfree(info);
373 }
374
375 static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry,
376 struct snd_info_buffer *buffer)
377 {
378 snd_pcm_proc_info_read(((struct snd_pcm_str *)entry->private_data)->substream,
379 buffer);
380 }
381
382 static void snd_pcm_substream_proc_info_read(struct snd_info_entry *entry,
383 struct snd_info_buffer *buffer)
384 {
385 snd_pcm_proc_info_read(entry->private_data, buffer);
386 }
387
388 static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry,
389 struct snd_info_buffer *buffer)
390 {
391 struct snd_pcm_substream *substream = entry->private_data;
392 struct snd_pcm_runtime *runtime;
393
394 mutex_lock(&substream->pcm->open_mutex);
395 runtime = substream->runtime;
396 if (!runtime) {
397 snd_iprintf(buffer, "closed\n");
398 goto unlock;
399 }
400 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
401 snd_iprintf(buffer, "no setup\n");
402 goto unlock;
403 }
404 snd_iprintf(buffer, "access: %s\n", snd_pcm_access_name(runtime->access));
405 snd_iprintf(buffer, "format: %s\n", snd_pcm_format_name(runtime->format));
406 snd_iprintf(buffer, "subformat: %s\n", snd_pcm_subformat_name(runtime->subformat));
407 snd_iprintf(buffer, "channels: %u\n", runtime->channels);
408 snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den);
409 snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size);
410 snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size);
411 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
412 if (substream->oss.oss) {
413 snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format));
414 snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels);
415 snd_iprintf(buffer, "OSS rate: %u\n", runtime->oss.rate);
416 snd_iprintf(buffer, "OSS period bytes: %lu\n", (unsigned long)runtime->oss.period_bytes);
417 snd_iprintf(buffer, "OSS periods: %u\n", runtime->oss.periods);
418 snd_iprintf(buffer, "OSS period frames: %lu\n", (unsigned long)runtime->oss.period_frames);
419 }
420 #endif
421 unlock:
422 mutex_unlock(&substream->pcm->open_mutex);
423 }
424
425 static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry,
426 struct snd_info_buffer *buffer)
427 {
428 struct snd_pcm_substream *substream = entry->private_data;
429 struct snd_pcm_runtime *runtime;
430
431 mutex_lock(&substream->pcm->open_mutex);
432 runtime = substream->runtime;
433 if (!runtime) {
434 snd_iprintf(buffer, "closed\n");
435 goto unlock;
436 }
437 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
438 snd_iprintf(buffer, "no setup\n");
439 goto unlock;
440 }
441 snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode));
442 snd_iprintf(buffer, "period_step: %u\n", runtime->period_step);
443 snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min);
444 snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold);
445 snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold);
446 snd_iprintf(buffer, "silence_threshold: %lu\n", runtime->silence_threshold);
447 snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size);
448 snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary);
449 unlock:
450 mutex_unlock(&substream->pcm->open_mutex);
451 }
452
453 static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
454 struct snd_info_buffer *buffer)
455 {
456 struct snd_pcm_substream *substream = entry->private_data;
457 struct snd_pcm_runtime *runtime;
458 struct snd_pcm_status status;
459 int err;
460
461 mutex_lock(&substream->pcm->open_mutex);
462 runtime = substream->runtime;
463 if (!runtime) {
464 snd_iprintf(buffer, "closed\n");
465 goto unlock;
466 }
467 memset(&status, 0, sizeof(status));
468 err = snd_pcm_status(substream, &status);
469 if (err < 0) {
470 snd_iprintf(buffer, "error %d\n", err);
471 goto unlock;
472 }
473 snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state));
474 snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid));
475 snd_iprintf(buffer, "trigger_time: %ld.%09ld\n",
476 status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec);
477 snd_iprintf(buffer, "tstamp : %ld.%09ld\n",
478 status.tstamp.tv_sec, status.tstamp.tv_nsec);
479 snd_iprintf(buffer, "delay : %ld\n", status.delay);
480 snd_iprintf(buffer, "avail : %ld\n", status.avail);
481 snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max);
482 snd_iprintf(buffer, "-----\n");
483 snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr);
484 snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr);
485 unlock:
486 mutex_unlock(&substream->pcm->open_mutex);
487 }
488
489 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
490 static void snd_pcm_xrun_injection_write(struct snd_info_entry *entry,
491 struct snd_info_buffer *buffer)
492 {
493 struct snd_pcm_substream *substream = entry->private_data;
494 struct snd_pcm_runtime *runtime;
495
496 snd_pcm_stream_lock_irq(substream);
497 runtime = substream->runtime;
498 if (runtime && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
499 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
500 snd_pcm_stream_unlock_irq(substream);
501 }
502
503 static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry,
504 struct snd_info_buffer *buffer)
505 {
506 struct snd_pcm_str *pstr = entry->private_data;
507 snd_iprintf(buffer, "%d\n", pstr->xrun_debug);
508 }
509
510 static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry,
511 struct snd_info_buffer *buffer)
512 {
513 struct snd_pcm_str *pstr = entry->private_data;
514 char line[64];
515 if (!snd_info_get_line(buffer, line, sizeof(line)))
516 pstr->xrun_debug = simple_strtoul(line, NULL, 10);
517 }
518 #endif
519
520 static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr)
521 {
522 struct snd_pcm *pcm = pstr->pcm;
523 struct snd_info_entry *entry;
524 char name[16];
525
526 sprintf(name, "pcm%i%c", pcm->device,
527 pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
528 if ((entry = snd_info_create_card_entry(pcm->card, name, pcm->card->proc_root)) == NULL)
529 return -ENOMEM;
530 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
531 if (snd_info_register(entry) < 0) {
532 snd_info_free_entry(entry);
533 return -ENOMEM;
534 }
535 pstr->proc_root = entry;
536
537 if ((entry = snd_info_create_card_entry(pcm->card, "info", pstr->proc_root)) != NULL) {
538 snd_info_set_text_ops(entry, pstr, snd_pcm_stream_proc_info_read);
539 if (snd_info_register(entry) < 0) {
540 snd_info_free_entry(entry);
541 entry = NULL;
542 }
543 }
544 pstr->proc_info_entry = entry;
545
546 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
547 if ((entry = snd_info_create_card_entry(pcm->card, "xrun_debug",
548 pstr->proc_root)) != NULL) {
549 entry->c.text.read = snd_pcm_xrun_debug_read;
550 entry->c.text.write = snd_pcm_xrun_debug_write;
551 entry->mode |= S_IWUSR;
552 entry->private_data = pstr;
553 if (snd_info_register(entry) < 0) {
554 snd_info_free_entry(entry);
555 entry = NULL;
556 }
557 }
558 pstr->proc_xrun_debug_entry = entry;
559 #endif
560 return 0;
561 }
562
563 static int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr)
564 {
565 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
566 snd_info_free_entry(pstr->proc_xrun_debug_entry);
567 pstr->proc_xrun_debug_entry = NULL;
568 #endif
569 snd_info_free_entry(pstr->proc_info_entry);
570 pstr->proc_info_entry = NULL;
571 snd_info_free_entry(pstr->proc_root);
572 pstr->proc_root = NULL;
573 return 0;
574 }
575
576 static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream)
577 {
578 struct snd_info_entry *entry;
579 struct snd_card *card;
580 char name[16];
581
582 card = substream->pcm->card;
583
584 sprintf(name, "sub%i", substream->number);
585 if ((entry = snd_info_create_card_entry(card, name, substream->pstr->proc_root)) == NULL)
586 return -ENOMEM;
587 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
588 if (snd_info_register(entry) < 0) {
589 snd_info_free_entry(entry);
590 return -ENOMEM;
591 }
592 substream->proc_root = entry;
593
594 if ((entry = snd_info_create_card_entry(card, "info", substream->proc_root)) != NULL) {
595 snd_info_set_text_ops(entry, substream,
596 snd_pcm_substream_proc_info_read);
597 if (snd_info_register(entry) < 0) {
598 snd_info_free_entry(entry);
599 entry = NULL;
600 }
601 }
602 substream->proc_info_entry = entry;
603
604 if ((entry = snd_info_create_card_entry(card, "hw_params", substream->proc_root)) != NULL) {
605 snd_info_set_text_ops(entry, substream,
606 snd_pcm_substream_proc_hw_params_read);
607 if (snd_info_register(entry) < 0) {
608 snd_info_free_entry(entry);
609 entry = NULL;
610 }
611 }
612 substream->proc_hw_params_entry = entry;
613
614 if ((entry = snd_info_create_card_entry(card, "sw_params", substream->proc_root)) != NULL) {
615 snd_info_set_text_ops(entry, substream,
616 snd_pcm_substream_proc_sw_params_read);
617 if (snd_info_register(entry) < 0) {
618 snd_info_free_entry(entry);
619 entry = NULL;
620 }
621 }
622 substream->proc_sw_params_entry = entry;
623
624 if ((entry = snd_info_create_card_entry(card, "status", substream->proc_root)) != NULL) {
625 snd_info_set_text_ops(entry, substream,
626 snd_pcm_substream_proc_status_read);
627 if (snd_info_register(entry) < 0) {
628 snd_info_free_entry(entry);
629 entry = NULL;
630 }
631 }
632 substream->proc_status_entry = entry;
633
634 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
635 entry = snd_info_create_card_entry(card, "xrun_injection",
636 substream->proc_root);
637 if (entry) {
638 entry->private_data = substream;
639 entry->c.text.read = NULL;
640 entry->c.text.write = snd_pcm_xrun_injection_write;
641 entry->mode = S_IFREG | S_IWUSR;
642 if (snd_info_register(entry) < 0) {
643 snd_info_free_entry(entry);
644 entry = NULL;
645 }
646 }
647 substream->proc_xrun_injection_entry = entry;
648 #endif /* CONFIG_SND_PCM_XRUN_DEBUG */
649
650 return 0;
651 }
652
653 static int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream)
654 {
655 snd_info_free_entry(substream->proc_info_entry);
656 substream->proc_info_entry = NULL;
657 snd_info_free_entry(substream->proc_hw_params_entry);
658 substream->proc_hw_params_entry = NULL;
659 snd_info_free_entry(substream->proc_sw_params_entry);
660 substream->proc_sw_params_entry = NULL;
661 snd_info_free_entry(substream->proc_status_entry);
662 substream->proc_status_entry = NULL;
663 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
664 snd_info_free_entry(substream->proc_xrun_injection_entry);
665 substream->proc_xrun_injection_entry = NULL;
666 #endif
667 snd_info_free_entry(substream->proc_root);
668 substream->proc_root = NULL;
669 return 0;
670 }
671 #else /* !CONFIG_SND_VERBOSE_PROCFS */
672 static inline int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) { return 0; }
673 static inline int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) { return 0; }
674 static inline int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) { return 0; }
675 static inline int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream) { return 0; }
676 #endif /* CONFIG_SND_VERBOSE_PROCFS */
677
678 static const struct attribute_group *pcm_dev_attr_groups[];
679
680 /**
681 * snd_pcm_new_stream - create a new PCM stream
682 * @pcm: the pcm instance
683 * @stream: the stream direction, SNDRV_PCM_STREAM_XXX
684 * @substream_count: the number of substreams
685 *
686 * Creates a new stream for the pcm.
687 * The corresponding stream on the pcm must have been empty before
688 * calling this, i.e. zero must be given to the argument of
689 * snd_pcm_new().
690 *
691 * Return: Zero if successful, or a negative error code on failure.
692 */
693 int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
694 {
695 int idx, err;
696 struct snd_pcm_str *pstr = &pcm->streams[stream];
697 struct snd_pcm_substream *substream, *prev;
698
699 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
700 mutex_init(&pstr->oss.setup_mutex);
701 #endif
702 pstr->stream = stream;
703 pstr->pcm = pcm;
704 pstr->substream_count = substream_count;
705 if (!substream_count)
706 return 0;
707
708 snd_device_initialize(&pstr->dev, pcm->card);
709 pstr->dev.groups = pcm_dev_attr_groups;
710 dev_set_name(&pstr->dev, "pcmC%iD%i%c", pcm->card->number, pcm->device,
711 stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
712
713 if (!pcm->internal) {
714 err = snd_pcm_stream_proc_init(pstr);
715 if (err < 0) {
716 pcm_err(pcm, "Error in snd_pcm_stream_proc_init\n");
717 return err;
718 }
719 }
720 prev = NULL;
721 for (idx = 0, prev = NULL; idx < substream_count; idx++) {
722 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
723 if (!substream)
724 return -ENOMEM;
725 substream->pcm = pcm;
726 substream->pstr = pstr;
727 substream->number = idx;
728 substream->stream = stream;
729 sprintf(substream->name, "subdevice #%i", idx);
730 substream->buffer_bytes_max = UINT_MAX;
731 if (prev == NULL)
732 pstr->substream = substream;
733 else
734 prev->next = substream;
735
736 if (!pcm->internal) {
737 err = snd_pcm_substream_proc_init(substream);
738 if (err < 0) {
739 pcm_err(pcm,
740 "Error in snd_pcm_stream_proc_init\n");
741 if (prev == NULL)
742 pstr->substream = NULL;
743 else
744 prev->next = NULL;
745 kfree(substream);
746 return err;
747 }
748 }
749 substream->group = &substream->self_group;
750 spin_lock_init(&substream->self_group.lock);
751 mutex_init(&substream->self_group.mutex);
752 INIT_LIST_HEAD(&substream->self_group.substreams);
753 list_add_tail(&substream->link_list, &substream->self_group.substreams);
754 atomic_set(&substream->mmap_count, 0);
755 prev = substream;
756 }
757 return 0;
758 }
759 EXPORT_SYMBOL(snd_pcm_new_stream);
760
761 static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
762 int playback_count, int capture_count, bool internal,
763 struct snd_pcm **rpcm)
764 {
765 struct snd_pcm *pcm;
766 int err;
767 static struct snd_device_ops ops = {
768 .dev_free = snd_pcm_dev_free,
769 .dev_register = snd_pcm_dev_register,
770 .dev_disconnect = snd_pcm_dev_disconnect,
771 };
772
773 if (snd_BUG_ON(!card))
774 return -ENXIO;
775 if (rpcm)
776 *rpcm = NULL;
777 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
778 if (!pcm)
779 return -ENOMEM;
780 pcm->card = card;
781 pcm->device = device;
782 pcm->internal = internal;
783 mutex_init(&pcm->open_mutex);
784 init_waitqueue_head(&pcm->open_wait);
785 INIT_LIST_HEAD(&pcm->list);
786 if (id)
787 strlcpy(pcm->id, id, sizeof(pcm->id));
788 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
789 snd_pcm_free(pcm);
790 return err;
791 }
792 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {
793 snd_pcm_free(pcm);
794 return err;
795 }
796 if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
797 snd_pcm_free(pcm);
798 return err;
799 }
800 if (rpcm)
801 *rpcm = pcm;
802 return 0;
803 }
804
805 /**
806 * snd_pcm_new - create a new PCM instance
807 * @card: the card instance
808 * @id: the id string
809 * @device: the device index (zero based)
810 * @playback_count: the number of substreams for playback
811 * @capture_count: the number of substreams for capture
812 * @rpcm: the pointer to store the new pcm instance
813 *
814 * Creates a new PCM instance.
815 *
816 * The pcm operators have to be set afterwards to the new instance
817 * via snd_pcm_set_ops().
818 *
819 * Return: Zero if successful, or a negative error code on failure.
820 */
821 int snd_pcm_new(struct snd_card *card, const char *id, int device,
822 int playback_count, int capture_count, struct snd_pcm **rpcm)
823 {
824 return _snd_pcm_new(card, id, device, playback_count, capture_count,
825 false, rpcm);
826 }
827 EXPORT_SYMBOL(snd_pcm_new);
828
829 /**
830 * snd_pcm_new_internal - create a new internal PCM instance
831 * @card: the card instance
832 * @id: the id string
833 * @device: the device index (zero based - shared with normal PCMs)
834 * @playback_count: the number of substreams for playback
835 * @capture_count: the number of substreams for capture
836 * @rpcm: the pointer to store the new pcm instance
837 *
838 * Creates a new internal PCM instance with no userspace device or procfs
839 * entries. This is used by ASoC Back End PCMs in order to create a PCM that
840 * will only be used internally by kernel drivers. i.e. it cannot be opened
841 * by userspace. It provides existing ASoC components drivers with a substream
842 * and access to any private data.
843 *
844 * The pcm operators have to be set afterwards to the new instance
845 * via snd_pcm_set_ops().
846 *
847 * Return: Zero if successful, or a negative error code on failure.
848 */
849 int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
850 int playback_count, int capture_count,
851 struct snd_pcm **rpcm)
852 {
853 return _snd_pcm_new(card, id, device, playback_count, capture_count,
854 true, rpcm);
855 }
856 EXPORT_SYMBOL(snd_pcm_new_internal);
857
858 static void free_chmap(struct snd_pcm_str *pstr)
859 {
860 if (pstr->chmap_kctl) {
861 snd_ctl_remove(pstr->pcm->card, pstr->chmap_kctl);
862 pstr->chmap_kctl = NULL;
863 }
864 }
865
866 static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
867 {
868 struct snd_pcm_substream *substream, *substream_next;
869 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
870 struct snd_pcm_oss_setup *setup, *setupn;
871 #endif
872 substream = pstr->substream;
873 while (substream) {
874 substream_next = substream->next;
875 snd_pcm_timer_done(substream);
876 snd_pcm_substream_proc_done(substream);
877 kfree(substream);
878 substream = substream_next;
879 }
880 snd_pcm_stream_proc_done(pstr);
881 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
882 for (setup = pstr->oss.setup_list; setup; setup = setupn) {
883 setupn = setup->next;
884 kfree(setup->task_name);
885 kfree(setup);
886 }
887 #endif
888 free_chmap(pstr);
889 if (pstr->substream_count)
890 put_device(&pstr->dev);
891 }
892
893 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
894 #define pcm_call_notify(pcm, call) \
895 do { \
896 struct snd_pcm_notify *_notify; \
897 list_for_each_entry(_notify, &snd_pcm_notify_list, list) \
898 _notify->call(pcm); \
899 } while (0)
900 #else
901 #define pcm_call_notify(pcm, call) do {} while (0)
902 #endif
903
904 static int snd_pcm_free(struct snd_pcm *pcm)
905 {
906 if (!pcm)
907 return 0;
908 if (!pcm->internal)
909 pcm_call_notify(pcm, n_unregister);
910 if (pcm->private_free)
911 pcm->private_free(pcm);
912 snd_pcm_lib_preallocate_free_for_all(pcm);
913 snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]);
914 snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]);
915 kfree(pcm);
916 return 0;
917 }
918
919 static int snd_pcm_dev_free(struct snd_device *device)
920 {
921 struct snd_pcm *pcm = device->device_data;
922 return snd_pcm_free(pcm);
923 }
924
925 int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
926 struct file *file,
927 struct snd_pcm_substream **rsubstream)
928 {
929 struct snd_pcm_str * pstr;
930 struct snd_pcm_substream *substream;
931 struct snd_pcm_runtime *runtime;
932 struct snd_card *card;
933 int prefer_subdevice;
934 size_t size;
935
936 if (snd_BUG_ON(!pcm || !rsubstream))
937 return -ENXIO;
938 if (snd_BUG_ON(stream != SNDRV_PCM_STREAM_PLAYBACK &&
939 stream != SNDRV_PCM_STREAM_CAPTURE))
940 return -EINVAL;
941 *rsubstream = NULL;
942 pstr = &pcm->streams[stream];
943 if (pstr->substream == NULL || pstr->substream_count == 0)
944 return -ENODEV;
945
946 card = pcm->card;
947 prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM);
948
949 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
950 int opposite = !stream;
951
952 for (substream = pcm->streams[opposite].substream; substream;
953 substream = substream->next) {
954 if (SUBSTREAM_BUSY(substream))
955 return -EAGAIN;
956 }
957 }
958
959 if (file->f_flags & O_APPEND) {
960 if (prefer_subdevice < 0) {
961 if (pstr->substream_count > 1)
962 return -EINVAL; /* must be unique */
963 substream = pstr->substream;
964 } else {
965 for (substream = pstr->substream; substream;
966 substream = substream->next)
967 if (substream->number == prefer_subdevice)
968 break;
969 }
970 if (! substream)
971 return -ENODEV;
972 if (! SUBSTREAM_BUSY(substream))
973 return -EBADFD;
974 substream->ref_count++;
975 *rsubstream = substream;
976 return 0;
977 }
978
979 for (substream = pstr->substream; substream; substream = substream->next) {
980 if (!SUBSTREAM_BUSY(substream) &&
981 (prefer_subdevice == -1 ||
982 substream->number == prefer_subdevice))
983 break;
984 }
985 if (substream == NULL)
986 return -EAGAIN;
987
988 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
989 if (runtime == NULL)
990 return -ENOMEM;
991
992 size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
993 runtime->status = snd_malloc_pages(size, GFP_KERNEL);
994 if (runtime->status == NULL) {
995 kfree(runtime);
996 return -ENOMEM;
997 }
998 memset((void*)runtime->status, 0, size);
999
1000 size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
1001 runtime->control = snd_malloc_pages(size, GFP_KERNEL);
1002 if (runtime->control == NULL) {
1003 snd_free_pages((void*)runtime->status,
1004 PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
1005 kfree(runtime);
1006 return -ENOMEM;
1007 }
1008 memset((void*)runtime->control, 0, size);
1009
1010 init_waitqueue_head(&runtime->sleep);
1011 init_waitqueue_head(&runtime->tsleep);
1012
1013 runtime->status->state = SNDRV_PCM_STATE_OPEN;
1014
1015 substream->runtime = runtime;
1016 substream->private_data = pcm->private_data;
1017 substream->ref_count = 1;
1018 substream->f_flags = file->f_flags;
1019 substream->pid = get_pid(task_pid(current));
1020 pstr->substream_opened++;
1021 *rsubstream = substream;
1022 return 0;
1023 }
1024
1025 void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
1026 {
1027 struct snd_pcm_runtime *runtime;
1028
1029 if (PCM_RUNTIME_CHECK(substream))
1030 return;
1031 runtime = substream->runtime;
1032 if (runtime->private_free != NULL)
1033 runtime->private_free(runtime);
1034 snd_free_pages((void*)runtime->status,
1035 PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
1036 snd_free_pages((void*)runtime->control,
1037 PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
1038 kfree(runtime->hw_constraints.rules);
1039 kfree(runtime);
1040 substream->runtime = NULL;
1041 put_pid(substream->pid);
1042 substream->pid = NULL;
1043 substream->pstr->substream_opened--;
1044 }
1045
1046 static ssize_t show_pcm_class(struct device *dev,
1047 struct device_attribute *attr, char *buf)
1048 {
1049 struct snd_pcm_str *pstr = container_of(dev, struct snd_pcm_str, dev);
1050 struct snd_pcm *pcm = pstr->pcm;
1051 const char *str;
1052 static const char *strs[SNDRV_PCM_CLASS_LAST + 1] = {
1053 [SNDRV_PCM_CLASS_GENERIC] = "generic",
1054 [SNDRV_PCM_CLASS_MULTI] = "multi",
1055 [SNDRV_PCM_CLASS_MODEM] = "modem",
1056 [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
1057 };
1058
1059 if (pcm->dev_class > SNDRV_PCM_CLASS_LAST)
1060 str = "none";
1061 else
1062 str = strs[pcm->dev_class];
1063 return snprintf(buf, PAGE_SIZE, "%s\n", str);
1064 }
1065
1066 static DEVICE_ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
1067 static struct attribute *pcm_dev_attrs[] = {
1068 &dev_attr_pcm_class.attr,
1069 NULL
1070 };
1071
1072 static const struct attribute_group pcm_dev_attr_group = {
1073 .attrs = pcm_dev_attrs,
1074 };
1075
1076 static const struct attribute_group *pcm_dev_attr_groups[] = {
1077 &pcm_dev_attr_group,
1078 NULL
1079 };
1080
1081 static int snd_pcm_dev_register(struct snd_device *device)
1082 {
1083 int cidx, err;
1084 struct snd_pcm_substream *substream;
1085 struct snd_pcm *pcm;
1086
1087 if (snd_BUG_ON(!device || !device->device_data))
1088 return -ENXIO;
1089 pcm = device->device_data;
1090 if (pcm->internal)
1091 return 0;
1092
1093 mutex_lock(&register_mutex);
1094 err = snd_pcm_add(pcm);
1095 if (err)
1096 goto unlock;
1097 for (cidx = 0; cidx < 2; cidx++) {
1098 int devtype = -1;
1099 if (pcm->streams[cidx].substream == NULL)
1100 continue;
1101 switch (cidx) {
1102 case SNDRV_PCM_STREAM_PLAYBACK:
1103 devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
1104 break;
1105 case SNDRV_PCM_STREAM_CAPTURE:
1106 devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
1107 break;
1108 }
1109 /* register pcm */
1110 err = snd_register_device(devtype, pcm->card, pcm->device,
1111 &snd_pcm_f_ops[cidx], pcm,
1112 &pcm->streams[cidx].dev);
1113 if (err < 0) {
1114 list_del_init(&pcm->list);
1115 goto unlock;
1116 }
1117
1118 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
1119 snd_pcm_timer_init(substream);
1120 }
1121
1122 pcm_call_notify(pcm, n_register);
1123
1124 unlock:
1125 mutex_unlock(&register_mutex);
1126 return err;
1127 }
1128
1129 static int snd_pcm_dev_disconnect(struct snd_device *device)
1130 {
1131 struct snd_pcm *pcm = device->device_data;
1132 struct snd_pcm_substream *substream;
1133 int cidx;
1134
1135 mutex_lock(&register_mutex);
1136 mutex_lock(&pcm->open_mutex);
1137 wake_up(&pcm->open_wait);
1138 list_del_init(&pcm->list);
1139 for (cidx = 0; cidx < 2; cidx++) {
1140 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) {
1141 snd_pcm_stream_lock_irq(substream);
1142 if (substream->runtime) {
1143 substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
1144 wake_up(&substream->runtime->sleep);
1145 wake_up(&substream->runtime->tsleep);
1146 }
1147 snd_pcm_stream_unlock_irq(substream);
1148 }
1149 }
1150 if (!pcm->internal) {
1151 pcm_call_notify(pcm, n_disconnect);
1152 }
1153 for (cidx = 0; cidx < 2; cidx++) {
1154 if (!pcm->internal)
1155 snd_unregister_device(&pcm->streams[cidx].dev);
1156 free_chmap(&pcm->streams[cidx]);
1157 }
1158 mutex_unlock(&pcm->open_mutex);
1159 mutex_unlock(&register_mutex);
1160 return 0;
1161 }
1162
1163 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
1164 /**
1165 * snd_pcm_notify - Add/remove the notify list
1166 * @notify: PCM notify list
1167 * @nfree: 0 = register, 1 = unregister
1168 *
1169 * This adds the given notifier to the global list so that the callback is
1170 * called for each registered PCM devices. This exists only for PCM OSS
1171 * emulation, so far.
1172 */
1173 int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
1174 {
1175 struct snd_pcm *pcm;
1176
1177 if (snd_BUG_ON(!notify ||
1178 !notify->n_register ||
1179 !notify->n_unregister ||
1180 !notify->n_disconnect))
1181 return -EINVAL;
1182 mutex_lock(&register_mutex);
1183 if (nfree) {
1184 list_del(&notify->list);
1185 list_for_each_entry(pcm, &snd_pcm_devices, list)
1186 notify->n_unregister(pcm);
1187 } else {
1188 list_add_tail(&notify->list, &snd_pcm_notify_list);
1189 list_for_each_entry(pcm, &snd_pcm_devices, list)
1190 notify->n_register(pcm);
1191 }
1192 mutex_unlock(&register_mutex);
1193 return 0;
1194 }
1195 EXPORT_SYMBOL(snd_pcm_notify);
1196 #endif /* CONFIG_SND_PCM_OSS */
1197
1198 #ifdef CONFIG_SND_PROC_FS
1199 /*
1200 * Info interface
1201 */
1202
1203 static void snd_pcm_proc_read(struct snd_info_entry *entry,
1204 struct snd_info_buffer *buffer)
1205 {
1206 struct snd_pcm *pcm;
1207
1208 mutex_lock(&register_mutex);
1209 list_for_each_entry(pcm, &snd_pcm_devices, list) {
1210 snd_iprintf(buffer, "%02i-%02i: %s : %s",
1211 pcm->card->number, pcm->device, pcm->id, pcm->name);
1212 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
1213 snd_iprintf(buffer, " : playback %i",
1214 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count);
1215 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
1216 snd_iprintf(buffer, " : capture %i",
1217 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count);
1218 snd_iprintf(buffer, "\n");
1219 }
1220 mutex_unlock(&register_mutex);
1221 }
1222
1223 static struct snd_info_entry *snd_pcm_proc_entry;
1224
1225 static void snd_pcm_proc_init(void)
1226 {
1227 struct snd_info_entry *entry;
1228
1229 if ((entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL)) != NULL) {
1230 snd_info_set_text_ops(entry, NULL, snd_pcm_proc_read);
1231 if (snd_info_register(entry) < 0) {
1232 snd_info_free_entry(entry);
1233 entry = NULL;
1234 }
1235 }
1236 snd_pcm_proc_entry = entry;
1237 }
1238
1239 static void snd_pcm_proc_done(void)
1240 {
1241 snd_info_free_entry(snd_pcm_proc_entry);
1242 }
1243
1244 #else /* !CONFIG_SND_PROC_FS */
1245 #define snd_pcm_proc_init()
1246 #define snd_pcm_proc_done()
1247 #endif /* CONFIG_SND_PROC_FS */
1248
1249
1250 /*
1251 * ENTRY functions
1252 */
1253
1254 static int __init alsa_pcm_init(void)
1255 {
1256 snd_ctl_register_ioctl(snd_pcm_control_ioctl);
1257 snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl);
1258 snd_pcm_proc_init();
1259 return 0;
1260 }
1261
1262 static void __exit alsa_pcm_exit(void)
1263 {
1264 snd_ctl_unregister_ioctl(snd_pcm_control_ioctl);
1265 snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl);
1266 snd_pcm_proc_done();
1267 }
1268
1269 module_init(alsa_pcm_init)
1270 module_exit(alsa_pcm_exit)