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