3 * Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h>
22 #include <linux/err.h>
23 #include <linux/platform_device.h>
24 #include <linux/jiffies.h>
25 #include <linux/slab.h>
26 #include <linux/time.h>
27 #include <linux/wait.h>
28 #include <linux/moduleparam.h>
29 #include <sound/core.h>
30 #include <sound/control.h>
31 #include <sound/tlv.h>
32 #include <sound/pcm.h>
33 #include <sound/rawmidi.h>
34 #include <sound/initval.h>
36 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
37 MODULE_DESCRIPTION("Dummy soundcard (/dev/null)");
38 MODULE_LICENSE("GPL");
39 MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
41 #define MAX_PCM_DEVICES 4
42 #define MAX_PCM_SUBSTREAMS 16
43 #define MAX_MIDI_DEVICES 2
45 #if 0 /* emu10k1 emulation */
46 #define MAX_BUFFER_SIZE (128 * 1024)
47 static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
50 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
52 if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0)
56 #define add_playback_constraints emu10k1_playback_constraints
59 #if 0 /* RME9652 emulation */
60 #define MAX_BUFFER_SIZE (26 * 64 * 1024)
61 #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
62 #define USE_CHANNELS_MIN 26
63 #define USE_CHANNELS_MAX 26
64 #define USE_PERIODS_MIN 2
65 #define USE_PERIODS_MAX 2
68 #if 0 /* ICE1712 emulation */
69 #define MAX_BUFFER_SIZE (256 * 1024)
70 #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
71 #define USE_CHANNELS_MIN 10
72 #define USE_CHANNELS_MAX 10
73 #define USE_PERIODS_MIN 1
74 #define USE_PERIODS_MAX 1024
77 #if 0 /* UDA1341 emulation */
78 #define MAX_BUFFER_SIZE (16380)
79 #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
80 #define USE_CHANNELS_MIN 2
81 #define USE_CHANNELS_MAX 2
82 #define USE_PERIODS_MIN 2
83 #define USE_PERIODS_MAX 255
86 #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */
87 #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
88 #define USE_CHANNELS_MIN 2
89 #define USE_CHANNELS_MAX 2
90 #define USE_RATE SNDRV_PCM_RATE_48000
91 #define USE_RATE_MIN 48000
92 #define USE_RATE_MAX 48000
96 #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
97 #define USE_CHANNELS_MIN 2
98 #define USE_CHANNELS_MAX 2
99 #define USE_RATE (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000)
100 #define USE_RATE_MIN 48000
101 #define USE_RATE_MAX 192000
102 #define MAX_BUFFER_SIZE ((65536-64)*8)
103 #define MAX_PERIOD_SIZE (65536-64)
104 #define USE_PERIODS_MIN 2
105 #define USE_PERIODS_MAX 8
110 #ifndef MAX_BUFFER_SIZE
111 #define MAX_BUFFER_SIZE (64*1024)
113 #ifndef MAX_PERIOD_SIZE
114 #define MAX_PERIOD_SIZE MAX_BUFFER_SIZE
117 #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
120 #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000
121 #define USE_RATE_MIN 5500
122 #define USE_RATE_MAX 48000
124 #ifndef USE_CHANNELS_MIN
125 #define USE_CHANNELS_MIN 1
127 #ifndef USE_CHANNELS_MAX
128 #define USE_CHANNELS_MAX 2
130 #ifndef USE_PERIODS_MIN
131 #define USE_PERIODS_MIN 1
133 #ifndef USE_PERIODS_MAX
134 #define USE_PERIODS_MAX 1024
136 #ifndef add_playback_constraints
137 #define add_playback_constraints(x) 0
139 #ifndef add_capture_constraints
140 #define add_capture_constraints(x) 0
143 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
144 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
145 static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
146 static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
147 static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
148 //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
150 module_param_array(index, int, NULL, 0444);
151 MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
152 module_param_array(id, charp, NULL, 0444);
153 MODULE_PARM_DESC(id, "ID string for dummy soundcard.");
154 module_param_array(enable, bool, NULL, 0444);
155 MODULE_PARM_DESC(enable, "Enable this dummy soundcard.");
156 module_param_array(pcm_devs, int, NULL, 0444);
157 MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
158 module_param_array(pcm_substreams, int, NULL, 0444);
159 MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
160 //module_param_array(midi_devs, int, NULL, 0444);
161 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
163 static struct platform_device *devices[SNDRV_CARDS];
165 #define MIXER_ADDR_MASTER 0
166 #define MIXER_ADDR_LINE 1
167 #define MIXER_ADDR_MIC 2
168 #define MIXER_ADDR_SYNTH 3
169 #define MIXER_ADDR_CD 4
170 #define MIXER_ADDR_LAST 4
173 struct snd_card *card;
175 spinlock_t mixer_lock;
176 int mixer_volume[MIXER_ADDR_LAST+1][2];
177 int capture_source[MIXER_ADDR_LAST+1][2];
180 struct snd_dummy_pcm {
181 struct snd_dummy *dummy;
183 struct timer_list timer;
184 unsigned int pcm_size;
185 unsigned int pcm_count;
186 unsigned int pcm_bps; /* bytes per second */
187 unsigned int pcm_jiffie; /* bytes per one jiffie */
188 unsigned int pcm_irq_pos; /* IRQ position */
189 unsigned int pcm_buf_pos; /* position in buffer */
190 struct snd_pcm_substream *substream;
194 static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
196 dpcm->timer.expires = 1 + jiffies;
197 add_timer(&dpcm->timer);
200 static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm)
202 del_timer(&dpcm->timer);
205 static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
207 struct snd_pcm_runtime *runtime = substream->runtime;
208 struct snd_dummy_pcm *dpcm = runtime->private_data;
211 spin_lock(&dpcm->lock);
213 case SNDRV_PCM_TRIGGER_START:
214 case SNDRV_PCM_TRIGGER_RESUME:
215 snd_card_dummy_pcm_timer_start(dpcm);
217 case SNDRV_PCM_TRIGGER_STOP:
218 case SNDRV_PCM_TRIGGER_SUSPEND:
219 snd_card_dummy_pcm_timer_stop(dpcm);
225 spin_unlock(&dpcm->lock);
229 static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
231 struct snd_pcm_runtime *runtime = substream->runtime;
232 struct snd_dummy_pcm *dpcm = runtime->private_data;
235 bps = runtime->rate * runtime->channels;
236 bps *= snd_pcm_format_width(runtime->format);
241 dpcm->pcm_jiffie = bps / HZ;
242 dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);
243 dpcm->pcm_count = snd_pcm_lib_period_bytes(substream);
244 dpcm->pcm_irq_pos = 0;
245 dpcm->pcm_buf_pos = 0;
249 static void snd_card_dummy_pcm_timer_function(unsigned long data)
251 struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data;
254 spin_lock_irqsave(&dpcm->lock, flags);
255 dpcm->timer.expires = 1 + jiffies;
256 add_timer(&dpcm->timer);
257 dpcm->pcm_irq_pos += dpcm->pcm_jiffie;
258 dpcm->pcm_buf_pos += dpcm->pcm_jiffie;
259 dpcm->pcm_buf_pos %= dpcm->pcm_size;
260 if (dpcm->pcm_irq_pos >= dpcm->pcm_count) {
261 dpcm->pcm_irq_pos %= dpcm->pcm_count;
262 spin_unlock_irqrestore(&dpcm->lock, flags);
263 snd_pcm_period_elapsed(dpcm->substream);
265 spin_unlock_irqrestore(&dpcm->lock, flags);
268 static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream)
270 struct snd_pcm_runtime *runtime = substream->runtime;
271 struct snd_dummy_pcm *dpcm = runtime->private_data;
273 return bytes_to_frames(runtime, dpcm->pcm_buf_pos);
276 static struct snd_pcm_hardware snd_card_dummy_playback =
278 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
279 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
280 .formats = USE_FORMATS,
282 .rate_min = USE_RATE_MIN,
283 .rate_max = USE_RATE_MAX,
284 .channels_min = USE_CHANNELS_MIN,
285 .channels_max = USE_CHANNELS_MAX,
286 .buffer_bytes_max = MAX_BUFFER_SIZE,
287 .period_bytes_min = 64,
288 .period_bytes_max = MAX_PERIOD_SIZE,
289 .periods_min = USE_PERIODS_MIN,
290 .periods_max = USE_PERIODS_MAX,
294 static struct snd_pcm_hardware snd_card_dummy_capture =
296 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
297 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
298 .formats = USE_FORMATS,
300 .rate_min = USE_RATE_MIN,
301 .rate_max = USE_RATE_MAX,
302 .channels_min = USE_CHANNELS_MIN,
303 .channels_max = USE_CHANNELS_MAX,
304 .buffer_bytes_max = MAX_BUFFER_SIZE,
305 .period_bytes_min = 64,
306 .period_bytes_max = MAX_PERIOD_SIZE,
307 .periods_min = USE_PERIODS_MIN,
308 .periods_max = USE_PERIODS_MAX,
312 static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime)
314 kfree(runtime->private_data);
317 static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
318 struct snd_pcm_hw_params *hw_params)
320 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
323 static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream)
325 return snd_pcm_lib_free_pages(substream);
328 static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream)
330 struct snd_dummy_pcm *dpcm;
332 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
335 init_timer(&dpcm->timer);
336 dpcm->timer.data = (unsigned long) dpcm;
337 dpcm->timer.function = snd_card_dummy_pcm_timer_function;
338 spin_lock_init(&dpcm->lock);
339 dpcm->substream = substream;
343 static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
345 struct snd_pcm_runtime *runtime = substream->runtime;
346 struct snd_dummy_pcm *dpcm;
349 if ((dpcm = new_pcm_stream(substream)) == NULL)
351 runtime->private_data = dpcm;
352 runtime->private_free = snd_card_dummy_runtime_free;
353 runtime->hw = snd_card_dummy_playback;
354 if (substream->pcm->device & 1) {
355 runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
356 runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
358 if (substream->pcm->device & 2)
359 runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
360 if ((err = add_playback_constraints(runtime)) < 0) {
368 static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream)
370 struct snd_pcm_runtime *runtime = substream->runtime;
371 struct snd_dummy_pcm *dpcm;
374 if ((dpcm = new_pcm_stream(substream)) == NULL)
376 runtime->private_data = dpcm;
377 runtime->private_free = snd_card_dummy_runtime_free;
378 runtime->hw = snd_card_dummy_capture;
379 if (substream->pcm->device == 1) {
380 runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
381 runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
383 if (substream->pcm->device & 2)
384 runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
385 if ((err = add_capture_constraints(runtime)) < 0) {
393 static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream)
398 static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream)
403 static struct snd_pcm_ops snd_card_dummy_playback_ops = {
404 .open = snd_card_dummy_playback_open,
405 .close = snd_card_dummy_playback_close,
406 .ioctl = snd_pcm_lib_ioctl,
407 .hw_params = snd_card_dummy_hw_params,
408 .hw_free = snd_card_dummy_hw_free,
409 .prepare = snd_card_dummy_pcm_prepare,
410 .trigger = snd_card_dummy_pcm_trigger,
411 .pointer = snd_card_dummy_pcm_pointer,
414 static struct snd_pcm_ops snd_card_dummy_capture_ops = {
415 .open = snd_card_dummy_capture_open,
416 .close = snd_card_dummy_capture_close,
417 .ioctl = snd_pcm_lib_ioctl,
418 .hw_params = snd_card_dummy_hw_params,
419 .hw_free = snd_card_dummy_hw_free,
420 .prepare = snd_card_dummy_pcm_prepare,
421 .trigger = snd_card_dummy_pcm_trigger,
422 .pointer = snd_card_dummy_pcm_pointer,
425 static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
431 if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device,
432 substreams, substreams, &pcm)) < 0)
435 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops);
436 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops);
437 pcm->private_data = dummy;
439 strcpy(pcm->name, "Dummy PCM");
440 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
441 snd_dma_continuous_data(GFP_KERNEL),
446 #define DUMMY_VOLUME(xname, xindex, addr) \
447 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
448 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
449 .name = xname, .index = xindex, \
450 .info = snd_dummy_volume_info, \
451 .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \
452 .private_value = addr, \
453 .tlv = { .p = db_scale_dummy } }
455 static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_info *uinfo)
458 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
460 uinfo->value.integer.min = -50;
461 uinfo->value.integer.max = 100;
465 static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol,
466 struct snd_ctl_elem_value *ucontrol)
468 struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
469 int addr = kcontrol->private_value;
471 spin_lock_irq(&dummy->mixer_lock);
472 ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0];
473 ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1];
474 spin_unlock_irq(&dummy->mixer_lock);
478 static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol,
479 struct snd_ctl_elem_value *ucontrol)
481 struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
482 int change, addr = kcontrol->private_value;
485 left = ucontrol->value.integer.value[0];
490 right = ucontrol->value.integer.value[1];
495 spin_lock_irq(&dummy->mixer_lock);
496 change = dummy->mixer_volume[addr][0] != left ||
497 dummy->mixer_volume[addr][1] != right;
498 dummy->mixer_volume[addr][0] = left;
499 dummy->mixer_volume[addr][1] = right;
500 spin_unlock_irq(&dummy->mixer_lock);
504 static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0);
506 #define DUMMY_CAPSRC(xname, xindex, addr) \
507 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
508 .info = snd_dummy_capsrc_info, \
509 .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \
510 .private_value = addr }
512 #define snd_dummy_capsrc_info snd_ctl_boolean_stereo_info
514 static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol,
515 struct snd_ctl_elem_value *ucontrol)
517 struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
518 int addr = kcontrol->private_value;
520 spin_lock_irq(&dummy->mixer_lock);
521 ucontrol->value.integer.value[0] = dummy->capture_source[addr][0];
522 ucontrol->value.integer.value[1] = dummy->capture_source[addr][1];
523 spin_unlock_irq(&dummy->mixer_lock);
527 static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
529 struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
530 int change, addr = kcontrol->private_value;
533 left = ucontrol->value.integer.value[0] & 1;
534 right = ucontrol->value.integer.value[1] & 1;
535 spin_lock_irq(&dummy->mixer_lock);
536 change = dummy->capture_source[addr][0] != left &&
537 dummy->capture_source[addr][1] != right;
538 dummy->capture_source[addr][0] = left;
539 dummy->capture_source[addr][1] = right;
540 spin_unlock_irq(&dummy->mixer_lock);
544 static struct snd_kcontrol_new snd_dummy_controls[] = {
545 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
546 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
547 DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
548 DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH),
549 DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE),
550 DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),
551 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
552 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
553 DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
554 DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
557 static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
559 struct snd_card *card = dummy->card;
563 snd_assert(dummy != NULL, return -EINVAL);
564 spin_lock_init(&dummy->mixer_lock);
565 strcpy(card->mixername, "Dummy Mixer");
567 for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
568 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0)
574 static int __devinit snd_dummy_probe(struct platform_device *devptr)
576 struct snd_card *card;
577 struct snd_dummy *dummy;
579 int dev = devptr->id;
581 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
582 sizeof(struct snd_dummy));
585 dummy = card->private_data;
587 for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
588 if (pcm_substreams[dev] < 1)
589 pcm_substreams[dev] = 1;
590 if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS)
591 pcm_substreams[dev] = MAX_PCM_SUBSTREAMS;
592 if ((err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev])) < 0)
595 if ((err = snd_card_dummy_new_mixer(dummy)) < 0)
597 strcpy(card->driver, "Dummy");
598 strcpy(card->shortname, "Dummy");
599 sprintf(card->longname, "Dummy %i", dev + 1);
601 snd_card_set_dev(card, &devptr->dev);
603 if ((err = snd_card_register(card)) == 0) {
604 platform_set_drvdata(devptr, card);
612 static int __devexit snd_dummy_remove(struct platform_device *devptr)
614 snd_card_free(platform_get_drvdata(devptr));
615 platform_set_drvdata(devptr, NULL);
620 static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state)
622 struct snd_card *card = platform_get_drvdata(pdev);
623 struct snd_dummy *dummy = card->private_data;
625 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
626 snd_pcm_suspend_all(dummy->pcm);
630 static int snd_dummy_resume(struct platform_device *pdev)
632 struct snd_card *card = platform_get_drvdata(pdev);
634 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
639 #define SND_DUMMY_DRIVER "snd_dummy"
641 static struct platform_driver snd_dummy_driver = {
642 .probe = snd_dummy_probe,
643 .remove = __devexit_p(snd_dummy_remove),
645 .suspend = snd_dummy_suspend,
646 .resume = snd_dummy_resume,
649 .name = SND_DUMMY_DRIVER
653 static void snd_dummy_unregister_all(void)
657 for (i = 0; i < ARRAY_SIZE(devices); ++i)
658 platform_device_unregister(devices[i]);
659 platform_driver_unregister(&snd_dummy_driver);
662 static int __init alsa_card_dummy_init(void)
666 if ((err = platform_driver_register(&snd_dummy_driver)) < 0)
670 for (i = 0; i < SNDRV_CARDS; i++) {
671 struct platform_device *device;
674 device = platform_device_register_simple(SND_DUMMY_DRIVER,
678 if (!platform_get_drvdata(device)) {
679 platform_device_unregister(device);
687 printk(KERN_ERR "Dummy soundcard not found or device busy\n");
689 snd_dummy_unregister_all();
695 static void __exit alsa_card_dummy_exit(void)
697 snd_dummy_unregister_all();
700 module_init(alsa_card_dummy_init)
701 module_exit(alsa_card_dummy_exit)