| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Dummy soundcard | 
 | 3 |  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz> | 
 | 4 |  * | 
 | 5 |  *   This program is free software; you can redistribute it and/or modify | 
 | 6 |  *   it under the terms of the GNU General Public License as published by | 
 | 7 |  *   the Free Software Foundation; either version 2 of the License, or | 
 | 8 |  *   (at your option) any later version. | 
 | 9 |  * | 
 | 10 |  *   This program is distributed in the hope that it will be useful, | 
 | 11 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 12 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 13 |  *   GNU General Public License for more details. | 
 | 14 |  * | 
 | 15 |  *   You should have received a copy of the GNU General Public License | 
 | 16 |  *   along with this program; if not, write to the Free Software | 
 | 17 |  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
 | 18 |  * | 
 | 19 |  */ | 
 | 20 |  | 
 | 21 | #include <sound/driver.h> | 
 | 22 | #include <linux/init.h> | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 23 | #include <linux/err.h> | 
 | 24 | #include <linux/platform_device.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/jiffies.h> | 
 | 26 | #include <linux/slab.h> | 
 | 27 | #include <linux/time.h> | 
 | 28 | #include <linux/wait.h> | 
 | 29 | #include <linux/moduleparam.h> | 
 | 30 | #include <sound/core.h> | 
 | 31 | #include <sound/control.h> | 
 | 32 | #include <sound/pcm.h> | 
 | 33 | #include <sound/rawmidi.h> | 
 | 34 | #include <sound/initval.h> | 
 | 35 |  | 
 | 36 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | 
 | 37 | MODULE_DESCRIPTION("Dummy soundcard (/dev/null)"); | 
 | 38 | MODULE_LICENSE("GPL"); | 
 | 39 | MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}"); | 
 | 40 |  | 
 | 41 | #define MAX_PCM_DEVICES		4 | 
 | 42 | #define MAX_PCM_SUBSTREAMS	16 | 
 | 43 | #define MAX_MIDI_DEVICES	2 | 
 | 44 |  | 
 | 45 | #if 0 /* emu10k1 emulation */ | 
 | 46 | #define MAX_BUFFER_SIZE		(128 * 1024) | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 47 | static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { | 
 | 49 | 	int err; | 
 | 50 | 	if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) | 
 | 51 | 		return err; | 
 | 52 | 	if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) | 
 | 53 | 		return err; | 
 | 54 | 	return 0; | 
 | 55 | } | 
 | 56 | #define add_playback_constraints emu10k1_playback_constraints | 
 | 57 | #endif | 
 | 58 |  | 
 | 59 | #if 0 /* RME9652 emulation */ | 
 | 60 | #define MAX_BUFFER_SIZE		(26 * 64 * 1024) | 
 | 61 | #define USE_FORMATS		SNDRV_PCM_FMTBIT_S32_LE | 
 | 62 | #define USE_CHANNELS_MIN	26 | 
 | 63 | #define USE_CHANNELS_MAX	26 | 
 | 64 | #define USE_PERIODS_MIN		2 | 
 | 65 | #define USE_PERIODS_MAX		2 | 
 | 66 | #endif | 
 | 67 |  | 
 | 68 | #if 0 /* ICE1712 emulation */ | 
 | 69 | #define MAX_BUFFER_SIZE		(256 * 1024) | 
 | 70 | #define USE_FORMATS		SNDRV_PCM_FMTBIT_S32_LE | 
 | 71 | #define USE_CHANNELS_MIN	10 | 
 | 72 | #define USE_CHANNELS_MAX	10 | 
 | 73 | #define USE_PERIODS_MIN		1 | 
 | 74 | #define USE_PERIODS_MAX		1024 | 
 | 75 | #endif | 
 | 76 |  | 
 | 77 | #if 0 /* UDA1341 emulation */ | 
 | 78 | #define MAX_BUFFER_SIZE		(16380) | 
 | 79 | #define USE_FORMATS		SNDRV_PCM_FMTBIT_S16_LE | 
 | 80 | #define USE_CHANNELS_MIN	2 | 
 | 81 | #define USE_CHANNELS_MAX	2 | 
 | 82 | #define USE_PERIODS_MIN		2 | 
 | 83 | #define USE_PERIODS_MAX		255 | 
 | 84 | #endif | 
 | 85 |  | 
 | 86 | #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */ | 
 | 87 | #define USE_FORMATS		SNDRV_PCM_FMTBIT_S16_LE | 
 | 88 | #define USE_CHANNELS_MIN	2 | 
 | 89 | #define USE_CHANNELS_MAX	2 | 
 | 90 | #define USE_RATE		SNDRV_PCM_RATE_48000 | 
 | 91 | #define USE_RATE_MIN		48000 | 
 | 92 | #define USE_RATE_MAX		48000 | 
 | 93 | #endif | 
 | 94 |  | 
