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