11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Dummy soundcard 3*c1017a4cSJaroslav Kysela * Copyright (c) by Jaroslav Kysela <perex@perex.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> 32fb567a8eSTakashi Iwai #include <sound/tlv.h> 331da177e4SLinus Torvalds #include <sound/pcm.h> 341da177e4SLinus Torvalds #include <sound/rawmidi.h> 351da177e4SLinus Torvalds #include <sound/initval.h> 361da177e4SLinus Torvalds 37*c1017a4cSJaroslav Kysela MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 381da177e4SLinus Torvalds MODULE_DESCRIPTION("Dummy soundcard (/dev/null)"); 391da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 401da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}"); 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #define MAX_PCM_DEVICES 4 431da177e4SLinus Torvalds #define MAX_PCM_SUBSTREAMS 16 441da177e4SLinus Torvalds #define MAX_MIDI_DEVICES 2 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds #if 0 /* emu10k1 emulation */ 471da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (128 * 1024) 484a4d2cfdSTakashi Iwai static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime) 491da177e4SLinus Torvalds { 501da177e4SLinus Torvalds int err; 511da177e4SLinus Torvalds if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 521da177e4SLinus Torvalds return err; 531da177e4SLinus Torvalds if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) 541da177e4SLinus Torvalds return err; 551da177e4SLinus Torvalds return 0; 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds #define add_playback_constraints emu10k1_playback_constraints 581da177e4SLinus Torvalds #endif 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #if 0 /* RME9652 emulation */ 611da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (26 * 64 * 1024) 621da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE 631da177e4SLinus Torvalds #define USE_CHANNELS_MIN 26 641da177e4SLinus Torvalds #define USE_CHANNELS_MAX 26 651da177e4SLinus Torvalds #define USE_PERIODS_MIN 2 661da177e4SLinus Torvalds #define USE_PERIODS_MAX 2 671da177e4SLinus Torvalds #endif 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds #if 0 /* ICE1712 emulation */ 701da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (256 * 1024) 711da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE 721da177e4SLinus Torvalds #define USE_CHANNELS_MIN 10 731da177e4SLinus Torvalds #define USE_CHANNELS_MAX 10 741da177e4SLinus Torvalds #define USE_PERIODS_MIN 1 751da177e4SLinus Torvalds #define USE_PERIODS_MAX 1024 761da177e4SLinus Torvalds #endif 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds #if 0 /* UDA1341 emulation */ 791da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (16380) 801da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE 811da177e4SLinus Torvalds #define USE_CHANNELS_MIN 2 821da177e4SLinus Torvalds #define USE_CHANNELS_MAX 2 831da177e4SLinus Torvalds #define USE_PERIODS_MIN 2 841da177e4SLinus Torvalds #define USE_PERIODS_MAX 255 851da177e4SLinus Torvalds #endif 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */ 881da177e4SLinus Torvalds #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE 891da177e4SLinus Torvalds #define USE_CHANNELS_MIN 2 901da177e4SLinus Torvalds #define USE_CHANNELS_MAX 2 911da177e4SLinus Torvalds #define USE_RATE SNDRV_PCM_RATE_48000 921da177e4SLinus Torvalds #define USE_RATE_MIN 48000 931da177e4SLinus Torvalds #define USE_RATE_MAX 48000 941da177e4SLinus Torvalds #endif 951da177e4SLinus Torvalds 962ad5dd8dSJaroslav Kysela #if 0 /* CA0106 */ 972ad5dd8dSJaroslav Kysela #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE 982ad5dd8dSJaroslav Kysela #define USE_CHANNELS_MIN 2 992ad5dd8dSJaroslav Kysela #define USE_CHANNELS_MAX 2 1002ad5dd8dSJaroslav Kysela #define USE_RATE (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000) 1012ad5dd8dSJaroslav Kysela #define USE_RATE_MIN 48000 1022ad5dd8dSJaroslav Kysela #define USE_RATE_MAX 192000 1032ad5dd8dSJaroslav Kysela #define MAX_BUFFER_SIZE ((65536-64)*8) 1042ad5dd8dSJaroslav Kysela #define MAX_PERIOD_SIZE (65536-64) 1052ad5dd8dSJaroslav Kysela #define USE_PERIODS_MIN 2 1062ad5dd8dSJaroslav Kysela #define USE_PERIODS_MAX 8 1072ad5dd8dSJaroslav Kysela #endif 1082ad5dd8dSJaroslav Kysela 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds /* defaults */ 1111da177e4SLinus Torvalds #ifndef MAX_BUFFER_SIZE 1121da177e4SLinus Torvalds #define MAX_BUFFER_SIZE (64*1024) 1131da177e4SLinus Torvalds #endif 1142ad5dd8dSJaroslav Kysela #ifndef MAX_PERIOD_SIZE 1152ad5dd8dSJaroslav Kysela #define MAX_PERIOD_SIZE MAX_BUFFER_SIZE 1162ad5dd8dSJaroslav Kysela #endif 1171da177e4SLinus Torvalds #ifndef USE_FORMATS 1181da177e4SLinus Torvalds #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE) 1191da177e4SLinus Torvalds #endif 1201da177e4SLinus Torvalds #ifndef USE_RATE 1211da177e4SLinus Torvalds #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 1221da177e4SLinus Torvalds #define USE_RATE_MIN 5500 1231da177e4SLinus Torvalds #define USE_RATE_MAX 48000 1241da177e4SLinus Torvalds #endif 1251da177e4SLinus Torvalds #ifndef USE_CHANNELS_MIN 1261da177e4SLinus Torvalds #define USE_CHANNELS_MIN 1 1271da177e4SLinus Torvalds #endif 1281da177e4SLinus Torvalds #ifndef USE_CHANNELS_MAX 1291da177e4SLinus Torvalds #define USE_CHANNELS_MAX 2 1301da177e4SLinus Torvalds #endif 1311da177e4SLinus Torvalds #ifndef USE_PERIODS_MIN 1321da177e4SLinus Torvalds #define USE_PERIODS_MIN 1 1331da177e4SLinus Torvalds #endif 1341da177e4SLinus Torvalds #ifndef USE_PERIODS_MAX 1351da177e4SLinus Torvalds #define USE_PERIODS_MAX 1024 1361da177e4SLinus Torvalds #endif 1371da177e4SLinus Torvalds #ifndef add_playback_constraints 1381da177e4SLinus Torvalds #define add_playback_constraints(x) 0 1391da177e4SLinus Torvalds #endif 1401da177e4SLinus Torvalds #ifndef add_capture_constraints 1411da177e4SLinus Torvalds #define add_capture_constraints(x) 0 1421da177e4SLinus Torvalds #endif 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 1451da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 1461da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; 1471da177e4SLinus Torvalds static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 1481da177e4SLinus Torvalds static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; 1491da177e4SLinus Torvalds //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444); 1521da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for dummy soundcard."); 1531da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444); 1541da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for dummy soundcard."); 1551da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444); 1561da177e4SLinus Torvalds MODULE_PARM_DESC(enable, "Enable this dummy soundcard."); 1571da177e4SLinus Torvalds module_param_array(pcm_devs, int, NULL, 0444); 1581da177e4SLinus Torvalds MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver."); 1591da177e4SLinus Torvalds module_param_array(pcm_substreams, int, NULL, 0444); 1601da177e4SLinus Torvalds MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver."); 1611da177e4SLinus Torvalds //module_param_array(midi_devs, int, NULL, 0444); 1621da177e4SLinus Torvalds //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); 1631da177e4SLinus Torvalds 164f7a9275dSClemens Ladisch static struct platform_device *devices[SNDRV_CARDS]; 165f7a9275dSClemens Ladisch 1661da177e4SLinus Torvalds #define MIXER_ADDR_MASTER 0 1671da177e4SLinus Torvalds #define MIXER_ADDR_LINE 1 1681da177e4SLinus Torvalds #define MIXER_ADDR_MIC 2 1691da177e4SLinus Torvalds #define MIXER_ADDR_SYNTH 3 1701da177e4SLinus Torvalds #define MIXER_ADDR_CD 4 1711da177e4SLinus Torvalds #define MIXER_ADDR_LAST 4 1721da177e4SLinus Torvalds 1734a4d2cfdSTakashi Iwai struct snd_dummy { 1744a4d2cfdSTakashi Iwai struct snd_card *card; 1756e65c1ccSTakashi Iwai struct snd_pcm *pcm; 1761da177e4SLinus Torvalds spinlock_t mixer_lock; 1771da177e4SLinus Torvalds int mixer_volume[MIXER_ADDR_LAST+1][2]; 1781da177e4SLinus Torvalds int capture_source[MIXER_ADDR_LAST+1][2]; 1794a4d2cfdSTakashi Iwai }; 1801da177e4SLinus Torvalds 1814a4d2cfdSTakashi Iwai struct snd_dummy_pcm { 1824a4d2cfdSTakashi Iwai struct snd_dummy *dummy; 1831da177e4SLinus Torvalds spinlock_t lock; 1841da177e4SLinus Torvalds struct timer_list timer; 1851da177e4SLinus Torvalds unsigned int pcm_size; 1861da177e4SLinus Torvalds unsigned int pcm_count; 1871da177e4SLinus Torvalds unsigned int pcm_bps; /* bytes per second */ 1881da177e4SLinus Torvalds unsigned int pcm_jiffie; /* bytes per one jiffie */ 1891da177e4SLinus Torvalds unsigned int pcm_irq_pos; /* IRQ position */ 1901da177e4SLinus Torvalds unsigned int pcm_buf_pos; /* position in buffer */ 1914a4d2cfdSTakashi Iwai struct snd_pcm_substream *substream; 1924a4d2cfdSTakashi Iwai }; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds 1954a4d2cfdSTakashi Iwai static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) 1961da177e4SLinus Torvalds { 1971da177e4SLinus Torvalds dpcm->timer.expires = 1 + jiffies; 1981da177e4SLinus Torvalds add_timer(&dpcm->timer); 1991da177e4SLinus Torvalds } 2001da177e4SLinus Torvalds 2014a4d2cfdSTakashi Iwai static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) 2021da177e4SLinus Torvalds { 2031da177e4SLinus Torvalds del_timer(&dpcm->timer); 2041da177e4SLinus Torvalds } 2051da177e4SLinus Torvalds 2064a4d2cfdSTakashi Iwai static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 2071da177e4SLinus Torvalds { 2084a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2094a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 210c8eb6ba1STakashi Iwai int err = 0; 2111da177e4SLinus Torvalds 212c8eb6ba1STakashi Iwai spin_lock(&dpcm->lock); 2136e65c1ccSTakashi Iwai switch (cmd) { 2146e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_START: 2156e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_RESUME: 216c8eb6ba1STakashi Iwai snd_card_dummy_pcm_timer_start(dpcm); 2176e65c1ccSTakashi Iwai break; 2186e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_STOP: 2196e65c1ccSTakashi Iwai case SNDRV_PCM_TRIGGER_SUSPEND: 220c8eb6ba1STakashi Iwai snd_card_dummy_pcm_timer_stop(dpcm); 2216e65c1ccSTakashi Iwai break; 2226e65c1ccSTakashi Iwai default: 223c8eb6ba1STakashi Iwai err = -EINVAL; 2246e65c1ccSTakashi Iwai break; 2251da177e4SLinus Torvalds } 226c8eb6ba1STakashi Iwai spin_unlock(&dpcm->lock); 2276e65c1ccSTakashi Iwai return 0; 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2304a4d2cfdSTakashi Iwai static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) 2311da177e4SLinus Torvalds { 2324a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2334a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 2341da177e4SLinus Torvalds unsigned int bps; 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds bps = runtime->rate * runtime->channels; 2371da177e4SLinus Torvalds bps *= snd_pcm_format_width(runtime->format); 2381da177e4SLinus Torvalds bps /= 8; 2391da177e4SLinus Torvalds if (bps <= 0) 2401da177e4SLinus Torvalds return -EINVAL; 2411da177e4SLinus Torvalds dpcm->pcm_bps = bps; 2421da177e4SLinus Torvalds dpcm->pcm_jiffie = bps / HZ; 2431da177e4SLinus Torvalds dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 2441da177e4SLinus Torvalds dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 2451da177e4SLinus Torvalds dpcm->pcm_irq_pos = 0; 2461da177e4SLinus Torvalds dpcm->pcm_buf_pos = 0; 2471da177e4SLinus Torvalds return 0; 2481da177e4SLinus Torvalds } 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds static void snd_card_dummy_pcm_timer_function(unsigned long data) 2511da177e4SLinus Torvalds { 2524a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; 253b32425acSTakashi Iwai unsigned long flags; 2541da177e4SLinus Torvalds 255b32425acSTakashi Iwai spin_lock_irqsave(&dpcm->lock, flags); 2561da177e4SLinus Torvalds dpcm->timer.expires = 1 + jiffies; 2571da177e4SLinus Torvalds add_timer(&dpcm->timer); 2581da177e4SLinus Torvalds dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 2591da177e4SLinus Torvalds dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 2601da177e4SLinus Torvalds dpcm->pcm_buf_pos %= dpcm->pcm_size; 2611da177e4SLinus Torvalds if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 2621da177e4SLinus Torvalds dpcm->pcm_irq_pos %= dpcm->pcm_count; 263b32425acSTakashi Iwai spin_unlock_irqrestore(&dpcm->lock, flags); 2641da177e4SLinus Torvalds snd_pcm_period_elapsed(dpcm->substream); 265b32425acSTakashi Iwai } else 266b32425acSTakashi Iwai spin_unlock_irqrestore(&dpcm->lock, flags); 2671da177e4SLinus Torvalds } 2681da177e4SLinus Torvalds 2694a4d2cfdSTakashi Iwai static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) 2701da177e4SLinus Torvalds { 2714a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 2724a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm = runtime->private_data; 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds return bytes_to_frames(runtime, dpcm->pcm_buf_pos); 2751da177e4SLinus Torvalds } 2761da177e4SLinus Torvalds 2774a4d2cfdSTakashi Iwai static struct snd_pcm_hardware snd_card_dummy_playback = 2781da177e4SLinus Torvalds { 2791da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 2806e65c1ccSTakashi Iwai SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 2811da177e4SLinus Torvalds .formats = USE_FORMATS, 2821da177e4SLinus Torvalds .rates = USE_RATE, 2831da177e4SLinus Torvalds .rate_min = USE_RATE_MIN, 2841da177e4SLinus Torvalds .rate_max = USE_RATE_MAX, 2851da177e4SLinus Torvalds .channels_min = USE_CHANNELS_MIN, 2861da177e4SLinus Torvalds .channels_max = USE_CHANNELS_MAX, 2871da177e4SLinus Torvalds .buffer_bytes_max = MAX_BUFFER_SIZE, 2881da177e4SLinus Torvalds .period_bytes_min = 64, 289e05d6964STakashi Iwai .period_bytes_max = MAX_PERIOD_SIZE, 2901da177e4SLinus Torvalds .periods_min = USE_PERIODS_MIN, 2911da177e4SLinus Torvalds .periods_max = USE_PERIODS_MAX, 2921da177e4SLinus Torvalds .fifo_size = 0, 2931da177e4SLinus Torvalds }; 2941da177e4SLinus Torvalds 2954a4d2cfdSTakashi Iwai static struct snd_pcm_hardware snd_card_dummy_capture = 2961da177e4SLinus Torvalds { 2971da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 2986e65c1ccSTakashi Iwai SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), 2991da177e4SLinus Torvalds .formats = USE_FORMATS, 3001da177e4SLinus Torvalds .rates = USE_RATE, 3011da177e4SLinus Torvalds .rate_min = USE_RATE_MIN, 3021da177e4SLinus Torvalds .rate_max = USE_RATE_MAX, 3031da177e4SLinus Torvalds .channels_min = USE_CHANNELS_MIN, 3041da177e4SLinus Torvalds .channels_max = USE_CHANNELS_MAX, 3051da177e4SLinus Torvalds .buffer_bytes_max = MAX_BUFFER_SIZE, 3061da177e4SLinus Torvalds .period_bytes_min = 64, 3072ad5dd8dSJaroslav Kysela .period_bytes_max = MAX_PERIOD_SIZE, 3081da177e4SLinus Torvalds .periods_min = USE_PERIODS_MIN, 3091da177e4SLinus Torvalds .periods_max = USE_PERIODS_MAX, 3101da177e4SLinus Torvalds .fifo_size = 0, 3111da177e4SLinus Torvalds }; 3121da177e4SLinus Torvalds 3134a4d2cfdSTakashi Iwai static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime) 3141da177e4SLinus Torvalds { 315c8eb6ba1STakashi Iwai kfree(runtime->private_data); 3161da177e4SLinus Torvalds } 3171da177e4SLinus Torvalds 3184a4d2cfdSTakashi Iwai static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream, 3194a4d2cfdSTakashi Iwai struct snd_pcm_hw_params *hw_params) 3201da177e4SLinus Torvalds { 3211da177e4SLinus Torvalds return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 3244a4d2cfdSTakashi Iwai static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream) 3251da177e4SLinus Torvalds { 3261da177e4SLinus Torvalds return snd_pcm_lib_free_pages(substream); 3271da177e4SLinus Torvalds } 3281da177e4SLinus Torvalds 3294a4d2cfdSTakashi Iwai static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) 330c8eb6ba1STakashi Iwai { 3314a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 332c8eb6ba1STakashi Iwai 333c8eb6ba1STakashi Iwai dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); 334c8eb6ba1STakashi Iwai if (! dpcm) 335c8eb6ba1STakashi Iwai return dpcm; 336c8eb6ba1STakashi Iwai init_timer(&dpcm->timer); 337c8eb6ba1STakashi Iwai dpcm->timer.data = (unsigned long) dpcm; 338c8eb6ba1STakashi Iwai dpcm->timer.function = snd_card_dummy_pcm_timer_function; 339c8eb6ba1STakashi Iwai spin_lock_init(&dpcm->lock); 340c8eb6ba1STakashi Iwai dpcm->substream = substream; 341c8eb6ba1STakashi Iwai return dpcm; 342c8eb6ba1STakashi Iwai } 343c8eb6ba1STakashi Iwai 3444a4d2cfdSTakashi Iwai static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream) 3451da177e4SLinus Torvalds { 3464a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 3474a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 3481da177e4SLinus Torvalds int err; 3491da177e4SLinus Torvalds 350c8eb6ba1STakashi Iwai if ((dpcm = new_pcm_stream(substream)) == NULL) 3511da177e4SLinus Torvalds return -ENOMEM; 3521da177e4SLinus Torvalds runtime->private_data = dpcm; 3531da177e4SLinus Torvalds runtime->private_free = snd_card_dummy_runtime_free; 3541da177e4SLinus Torvalds runtime->hw = snd_card_dummy_playback; 3551da177e4SLinus Torvalds if (substream->pcm->device & 1) { 3561da177e4SLinus Torvalds runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 3571da177e4SLinus Torvalds runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 3581da177e4SLinus Torvalds } 3591da177e4SLinus Torvalds if (substream->pcm->device & 2) 3601da177e4SLinus Torvalds runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 3611da177e4SLinus Torvalds if ((err = add_playback_constraints(runtime)) < 0) { 3621da177e4SLinus Torvalds kfree(dpcm); 3631da177e4SLinus Torvalds return err; 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds return 0; 3671da177e4SLinus Torvalds } 3681da177e4SLinus Torvalds 3694a4d2cfdSTakashi Iwai static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream) 3701da177e4SLinus Torvalds { 3714a4d2cfdSTakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime; 3724a4d2cfdSTakashi Iwai struct snd_dummy_pcm *dpcm; 3731da177e4SLinus Torvalds int err; 3741da177e4SLinus Torvalds 375c8eb6ba1STakashi Iwai if ((dpcm = new_pcm_stream(substream)) == NULL) 3761da177e4SLinus Torvalds return -ENOMEM; 3771da177e4SLinus Torvalds runtime->private_data = dpcm; 3781da177e4SLinus Torvalds runtime->private_free = snd_card_dummy_runtime_free; 3791da177e4SLinus Torvalds runtime->hw = snd_card_dummy_capture; 3801da177e4SLinus Torvalds if (substream->pcm->device == 1) { 3811da177e4SLinus Torvalds runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 3821da177e4SLinus Torvalds runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds if (substream->pcm->device & 2) 3851da177e4SLinus Torvalds runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); 3861da177e4SLinus Torvalds if ((err = add_capture_constraints(runtime)) < 0) { 3871da177e4SLinus Torvalds kfree(dpcm); 3881da177e4SLinus Torvalds return err; 3891da177e4SLinus Torvalds } 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds return 0; 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds 3944a4d2cfdSTakashi Iwai static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream) 3951da177e4SLinus Torvalds { 3961da177e4SLinus Torvalds return 0; 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds 3994a4d2cfdSTakashi Iwai static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream) 4001da177e4SLinus Torvalds { 4011da177e4SLinus Torvalds return 0; 4021da177e4SLinus Torvalds } 4031da177e4SLinus Torvalds 4044a4d2cfdSTakashi Iwai static struct snd_pcm_ops snd_card_dummy_playback_ops = { 4051da177e4SLinus Torvalds .open = snd_card_dummy_playback_open, 4061da177e4SLinus Torvalds .close = snd_card_dummy_playback_close, 4071da177e4SLinus Torvalds .ioctl = snd_pcm_lib_ioctl, 4081da177e4SLinus Torvalds .hw_params = snd_card_dummy_hw_params, 4091da177e4SLinus Torvalds .hw_free = snd_card_dummy_hw_free, 410c8eb6ba1STakashi Iwai .prepare = snd_card_dummy_pcm_prepare, 411c8eb6ba1STakashi Iwai .trigger = snd_card_dummy_pcm_trigger, 412c8eb6ba1STakashi Iwai .pointer = snd_card_dummy_pcm_pointer, 4131da177e4SLinus Torvalds }; 4141da177e4SLinus Torvalds 4154a4d2cfdSTakashi Iwai static struct snd_pcm_ops snd_card_dummy_capture_ops = { 4161da177e4SLinus Torvalds .open = snd_card_dummy_capture_open, 4171da177e4SLinus Torvalds .close = snd_card_dummy_capture_close, 4181da177e4SLinus Torvalds .ioctl = snd_pcm_lib_ioctl, 4191da177e4SLinus Torvalds .hw_params = snd_card_dummy_hw_params, 4201da177e4SLinus Torvalds .hw_free = snd_card_dummy_hw_free, 421c8eb6ba1STakashi Iwai .prepare = snd_card_dummy_pcm_prepare, 422c8eb6ba1STakashi Iwai .trigger = snd_card_dummy_pcm_trigger, 423c8eb6ba1STakashi Iwai .pointer = snd_card_dummy_pcm_pointer, 4241da177e4SLinus Torvalds }; 4251da177e4SLinus Torvalds 426788c6043SPrarit Bhargava static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device, 427788c6043SPrarit Bhargava int substreams) 4281da177e4SLinus Torvalds { 4294a4d2cfdSTakashi Iwai struct snd_pcm *pcm; 4301da177e4SLinus Torvalds int err; 4311da177e4SLinus Torvalds 4324a4d2cfdSTakashi Iwai if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device, 4334a4d2cfdSTakashi Iwai substreams, substreams, &pcm)) < 0) 4341da177e4SLinus Torvalds return err; 4356e65c1ccSTakashi Iwai dummy->pcm = pcm; 4361da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops); 4371da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops); 4381da177e4SLinus Torvalds pcm->private_data = dummy; 4391da177e4SLinus Torvalds pcm->info_flags = 0; 4401da177e4SLinus Torvalds strcpy(pcm->name, "Dummy PCM"); 4411da177e4SLinus Torvalds snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, 4421da177e4SLinus Torvalds snd_dma_continuous_data(GFP_KERNEL), 4431da177e4SLinus Torvalds 0, 64*1024); 4441da177e4SLinus Torvalds return 0; 4451da177e4SLinus Torvalds } 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds #define DUMMY_VOLUME(xname, xindex, addr) \ 448fb567a8eSTakashi Iwai { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 449fb567a8eSTakashi Iwai .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 450fb567a8eSTakashi Iwai .name = xname, .index = xindex, \ 4511da177e4SLinus Torvalds .info = snd_dummy_volume_info, \ 4521da177e4SLinus Torvalds .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ 453fb567a8eSTakashi Iwai .private_value = addr, \ 454fb567a8eSTakashi Iwai .tlv = { .p = db_scale_dummy } } 4551da177e4SLinus Torvalds 4564a4d2cfdSTakashi Iwai static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, 4574a4d2cfdSTakashi Iwai struct snd_ctl_elem_info *uinfo) 4581da177e4SLinus Torvalds { 4591da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 4601da177e4SLinus Torvalds uinfo->count = 2; 4611da177e4SLinus Torvalds uinfo->value.integer.min = -50; 4621da177e4SLinus Torvalds uinfo->value.integer.max = 100; 4631da177e4SLinus Torvalds return 0; 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 4664a4d2cfdSTakashi Iwai static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, 4674a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 4681da177e4SLinus Torvalds { 4694a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 4701da177e4SLinus Torvalds int addr = kcontrol->private_value; 4711da177e4SLinus Torvalds 472c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 4731da177e4SLinus Torvalds ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; 4741da177e4SLinus Torvalds ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; 475c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 4761da177e4SLinus Torvalds return 0; 4771da177e4SLinus Torvalds } 4781da177e4SLinus Torvalds 4794a4d2cfdSTakashi Iwai static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, 4804a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 4811da177e4SLinus Torvalds { 4824a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 4831da177e4SLinus Torvalds int change, addr = kcontrol->private_value; 4841da177e4SLinus Torvalds int left, right; 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds left = ucontrol->value.integer.value[0]; 4871da177e4SLinus Torvalds if (left < -50) 4881da177e4SLinus Torvalds left = -50; 4891da177e4SLinus Torvalds if (left > 100) 4901da177e4SLinus Torvalds left = 100; 4911da177e4SLinus Torvalds right = ucontrol->value.integer.value[1]; 4921da177e4SLinus Torvalds if (right < -50) 4931da177e4SLinus Torvalds right = -50; 4941da177e4SLinus Torvalds if (right > 100) 4951da177e4SLinus Torvalds right = 100; 496c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 4971da177e4SLinus Torvalds change = dummy->mixer_volume[addr][0] != left || 4981da177e4SLinus Torvalds dummy->mixer_volume[addr][1] != right; 4991da177e4SLinus Torvalds dummy->mixer_volume[addr][0] = left; 5001da177e4SLinus Torvalds dummy->mixer_volume[addr][1] = right; 501c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5021da177e4SLinus Torvalds return change; 5031da177e4SLinus Torvalds } 5041da177e4SLinus Torvalds 5050cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0); 506fb567a8eSTakashi Iwai 5071da177e4SLinus Torvalds #define DUMMY_CAPSRC(xname, xindex, addr) \ 5081da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 5091da177e4SLinus Torvalds .info = snd_dummy_capsrc_info, \ 5101da177e4SLinus Torvalds .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ 5111da177e4SLinus Torvalds .private_value = addr } 5121da177e4SLinus Torvalds 513a5ce8890STakashi Iwai #define snd_dummy_capsrc_info snd_ctl_boolean_stereo_info 5141da177e4SLinus Torvalds 5154a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, 5164a4d2cfdSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 5171da177e4SLinus Torvalds { 5184a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 5191da177e4SLinus Torvalds int addr = kcontrol->private_value; 5201da177e4SLinus Torvalds 521c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 5221da177e4SLinus Torvalds ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; 5231da177e4SLinus Torvalds ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; 524c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5251da177e4SLinus Torvalds return 0; 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds 5284a4d2cfdSTakashi Iwai static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 5291da177e4SLinus Torvalds { 5304a4d2cfdSTakashi Iwai struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); 5311da177e4SLinus Torvalds int change, addr = kcontrol->private_value; 5321da177e4SLinus Torvalds int left, right; 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds left = ucontrol->value.integer.value[0] & 1; 5351da177e4SLinus Torvalds right = ucontrol->value.integer.value[1] & 1; 536c8eb6ba1STakashi Iwai spin_lock_irq(&dummy->mixer_lock); 5371da177e4SLinus Torvalds change = dummy->capture_source[addr][0] != left && 5381da177e4SLinus Torvalds dummy->capture_source[addr][1] != right; 5391da177e4SLinus Torvalds dummy->capture_source[addr][0] = left; 5401da177e4SLinus Torvalds dummy->capture_source[addr][1] = right; 541c8eb6ba1STakashi Iwai spin_unlock_irq(&dummy->mixer_lock); 5421da177e4SLinus Torvalds return change; 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds 5454a4d2cfdSTakashi Iwai static struct snd_kcontrol_new snd_dummy_controls[] = { 5461da177e4SLinus Torvalds DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), 5471da177e4SLinus Torvalds DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), 5481da177e4SLinus Torvalds DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), 549e05d6964STakashi Iwai DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH), 5501da177e4SLinus Torvalds DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), 551e05d6964STakashi Iwai DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE), 5521da177e4SLinus Torvalds DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), 553e05d6964STakashi Iwai DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC), 5541da177e4SLinus Torvalds DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), 555e05d6964STakashi Iwai DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD) 5561da177e4SLinus Torvalds }; 5571da177e4SLinus Torvalds 558788c6043SPrarit Bhargava static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy) 5591da177e4SLinus Torvalds { 5604a4d2cfdSTakashi Iwai struct snd_card *card = dummy->card; 5611da177e4SLinus Torvalds unsigned int idx; 5621da177e4SLinus Torvalds int err; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds snd_assert(dummy != NULL, return -EINVAL); 5651da177e4SLinus Torvalds spin_lock_init(&dummy->mixer_lock); 5661da177e4SLinus Torvalds strcpy(card->mixername, "Dummy Mixer"); 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { 5691da177e4SLinus Torvalds if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0) 5701da177e4SLinus Torvalds return err; 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds return 0; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 575788c6043SPrarit Bhargava static int __devinit snd_dummy_probe(struct platform_device *devptr) 5761da177e4SLinus Torvalds { 5774a4d2cfdSTakashi Iwai struct snd_card *card; 5784a4d2cfdSTakashi Iwai struct snd_dummy *dummy; 5791da177e4SLinus Torvalds int idx, err; 5806e65c1ccSTakashi Iwai int dev = devptr->id; 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds card = snd_card_new(index[dev], id[dev], THIS_MODULE, 5834a4d2cfdSTakashi Iwai sizeof(struct snd_dummy)); 5841da177e4SLinus Torvalds if (card == NULL) 5851da177e4SLinus Torvalds return -ENOMEM; 5864a4d2cfdSTakashi Iwai dummy = card->private_data; 5871da177e4SLinus Torvalds dummy->card = card; 5881da177e4SLinus Torvalds for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { 5891da177e4SLinus Torvalds if (pcm_substreams[dev] < 1) 5901da177e4SLinus Torvalds pcm_substreams[dev] = 1; 5911da177e4SLinus Torvalds if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) 5921da177e4SLinus Torvalds pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; 5931da177e4SLinus Torvalds if ((err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev])) < 0) 5941da177e4SLinus Torvalds goto __nodev; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds if ((err = snd_card_dummy_new_mixer(dummy)) < 0) 5971da177e4SLinus Torvalds goto __nodev; 5981da177e4SLinus Torvalds strcpy(card->driver, "Dummy"); 5991da177e4SLinus Torvalds strcpy(card->shortname, "Dummy"); 6001da177e4SLinus Torvalds sprintf(card->longname, "Dummy %i", dev + 1); 60116dab54bSTakashi Iwai 6026e65c1ccSTakashi Iwai snd_card_set_dev(card, &devptr->dev); 60316dab54bSTakashi Iwai 6041da177e4SLinus Torvalds if ((err = snd_card_register(card)) == 0) { 6056e65c1ccSTakashi Iwai platform_set_drvdata(devptr, card); 6061da177e4SLinus Torvalds return 0; 6071da177e4SLinus Torvalds } 6081da177e4SLinus Torvalds __nodev: 6091da177e4SLinus Torvalds snd_card_free(card); 6101da177e4SLinus Torvalds return err; 6111da177e4SLinus Torvalds } 6121da177e4SLinus Torvalds 613788c6043SPrarit Bhargava static int __devexit snd_dummy_remove(struct platform_device *devptr) 6146e65c1ccSTakashi Iwai { 6156e65c1ccSTakashi Iwai snd_card_free(platform_get_drvdata(devptr)); 6166e65c1ccSTakashi Iwai platform_set_drvdata(devptr, NULL); 6176e65c1ccSTakashi Iwai return 0; 6186e65c1ccSTakashi Iwai } 6196e65c1ccSTakashi Iwai 6206e65c1ccSTakashi Iwai #ifdef CONFIG_PM 6216e65c1ccSTakashi Iwai static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state) 6226e65c1ccSTakashi Iwai { 6236e65c1ccSTakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 6246e65c1ccSTakashi Iwai struct snd_dummy *dummy = card->private_data; 6256e65c1ccSTakashi Iwai 6266e65c1ccSTakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 6276e65c1ccSTakashi Iwai snd_pcm_suspend_all(dummy->pcm); 6286e65c1ccSTakashi Iwai return 0; 6296e65c1ccSTakashi Iwai } 6306e65c1ccSTakashi Iwai 6316e65c1ccSTakashi Iwai static int snd_dummy_resume(struct platform_device *pdev) 6326e65c1ccSTakashi Iwai { 6336e65c1ccSTakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 6346e65c1ccSTakashi Iwai 6356e65c1ccSTakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0); 6366e65c1ccSTakashi Iwai return 0; 6376e65c1ccSTakashi Iwai } 6386e65c1ccSTakashi Iwai #endif 6396e65c1ccSTakashi Iwai 6406e65c1ccSTakashi Iwai #define SND_DUMMY_DRIVER "snd_dummy" 6416e65c1ccSTakashi Iwai 6426e65c1ccSTakashi Iwai static struct platform_driver snd_dummy_driver = { 6436e65c1ccSTakashi Iwai .probe = snd_dummy_probe, 644788c6043SPrarit Bhargava .remove = __devexit_p(snd_dummy_remove), 6456e65c1ccSTakashi Iwai #ifdef CONFIG_PM 6466e65c1ccSTakashi Iwai .suspend = snd_dummy_suspend, 6476e65c1ccSTakashi Iwai .resume = snd_dummy_resume, 6486e65c1ccSTakashi Iwai #endif 6496e65c1ccSTakashi Iwai .driver = { 6506e65c1ccSTakashi Iwai .name = SND_DUMMY_DRIVER 6516e65c1ccSTakashi Iwai }, 6526e65c1ccSTakashi Iwai }; 6536e65c1ccSTakashi Iwai 654c12aad6eSRandy Dunlap static void snd_dummy_unregister_all(void) 655f7a9275dSClemens Ladisch { 656f7a9275dSClemens Ladisch int i; 657f7a9275dSClemens Ladisch 658f7a9275dSClemens Ladisch for (i = 0; i < ARRAY_SIZE(devices); ++i) 659f7a9275dSClemens Ladisch platform_device_unregister(devices[i]); 660f7a9275dSClemens Ladisch platform_driver_unregister(&snd_dummy_driver); 661f7a9275dSClemens Ladisch } 662f7a9275dSClemens Ladisch 6631da177e4SLinus Torvalds static int __init alsa_card_dummy_init(void) 6641da177e4SLinus Torvalds { 6656e65c1ccSTakashi Iwai int i, cards, err; 6661da177e4SLinus Torvalds 6676e65c1ccSTakashi Iwai if ((err = platform_driver_register(&snd_dummy_driver)) < 0) 6686e65c1ccSTakashi Iwai return err; 6696e65c1ccSTakashi Iwai 6706e65c1ccSTakashi Iwai cards = 0; 6718278ca8fSTakashi Iwai for (i = 0; i < SNDRV_CARDS; i++) { 6726e65c1ccSTakashi Iwai struct platform_device *device; 6738278ca8fSTakashi Iwai if (! enable[i]) 6748278ca8fSTakashi Iwai continue; 6756e65c1ccSTakashi Iwai device = platform_device_register_simple(SND_DUMMY_DRIVER, 6766e65c1ccSTakashi Iwai i, NULL, 0); 677a182ee98SRene Herman if (IS_ERR(device)) 678a182ee98SRene Herman continue; 6797152447dSRene Herman if (!platform_get_drvdata(device)) { 6807152447dSRene Herman platform_device_unregister(device); 6817152447dSRene Herman continue; 6827152447dSRene Herman } 683f7a9275dSClemens Ladisch devices[i] = device; 6841da177e4SLinus Torvalds cards++; 6851da177e4SLinus Torvalds } 6861da177e4SLinus Torvalds if (!cards) { 6871da177e4SLinus Torvalds #ifdef MODULE 6881da177e4SLinus Torvalds printk(KERN_ERR "Dummy soundcard not found or device busy\n"); 6891da177e4SLinus Torvalds #endif 690a182ee98SRene Herman snd_dummy_unregister_all(); 691a182ee98SRene Herman return -ENODEV; 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds return 0; 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds static void __exit alsa_card_dummy_exit(void) 6971da177e4SLinus Torvalds { 698f7a9275dSClemens Ladisch snd_dummy_unregister_all(); 6991da177e4SLinus Torvalds } 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds module_init(alsa_card_dummy_init) 7021da177e4SLinus Torvalds module_exit(alsa_card_dummy_exit) 703