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 147*f7a9275dSClemens Ladisch static struct platform_device *devices[SNDRV_CARDS]; 148*f7a9275dSClemens Ladisch 1491da177e4SLinus Torvalds #define MIXER_ADDR_MASTER 0 1501da177e4SLinus Torvalds #define MIXER_ADDR_LINE 1 1511da177e4SLinus Torvalds #define MIXER_ADDR_MIC 2 1521da177e4SLinus Torvalds #define MIXER_ADDR_SYNTH 3 1531da177e4SLinus Torvalds #define MIXER_ADDR_CD 4 1541da177e4SLinus Torvalds #define MIXER_ADDR_LAST 4 1551da177e4SLinus Torvalds 1564a4d2cfdSTakashi Iwai struct snd_dummy { 1574a4d2cfdSTakashi Iwai struct snd_card *card; 1586e65c1ccSTakashi Iwai struct snd_pcm *pcm; 1591da177e4SLinus Torvalds spinlock_t mixer_lock; 1601da177e4SLinus Torvalds int mixer_volume[MIXER_ADDR_LAST+1][2]; 1611da177e4SLinus Torvalds int capture_source[MIXER_ADDR_LAST+1][2]; 1624a4d2cfdSTakashi Iwai }; 1631da177e4SLinus Torvalds 1644a4d2cfdSTakashi Iwai struct snd_dummy_pcm { 1654a4d2cfdSTakashi Iwai struct snd_dummy *dummy; 1661da177e4SLinus Torvalds spinlock_t lock; 1671da177e4SLinus Torvalds struct timer_list timer; 1681da177e4SLinus Torvalds unsigned int pcm_size; 1691da177e4SLinus Torvalds unsigned int pcm_count; 1701da177e4SLinus Torvalds unsigned int pcm_bps; /* bytes per second */ 1711da177e4SLinus Torvalds unsigned int pcm_jiffie; /* bytes per one jiffie */ 1721da177e4SLinus Torvalds unsigned int pcm_irq_pos; /* IRQ position */ 1731da177e4SLinus Torvalds unsigned int pcm_buf_pos; /* position in buffer */ 1744a4d2cfdSTakashi Iwai struct snd_pcm_substream *substream; 1754a4d2cfdSTakashi Iwai }; 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds 1784a4d2cfdSTakashi Iwai static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) 1791da177e4SLinus Torvalds { 1801da177e4SLinus Torvalds dpcm->timer.expires = 1 + jiffies; 1811da177e4SLinus Torvalds add_timer(&dpcm->timer); 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 1844a4d2cfdSTakashi Iwai static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) 1851da177e4SLinus Torvalds { 1861da177e4SLinus Torvalds del_timer(&dpcm->timer); 1871da177e4SLinus Torvalds } 1881da177e4SLinus Torvalds 1894a4d2cfdSTakashi Iwai static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1901da177e4SLinus Torvalds { 1914a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 1924a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 193c8eb6ba1STakashi Iwai int err = 0; 1941da177e4SLinus Torvalds 195c8eb6ba1STakashi Iwai spin_lock(&dpcm->lock); 1966e65c1ccSTakashi Iwai switch (cmd) { 1976e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_START: 1986e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_RESUME: 199c8eb6ba1STakashi Iwai snd_card_dummy_pcm_timer_start(dpcm); 2006e65c1ccSTakashi Iwai break; 2016e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_STOP: 2026e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_SUSPEND: 203c8eb6ba1STakashi Iwai snd_card_dummy_pcm_timer_stop(dpcm); 2046e65c1ccSTakashi Iwai break; 2056e65c1ccSTakashi Iwai default: 206c8eb6ba1STakashi Iwai err = -EINVAL; 2076e65c1ccSTakashi Iwai break; 2081da177e4SLinus Torvalds } 209c8eb6ba1STakashi Iwai spin_unlock(&dpcm->lock); 2106e65c1ccSTakashi Iwai return 0; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2134a4d2cfdSTakashi Iwai static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) 2141da177e4SLinus Torvalds { 2154a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2164a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 2171da177e4SLinus Torvalds unsigned int bps; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds bps = runtime->rate * runtime->channels; 2201da177e4SLinus Torvalds bps *= snd_pcm_format_width(runtime->format); 2211da177e4SLinus Torvalds bps /= 8; 2221da177e4SLinus Torvalds if (bps <= 0) 2231da177e4SLinus Torvalds return -EINVAL; 2241da177e4SLinus Torvalds dpcm->pcm_bps = bps; 2251da177e4SLinus Torvalds dpcm->pcm_jiffie = bps / HZ; 2261da177e4SLinus Torvalds dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 2271da177e4SLinus Torvalds dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 2281da177e4SLinus Torvalds dpcm->pcm_irq_pos = 0; 2291da177e4SLinus Torvalds dpcm->pcm_buf_pos = 0; 2301da177e4SLinus Torvalds return 0; 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds static void snd_card_dummy_pcm_timer_function(unsigned long data) 2341da177e4SLinus Torvalds { 2354a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; 236b32425acSTakashi Iwai unsigned long flags; 2371da177e4SLinus Torvalds 238b32425acSTakashi Iwai spin_lock_irqsave(&dpcm->lock, flags); 2391da177e4SLinus Torvalds dpcm->timer.expires = 1 + jiffies; 2401da177e4SLinus Torvalds add_timer(&dpcm->timer); 2411da177e4SLinus Torvalds dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 2421da177e4SLinus Torvalds dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 2431da177e4SLinus Torvalds dpcm->pcm_buf_pos %= dpcm->pcm_size; 2441da177e4SLinus Torvalds if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 2451da177e4SLinus Torvalds dpcm->pcm_irq_pos %= dpcm->pcm_count; 246b32425acSTakashi Iwai spin_unlock_irqrestore(&dpcm->lock, flags); 2471da177e4SLinus Torvalds snd_pcm_period_elapsed(dpcm->substream); 248b32425acSTakashi Iwai } else 249b32425acSTakashi Iwai spin_unlock_irqrestore(&dpcm->lock, flags); 2501da177e4SLinus Torvalds } 2511da177e4SLinus Torvalds 2524a4d2cfdSTakashi Iwai static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) 2531da177e4SLinus Torvalds { 2544a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2554a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds return bytes_to_frames(runtime, dpcm->pcm_buf_pos); 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 2604a4d2cfdSTakashi Iwai static struct snd_pcm_hardware snd_card_dummy_playback = 2611da177e4SLinus Torvalds { 2621da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 2636e65c1ccSTakashi Iwai SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 2641da177e4SLinus Torvalds .formats = USE_FORMATS, 2651da177e4SLinus Torvalds .rates = USE_RATE, 2661da177e4SLinus Torvalds .rate_min = USE_RATE_MIN, 2671da177e4SLinus Torvalds .rate_max = USE_RATE_MAX, 2681da177e4SLinus Torvalds .channels_min = USE_CHANNELS_MIN, 2691da177e4SLinus Torvalds .channels_max = USE_CHANNELS_MAX, 2701da177e4SLinus Torvalds .buffer_bytes_max = MAX_BUFFER_SIZE, 2711da177e4SLinus Torvalds .period_bytes_min = 64, 2721da177e4SLinus Torvalds .period_bytes_max = MAX_BUFFER_SIZE, 2731da177e4SLinus Torvalds .periods_min = USE_PERIODS_MIN, 2741da177e4SLinus Torvalds .periods_max = USE_PERIODS_MAX, 2751da177e4SLinus Torvalds .fifo_size = 0, 2761da177e4SLinus Torvalds }; 2771da177e4SLinus Torvalds 2784a4d2cfdSTakashi Iwai static struct snd_pcm_hardware snd_card_dummy_capture = 2791da177e4SLinus Torvalds { 2801da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 2816e65c1ccSTakashi Iwai SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 2821da177e4SLinus Torvalds .formats = USE_FORMATS, 2831da177e4SLinus Torvalds .rates = USE_RATE, 2841da177e4SLinus Torvalds .rate_min = USE_RATE_MIN, 2851da177e4SLinus Torvalds .rate_max = USE_RATE_MAX, 2861da177e4SLinus Torvalds .channels_min = USE_CHANNELS_MIN, 2871da177e4SLinus Torvalds .channels_max = USE_CHANNELS_MAX, 2881da177e4SLinus Torvalds .buffer_bytes_max = MAX_BUFFER_SIZE, 2891da177e4SLinus Torvalds .period_bytes_min = 64, 2901da177e4SLinus Torvalds .period_bytes_max = MAX_BUFFER_SIZE, 2911da177e4SLinus Torvalds .periods_min = USE_PERIODS_MIN, 2921da177e4SLinus Torvalds .periods_max = USE_PERIODS_MAX, 2931da177e4SLinus Torvalds .fifo_size = 0, 2941da177e4SLinus Torvalds }; 2951da177e4SLinus Torvalds 2964a4d2cfdSTakashi Iwai static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime) 2971da177e4SLinus Torvalds { 298c8eb6ba1STakashi Iwai kfree(runtime->private_data); 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 3014a4d2cfdSTakashi Iwai static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream, 3024a4d2cfdSTakashi Iwai struct snd_pcm_hw_params *hw_params) 3031da177e4SLinus Torvalds { 3041da177e4SLinus Torvalds return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 3051da177e4SLinus Torvalds } 3061da177e4SLinus Torvalds 3074a4d2cfdSTakashi Iwai static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream) 3081da177e4SLinus Torvalds { 3091da177e4SLinus Torvalds return snd_pcm_lib_free_pages(substream); 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 3124a4d2cfdSTakashi Iwai static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) 313c8eb6ba1STakashi Iwai { 3144a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 315c8eb6ba1STakashi Iwai 316c8eb6ba1STakashi Iwai dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); 317c8eb6ba1STakashi Iwai if (! dpcm) 318c8eb6ba1STakashi Iwai return dpcm; 319c8eb6ba1STakashi Iwai init_timer(&dpcm->timer); 320c8eb6ba1STakashi Iwai dpcm->timer.data = (unsigned long) dpcm; 321c8eb6ba1STakashi Iwai dpcm->timer.function = snd_card_dummy_pcm_timer_function; 322c8eb6ba1STakashi Iwai spin_lock_init(&dpcm->lock); 323c8eb6ba1STakashi Iwai dpcm->substream = substream; 324c8eb6ba1STakashi Iwai return dpcm; 325c8eb6ba1STakashi Iwai } 326c8eb6ba1STakashi Iwai 3274a4d2cfdSTakashi Iwai static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream) 3281da177e4SLinus Torvalds { 3294a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 3304a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 3311da177e4SLinus Torvalds int err; 3321da177e4SLinus Torvalds 333c8eb6ba1STakashi Iwai if ((dpcm = new_pcm_stream(substream)) == NULL) 3341da177e4SLinus Torvalds return -ENOMEM; 3351da177e4SLinus Torvalds runtime->private_data = dpcm; 3361da177e4SLinus Torvalds runtime->private_free = snd_card_dummy_runtime_free; 3371da177e4SLinus Torvalds runtime->hw = snd_card_dummy_playback; 3381da177e4SLinus Torvalds if (substream->pcm->device & 1) { 3391da177e4SLinus Torvalds runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 3401da177e4SLinus Torvalds runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 3411da177e4SLinus Torvalds } 3421da177e4SLinus Torvalds if (substream->pcm->device & 2) 3431da177e4SLinus Torvalds runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 3441da177e4SLinus Torvalds if ((err = add_playback_constraints(runtime)) < 0) { 3451da177e4SLinus Torvalds kfree(dpcm); 3461da177e4SLinus Torvalds return err; 3471da177e4SLinus Torvalds } 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds return 0; 3501da177e4SLinus Torvalds } 3511da177e4SLinus Torvalds 3524a4d2cfdSTakashi Iwai static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream) 3531da177e4SLinus Torvalds { 3544a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 3554a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 3561da177e4SLinus Torvalds int err; 3571da177e4SLinus Torvalds 358c8eb6ba1STakashi Iwai if ((dpcm = new_pcm_stream(substream)) == NULL) 3591da177e4SLinus Torvalds return -ENOMEM; 3601da177e4SLinus Torvalds runtime->private_data = dpcm; 3611da177e4SLinus Torvalds runtime->private_free = snd_card_dummy_runtime_free; 3621da177e4SLinus Torvalds runtime->hw = snd_card_dummy_capture; 3631da177e4SLinus Torvalds if (substream->pcm->device == 1) { 3641da177e4SLinus Torvalds runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 3651da177e4SLinus Torvalds runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds if (substream->pcm->device & 2) 3681da177e4SLinus Torvalds runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 3691da177e4SLinus Torvalds if ((err = add_capture_constraints(runtime)) < 0) { 3701da177e4SLinus Torvalds kfree(dpcm); 3711da177e4SLinus Torvalds return err; 3721da177e4SLinus Torvalds } 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds return 0; 3751da177e4SLinus Torvalds } 3761da177e4SLinus Torvalds 3774a4d2cfdSTakashi Iwai static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream) 3781da177e4SLinus Torvalds { 3791da177e4SLinus Torvalds return 0; 3801da177e4SLinus Torvalds } 3811da177e4SLinus Torvalds 3824a4d2cfdSTakashi Iwai static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream) 3831da177e4SLinus Torvalds { 3841da177e4SLinus Torvalds return 0; 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds 3874a4d2cfdSTakashi Iwai static struct snd_pcm_ops snd_card_dummy_playback_ops = { 3881da177e4SLinus Torvalds .open = snd_card_dummy_playback_open, 3891da177e4SLinus Torvalds .close = snd_card_dummy_playback_close, 3901da177e4SLinus Torvalds .ioctl = snd_pcm_lib_ioctl, 3911da177e4SLinus Torvalds .hw_params = snd_card_dummy_hw_params, 3921da177e4SLinus Torvalds .hw_free = snd_card_dummy_hw_free, 393c8eb6ba1STakashi Iwai .prepare = snd_card_dummy_pcm_prepare, 394c8eb6ba1STakashi Iwai .trigger = snd_card_dummy_pcm_trigger, 395c8eb6ba1STakashi Iwai .pointer = snd_card_dummy_pcm_pointer, 3961da177e4SLinus Torvalds }; 3971da177e4SLinus Torvalds 3984a4d2cfdSTakashi Iwai static struct snd_pcm_ops snd_card_dummy_capture_ops = { 3991da177e4SLinus Torvalds .open = snd_card_dummy_capture_open, 4001da177e4SLinus Torvalds .close = snd_card_dummy_capture_close, 4011da177e4SLinus Torvalds .ioctl = snd_pcm_lib_ioctl, 4021da177e4SLinus Torvalds .hw_params = snd_card_dummy_hw_params, 4031da177e4SLinus Torvalds .hw_free = snd_card_dummy_hw_free, 404c8eb6ba1STakashi Iwai .prepare = snd_card_dummy_pcm_prepare, 405c8eb6ba1STakashi Iwai .trigger = snd_card_dummy_pcm_trigger, 406c8eb6ba1STakashi Iwai .pointer = snd_card_dummy_pcm_pointer, 4071da177e4SLinus Torvalds }; 4081da177e4SLinus Torvalds 4094a4d2cfdSTakashi Iwai static int __init snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams) 4101da177e4SLinus Torvalds { 4114a4d2cfdSTakashi Iwai struct snd_pcm *pcm; 4121da177e4SLinus Torvalds int err; 4131da177e4SLinus Torvalds 4144a4d2cfdSTakashi Iwai if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device, 4154a4d2cfdSTakashi Iwai substreams, substreams, &pcm)) < 0) 4161da177e4SLinus Torvalds return err; 4176e65c1ccSTakashi Iwai dummy->pcm = pcm; 4181da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops); 4191da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops); 4201da177e4SLinus Torvalds pcm->private_data = dummy; 4211da177e4SLinus Torvalds pcm->info_flags = 0; 4221da177e4SLinus Torvalds strcpy(pcm->name, "Dummy PCM"); 4231da177e4SLinus Torvalds snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, 4241da177e4SLinus Torvalds snd_dma_continuous_data(GFP_KERNEL), 4251da177e4SLinus Torvalds 0, 64*1024); 4261da177e4SLinus Torvalds return 0; 4271da177e4SLinus Torvalds } 4281da177e4SLinus Torvalds 4291da177e4SLinus Torvalds #define DUMMY_VOLUME(xname, xindex, addr) \ 4301da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 4311da177e4SLinus Torvalds .info = snd_dummy_volume_info, \ 4321da177e4SLinus Torvalds .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ 4331da177e4SLinus Torvalds .private_value = addr } 4341da177e4SLinus Torvalds 4354a4d2cfdSTakashi Iwai static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, 4364a4d2cfdSTakashi Iwai struct snd_ctl_elem_info *uinfo) 4371da177e4SLinus Torvalds { 4381da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 4391da177e4SLinus Torvalds uinfo->count = 2; 4401da177e4SLinus Torvalds uinfo->value.integer.min = -50; 4411da177e4SLinus Torvalds uinfo->value.integer.max = 100; 4421da177e4SLinus Torvalds return 0; 4431da177e4SLinus Torvalds } 4441da177e4SLinus Torvalds 4454a4d2cfdSTakashi Iwai static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, 4464a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 4471da177e4SLinus Torvalds { 4484a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 4491da177e4SLinus Torvalds int addr = kcontrol->private_value; 4501da177e4SLinus Torvalds 451c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 4521da177e4SLinus Torvalds ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; 4531da177e4SLinus Torvalds ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; 454c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 4551da177e4SLinus Torvalds return 0; 4561da177e4SLinus Torvalds } 4571da177e4SLinus Torvalds 4584a4d2cfdSTakashi Iwai static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, 4594a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 4601da177e4SLinus Torvalds { 4614a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 4621da177e4SLinus Torvalds int change, addr = kcontrol->private_value; 4631da177e4SLinus Torvalds int left, right; 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds left = ucontrol->value.integer.value[0]; 4661da177e4SLinus Torvalds if (left < -50) 4671da177e4SLinus Torvalds left = -50; 4681da177e4SLinus Torvalds if (left > 100) 4691da177e4SLinus Torvalds left = 100; 4701da177e4SLinus Torvalds right = ucontrol->value.integer.value[1]; 4711da177e4SLinus Torvalds if (right < -50) 4721da177e4SLinus Torvalds right = -50; 4731da177e4SLinus Torvalds if (right > 100) 4741da177e4SLinus Torvalds right = 100; 475c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 4761da177e4SLinus Torvalds change = dummy->mixer_volume[addr][0] != left || 4771da177e4SLinus Torvalds dummy->mixer_volume[addr][1] != right; 4781da177e4SLinus Torvalds dummy->mixer_volume[addr][0] = left; 4791da177e4SLinus Torvalds dummy->mixer_volume[addr][1] = right; 480c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 4811da177e4SLinus Torvalds return change; 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds #define DUMMY_CAPSRC(xname, xindex, addr) \ 4851da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 4861da177e4SLinus Torvalds .info = snd_dummy_capsrc_info, \ 4871da177e4SLinus Torvalds .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ 4881da177e4SLinus Torvalds .private_value = addr } 4891da177e4SLinus Torvalds 4904a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_info(struct snd_kcontrol *kcontrol, 4914a4d2cfdSTakashi Iwai struct snd_ctl_elem_info *uinfo) 4921da177e4SLinus Torvalds { 4931da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 4941da177e4SLinus Torvalds uinfo->count = 2; 4951da177e4SLinus Torvalds uinfo->value.integer.min = 0; 4961da177e4SLinus Torvalds uinfo->value.integer.max = 1; 4971da177e4SLinus Torvalds return 0; 4981da177e4SLinus Torvalds } 4991da177e4SLinus Torvalds 5004a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, 5014a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 5021da177e4SLinus Torvalds { 5034a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 5041da177e4SLinus Torvalds int addr = kcontrol->private_value; 5051da177e4SLinus Torvalds 506c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 5071da177e4SLinus Torvalds ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; 5081da177e4SLinus Torvalds ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; 509c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5101da177e4SLinus Torvalds return 0; 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds 5134a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 5141da177e4SLinus Torvalds { 5154a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 5161da177e4SLinus Torvalds int change, addr = kcontrol->private_value; 5171da177e4SLinus Torvalds int left, right; 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds left = ucontrol->value.integer.value[0] & 1; 5201da177e4SLinus Torvalds right = ucontrol->value.integer.value[1] & 1; 521c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 5221da177e4SLinus Torvalds change = dummy->capture_source[addr][0] != left && 5231da177e4SLinus Torvalds dummy->capture_source[addr][1] != right; 5241da177e4SLinus Torvalds dummy->capture_source[addr][0] = left; 5251da177e4SLinus Torvalds dummy->capture_source[addr][1] = right; 526c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5271da177e4SLinus Torvalds return change; 5281da177e4SLinus Torvalds } 5291da177e4SLinus Torvalds 5304a4d2cfdSTakashi Iwai static struct snd_kcontrol_new snd_dummy_controls[] = { 5311da177e4SLinus Torvalds DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), 5321da177e4SLinus Torvalds DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), 5331da177e4SLinus Torvalds DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), 5341da177e4SLinus Torvalds DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_MASTER), 5351da177e4SLinus Torvalds DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), 5361da177e4SLinus Torvalds DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_MASTER), 5371da177e4SLinus Torvalds DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), 5381da177e4SLinus Torvalds DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MASTER), 5391da177e4SLinus Torvalds DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), 5401da177e4SLinus Torvalds DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER) 5411da177e4SLinus Torvalds }; 5421da177e4SLinus Torvalds 5434a4d2cfdSTakashi Iwai static int __init snd_card_dummy_new_mixer(struct snd_dummy *dummy) 5441da177e4SLinus Torvalds { 5454a4d2cfdSTakashi Iwai struct snd_card *card = dummy->card; 5461da177e4SLinus Torvalds unsigned int idx; 5471da177e4SLinus Torvalds int err; 5481da177e4SLinus Torvalds 5491da177e4SLinus Torvalds snd_assert(dummy != NULL, return -EINVAL); 5501da177e4SLinus Torvalds spin_lock_init(&dummy->mixer_lock); 5511da177e4SLinus Torvalds strcpy(card->mixername, "Dummy Mixer"); 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { 5541da177e4SLinus Torvalds if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0) 5551da177e4SLinus Torvalds return err; 5561da177e4SLinus Torvalds } 5571da177e4SLinus Torvalds return 0; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds 5606e65c1ccSTakashi Iwai static int __init snd_dummy_probe(struct platform_device *devptr) 5611da177e4SLinus Torvalds { 5624a4d2cfdSTakashi Iwai struct snd_card *card; 5634a4d2cfdSTakashi Iwai struct snd_dummy *dummy; 5641da177e4SLinus Torvalds int idx, err; 5656e65c1ccSTakashi Iwai int dev = devptr->id; 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds card = snd_card_new(index[dev], id[dev], THIS_MODULE, 5684a4d2cfdSTakashi Iwai sizeof(struct snd_dummy)); 5691da177e4SLinus Torvalds if (card == NULL) 5701da177e4SLinus Torvalds return -ENOMEM; 5714a4d2cfdSTakashi Iwai dummy = card->private_data; 5721da177e4SLinus Torvalds dummy->card = card; 5731da177e4SLinus Torvalds for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { 5741da177e4SLinus Torvalds if (pcm_substreams[dev] < 1) 5751da177e4SLinus Torvalds pcm_substreams[dev] = 1; 5761da177e4SLinus Torvalds if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) 5771da177e4SLinus Torvalds pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; 5781da177e4SLinus Torvalds if ((err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev])) < 0) 5791da177e4SLinus Torvalds goto __nodev; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds if ((err = snd_card_dummy_new_mixer(dummy)) < 0) 5821da177e4SLinus Torvalds goto __nodev; 5831da177e4SLinus Torvalds strcpy(card->driver, "Dummy"); 5841da177e4SLinus Torvalds strcpy(card->shortname, "Dummy"); 5851da177e4SLinus Torvalds sprintf(card->longname, "Dummy %i", dev + 1); 58616dab54bSTakashi Iwai 5876e65c1ccSTakashi Iwai snd_card_set_dev(card, &devptr->dev); 58816dab54bSTakashi Iwai 5891da177e4SLinus Torvalds if ((err = snd_card_register(card)) == 0) { 5906e65c1ccSTakashi Iwai platform_set_drvdata(devptr, card); 5911da177e4SLinus Torvalds return 0; 5921da177e4SLinus Torvalds } 5931da177e4SLinus Torvalds __nodev: 5941da177e4SLinus Torvalds snd_card_free(card); 5951da177e4SLinus Torvalds return err; 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds 5986e65c1ccSTakashi Iwai static int snd_dummy_remove(struct platform_device *devptr) 5996e65c1ccSTakashi Iwai { 6006e65c1ccSTakashi Iwai snd_card_free(platform_get_drvdata(devptr)); 6016e65c1ccSTakashi Iwai platform_set_drvdata(devptr, NULL); 6026e65c1ccSTakashi Iwai return 0; 6036e65c1ccSTakashi Iwai } 6046e65c1ccSTakashi Iwai 6056e65c1ccSTakashi Iwai #ifdef CONFIG_PM 6066e65c1ccSTakashi Iwai static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state) 6076e65c1ccSTakashi Iwai { 6086e65c1ccSTakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 6096e65c1ccSTakashi Iwai struct snd_dummy *dummy = card->private_data; 6106e65c1ccSTakashi Iwai 6116e65c1ccSTakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 6126e65c1ccSTakashi Iwai snd_pcm_suspend_all(dummy->pcm); 6136e65c1ccSTakashi Iwai return 0; 6146e65c1ccSTakashi Iwai } 6156e65c1ccSTakashi Iwai 6166e65c1ccSTakashi Iwai static int snd_dummy_resume(struct platform_device *pdev) 6176e65c1ccSTakashi Iwai { 6186e65c1ccSTakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 6196e65c1ccSTakashi Iwai 6206e65c1ccSTakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0); 6216e65c1ccSTakashi Iwai return 0; 6226e65c1ccSTakashi Iwai } 6236e65c1ccSTakashi Iwai #endif 6246e65c1ccSTakashi Iwai 6256e65c1ccSTakashi Iwai #define SND_DUMMY_DRIVER "snd_dummy" 6266e65c1ccSTakashi Iwai 6276e65c1ccSTakashi Iwai static struct platform_driver snd_dummy_driver = { 6286e65c1ccSTakashi Iwai .probe = snd_dummy_probe, 6296e65c1ccSTakashi Iwai .remove = snd_dummy_remove, 6306e65c1ccSTakashi Iwai #ifdef CONFIG_PM 6316e65c1ccSTakashi Iwai .suspend = snd_dummy_suspend, 6326e65c1ccSTakashi Iwai .resume = snd_dummy_resume, 6336e65c1ccSTakashi Iwai #endif 6346e65c1ccSTakashi Iwai .driver = { 6356e65c1ccSTakashi Iwai .name = SND_DUMMY_DRIVER 6366e65c1ccSTakashi Iwai }, 6376e65c1ccSTakashi Iwai }; 6386e65c1ccSTakashi Iwai 639*f7a9275dSClemens Ladisch static void __init_or_module snd_dummy_unregister_all(void) 640*f7a9275dSClemens Ladisch { 641*f7a9275dSClemens Ladisch int i; 642*f7a9275dSClemens Ladisch 643*f7a9275dSClemens Ladisch for (i = 0; i < ARRAY_SIZE(devices); ++i) 644*f7a9275dSClemens Ladisch platform_device_unregister(devices[i]); 645*f7a9275dSClemens Ladisch platform_driver_unregister(&snd_dummy_driver); 646*f7a9275dSClemens Ladisch } 647*f7a9275dSClemens Ladisch 6481da177e4SLinus Torvalds static int __init alsa_card_dummy_init(void) 6491da177e4SLinus Torvalds { 6506e65c1ccSTakashi Iwai int i, cards, err; 6511da177e4SLinus Torvalds 6526e65c1ccSTakashi Iwai if ((err = platform_driver_register(&snd_dummy_driver)) < 0) 6536e65c1ccSTakashi Iwai return err; 6546e65c1ccSTakashi Iwai 6556e65c1ccSTakashi Iwai cards = 0; 6566e65c1ccSTakashi Iwai for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { 6576e65c1ccSTakashi Iwai struct platform_device *device; 6586e65c1ccSTakashi Iwai device = platform_device_register_simple(SND_DUMMY_DRIVER, 6596e65c1ccSTakashi Iwai i, NULL, 0); 6606e65c1ccSTakashi Iwai if (IS_ERR(device)) { 6616e65c1ccSTakashi Iwai err = PTR_ERR(device); 6626e65c1ccSTakashi Iwai goto errout; 6631da177e4SLinus Torvalds } 664*f7a9275dSClemens Ladisch devices[i] = device; 6651da177e4SLinus Torvalds cards++; 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds if (!cards) { 6681da177e4SLinus Torvalds #ifdef MODULE 6691da177e4SLinus Torvalds printk(KERN_ERR "Dummy soundcard not found or device busy\n"); 6701da177e4SLinus Torvalds #endif 6716e65c1ccSTakashi Iwai err = -ENODEV; 6726e65c1ccSTakashi Iwai goto errout; 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds return 0; 6756e65c1ccSTakashi Iwai 6766e65c1ccSTakashi Iwai errout: 677*f7a9275dSClemens Ladisch snd_dummy_unregister_all(); 6786e65c1ccSTakashi Iwai return err; 6791da177e4SLinus Torvalds } 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds static void __exit alsa_card_dummy_exit(void) 6821da177e4SLinus Torvalds { 683*f7a9275dSClemens Ladisch snd_dummy_unregister_all(); 6841da177e4SLinus Torvalds } 6851da177e4SLinus Torvalds 6861da177e4SLinus Torvalds module_init(alsa_card_dummy_init) 6871da177e4SLinus Torvalds module_exit(alsa_card_dummy_exit) 688