11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Dummy soundcard 31da177e4SLinus Torvalds * Copyright (c) by Jaroslav Kysela <perex@suse.cz> 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 61da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 71da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 81da177e4SLinus Torvalds * (at your option) any later version. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 111da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 121da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131da177e4SLinus Torvalds * GNU General Public License for more details. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 161da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 171da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #include <sound/driver.h> 221da177e4SLinus Torvalds #include <linux/init.h> 236e65c1ccSTakashi Iwai #include <linux/err.h> 246e65c1ccSTakashi Iwai #include <linux/platform_device.h> 251da177e4SLinus Torvalds #include <linux/jiffies.h> 261da177e4SLinus Torvalds #include <linux/slab.h> 271da177e4SLinus Torvalds #include <linux/time.h> 281da177e4SLinus Torvalds #include <linux/wait.h> 291da177e4SLinus Torvalds #include <linux/moduleparam.h> 301da177e4SLinus Torvalds #include <sound/core.h> 311da177e4SLinus Torvalds #include <sound/control.h> 321da177e4SLinus Torvalds #include <sound/pcm.h> 331da177e4SLinus Torvalds #include <sound/rawmidi.h> 341da177e4SLinus Torvalds #include <sound/initval.h> 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); 371da177e4SLinus Torvalds MODULE_DESCRIPTION("Dummy soundcard (/dev/null)"); 381da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 391da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}"); 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #define MAX_PCM_DEVICES 4 421da177e4SLinus Torvalds #define MAX_PCM_SUBSTREAMS 16 431da177e4SLinus Torvalds #define MAX_MIDI_DEVICES 2 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #if 0 /* emu10k1 emulation */ 461da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (128 * 1024) 474a4d2cfdSTakashi Iwai static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime) 481da177e4SLinus Torvalds { 491da177e4SLinus Torvalds int err; 501da177e4SLinus Torvalds if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 511da177e4SLinus Torvalds return err; 521da177e4SLinus Torvalds if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) 531da177e4SLinus Torvalds return err; 541da177e4SLinus Torvalds return 0; 551da177e4SLinus Torvalds } 561da177e4SLinus Torvalds #define add_playback_constraints emu10k1_playback_constraints 571da177e4SLinus Torvalds #endif 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds #if 0 /* RME9652 emulation */ 601da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (26 * 64 * 1024) 611da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE 621da177e4SLinus Torvalds #define USE_CHANNELS_MIN 26 631da177e4SLinus Torvalds #define USE_CHANNELS_MAX 26 641da177e4SLinus Torvalds #define USE_PERIODS_MIN 2 651da177e4SLinus Torvalds #define USE_PERIODS_MAX 2 661da177e4SLinus Torvalds #endif 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds #if 0 /* ICE1712 emulation */ 691da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (256 * 1024) 701da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE 711da177e4SLinus Torvalds #define USE_CHANNELS_MIN 10 721da177e4SLinus Torvalds #define USE_CHANNELS_MAX 10 731da177e4SLinus Torvalds #define USE_PERIODS_MIN 1 741da177e4SLinus Torvalds #define USE_PERIODS_MAX 1024 751da177e4SLinus Torvalds #endif 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds #if 0 /* UDA1341 emulation */ 781da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (16380) 791da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE 801da177e4SLinus Torvalds #define USE_CHANNELS_MIN 2 811da177e4SLinus Torvalds #define USE_CHANNELS_MAX 2 821da177e4SLinus Torvalds #define USE_PERIODS_MIN 2 831da177e4SLinus Torvalds #define USE_PERIODS_MAX 255 841da177e4SLinus Torvalds #endif 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */ 871da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE 881da177e4SLinus Torvalds #define USE_CHANNELS_MIN 2 891da177e4SLinus Torvalds #define USE_CHANNELS_MAX 2 901da177e4SLinus Torvalds #define USE_RATE SNDRV_PCM_RATE_48000 911da177e4SLinus Torvalds #define USE_RATE_MIN 48000 921da177e4SLinus Torvalds #define USE_RATE_MAX 48000 931da177e4SLinus Torvalds #endif 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds /* defaults */ 971da177e4SLinus Torvalds #ifndef MAX_BUFFER_SIZE 981da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (64*1024) 991da177e4SLinus Torvalds #endif 1001da177e4SLinus Torvalds #ifndef USE_FORMATS 1011da177e4SLinus Torvalds #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE) 1021da177e4SLinus Torvalds #endif 1031da177e4SLinus Torvalds #ifndef USE_RATE 1041da177e4SLinus Torvalds #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 1051da177e4SLinus Torvalds #define USE_RATE_MIN 5500 1061da177e4SLinus Torvalds #define USE_RATE_MAX 48000 1071da177e4SLinus Torvalds #endif 1081da177e4SLinus Torvalds #ifndef USE_CHANNELS_MIN 1091da177e4SLinus Torvalds #define USE_CHANNELS_MIN 1 1101da177e4SLinus Torvalds #endif 1111da177e4SLinus Torvalds #ifndef USE_CHANNELS_MAX 1121da177e4SLinus Torvalds #define USE_CHANNELS_MAX 2 1131da177e4SLinus Torvalds #endif 1141da177e4SLinus Torvalds #ifndef USE_PERIODS_MIN 1151da177e4SLinus Torvalds #define USE_PERIODS_MIN 1 1161da177e4SLinus Torvalds #endif 1171da177e4SLinus Torvalds #ifndef USE_PERIODS_MAX 1181da177e4SLinus Torvalds #define USE_PERIODS_MAX 1024 1191da177e4SLinus Torvalds #endif 1201da177e4SLinus Torvalds #ifndef add_playback_constraints 1211da177e4SLinus Torvalds #define add_playback_constraints(x) 0 1221da177e4SLinus Torvalds #endif 1231da177e4SLinus Torvalds #ifndef add_capture_constraints 1241da177e4SLinus Torvalds #define add_capture_constraints(x) 0 1251da177e4SLinus Torvalds #endif 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 1281da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 1291da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; 1301da177e4SLinus Torvalds static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 1311da177e4SLinus Torvalds static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; 1321da177e4SLinus Torvalds //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444); 1351da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for dummy soundcard."); 1361da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444); 1371da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for dummy soundcard."); 1381da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444); 1391da177e4SLinus Torvalds MODULE_PARM_DESC(enable, "Enable this dummy soundcard."); 1401da177e4SLinus Torvalds module_param_array(pcm_devs, int, NULL, 0444); 1411da177e4SLinus Torvalds MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver."); 1421da177e4SLinus Torvalds module_param_array(pcm_substreams, int, NULL, 0444); 1431da177e4SLinus Torvalds MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver."); 1441da177e4SLinus Torvalds //module_param_array(midi_devs, int, NULL, 0444); 1451da177e4SLinus Torvalds //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds #define MIXER_ADDR_MASTER 0 1481da177e4SLinus Torvalds #define MIXER_ADDR_LINE 1 1491da177e4SLinus Torvalds #define MIXER_ADDR_MIC 2 1501da177e4SLinus Torvalds #define MIXER_ADDR_SYNTH 3 1511da177e4SLinus Torvalds #define MIXER_ADDR_CD 4 1521da177e4SLinus Torvalds #define MIXER_ADDR_LAST 4 1531da177e4SLinus Torvalds 1544a4d2cfdSTakashi Iwai struct snd_dummy { 1554a4d2cfdSTakashi Iwai struct snd_card *card; 1566e65c1ccSTakashi Iwai struct snd_pcm *pcm; 1571da177e4SLinus Torvalds spinlock_t mixer_lock; 1581da177e4SLinus Torvalds int mixer_volume[MIXER_ADDR_LAST+1][2]; 1591da177e4SLinus Torvalds int capture_source[MIXER_ADDR_LAST+1][2]; 1604a4d2cfdSTakashi Iwai }; 1611da177e4SLinus Torvalds 1624a4d2cfdSTakashi Iwai struct snd_dummy_pcm { 1634a4d2cfdSTakashi Iwai struct snd_dummy *dummy; 1641da177e4SLinus Torvalds spinlock_t lock; 1651da177e4SLinus Torvalds struct timer_list timer; 1661da177e4SLinus Torvalds unsigned int pcm_size; 1671da177e4SLinus Torvalds unsigned int pcm_count; 1681da177e4SLinus Torvalds unsigned int pcm_bps; /* bytes per second */ 1691da177e4SLinus Torvalds unsigned int pcm_jiffie; /* bytes per one jiffie */ 1701da177e4SLinus Torvalds unsigned int pcm_irq_pos; /* IRQ position */ 1711da177e4SLinus Torvalds unsigned int pcm_buf_pos; /* position in buffer */ 1724a4d2cfdSTakashi Iwai struct snd_pcm_substream *substream; 1734a4d2cfdSTakashi Iwai }; 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds 1764a4d2cfdSTakashi Iwai static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) 1771da177e4SLinus Torvalds { 1781da177e4SLinus Torvalds dpcm->timer.expires = 1 + jiffies; 1791da177e4SLinus Torvalds add_timer(&dpcm->timer); 1801da177e4SLinus Torvalds } 1811da177e4SLinus Torvalds 1824a4d2cfdSTakashi Iwai static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) 1831da177e4SLinus Torvalds { 1841da177e4SLinus Torvalds del_timer(&dpcm->timer); 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1874a4d2cfdSTakashi Iwai static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1881da177e4SLinus Torvalds { 1894a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 1904a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 191c8eb6ba1STakashi Iwai int err = 0; 1921da177e4SLinus Torvalds 193c8eb6ba1STakashi Iwai spin_lock(&dpcm->lock); 1946e65c1ccSTakashi Iwai switch (cmd) { 1956e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_START: 1966e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_RESUME: 197c8eb6ba1STakashi Iwai snd_card_dummy_pcm_timer_start(dpcm); 1986e65c1ccSTakashi Iwai break; 1996e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_STOP: 2006e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_SUSPEND: 201c8eb6ba1STakashi Iwai snd_card_dummy_pcm_timer_stop(dpcm); 2026e65c1ccSTakashi Iwai break; 2036e65c1ccSTakashi Iwai default: 204c8eb6ba1STakashi Iwai err = -EINVAL; 2056e65c1ccSTakashi Iwai break; 2061da177e4SLinus Torvalds } 207c8eb6ba1STakashi Iwai spin_unlock(&dpcm->lock); 2086e65c1ccSTakashi Iwai return 0; 2091da177e4SLinus Torvalds } 2101da177e4SLinus Torvalds 2114a4d2cfdSTakashi Iwai static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) 2121da177e4SLinus Torvalds { 2134a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2144a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 2151da177e4SLinus Torvalds unsigned int bps; 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds bps = runtime->rate * runtime->channels; 2181da177e4SLinus Torvalds bps *= snd_pcm_format_width(runtime->format); 2191da177e4SLinus Torvalds bps /= 8; 2201da177e4SLinus Torvalds if (bps <= 0) 2211da177e4SLinus Torvalds return -EINVAL; 2221da177e4SLinus Torvalds dpcm->pcm_bps = bps; 2231da177e4SLinus Torvalds dpcm->pcm_jiffie = bps / HZ; 2241da177e4SLinus Torvalds dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 2251da177e4SLinus Torvalds dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 2261da177e4SLinus Torvalds dpcm->pcm_irq_pos = 0; 2271da177e4SLinus Torvalds dpcm->pcm_buf_pos = 0; 2281da177e4SLinus Torvalds return 0; 2291da177e4SLinus Torvalds } 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds static void snd_card_dummy_pcm_timer_function(unsigned long data) 2321da177e4SLinus Torvalds { 2334a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; 234*b32425acSTakashi Iwai unsigned long flags; 2351da177e4SLinus Torvalds 236*b32425acSTakashi Iwai spin_lock_irqsave(&dpcm->lock, flags); 2371da177e4SLinus Torvalds dpcm->timer.expires = 1 + jiffies; 2381da177e4SLinus Torvalds add_timer(&dpcm->timer); 2391da177e4SLinus Torvalds dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 2401da177e4SLinus Torvalds dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 2411da177e4SLinus Torvalds dpcm->pcm_buf_pos %= dpcm->pcm_size; 2421da177e4SLinus Torvalds if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 2431da177e4SLinus Torvalds dpcm->pcm_irq_pos %= dpcm->pcm_count; 244*b32425acSTakashi Iwai spin_unlock_irqrestore(&dpcm->lock, flags); 2451da177e4SLinus Torvalds snd_pcm_period_elapsed(dpcm->substream); 246*b32425acSTakashi Iwai } else 247*b32425acSTakashi Iwai spin_unlock_irqrestore(&dpcm->lock, flags); 2481da177e4SLinus Torvalds } 2491da177e4SLinus Torvalds 2504a4d2cfdSTakashi Iwai static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) 2511da177e4SLinus Torvalds { 2524a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2534a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds return bytes_to_frames(runtime, dpcm->pcm_buf_pos); 2561da177e4SLinus Torvalds } 2571da177e4SLinus Torvalds 2584a4d2cfdSTakashi Iwai static struct snd_pcm_hardware snd_card_dummy_playback = 2591da177e4SLinus Torvalds { 2601da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 2616e65c1ccSTakashi Iwai SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 2621da177e4SLinus Torvalds .formats = USE_FORMATS, 2631da177e4SLinus Torvalds .rates = USE_RATE, 2641da177e4SLinus Torvalds .rate_min = USE_RATE_MIN, 2651da177e4SLinus Torvalds .rate_max = USE_RATE_MAX, 2661da177e4SLinus Torvalds .channels_min = USE_CHANNELS_MIN, 2671da177e4SLinus Torvalds .channels_max = USE_CHANNELS_MAX, 2681da177e4SLinus Torvalds .buffer_bytes_max = MAX_BUFFER_SIZE, 2691da177e4SLinus Torvalds .period_bytes_min = 64, 2701da177e4SLinus Torvalds .period_bytes_max = MAX_BUFFER_SIZE, 2711da177e4SLinus Torvalds .periods_min = USE_PERIODS_MIN, 2721da177e4SLinus Torvalds .periods_max = USE_PERIODS_MAX, 2731da177e4SLinus Torvalds .fifo_size = 0, 2741da177e4SLinus Torvalds }; 2751da177e4SLinus Torvalds 2764a4d2cfdSTakashi Iwai static struct snd_pcm_hardware snd_card_dummy_capture = 2771da177e4SLinus Torvalds { 2781da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 2796e65c1ccSTakashi Iwai SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 2801da177e4SLinus Torvalds .formats = USE_FORMATS, 2811da177e4SLinus Torvalds .rates = USE_RATE, 2821da177e4SLinus Torvalds .rate_min = USE_RATE_MIN, 2831da177e4SLinus Torvalds .rate_max = USE_RATE_MAX, 2841da177e4SLinus Torvalds .channels_min = USE_CHANNELS_MIN, 2851da177e4SLinus Torvalds .channels_max = USE_CHANNELS_MAX, 2861da177e4SLinus Torvalds .buffer_bytes_max = MAX_BUFFER_SIZE, 2871da177e4SLinus Torvalds .period_bytes_min = 64, 2881da177e4SLinus Torvalds .period_bytes_max = MAX_BUFFER_SIZE, 2891da177e4SLinus Torvalds .periods_min = USE_PERIODS_MIN, 2901da177e4SLinus Torvalds .periods_max = USE_PERIODS_MAX, 2911da177e4SLinus Torvalds .fifo_size = 0, 2921da177e4SLinus Torvalds }; 2931da177e4SLinus Torvalds 2944a4d2cfdSTakashi Iwai static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime) 2951da177e4SLinus Torvalds { 296c8eb6ba1STakashi Iwai kfree(runtime->private_data); 2971da177e4SLinus Torvalds } 2981da177e4SLinus Torvalds 2994a4d2cfdSTakashi Iwai static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream, 3004a4d2cfdSTakashi Iwai struct snd_pcm_hw_params *hw_params) 3011da177e4SLinus Torvalds { 3021da177e4SLinus Torvalds return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 3031da177e4SLinus Torvalds } 3041da177e4SLinus Torvalds 3054a4d2cfdSTakashi Iwai static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream) 3061da177e4SLinus Torvalds { 3071da177e4SLinus Torvalds return snd_pcm_lib_free_pages(substream); 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3104a4d2cfdSTakashi Iwai static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) 311c8eb6ba1STakashi Iwai { 3124a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 313c8eb6ba1STakashi Iwai 314c8eb6ba1STakashi Iwai dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); 315c8eb6ba1STakashi Iwai if (! dpcm) 316c8eb6ba1STakashi Iwai return dpcm; 317c8eb6ba1STakashi Iwai init_timer(&dpcm->timer); 318c8eb6ba1STakashi Iwai dpcm->timer.data = (unsigned long) dpcm; 319c8eb6ba1STakashi Iwai dpcm->timer.function = snd_card_dummy_pcm_timer_function; 320c8eb6ba1STakashi Iwai spin_lock_init(&dpcm->lock); 321c8eb6ba1STakashi Iwai dpcm->substream = substream; 322c8eb6ba1STakashi Iwai return dpcm; 323c8eb6ba1STakashi Iwai } 324c8eb6ba1STakashi Iwai 3254a4d2cfdSTakashi Iwai static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream) 3261da177e4SLinus Torvalds { 3274a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 3284a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 3291da177e4SLinus Torvalds int err; 3301da177e4SLinus Torvalds 331c8eb6ba1STakashi Iwai if ((dpcm = new_pcm_stream(substream)) == NULL) 3321da177e4SLinus Torvalds return -ENOMEM; 3331da177e4SLinus Torvalds runtime->private_data = dpcm; 3341da177e4SLinus Torvalds runtime->private_free = snd_card_dummy_runtime_free; 3351da177e4SLinus Torvalds runtime->hw = snd_card_dummy_playback; 3361da177e4SLinus Torvalds if (substream->pcm->device & 1) { 3371da177e4SLinus Torvalds runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 3381da177e4SLinus Torvalds runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 3391da177e4SLinus Torvalds } 3401da177e4SLinus Torvalds if (substream->pcm->device & 2) 3411da177e4SLinus Torvalds runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 3421da177e4SLinus Torvalds if ((err = add_playback_constraints(runtime)) < 0) { 3431da177e4SLinus Torvalds kfree(dpcm); 3441da177e4SLinus Torvalds return err; 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds return 0; 3481da177e4SLinus Torvalds } 3491da177e4SLinus Torvalds 3504a4d2cfdSTakashi Iwai static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream) 3511da177e4SLinus Torvalds { 3524a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 3534a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 3541da177e4SLinus Torvalds int err; 3551da177e4SLinus Torvalds 356c8eb6ba1STakashi Iwai if ((dpcm = new_pcm_stream(substream)) == NULL) 3571da177e4SLinus Torvalds return -ENOMEM; 3581da177e4SLinus Torvalds runtime->private_data = dpcm; 3591da177e4SLinus Torvalds runtime->private_free = snd_card_dummy_runtime_free; 3601da177e4SLinus Torvalds runtime->hw = snd_card_dummy_capture; 3611da177e4SLinus Torvalds if (substream->pcm->device == 1) { 3621da177e4SLinus Torvalds runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 3631da177e4SLinus Torvalds runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds if (substream->pcm->device & 2) 3661da177e4SLinus Torvalds runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 3671da177e4SLinus Torvalds if ((err = add_capture_constraints(runtime)) < 0) { 3681da177e4SLinus Torvalds kfree(dpcm); 3691da177e4SLinus Torvalds return err; 3701da177e4SLinus Torvalds } 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds return 0; 3731da177e4SLinus Torvalds } 3741da177e4SLinus Torvalds 3754a4d2cfdSTakashi Iwai static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream) 3761da177e4SLinus Torvalds { 3771da177e4SLinus Torvalds return 0; 3781da177e4SLinus Torvalds } 3791da177e4SLinus Torvalds 3804a4d2cfdSTakashi Iwai static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream) 3811da177e4SLinus Torvalds { 3821da177e4SLinus Torvalds return 0; 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds 3854a4d2cfdSTakashi Iwai static struct snd_pcm_ops snd_card_dummy_playback_ops = { 3861da177e4SLinus Torvalds .open = snd_card_dummy_playback_open, 3871da177e4SLinus Torvalds .close = snd_card_dummy_playback_close, 3881da177e4SLinus Torvalds .ioctl = snd_pcm_lib_ioctl, 3891da177e4SLinus Torvalds .hw_params = snd_card_dummy_hw_params, 3901da177e4SLinus Torvalds .hw_free = snd_card_dummy_hw_free, 391c8eb6ba1STakashi Iwai .prepare = snd_card_dummy_pcm_prepare, 392c8eb6ba1STakashi Iwai .trigger = snd_card_dummy_pcm_trigger, 393c8eb6ba1STakashi Iwai .pointer = snd_card_dummy_pcm_pointer, 3941da177e4SLinus Torvalds }; 3951da177e4SLinus Torvalds 3964a4d2cfdSTakashi Iwai static struct snd_pcm_ops snd_card_dummy_capture_ops = { 3971da177e4SLinus Torvalds .open = snd_card_dummy_capture_open, 3981da177e4SLinus Torvalds .close = snd_card_dummy_capture_close, 3991da177e4SLinus Torvalds .ioctl = snd_pcm_lib_ioctl, 4001da177e4SLinus Torvalds .hw_params = snd_card_dummy_hw_params, 4011da177e4SLinus Torvalds .hw_free = snd_card_dummy_hw_free, 402c8eb6ba1STakashi Iwai .prepare = snd_card_dummy_pcm_prepare, 403c8eb6ba1STakashi Iwai .trigger = snd_card_dummy_pcm_trigger, 404c8eb6ba1STakashi Iwai .pointer = snd_card_dummy_pcm_pointer, 4051da177e4SLinus Torvalds }; 4061da177e4SLinus Torvalds 4074a4d2cfdSTakashi Iwai static int __init snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams) 4081da177e4SLinus Torvalds { 4094a4d2cfdSTakashi Iwai struct snd_pcm *pcm; 4101da177e4SLinus Torvalds int err; 4111da177e4SLinus Torvalds 4124a4d2cfdSTakashi Iwai if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device, 4134a4d2cfdSTakashi Iwai substreams, substreams, &pcm)) < 0) 4141da177e4SLinus Torvalds return err; 4156e65c1ccSTakashi Iwai dummy->pcm = pcm; 4161da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops); 4171da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops); 4181da177e4SLinus Torvalds pcm->private_data = dummy; 4191da177e4SLinus Torvalds pcm->info_flags = 0; 4201da177e4SLinus Torvalds strcpy(pcm->name, "Dummy PCM"); 4211da177e4SLinus Torvalds snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, 4221da177e4SLinus Torvalds snd_dma_continuous_data(GFP_KERNEL), 4231da177e4SLinus Torvalds 0, 64*1024); 4241da177e4SLinus Torvalds return 0; 4251da177e4SLinus Torvalds } 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds #define DUMMY_VOLUME(xname, xindex, addr) \ 4281da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 4291da177e4SLinus Torvalds .info = snd_dummy_volume_info, \ 4301da177e4SLinus Torvalds .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ 4311da177e4SLinus Torvalds .private_value = addr } 4321da177e4SLinus Torvalds 4334a4d2cfdSTakashi Iwai static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, 4344a4d2cfdSTakashi Iwai struct snd_ctl_elem_info *uinfo) 4351da177e4SLinus Torvalds { 4361da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 4371da177e4SLinus Torvalds uinfo->count = 2; 4381da177e4SLinus Torvalds uinfo->value.integer.min = -50; 4391da177e4SLinus Torvalds uinfo->value.integer.max = 100; 4401da177e4SLinus Torvalds return 0; 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds 4434a4d2cfdSTakashi Iwai static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, 4444a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 4451da177e4SLinus Torvalds { 4464a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 4471da177e4SLinus Torvalds int addr = kcontrol->private_value; 4481da177e4SLinus Torvalds 449c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 4501da177e4SLinus Torvalds ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; 4511da177e4SLinus Torvalds ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; 452c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 4531da177e4SLinus Torvalds return 0; 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds 4564a4d2cfdSTakashi Iwai static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, 4574a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 4581da177e4SLinus Torvalds { 4594a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 4601da177e4SLinus Torvalds int change, addr = kcontrol->private_value; 4611da177e4SLinus Torvalds int left, right; 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds left = ucontrol->value.integer.value[0]; 4641da177e4SLinus Torvalds if (left < -50) 4651da177e4SLinus Torvalds left = -50; 4661da177e4SLinus Torvalds if (left > 100) 4671da177e4SLinus Torvalds left = 100; 4681da177e4SLinus Torvalds right = ucontrol->value.integer.value[1]; 4691da177e4SLinus Torvalds if (right < -50) 4701da177e4SLinus Torvalds right = -50; 4711da177e4SLinus Torvalds if (right > 100) 4721da177e4SLinus Torvalds right = 100; 473c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 4741da177e4SLinus Torvalds change = dummy->mixer_volume[addr][0] != left || 4751da177e4SLinus Torvalds dummy->mixer_volume[addr][1] != right; 4761da177e4SLinus Torvalds dummy->mixer_volume[addr][0] = left; 4771da177e4SLinus Torvalds dummy->mixer_volume[addr][1] = right; 478c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 4791da177e4SLinus Torvalds return change; 4801da177e4SLinus Torvalds } 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds #define DUMMY_CAPSRC(xname, xindex, addr) \ 4831da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 4841da177e4SLinus Torvalds .info = snd_dummy_capsrc_info, \ 4851da177e4SLinus Torvalds .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ 4861da177e4SLinus Torvalds .private_value = addr } 4871da177e4SLinus Torvalds 4884a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_info(struct snd_kcontrol *kcontrol, 4894a4d2cfdSTakashi Iwai struct snd_ctl_elem_info *uinfo) 4901da177e4SLinus Torvalds { 4911da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 4921da177e4SLinus Torvalds uinfo->count = 2; 4931da177e4SLinus Torvalds uinfo->value.integer.min = 0; 4941da177e4SLinus Torvalds uinfo->value.integer.max = 1; 4951da177e4SLinus Torvalds return 0; 4961da177e4SLinus Torvalds } 4971da177e4SLinus Torvalds 4984a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, 4994a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 5001da177e4SLinus Torvalds { 5014a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 5021da177e4SLinus Torvalds int addr = kcontrol->private_value; 5031da177e4SLinus Torvalds 504c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 5051da177e4SLinus Torvalds ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; 5061da177e4SLinus Torvalds ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; 507c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5081da177e4SLinus Torvalds return 0; 5091da177e4SLinus Torvalds } 5101da177e4SLinus Torvalds 5114a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 5121da177e4SLinus Torvalds { 5134a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 5141da177e4SLinus Torvalds int change, addr = kcontrol->private_value; 5151da177e4SLinus Torvalds int left, right; 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds left = ucontrol->value.integer.value[0] & 1; 5181da177e4SLinus Torvalds right = ucontrol->value.integer.value[1] & 1; 519c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 5201da177e4SLinus Torvalds change = dummy->capture_source[addr][0] != left && 5211da177e4SLinus Torvalds dummy->capture_source[addr][1] != right; 5221da177e4SLinus Torvalds dummy->capture_source[addr][0] = left; 5231da177e4SLinus Torvalds dummy->capture_source[addr][1] = right; 524c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5251da177e4SLinus Torvalds return change; 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds 5284a4d2cfdSTakashi Iwai static struct snd_kcontrol_new snd_dummy_controls[] = { 5291da177e4SLinus Torvalds DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), 5301da177e4SLinus Torvalds DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), 5311da177e4SLinus Torvalds DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), 5321da177e4SLinus Torvalds DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_MASTER), 5331da177e4SLinus Torvalds DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), 5341da177e4SLinus Torvalds DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_MASTER), 5351da177e4SLinus Torvalds DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), 5361da177e4SLinus Torvalds DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MASTER), 5371da177e4SLinus Torvalds DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), 5381da177e4SLinus Torvalds DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER) 5391da177e4SLinus Torvalds }; 5401da177e4SLinus Torvalds 5414a4d2cfdSTakashi Iwai static int __init snd_card_dummy_new_mixer(struct snd_dummy *dummy) 5421da177e4SLinus Torvalds { 5434a4d2cfdSTakashi Iwai struct snd_card *card = dummy->card; 5441da177e4SLinus Torvalds unsigned int idx; 5451da177e4SLinus Torvalds int err; 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds snd_assert(dummy != NULL, return -EINVAL); 5481da177e4SLinus Torvalds spin_lock_init(&dummy->mixer_lock); 5491da177e4SLinus Torvalds strcpy(card->mixername, "Dummy Mixer"); 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { 5521da177e4SLinus Torvalds if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0) 5531da177e4SLinus Torvalds return err; 5541da177e4SLinus Torvalds } 5551da177e4SLinus Torvalds return 0; 5561da177e4SLinus Torvalds } 5571da177e4SLinus Torvalds 5586e65c1ccSTakashi Iwai static int __init snd_dummy_probe(struct platform_device *devptr) 5591da177e4SLinus Torvalds { 5604a4d2cfdSTakashi Iwai struct snd_card *card; 5614a4d2cfdSTakashi Iwai struct snd_dummy *dummy; 5621da177e4SLinus Torvalds int idx, err; 5636e65c1ccSTakashi Iwai int dev = devptr->id; 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds card = snd_card_new(index[dev], id[dev], THIS_MODULE, 5664a4d2cfdSTakashi Iwai sizeof(struct snd_dummy)); 5671da177e4SLinus Torvalds if (card == NULL) 5681da177e4SLinus Torvalds return -ENOMEM; 5694a4d2cfdSTakashi Iwai dummy = card->private_data; 5701da177e4SLinus Torvalds dummy->card = card; 5711da177e4SLinus Torvalds for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { 5721da177e4SLinus Torvalds if (pcm_substreams[dev] < 1) 5731da177e4SLinus Torvalds pcm_substreams[dev] = 1; 5741da177e4SLinus Torvalds if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) 5751da177e4SLinus Torvalds pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; 5761da177e4SLinus Torvalds if ((err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev])) < 0) 5771da177e4SLinus Torvalds goto __nodev; 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds if ((err = snd_card_dummy_new_mixer(dummy)) < 0) 5801da177e4SLinus Torvalds goto __nodev; 5811da177e4SLinus Torvalds strcpy(card->driver, "Dummy"); 5821da177e4SLinus Torvalds strcpy(card->shortname, "Dummy"); 5831da177e4SLinus Torvalds sprintf(card->longname, "Dummy %i", dev + 1); 58416dab54bSTakashi Iwai 5856e65c1ccSTakashi Iwai snd_card_set_dev(card, &devptr->dev); 58616dab54bSTakashi Iwai 5871da177e4SLinus Torvalds if ((err = snd_card_register(card)) == 0) { 5886e65c1ccSTakashi Iwai platform_set_drvdata(devptr, card); 5891da177e4SLinus Torvalds return 0; 5901da177e4SLinus Torvalds } 5911da177e4SLinus Torvalds __nodev: 5921da177e4SLinus Torvalds snd_card_free(card); 5931da177e4SLinus Torvalds return err; 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds 5966e65c1ccSTakashi Iwai static int snd_dummy_remove(struct platform_device *devptr) 5976e65c1ccSTakashi Iwai { 5986e65c1ccSTakashi Iwai snd_card_free(platform_get_drvdata(devptr)); 5996e65c1ccSTakashi Iwai platform_set_drvdata(devptr, NULL); 6006e65c1ccSTakashi Iwai return 0; 6016e65c1ccSTakashi Iwai } 6026e65c1ccSTakashi Iwai 6036e65c1ccSTakashi Iwai #ifdef CONFIG_PM 6046e65c1ccSTakashi Iwai static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state) 6056e65c1ccSTakashi Iwai { 6066e65c1ccSTakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 6076e65c1ccSTakashi Iwai struct snd_dummy *dummy = card->private_data; 6086e65c1ccSTakashi Iwai 6096e65c1ccSTakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 6106e65c1ccSTakashi Iwai snd_pcm_suspend_all(dummy->pcm); 6116e65c1ccSTakashi Iwai return 0; 6126e65c1ccSTakashi Iwai } 6136e65c1ccSTakashi Iwai 6146e65c1ccSTakashi Iwai static int snd_dummy_resume(struct platform_device *pdev) 6156e65c1ccSTakashi Iwai { 6166e65c1ccSTakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 6176e65c1ccSTakashi Iwai 6186e65c1ccSTakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0); 6196e65c1ccSTakashi Iwai return 0; 6206e65c1ccSTakashi Iwai } 6216e65c1ccSTakashi Iwai #endif 6226e65c1ccSTakashi Iwai 6236e65c1ccSTakashi Iwai #define SND_DUMMY_DRIVER "snd_dummy" 6246e65c1ccSTakashi Iwai 6256e65c1ccSTakashi Iwai static struct platform_driver snd_dummy_driver = { 6266e65c1ccSTakashi Iwai .probe = snd_dummy_probe, 6276e65c1ccSTakashi Iwai .remove = snd_dummy_remove, 6286e65c1ccSTakashi Iwai #ifdef CONFIG_PM 6296e65c1ccSTakashi Iwai .suspend = snd_dummy_suspend, 6306e65c1ccSTakashi Iwai .resume = snd_dummy_resume, 6316e65c1ccSTakashi Iwai #endif 6326e65c1ccSTakashi Iwai .driver = { 6336e65c1ccSTakashi Iwai .name = SND_DUMMY_DRIVER 6346e65c1ccSTakashi Iwai }, 6356e65c1ccSTakashi Iwai }; 6366e65c1ccSTakashi Iwai 6371da177e4SLinus Torvalds static int __init alsa_card_dummy_init(void) 6381da177e4SLinus Torvalds { 6396e65c1ccSTakashi Iwai int i, cards, err; 6401da177e4SLinus Torvalds 6416e65c1ccSTakashi Iwai if ((err = platform_driver_register(&snd_dummy_driver)) < 0) 6426e65c1ccSTakashi Iwai return err; 6436e65c1ccSTakashi Iwai 6446e65c1ccSTakashi Iwai cards = 0; 6456e65c1ccSTakashi Iwai for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { 6466e65c1ccSTakashi Iwai struct platform_device *device; 6476e65c1ccSTakashi Iwai device = platform_device_register_simple(SND_DUMMY_DRIVER, 6486e65c1ccSTakashi Iwai i, NULL, 0); 6496e65c1ccSTakashi Iwai if (IS_ERR(device)) { 6506e65c1ccSTakashi Iwai err = PTR_ERR(device); 6516e65c1ccSTakashi Iwai goto errout; 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds cards++; 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds if (!cards) { 6561da177e4SLinus Torvalds #ifdef MODULE 6571da177e4SLinus Torvalds printk(KERN_ERR "Dummy soundcard not found or device busy\n"); 6581da177e4SLinus Torvalds #endif 6596e65c1ccSTakashi Iwai err = -ENODEV; 6606e65c1ccSTakashi Iwai goto errout; 6611da177e4SLinus Torvalds } 6621da177e4SLinus Torvalds return 0; 6636e65c1ccSTakashi Iwai 6646e65c1ccSTakashi Iwai errout: 6656e65c1ccSTakashi Iwai platform_driver_unregister(&snd_dummy_driver); 6666e65c1ccSTakashi Iwai return err; 6671da177e4SLinus Torvalds } 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds static void __exit alsa_card_dummy_exit(void) 6701da177e4SLinus Torvalds { 6716e65c1ccSTakashi Iwai platform_driver_unregister(&snd_dummy_driver); 6721da177e4SLinus Torvalds } 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds module_init(alsa_card_dummy_init) 6751da177e4SLinus Torvalds module_exit(alsa_card_dummy_exit) 676