3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/jiffies.h>
24 #include <linux/slab.h>
25 #include <linux/time.h>
26 #include <linux/wait.h>
27 #include <linux/moduleparam.h>
28 #include <sound/core.h>
29 #include <sound/control.h>
30 #include <sound/pcm.h>
31 #include <sound/rawmidi.h>
32 #include <sound/initval.h>
34 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
35 MODULE_DESCRIPTION("Dummy soundcard (/dev/null)");
36 MODULE_LICENSE("GPL");
37 MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
39 #define MAX_PCM_DEVICES 4
40 #define MAX_PCM_SUBSTREAMS 16
41 #define MAX_MIDI_DEVICES 2
43 #if 0 /* emu10k1 emulation */
44 #define MAX_BUFFER_SIZE (128 * 1024)
45 static int emu10k1_playback_constraints(snd_pcm_runtime_t
*runtime
)
48 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
50 if ((err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 256, UINT_MAX
)) < 0)
54 #define add_playback_constraints emu10k1_playback_constraints
57 #if 0 /* RME9652 emulation */
58 #define MAX_BUFFER_SIZE (26 * 64 * 1024)
59 #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
60 #define USE_CHANNELS_MIN 26
61 #define USE_CHANNELS_MAX 26
62 #define USE_PERIODS_MIN 2
63 #define USE_PERIODS_MAX 2
66 #if 0 /* ICE1712 emulation */
67 #define MAX_BUFFER_SIZE (256 * 1024)
68 #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
69 #define USE_CHANNELS_MIN 10
70 #define USE_CHANNELS_MAX 10
71 #define USE_PERIODS_MIN 1
72 #define USE_PERIODS_MAX 1024
75 #if 0 /* UDA1341 emulation */
76 #define MAX_BUFFER_SIZE (16380)
77 #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
78 #define USE_CHANNELS_MIN 2
79 #define USE_CHANNELS_MAX 2
80 #define USE_PERIODS_MIN 2
81 #define USE_PERIODS_MAX 255
84 #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */
85 #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
86 #define USE_CHANNELS_MIN 2
87 #define USE_CHANNELS_MAX 2
88 #define USE_RATE SNDRV_PCM_RATE_48000
89 #define USE_RATE_MIN 48000
90 #define USE_RATE_MAX 48000
95 #ifndef MAX_BUFFER_SIZE
96 #define MAX_BUFFER_SIZE (64*1024)
99 #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
102 #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000
103 #define USE_RATE_MIN 5500
104 #define USE_RATE_MAX 48000
106 #ifndef USE_CHANNELS_MIN
107 #define USE_CHANNELS_MIN 1
109 #ifndef USE_CHANNELS_MAX
110 #define USE_CHANNELS_MAX 2
112 #ifndef USE_PERIODS_MIN
113 #define USE_PERIODS_MIN 1
115 #ifndef USE_PERIODS_MAX
116 #define USE_PERIODS_MAX 1024
118 #ifndef add_playback_constraints
119 #define add_playback_constraints(x) 0
121 #ifndef add_capture_constraints
122 #define add_capture_constraints(x) 0
125 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
126 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
127 static int enable
[SNDRV_CARDS
] = {1, [1 ... (SNDRV_CARDS
- 1)] = 0};
128 static int pcm_devs
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 1};
129 static int pcm_substreams
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 8};
130 //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
131 static int boot_devs
;
133 module_param_array(index
, int, boot_devs
, 0444);
134 MODULE_PARM_DESC(index
, "Index value for dummy soundcard.");
135 module_param_array(id
, charp
, boot_devs
, 0444);
136 MODULE_PARM_DESC(id
, "ID string for dummy soundcard.");
137 module_param_array(enable
, bool, boot_devs
, 0444);
138 MODULE_PARM_DESC(enable
, "Enable this dummy soundcard.");
139 module_param_array(pcm_devs
, int, boot_devs
, 0444);
140 MODULE_PARM_DESC(pcm_devs
, "PCM devices # (0-4) for dummy driver.");
141 module_param_array(pcm_substreams
, int, boot_devs
, 0444);
142 MODULE_PARM_DESC(pcm_substreams
, "PCM substreams # (1-16) for dummy driver.");
143 //module_param_array(midi_devs, int, boot_devs, 0444);
144 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
146 #define MIXER_ADDR_MASTER 0
147 #define MIXER_ADDR_LINE 1
148 #define MIXER_ADDR_MIC 2
149 #define MIXER_ADDR_SYNTH 3
150 #define MIXER_ADDR_CD 4
151 #define MIXER_ADDR_LAST 4
153 typedef struct snd_card_dummy
{
155 spinlock_t mixer_lock
;
156 int mixer_volume
[MIXER_ADDR_LAST
+1][2];
157 int capture_source
[MIXER_ADDR_LAST
+1][2];
160 typedef struct snd_card_dummy_pcm
{
161 snd_card_dummy_t
*dummy
;
163 struct timer_list timer
;
164 unsigned int pcm_size
;
165 unsigned int pcm_count
;
166 unsigned int pcm_bps
; /* bytes per second */
167 unsigned int pcm_jiffie
; /* bytes per one jiffie */
168 unsigned int pcm_irq_pos
; /* IRQ position */
169 unsigned int pcm_buf_pos
; /* position in buffer */
170 snd_pcm_substream_t
*substream
;
171 } snd_card_dummy_pcm_t
;
173 static snd_card_t
*snd_dummy_cards
[SNDRV_CARDS
] = SNDRV_DEFAULT_PTR
;
176 static void snd_card_dummy_pcm_timer_start(snd_pcm_substream_t
* substream
)
178 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
179 snd_card_dummy_pcm_t
*dpcm
= runtime
->private_data
;
181 dpcm
->timer
.expires
= 1 + jiffies
;
182 add_timer(&dpcm
->timer
);
185 static void snd_card_dummy_pcm_timer_stop(snd_pcm_substream_t
* substream
)
187 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
188 snd_card_dummy_pcm_t
*dpcm
= runtime
->private_data
;
190 del_timer(&dpcm
->timer
);
193 static int snd_card_dummy_playback_trigger(snd_pcm_substream_t
* substream
,
196 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
197 snd_card_dummy_pcm_timer_start(substream
);
198 } else if (cmd
== SNDRV_PCM_TRIGGER_STOP
) {
199 snd_card_dummy_pcm_timer_stop(substream
);
206 static int snd_card_dummy_capture_trigger(snd_pcm_substream_t
* substream
,
209 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
210 snd_card_dummy_pcm_timer_start(substream
);
211 } else if (cmd
== SNDRV_PCM_TRIGGER_STOP
) {
212 snd_card_dummy_pcm_timer_stop(substream
);
219 static int snd_card_dummy_pcm_prepare(snd_pcm_substream_t
* substream
)
221 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
222 snd_card_dummy_pcm_t
*dpcm
= runtime
->private_data
;
225 bps
= runtime
->rate
* runtime
->channels
;
226 bps
*= snd_pcm_format_width(runtime
->format
);
231 dpcm
->pcm_jiffie
= bps
/ HZ
;
232 dpcm
->pcm_size
= snd_pcm_lib_buffer_bytes(substream
);
233 dpcm
->pcm_count
= snd_pcm_lib_period_bytes(substream
);
234 dpcm
->pcm_irq_pos
= 0;
235 dpcm
->pcm_buf_pos
= 0;
239 static int snd_card_dummy_playback_prepare(snd_pcm_substream_t
* substream
)
241 return snd_card_dummy_pcm_prepare(substream
);
244 static int snd_card_dummy_capture_prepare(snd_pcm_substream_t
* substream
)
246 return snd_card_dummy_pcm_prepare(substream
);
249 static void snd_card_dummy_pcm_timer_function(unsigned long data
)
251 snd_card_dummy_pcm_t
*dpcm
= (snd_card_dummy_pcm_t
*)data
;
253 dpcm
->timer
.expires
= 1 + jiffies
;
254 add_timer(&dpcm
->timer
);
255 spin_lock_irq(&dpcm
->lock
);
256 dpcm
->pcm_irq_pos
+= dpcm
->pcm_jiffie
;
257 dpcm
->pcm_buf_pos
+= dpcm
->pcm_jiffie
;
258 dpcm
->pcm_buf_pos
%= dpcm
->pcm_size
;
259 if (dpcm
->pcm_irq_pos
>= dpcm
->pcm_count
) {
260 dpcm
->pcm_irq_pos
%= dpcm
->pcm_count
;
261 snd_pcm_period_elapsed(dpcm
->substream
);
263 spin_unlock_irq(&dpcm
->lock
);
266 static snd_pcm_uframes_t
snd_card_dummy_playback_pointer(snd_pcm_substream_t
* substream
)
268 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
269 snd_card_dummy_pcm_t
*dpcm
= runtime
->private_data
;
271 return bytes_to_frames(runtime
, dpcm
->pcm_buf_pos
);
274 static snd_pcm_uframes_t
snd_card_dummy_capture_pointer(snd_pcm_substream_t
* substream
)
276 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
277 snd_card_dummy_pcm_t
*dpcm
= runtime
->private_data
;
279 return bytes_to_frames(runtime
, dpcm
->pcm_buf_pos
);
282 static snd_pcm_hardware_t snd_card_dummy_playback
=
284 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
285 SNDRV_PCM_INFO_MMAP_VALID
),
286 .formats
= USE_FORMATS
,
288 .rate_min
= USE_RATE_MIN
,
289 .rate_max
= USE_RATE_MAX
,
290 .channels_min
= USE_CHANNELS_MIN
,
291 .channels_max
= USE_CHANNELS_MAX
,
292 .buffer_bytes_max
= MAX_BUFFER_SIZE
,
293 .period_bytes_min
= 64,
294 .period_bytes_max
= MAX_BUFFER_SIZE
,
295 .periods_min
= USE_PERIODS_MIN
,
296 .periods_max
= USE_PERIODS_MAX
,
300 static snd_pcm_hardware_t snd_card_dummy_capture
=
302 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
303 SNDRV_PCM_INFO_MMAP_VALID
),
304 .formats
= USE_FORMATS
,
306 .rate_min
= USE_RATE_MIN
,
307 .rate_max
= USE_RATE_MAX
,
308 .channels_min
= USE_CHANNELS_MIN
,
309 .channels_max
= USE_CHANNELS_MAX
,
310 .buffer_bytes_max
= MAX_BUFFER_SIZE
,
311 .period_bytes_min
= 64,
312 .period_bytes_max
= MAX_BUFFER_SIZE
,
313 .periods_min
= USE_PERIODS_MIN
,
314 .periods_max
= USE_PERIODS_MAX
,
318 static void snd_card_dummy_runtime_free(snd_pcm_runtime_t
*runtime
)
320 snd_card_dummy_pcm_t
*dpcm
= runtime
->private_data
;
324 static int snd_card_dummy_hw_params(snd_pcm_substream_t
* substream
,
325 snd_pcm_hw_params_t
* hw_params
)
327 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
330 static int snd_card_dummy_hw_free(snd_pcm_substream_t
* substream
)
332 return snd_pcm_lib_free_pages(substream
);
335 static int snd_card_dummy_playback_open(snd_pcm_substream_t
* substream
)
337 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
338 snd_card_dummy_pcm_t
*dpcm
;
341 dpcm
= kcalloc(1, sizeof(*dpcm
), GFP_KERNEL
);
344 init_timer(&dpcm
->timer
);
345 dpcm
->timer
.data
= (unsigned long) dpcm
;
346 dpcm
->timer
.function
= snd_card_dummy_pcm_timer_function
;
347 spin_lock_init(&dpcm
->lock
);
348 dpcm
->substream
= substream
;
349 runtime
->private_data
= dpcm
;
350 runtime
->private_free
= snd_card_dummy_runtime_free
;
351 runtime
->hw
= snd_card_dummy_playback
;
352 if (substream
->pcm
->device
& 1) {
353 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_INTERLEAVED
;
354 runtime
->hw
.info
|= SNDRV_PCM_INFO_NONINTERLEAVED
;
356 if (substream
->pcm
->device
& 2)
357 runtime
->hw
.info
&= ~(SNDRV_PCM_INFO_MMAP
|SNDRV_PCM_INFO_MMAP_VALID
);
358 if ((err
= add_playback_constraints(runtime
)) < 0) {
366 static int snd_card_dummy_capture_open(snd_pcm_substream_t
* substream
)
368 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
369 snd_card_dummy_pcm_t
*dpcm
;
372 dpcm
= kcalloc(1, sizeof(*dpcm
), GFP_KERNEL
);
375 init_timer(&dpcm
->timer
);
376 dpcm
->timer
.data
= (unsigned long) dpcm
;
377 dpcm
->timer
.function
= snd_card_dummy_pcm_timer_function
;
378 spin_lock_init(&dpcm
->lock
);
379 dpcm
->substream
= substream
;
380 runtime
->private_data
= dpcm
;
381 runtime
->private_free
= snd_card_dummy_runtime_free
;
382 runtime
->hw
= snd_card_dummy_capture
;
383 if (substream
->pcm
->device
== 1) {
384 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_INTERLEAVED
;
385 runtime
->hw
.info
|= SNDRV_PCM_INFO_NONINTERLEAVED
;
387 if (substream
->pcm
->device
& 2)
388 runtime
->hw
.info
&= ~(SNDRV_PCM_INFO_MMAP
|SNDRV_PCM_INFO_MMAP_VALID
);
389 if ((err
= add_capture_constraints(runtime
)) < 0) {
397 static int snd_card_dummy_playback_close(snd_pcm_substream_t
* substream
)
402 static int snd_card_dummy_capture_close(snd_pcm_substream_t
* substream
)
407 static snd_pcm_ops_t snd_card_dummy_playback_ops
= {
408 .open
= snd_card_dummy_playback_open
,
409 .close
= snd_card_dummy_playback_close
,
410 .ioctl
= snd_pcm_lib_ioctl
,
411 .hw_params
= snd_card_dummy_hw_params
,
412 .hw_free
= snd_card_dummy_hw_free
,
413 .prepare
= snd_card_dummy_playback_prepare
,
414 .trigger
= snd_card_dummy_playback_trigger
,
415 .pointer
= snd_card_dummy_playback_pointer
,
418 static snd_pcm_ops_t snd_card_dummy_capture_ops
= {
419 .open
= snd_card_dummy_capture_open
,
420 .close
= snd_card_dummy_capture_close
,
421 .ioctl
= snd_pcm_lib_ioctl
,
422 .hw_params
= snd_card_dummy_hw_params
,
423 .hw_free
= snd_card_dummy_hw_free
,
424 .prepare
= snd_card_dummy_capture_prepare
,
425 .trigger
= snd_card_dummy_capture_trigger
,
426 .pointer
= snd_card_dummy_capture_pointer
,
429 static int __init
snd_card_dummy_pcm(snd_card_dummy_t
*dummy
, int device
, int substreams
)
434 if ((err
= snd_pcm_new(dummy
->card
, "Dummy PCM", device
, substreams
, substreams
, &pcm
)) < 0)
436 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_card_dummy_playback_ops
);
437 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_card_dummy_capture_ops
);
438 pcm
->private_data
= dummy
;
440 strcpy(pcm
->name
, "Dummy PCM");
441 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_CONTINUOUS
,
442 snd_dma_continuous_data(GFP_KERNEL
),
447 #define DUMMY_VOLUME(xname, xindex, addr) \
448 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
449 .info = snd_dummy_volume_info, \
450 .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \
451 .private_value = addr }
453 static int snd_dummy_volume_info(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_info_t
* uinfo
)
455 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
457 uinfo
->value
.integer
.min
= -50;
458 uinfo
->value
.integer
.max
= 100;
462 static int snd_dummy_volume_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
464 snd_card_dummy_t
*dummy
= snd_kcontrol_chip(kcontrol
);
466 int addr
= kcontrol
->private_value
;
468 spin_lock_irqsave(&dummy
->mixer_lock
, flags
);
469 ucontrol
->value
.integer
.value
[0] = dummy
->mixer_volume
[addr
][0];
470 ucontrol
->value
.integer
.value
[1] = dummy
->mixer_volume
[addr
][1];
471 spin_unlock_irqrestore(&dummy
->mixer_lock
, flags
);
475 static int snd_dummy_volume_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
477 snd_card_dummy_t
*dummy
= snd_kcontrol_chip(kcontrol
);
479 int change
, addr
= kcontrol
->private_value
;
482 left
= ucontrol
->value
.integer
.value
[0];
487 right
= ucontrol
->value
.integer
.value
[1];
492 spin_lock_irqsave(&dummy
->mixer_lock
, flags
);
493 change
= dummy
->mixer_volume
[addr
][0] != left
||
494 dummy
->mixer_volume
[addr
][1] != right
;
495 dummy
->mixer_volume
[addr
][0] = left
;
496 dummy
->mixer_volume
[addr
][1] = right
;
497 spin_unlock_irqrestore(&dummy
->mixer_lock
, flags
);
501 #define DUMMY_CAPSRC(xname, xindex, addr) \
502 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
503 .info = snd_dummy_capsrc_info, \
504 .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \
505 .private_value = addr }
507 static int snd_dummy_capsrc_info(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_info_t
* uinfo
)
509 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
511 uinfo
->value
.integer
.min
= 0;
512 uinfo
->value
.integer
.max
= 1;
516 static int snd_dummy_capsrc_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
518 snd_card_dummy_t
*dummy
= snd_kcontrol_chip(kcontrol
);
520 int addr
= kcontrol
->private_value
;
522 spin_lock_irqsave(&dummy
->mixer_lock
, flags
);
523 ucontrol
->value
.integer
.value
[0] = dummy
->capture_source
[addr
][0];
524 ucontrol
->value
.integer
.value
[1] = dummy
->capture_source
[addr
][1];
525 spin_unlock_irqrestore(&dummy
->mixer_lock
, flags
);
529 static int snd_dummy_capsrc_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
531 snd_card_dummy_t
*dummy
= snd_kcontrol_chip(kcontrol
);
533 int change
, addr
= kcontrol
->private_value
;
536 left
= ucontrol
->value
.integer
.value
[0] & 1;
537 right
= ucontrol
->value
.integer
.value
[1] & 1;
538 spin_lock_irqsave(&dummy
->mixer_lock
, flags
);
539 change
= dummy
->capture_source
[addr
][0] != left
&&
540 dummy
->capture_source
[addr
][1] != right
;
541 dummy
->capture_source
[addr
][0] = left
;
542 dummy
->capture_source
[addr
][1] = right
;
543 spin_unlock_irqrestore(&dummy
->mixer_lock
, flags
);
547 static snd_kcontrol_new_t snd_dummy_controls
[] = {
548 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER
),
549 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER
),
550 DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH
),
551 DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_MASTER
),
552 DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE
),
553 DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_MASTER
),
554 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC
),
555 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MASTER
),
556 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD
),
557 DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER
)
560 int __init
snd_card_dummy_new_mixer(snd_card_dummy_t
* dummy
)
562 snd_card_t
*card
= dummy
->card
;
566 snd_assert(dummy
!= NULL
, return -EINVAL
);
567 spin_lock_init(&dummy
->mixer_lock
);
568 strcpy(card
->mixername
, "Dummy Mixer");
570 for (idx
= 0; idx
< ARRAY_SIZE(snd_dummy_controls
); idx
++) {
571 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_dummy_controls
[idx
], dummy
))) < 0)
577 static int __init
snd_card_dummy_probe(int dev
)
580 struct snd_card_dummy
*dummy
;
585 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
,
586 sizeof(struct snd_card_dummy
));
589 dummy
= (struct snd_card_dummy
*)card
->private_data
;
591 for (idx
= 0; idx
< MAX_PCM_DEVICES
&& idx
< pcm_devs
[dev
]; idx
++) {
592 if (pcm_substreams
[dev
] < 1)
593 pcm_substreams
[dev
] = 1;
594 if (pcm_substreams
[dev
] > MAX_PCM_SUBSTREAMS
)
595 pcm_substreams
[dev
] = MAX_PCM_SUBSTREAMS
;
596 if ((err
= snd_card_dummy_pcm(dummy
, idx
, pcm_substreams
[dev
])) < 0)
599 if ((err
= snd_card_dummy_new_mixer(dummy
)) < 0)
601 strcpy(card
->driver
, "Dummy");
602 strcpy(card
->shortname
, "Dummy");
603 sprintf(card
->longname
, "Dummy %i", dev
+ 1);
604 if ((err
= snd_card_register(card
)) == 0) {
605 snd_dummy_cards
[dev
] = card
;
613 static int __init
alsa_card_dummy_init(void)
617 for (dev
= cards
= 0; dev
< SNDRV_CARDS
&& enable
[dev
]; dev
++) {
618 if (snd_card_dummy_probe(dev
) < 0) {
620 printk(KERN_ERR
"Dummy soundcard #%i not found or device busy\n", dev
+ 1);
628 printk(KERN_ERR
"Dummy soundcard not found or device busy\n");
635 static void __exit
alsa_card_dummy_exit(void)
639 for (idx
= 0; idx
< SNDRV_CARDS
; idx
++)
640 snd_card_free(snd_dummy_cards
[idx
]);
643 module_init(alsa_card_dummy_init
)
644 module_exit(alsa_card_dummy_exit
)