| Jaroslav Kysela | 2ad5dd8 | 2006-01-03 14:27:21 +0100 | [diff] [blame] | 95 | #if 0 /* CA0106 */ | 
 | 96 | #define USE_FORMATS		SNDRV_PCM_FMTBIT_S16_LE | 
 | 97 | #define USE_CHANNELS_MIN	2 | 
 | 98 | #define USE_CHANNELS_MAX	2 | 
 | 99 | #define USE_RATE		(SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000)  | 
 | 100 | #define USE_RATE_MIN		48000  | 
 | 101 | #define USE_RATE_MAX		192000 | 
 | 102 | #define MAX_BUFFER_SIZE		((65536-64)*8) | 
 | 103 | #define MAX_PERIOD_SIZE		(65536-64) | 
 | 104 | #define USE_PERIODS_MIN		2 | 
 | 105 | #define USE_PERIODS_MAX		8 | 
 | 106 | #endif | 
 | 107 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
 | 109 | /* defaults */ | 
 | 110 | #ifndef MAX_BUFFER_SIZE | 
 | 111 | #define MAX_BUFFER_SIZE		(64*1024) | 
 | 112 | #endif | 
| Jaroslav Kysela | 2ad5dd8 | 2006-01-03 14:27:21 +0100 | [diff] [blame] | 113 | #ifndef MAX_PERIOD_SIZE | 
 | 114 | #define MAX_PERIOD_SIZE		MAX_BUFFER_SIZE | 
 | 115 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #ifndef USE_FORMATS | 
 | 117 | #define USE_FORMATS 		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE) | 
 | 118 | #endif | 
 | 119 | #ifndef USE_RATE | 
 | 120 | #define USE_RATE		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 | 
 | 121 | #define USE_RATE_MIN		5500 | 
 | 122 | #define USE_RATE_MAX		48000 | 
 | 123 | #endif | 
 | 124 | #ifndef USE_CHANNELS_MIN | 
 | 125 | #define USE_CHANNELS_MIN 	1 | 
 | 126 | #endif | 
 | 127 | #ifndef USE_CHANNELS_MAX | 
 | 128 | #define USE_CHANNELS_MAX 	2 | 
 | 129 | #endif | 
 | 130 | #ifndef USE_PERIODS_MIN | 
 | 131 | #define USE_PERIODS_MIN 	1 | 
 | 132 | #endif | 
 | 133 | #ifndef USE_PERIODS_MAX | 
 | 134 | #define USE_PERIODS_MAX 	1024 | 
 | 135 | #endif | 
 | 136 | #ifndef add_playback_constraints | 
 | 137 | #define add_playback_constraints(x) 0 | 
 | 138 | #endif | 
 | 139 | #ifndef add_capture_constraints | 
 | 140 | #define add_capture_constraints(x) 0 | 
 | 141 | #endif | 
 | 142 |  | 
 | 143 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */ | 
 | 144 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ | 
 | 145 | static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; | 
 | 146 | static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; | 
 | 147 | static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; | 
 | 148 | //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; | 
 | 149 |  | 
 | 150 | module_param_array(index, int, NULL, 0444); | 
 | 151 | MODULE_PARM_DESC(index, "Index value for dummy soundcard."); | 
 | 152 | module_param_array(id, charp, NULL, 0444); | 
 | 153 | MODULE_PARM_DESC(id, "ID string for dummy soundcard."); | 
 | 154 | module_param_array(enable, bool, NULL, 0444); | 
 | 155 | MODULE_PARM_DESC(enable, "Enable this dummy soundcard."); | 
 | 156 | module_param_array(pcm_devs, int, NULL, 0444); | 
 | 157 | MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver."); | 
 | 158 | module_param_array(pcm_substreams, int, NULL, 0444); | 
 | 159 | MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver."); | 
 | 160 | //module_param_array(midi_devs, int, NULL, 0444); | 
 | 161 | //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); | 
 | 162 |  | 
| Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 163 | static struct platform_device *devices[SNDRV_CARDS]; | 
 | 164 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #define MIXER_ADDR_MASTER	0 | 
 | 166 | #define MIXER_ADDR_LINE		1 | 
 | 167 | #define MIXER_ADDR_MIC		2 | 
 | 168 | #define MIXER_ADDR_SYNTH	3 | 
 | 169 | #define MIXER_ADDR_CD		4 | 
 | 170 | #define MIXER_ADDR_LAST		4 | 
 | 171 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 172 | struct snd_dummy { | 
 | 173 | 	struct snd_card *card; | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 174 | 	struct snd_pcm *pcm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | 	spinlock_t mixer_lock; | 
 | 176 | 	int mixer_volume[MIXER_ADDR_LAST+1][2]; | 
 | 177 | 	int capture_source[MIXER_ADDR_LAST+1][2]; | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 178 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 180 | struct snd_dummy_pcm { | 
 | 181 | 	struct snd_dummy *dummy; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | 	spinlock_t lock; | 
 | 183 | 	struct timer_list timer; | 
 | 184 | 	unsigned int pcm_size; | 
 | 185 | 	unsigned int pcm_count; | 
 | 186 | 	unsigned int pcm_bps;		/* bytes per second */ | 
 | 187 | 	unsigned int pcm_jiffie;	/* bytes per one jiffie */ | 
 | 188 | 	unsigned int pcm_irq_pos;	/* IRQ position */ | 
 | 189 | 	unsigned int pcm_buf_pos;	/* position in buffer */ | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 190 | 	struct snd_pcm_substream *substream; | 
 | 191 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 194 | static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | 	dpcm->timer.expires = 1 + jiffies; | 
 | 197 | 	add_timer(&dpcm->timer); | 
 | 198 | } | 
 | 199 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 200 | static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | 	del_timer(&dpcm->timer); | 
 | 203 | } | 
 | 204 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 205 | static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 207 | 	struct snd_pcm_runtime *runtime = substream->runtime; | 
 | 208 | 	struct snd_dummy_pcm *dpcm = runtime->private_data; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 209 | 	int err = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 |  | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 211 | 	spin_lock(&dpcm->lock); | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 212 | 	switch (cmd) { | 
 | 213 | 	case SNDRV_PCM_TRIGGER_START: | 
 | 214 | 	case SNDRV_PCM_TRIGGER_RESUME: | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 215 | 		snd_card_dummy_pcm_timer_start(dpcm); | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 216 | 		break; | 
 | 217 | 	case SNDRV_PCM_TRIGGER_STOP: | 
 | 218 | 	case SNDRV_PCM_TRIGGER_SUSPEND: | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 219 | 		snd_card_dummy_pcm_timer_stop(dpcm); | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 220 | 		break; | 
 | 221 | 	default: | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 222 | 		err = -EINVAL; | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 223 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | 	} | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 225 | 	spin_unlock(&dpcm->lock); | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 226 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } | 
 | 228 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 229 | static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 231 | 	struct snd_pcm_runtime *runtime = substream->runtime; | 
 | 232 | 	struct snd_dummy_pcm *dpcm = runtime->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | 	unsigned int bps; | 
 | 234 |  | 
 | 235 | 	bps = runtime->rate * runtime->channels; | 
 | 236 | 	bps *= snd_pcm_format_width(runtime->format); | 
 | 237 | 	bps /= 8; | 
 | 238 | 	if (bps <= 0) | 
 | 239 | 		return -EINVAL; | 
 | 240 | 	dpcm->pcm_bps = bps; | 
 | 241 | 	dpcm->pcm_jiffie = bps / HZ; | 
 | 242 | 	dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); | 
 | 243 | 	dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); | 
 | 244 | 	dpcm->pcm_irq_pos = 0; | 
 | 245 | 	dpcm->pcm_buf_pos = 0; | 
 | 246 | 	return 0; | 
 | 247 | } | 
 | 248 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | static void snd_card_dummy_pcm_timer_function(unsigned long data) | 
 | 250 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 251 | 	struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; | 
| Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 252 | 	unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | 	 | 
| Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 254 | 	spin_lock_irqsave(&dpcm->lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | 	dpcm->timer.expires = 1 + jiffies; | 
 | 256 | 	add_timer(&dpcm->timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | 	dpcm->pcm_irq_pos += dpcm->pcm_jiffie; | 
 | 258 | 	dpcm->pcm_buf_pos += dpcm->pcm_jiffie; | 
 | 259 | 	dpcm->pcm_buf_pos %= dpcm->pcm_size; | 
 | 260 | 	if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { | 
 | 261 | 		dpcm->pcm_irq_pos %= dpcm->pcm_count; | 
| Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 262 | 		spin_unlock_irqrestore(&dpcm->lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | 		snd_pcm_period_elapsed(dpcm->substream); | 
| Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 264 | 	} else | 
 | 265 | 		spin_unlock_irqrestore(&dpcm->lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } | 
 | 267 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 268 | static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 270 | 	struct snd_pcm_runtime *runtime = substream->runtime; | 
 | 271 | 	struct snd_dummy_pcm *dpcm = runtime->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 |  | 
 | 273 | 	return bytes_to_frames(runtime, dpcm->pcm_buf_pos); | 
 | 274 | } | 
 | 275 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 276 | static struct snd_pcm_hardware snd_card_dummy_playback = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { | 
 | 278 | 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 279 | 				 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | 	.formats =		USE_FORMATS, | 
 | 281 | 	.rates =		USE_RATE, | 
 | 282 | 	.rate_min =		USE_RATE_MIN, | 
 | 283 | 	.rate_max =		USE_RATE_MAX, | 
 | 284 | 	.channels_min =		USE_CHANNELS_MIN, | 
 | 285 | 	.channels_max =		USE_CHANNELS_MAX, | 
 | 286 | 	.buffer_bytes_max =	MAX_BUFFER_SIZE, | 
 | 287 | 	.period_bytes_min =	64, | 
 | 288 | 	.period_bytes_max =	MAX_BUFFER_SIZE, | 
 | 289 | 	.periods_min =		USE_PERIODS_MIN, | 
 | 290 | 	.periods_max =		USE_PERIODS_MAX, | 
 | 291 | 	.fifo_size =		0, | 
 | 292 | }; | 
 | 293 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 294 | static struct snd_pcm_hardware snd_card_dummy_capture = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { | 
 | 296 | 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 297 | 				 SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | 	.formats =		USE_FORMATS, | 
 | 299 | 	.rates =		USE_RATE, | 
 | 300 | 	.rate_min =		USE_RATE_MIN, | 
 | 301 | 	.rate_max =		USE_RATE_MAX, | 
 | 302 | 	.channels_min =		USE_CHANNELS_MIN, | 
 | 303 | 	.channels_max =		USE_CHANNELS_MAX, | 
 | 304 | 	.buffer_bytes_max =	MAX_BUFFER_SIZE, | 
 | 305 | 	.period_bytes_min =	64, | 
| Jaroslav Kysela | 2ad5dd8 | 2006-01-03 14:27:21 +0100 | [diff] [blame] | 306 | 	.period_bytes_max =	MAX_PERIOD_SIZE, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 	.periods_min =		USE_PERIODS_MIN, | 
 | 308 | 	.periods_max =		USE_PERIODS_MAX, | 
 | 309 | 	.fifo_size =		0, | 
 | 310 | }; | 
 | 311 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 312 | static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 314 | 	kfree(runtime->private_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } | 
 | 316 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 317 | static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream, | 
 | 318 | 				    struct snd_pcm_hw_params *hw_params) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { | 
 | 320 | 	return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); | 
 | 321 | } | 
 | 322 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 323 | static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { | 
 | 325 | 	return snd_pcm_lib_free_pages(substream); | 
 | 326 | } | 
 | 327 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 328 | static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 329 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 330 | 	struct snd_dummy_pcm *dpcm; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 331 |  | 
 | 332 | 	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); | 
 | 333 | 	if (! dpcm) | 
 | 334 | 		return dpcm; | 
 | 335 | 	init_timer(&dpcm->timer); | 
 | 336 | 	dpcm->timer.data = (unsigned long) dpcm; | 
 | 337 | 	dpcm->timer.function = snd_card_dummy_pcm_timer_function; | 
 | 338 | 	spin_lock_init(&dpcm->lock); | 
 | 339 | 	dpcm->substream = substream; | 
 | 340 | 	return dpcm; | 
 | 341 | } | 
 | 342 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 343 | static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 345 | 	struct snd_pcm_runtime *runtime = substream->runtime; | 
 | 346 | 	struct snd_dummy_pcm *dpcm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | 	int err; | 
 | 348 |  | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 349 | 	if ((dpcm = new_pcm_stream(substream)) == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | 	runtime->private_data = dpcm; | 
 | 352 | 	runtime->private_free = snd_card_dummy_runtime_free; | 
 | 353 | 	runtime->hw = snd_card_dummy_playback; | 
 | 354 | 	if (substream->pcm->device & 1) { | 
 | 355 | 		runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; | 
 | 356 | 		runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; | 
 | 357 | 	} | 
 | 358 | 	if (substream->pcm->device & 2) | 
 | 359 | 		runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); | 
 | 360 | 	if ((err = add_playback_constraints(runtime)) < 0) { | 
 | 361 | 		kfree(dpcm); | 
 | 362 | 		return err; | 
 | 363 | 	} | 
 | 364 |  | 
 | 365 | 	return 0; | 
 | 366 | } | 
 | 367 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 368 | static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 370 | 	struct snd_pcm_runtime *runtime = substream->runtime; | 
 | 371 | 	struct snd_dummy_pcm *dpcm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | 	int err; | 
 | 373 |  | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 374 | 	if ((dpcm = new_pcm_stream(substream)) == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | 	runtime->private_data = dpcm; | 
 | 377 | 	runtime->private_free = snd_card_dummy_runtime_free; | 
 | 378 | 	runtime->hw = snd_card_dummy_capture; | 
 | 379 | 	if (substream->pcm->device == 1) { | 
 | 380 | 		runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; | 
 | 381 | 		runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; | 
 | 382 | 	} | 
 | 383 | 	if (substream->pcm->device & 2) | 
 | 384 | 		runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID); | 
 | 385 | 	if ((err = add_capture_constraints(runtime)) < 0) { | 
 | 386 | 		kfree(dpcm); | 
 | 387 | 		return err; | 
 | 388 | 	} | 
 | 389 |  | 
 | 390 | 	return 0; | 
 | 391 | } | 
 | 392 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 393 | static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { | 
 | 395 | 	return 0; | 
 | 396 | } | 
 | 397 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 398 | static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { | 
 | 400 | 	return 0; | 
 | 401 | } | 
 | 402 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 403 | static struct snd_pcm_ops snd_card_dummy_playback_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | 	.open =			snd_card_dummy_playback_open, | 
 | 405 | 	.close =		snd_card_dummy_playback_close, | 
 | 406 | 	.ioctl =		snd_pcm_lib_ioctl, | 
 | 407 | 	.hw_params =		snd_card_dummy_hw_params, | 
 | 408 | 	.hw_free =		snd_card_dummy_hw_free, | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 409 | 	.prepare =		snd_card_dummy_pcm_prepare, | 
 | 410 | 	.trigger =		snd_card_dummy_pcm_trigger, | 
 | 411 | 	.pointer =		snd_card_dummy_pcm_pointer, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | }; | 
 | 413 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 414 | static struct snd_pcm_ops snd_card_dummy_capture_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | 	.open =			snd_card_dummy_capture_open, | 
 | 416 | 	.close =		snd_card_dummy_capture_close, | 
 | 417 | 	.ioctl =		snd_pcm_lib_ioctl, | 
 | 418 | 	.hw_params =		snd_card_dummy_hw_params, | 
 | 419 | 	.hw_free =		snd_card_dummy_hw_free, | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 420 | 	.prepare =		snd_card_dummy_pcm_prepare, | 
 | 421 | 	.trigger =		snd_card_dummy_pcm_trigger, | 
 | 422 | 	.pointer =		snd_card_dummy_pcm_pointer, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | }; | 
 | 424 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 425 | static int __init snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 427 | 	struct snd_pcm *pcm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | 	int err; | 
 | 429 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 430 | 	if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device, | 
 | 431 | 			       substreams, substreams, &pcm)) < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | 		return err; | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 433 | 	dummy->pcm = pcm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops); | 
 | 435 | 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops); | 
 | 436 | 	pcm->private_data = dummy; | 
 | 437 | 	pcm->info_flags = 0; | 
 | 438 | 	strcpy(pcm->name, "Dummy PCM"); | 
 | 439 | 	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, | 
 | 440 | 					      snd_dma_continuous_data(GFP_KERNEL), | 
 | 441 | 					      0, 64*1024); | 
 | 442 | 	return 0; | 
 | 443 | } | 
 | 444 |  | 
 | 445 | #define DUMMY_VOLUME(xname, xindex, addr) \ | 
 | 446 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | 
 | 447 |   .info = snd_dummy_volume_info, \ | 
 | 448 |   .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ | 
 | 449 |   .private_value = addr } | 
 | 450 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 451 | static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, | 
 | 452 | 				 struct snd_ctl_elem_info *uinfo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { | 
 | 454 | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
 | 455 | 	uinfo->count = 2; | 
 | 456 | 	uinfo->value.integer.min = -50; | 
 | 457 | 	uinfo->value.integer.max = 100; | 
 | 458 | 	return 0; | 
 | 459 | } | 
 | 460 |   | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 461 | static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, | 
 | 462 | 				struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 464 | 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | 	int addr = kcontrol->private_value; | 
 | 466 |  | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 467 | 	spin_lock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | 	ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; | 
 | 469 | 	ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 470 | 	spin_unlock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | 	return 0; | 
 | 472 | } | 
 | 473 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 474 | static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, | 
 | 475 | 				struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 477 | 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | 	int change, addr = kcontrol->private_value; | 
 | 479 | 	int left, right; | 
 | 480 |  | 
 | 481 | 	left = ucontrol->value.integer.value[0]; | 
 | 482 | 	if (left < -50) | 
 | 483 | 		left = -50; | 
 | 484 | 	if (left > 100) | 
 | 485 | 		left = 100; | 
 | 486 | 	right = ucontrol->value.integer.value[1]; | 
 | 487 | 	if (right < -50) | 
 | 488 | 		right = -50; | 
 | 489 | 	if (right > 100) | 
 | 490 | 		right = 100; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 491 | 	spin_lock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | 	change = dummy->mixer_volume[addr][0] != left || | 
 | 493 | 	         dummy->mixer_volume[addr][1] != right; | 
 | 494 | 	dummy->mixer_volume[addr][0] = left; | 
 | 495 | 	dummy->mixer_volume[addr][1] = right; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 496 | 	spin_unlock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | 	return change; | 
 | 498 | } | 
 | 499 |  | 
 | 500 | #define DUMMY_CAPSRC(xname, xindex, addr) \ | 
 | 501 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | 
 | 502 |   .info = snd_dummy_capsrc_info, \ | 
 | 503 |   .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ | 
 | 504 |   .private_value = addr } | 
 | 505 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 506 | static int snd_dummy_capsrc_info(struct snd_kcontrol *kcontrol, | 
 | 507 | 				 struct snd_ctl_elem_info *uinfo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { | 
 | 509 | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | 
 | 510 | 	uinfo->count = 2; | 
 | 511 | 	uinfo->value.integer.min = 0; | 
 | 512 | 	uinfo->value.integer.max = 1; | 
 | 513 | 	return 0; | 
 | 514 | } | 
 | 515 |   | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 516 | static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, | 
 | 517 | 				struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 519 | 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | 	int addr = kcontrol->private_value; | 
 | 521 |  | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 522 | 	spin_lock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | 	ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; | 
 | 524 | 	ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 525 | 	spin_unlock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | 	return 0; | 
 | 527 | } | 
 | 528 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 529 | static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 531 | 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | 	int change, addr = kcontrol->private_value; | 
 | 533 | 	int left, right; | 
 | 534 |  | 
 | 535 | 	left = ucontrol->value.integer.value[0] & 1; | 
 | 536 | 	right = ucontrol->value.integer.value[1] & 1; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 537 | 	spin_lock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | 	change = dummy->capture_source[addr][0] != left && | 
 | 539 | 	         dummy->capture_source[addr][1] != right; | 
 | 540 | 	dummy->capture_source[addr][0] = left; | 
 | 541 | 	dummy->capture_source[addr][1] = right; | 
| Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 542 | 	spin_unlock_irq(&dummy->mixer_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | 	return change; | 
 | 544 | } | 
 | 545 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 546 | static struct snd_kcontrol_new snd_dummy_controls[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), | 
 | 548 | DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), | 
 | 549 | DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), | 
 | 550 | DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_MASTER), | 
 | 551 | DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), | 
 | 552 | DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_MASTER), | 
 | 553 | DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), | 
 | 554 | DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MASTER), | 
 | 555 | DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), | 
 | 556 | DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER) | 
 | 557 | }; | 
 | 558 |  | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 559 | static int __init snd_card_dummy_new_mixer(struct snd_dummy *dummy) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 561 | 	struct snd_card *card = dummy->card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | 	unsigned int idx; | 
 | 563 | 	int err; | 
 | 564 |  | 
 | 565 | 	snd_assert(dummy != NULL, return -EINVAL); | 
 | 566 | 	spin_lock_init(&dummy->mixer_lock); | 
 | 567 | 	strcpy(card->mixername, "Dummy Mixer"); | 
 | 568 |  | 
 | 569 | 	for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { | 
 | 570 | 		if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0) | 
 | 571 | 			return err; | 
 | 572 | 	} | 
 | 573 | 	return 0; | 
 | 574 | } | 
 | 575 |  | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 576 | static int __init snd_dummy_probe(struct platform_device *devptr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 578 | 	struct snd_card *card; | 
 | 579 | 	struct snd_dummy *dummy; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | 	int idx, err; | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 581 | 	int dev = devptr->id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | 	card = snd_card_new(index[dev], id[dev], THIS_MODULE, | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 584 | 			    sizeof(struct snd_dummy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 	if (card == NULL) | 
 | 586 | 		return -ENOMEM; | 
| Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 587 | 	dummy = card->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | 	dummy->card = card; | 
 | 589 | 	for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { | 
 | 590 | 		if (pcm_substreams[dev] < 1) | 
 | 591 | 			pcm_substreams[dev] = 1; | 
 | 592 | 		if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) | 
 | 593 | 			pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; | 
 | 594 | 		if ((err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev])) < 0) | 
 | 595 | 			goto __nodev; | 
 | 596 | 	} | 
 | 597 | 	if ((err = snd_card_dummy_new_mixer(dummy)) < 0) | 
 | 598 | 		goto __nodev; | 
 | 599 | 	strcpy(card->driver, "Dummy"); | 
 | 600 | 	strcpy(card->shortname, "Dummy"); | 
 | 601 | 	sprintf(card->longname, "Dummy %i", dev + 1); | 
| Takashi Iwai | 16dab54 | 2005-09-05 17:17:58 +0200 | [diff] [blame] | 602 |  | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 603 | 	snd_card_set_dev(card, &devptr->dev); | 
| Takashi Iwai | 16dab54 | 2005-09-05 17:17:58 +0200 | [diff] [blame] | 604 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | 	if ((err = snd_card_register(card)) == 0) { | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 606 | 		platform_set_drvdata(devptr, card); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | 		return 0; | 
 | 608 | 	} | 
 | 609 |       __nodev: | 
 | 610 | 	snd_card_free(card); | 
 | 611 | 	return err; | 
 | 612 | } | 
 | 613 |  | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 614 | static int snd_dummy_remove(struct platform_device *devptr) | 
 | 615 | { | 
 | 616 | 	snd_card_free(platform_get_drvdata(devptr)); | 
 | 617 | 	platform_set_drvdata(devptr, NULL); | 
 | 618 | 	return 0; | 
 | 619 | } | 
 | 620 |  | 
 | 621 | #ifdef CONFIG_PM | 
 | 622 | static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state) | 
 | 623 | { | 
 | 624 | 	struct snd_card *card = platform_get_drvdata(pdev); | 
 | 625 | 	struct snd_dummy *dummy = card->private_data; | 
 | 626 |  | 
 | 627 | 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | 
 | 628 | 	snd_pcm_suspend_all(dummy->pcm); | 
 | 629 | 	return 0; | 
 | 630 | } | 
 | 631 | 	 | 
 | 632 | static int snd_dummy_resume(struct platform_device *pdev) | 
 | 633 | { | 
 | 634 | 	struct snd_card *card = platform_get_drvdata(pdev); | 
 | 635 |  | 
 | 636 | 	snd_power_change_state(card, SNDRV_CTL_POWER_D0); | 
 | 637 | 	return 0; | 
 | 638 | } | 
 | 639 | #endif | 
 | 640 |  | 
 | 641 | #define SND_DUMMY_DRIVER	"snd_dummy" | 
 | 642 |  | 
 | 643 | static struct platform_driver snd_dummy_driver = { | 
 | 644 | 	.probe		= snd_dummy_probe, | 
 | 645 | 	.remove		= snd_dummy_remove, | 
 | 646 | #ifdef CONFIG_PM | 
 | 647 | 	.suspend	= snd_dummy_suspend, | 
 | 648 | 	.resume		= snd_dummy_resume, | 
 | 649 | #endif | 
 | 650 | 	.driver		= { | 
 | 651 | 		.name	= SND_DUMMY_DRIVER | 
 | 652 | 	}, | 
 | 653 | }; | 
 | 654 |  | 
| Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 655 | static void __init_or_module snd_dummy_unregister_all(void) | 
 | 656 | { | 
 | 657 | 	int i; | 
 | 658 |  | 
 | 659 | 	for (i = 0; i < ARRAY_SIZE(devices); ++i) | 
 | 660 | 		platform_device_unregister(devices[i]); | 
 | 661 | 	platform_driver_unregister(&snd_dummy_driver); | 
 | 662 | } | 
 | 663 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | static int __init alsa_card_dummy_init(void) | 
 | 665 | { | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 666 | 	int i, cards, err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 |  | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 668 | 	if ((err = platform_driver_register(&snd_dummy_driver)) < 0) | 
 | 669 | 		return err; | 
 | 670 |  | 
 | 671 | 	cards = 0; | 
 | 672 | 	for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { | 
 | 673 | 		struct platform_device *device; | 
 | 674 | 		device = platform_device_register_simple(SND_DUMMY_DRIVER, | 
 | 675 | 							 i, NULL, 0); | 
 | 676 | 		if (IS_ERR(device)) { | 
 | 677 | 			err = PTR_ERR(device); | 
 | 678 | 			goto errout; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | 		} | 
| Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 680 | 		devices[i] = device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | 		cards++; | 
 | 682 | 	} | 
 | 683 | 	if (!cards) { | 
 | 684 | #ifdef MODULE | 
 | 685 | 		printk(KERN_ERR "Dummy soundcard not found or device busy\n"); | 
 | 686 | #endif | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 687 | 		err = -ENODEV; | 
 | 688 | 		goto errout; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | 	} | 
 | 690 | 	return 0; | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 691 |  | 
 | 692 |  errout: | 
| Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 693 | 	snd_dummy_unregister_all(); | 
| Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 694 | 	return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } | 
 | 696 |  | 
 | 697 | static void __exit alsa_card_dummy_exit(void) | 
 | 698 | { | 
| Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 699 | 	snd_dummy_unregister_all(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } | 
 | 701 |  | 
 | 702 | module_init(alsa_card_dummy_init) | 
 | 703 | module_exit(alsa_card_dummy_exit) |