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> |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 28 | #include <linux/hrtimer.h> |
| 29 | #include <linux/math64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/moduleparam.h> |
| 31 | #include <sound/core.h> |
| 32 | #include <sound/control.h> |
Takashi Iwai | fb567a8 | 2006-08-23 13:07:19 +0200 | [diff] [blame] | 33 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <sound/pcm.h> |
| 35 | #include <sound/rawmidi.h> |
Takashi Iwai | 9b151fe | 2009-09-08 14:30:49 +0200 | [diff] [blame] | 36 | #include <sound/info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <sound/initval.h> |
| 38 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 39 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | MODULE_DESCRIPTION("Dummy soundcard (/dev/null)"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}"); |
| 43 | |
| 44 | #define MAX_PCM_DEVICES 4 |
Takashi Iwai | b888d1c | 2009-09-08 18:15:17 +0200 | [diff] [blame] | 45 | #define MAX_PCM_SUBSTREAMS 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define MAX_MIDI_DEVICES 2 |
| 47 | |
| 48 | #if 0 /* emu10k1 emulation */ |
| 49 | #define MAX_BUFFER_SIZE (128 * 1024) |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 50 | static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | int err; |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 53 | err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
| 54 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | return err; |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 56 | 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] | 57 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return err; |
| 59 | return 0; |
| 60 | } |
| 61 | #define add_playback_constraints emu10k1_playback_constraints |
| 62 | #endif |
| 63 | |
| 64 | #if 0 /* RME9652 emulation */ |
| 65 | #define MAX_BUFFER_SIZE (26 * 64 * 1024) |
| 66 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE |
| 67 | #define USE_CHANNELS_MIN 26 |
| 68 | #define USE_CHANNELS_MAX 26 |
| 69 | #define USE_PERIODS_MIN 2 |
| 70 | #define USE_PERIODS_MAX 2 |
| 71 | #endif |
| 72 | |
| 73 | #if 0 /* ICE1712 emulation */ |
| 74 | #define MAX_BUFFER_SIZE (256 * 1024) |
| 75 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE |
| 76 | #define USE_CHANNELS_MIN 10 |
| 77 | #define USE_CHANNELS_MAX 10 |
| 78 | #define USE_PERIODS_MIN 1 |
| 79 | #define USE_PERIODS_MAX 1024 |
| 80 | #endif |
| 81 | |
| 82 | #if 0 /* UDA1341 emulation */ |
| 83 | #define MAX_BUFFER_SIZE (16380) |
| 84 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 85 | #define USE_CHANNELS_MIN 2 |
| 86 | #define USE_CHANNELS_MAX 2 |
| 87 | #define USE_PERIODS_MIN 2 |
| 88 | #define USE_PERIODS_MAX 255 |
| 89 | #endif |
| 90 | |
| 91 | #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */ |
| 92 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 93 | #define USE_CHANNELS_MIN 2 |
| 94 | #define USE_CHANNELS_MAX 2 |
| 95 | #define USE_RATE SNDRV_PCM_RATE_48000 |
| 96 | #define USE_RATE_MIN 48000 |
| 97 | #define USE_RATE_MAX 48000 |
| 98 | #endif |
| 99 | |
Jaroslav Kysela | 2ad5dd8 | 2006-01-03 14:27:21 +0100 | [diff] [blame] | 100 | #if 0 /* CA0106 */ |
| 101 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 102 | #define USE_CHANNELS_MIN 2 |
| 103 | #define USE_CHANNELS_MAX 2 |
| 104 | #define USE_RATE (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000) |
| 105 | #define USE_RATE_MIN 48000 |
| 106 | #define USE_RATE_MAX 192000 |
| 107 | #define MAX_BUFFER_SIZE ((65536-64)*8) |
| 108 | #define MAX_PERIOD_SIZE (65536-64) |
| 109 | #define USE_PERIODS_MIN 2 |
| 110 | #define USE_PERIODS_MAX 8 |
| 111 | #endif |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* defaults */ |
| 115 | #ifndef MAX_BUFFER_SIZE |
| 116 | #define MAX_BUFFER_SIZE (64*1024) |
| 117 | #endif |
Jaroslav Kysela | 2ad5dd8 | 2006-01-03 14:27:21 +0100 | [diff] [blame] | 118 | #ifndef MAX_PERIOD_SIZE |
| 119 | #define MAX_PERIOD_SIZE MAX_BUFFER_SIZE |
| 120 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #ifndef USE_FORMATS |
| 122 | #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE) |
| 123 | #endif |
| 124 | #ifndef USE_RATE |
| 125 | #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 |
| 126 | #define USE_RATE_MIN 5500 |
| 127 | #define USE_RATE_MAX 48000 |
| 128 | #endif |
| 129 | #ifndef USE_CHANNELS_MIN |
| 130 | #define USE_CHANNELS_MIN 1 |
| 131 | #endif |
| 132 | #ifndef USE_CHANNELS_MAX |
| 133 | #define USE_CHANNELS_MAX 2 |
| 134 | #endif |
| 135 | #ifndef USE_PERIODS_MIN |
| 136 | #define USE_PERIODS_MIN 1 |
| 137 | #endif |
| 138 | #ifndef USE_PERIODS_MAX |
| 139 | #define USE_PERIODS_MAX 1024 |
| 140 | #endif |
| 141 | #ifndef add_playback_constraints |
| 142 | #define add_playback_constraints(x) 0 |
| 143 | #endif |
| 144 | #ifndef add_capture_constraints |
| 145 | #define add_capture_constraints(x) 0 |
| 146 | #endif |
| 147 | |
| 148 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 149 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 150 | static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; |
| 151 | static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
| 152 | static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; |
| 153 | //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 154 | #ifdef CONFIG_HIGH_RES_TIMERS |
| 155 | static int hrtimer = 1; |
| 156 | #endif |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 157 | static int fake_buffer = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | module_param_array(index, int, NULL, 0444); |
| 160 | MODULE_PARM_DESC(index, "Index value for dummy soundcard."); |
| 161 | module_param_array(id, charp, NULL, 0444); |
| 162 | MODULE_PARM_DESC(id, "ID string for dummy soundcard."); |
| 163 | module_param_array(enable, bool, NULL, 0444); |
| 164 | MODULE_PARM_DESC(enable, "Enable this dummy soundcard."); |
| 165 | module_param_array(pcm_devs, int, NULL, 0444); |
| 166 | MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver."); |
| 167 | module_param_array(pcm_substreams, int, NULL, 0444); |
Takashi Iwai | 23aebca | 2009-11-02 14:10:59 +0100 | [diff] [blame^] | 168 | MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | //module_param_array(midi_devs, int, NULL, 0444); |
| 170 | //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 171 | module_param(fake_buffer, bool, 0444); |
| 172 | MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations."); |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 173 | #ifdef CONFIG_HIGH_RES_TIMERS |
| 174 | module_param(hrtimer, bool, 0644); |
| 175 | MODULE_PARM_DESC(hrtimer, "Use hrtimer as the timer source."); |
| 176 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 178 | static struct platform_device *devices[SNDRV_CARDS]; |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | #define MIXER_ADDR_MASTER 0 |
| 181 | #define MIXER_ADDR_LINE 1 |
| 182 | #define MIXER_ADDR_MIC 2 |
| 183 | #define MIXER_ADDR_SYNTH 3 |
| 184 | #define MIXER_ADDR_CD 4 |
| 185 | #define MIXER_ADDR_LAST 4 |
| 186 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 187 | struct dummy_timer_ops { |
| 188 | int (*create)(struct snd_pcm_substream *); |
| 189 | void (*free)(struct snd_pcm_substream *); |
| 190 | int (*prepare)(struct snd_pcm_substream *); |
| 191 | int (*start)(struct snd_pcm_substream *); |
| 192 | int (*stop)(struct snd_pcm_substream *); |
| 193 | snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *); |
| 194 | }; |
| 195 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 196 | struct snd_dummy { |
| 197 | struct snd_card *card; |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 198 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | spinlock_t mixer_lock; |
| 200 | int mixer_volume[MIXER_ADDR_LAST+1][2]; |
| 201 | int capture_source[MIXER_ADDR_LAST+1][2]; |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 202 | const struct dummy_timer_ops *timer_ops; |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 203 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 205 | /* |
| 206 | * system timer interface |
| 207 | */ |
| 208 | |
| 209 | struct dummy_systimer_pcm { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | spinlock_t lock; |
| 211 | struct timer_list timer; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 212 | unsigned long base_time; |
| 213 | unsigned int frac_pos; /* fractional sample position (based HZ) */ |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 214 | unsigned int frac_period_rest; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 215 | unsigned int frac_buffer_size; /* buffer_size * HZ */ |
| 216 | unsigned int frac_period_size; /* period_size * HZ */ |
| 217 | unsigned int rate; |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 218 | int elapsed; |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 219 | struct snd_pcm_substream *substream; |
| 220 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 222 | static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm) |
| 223 | { |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 224 | dpcm->timer.expires = jiffies + |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 225 | (dpcm->frac_period_rest + dpcm->rate - 1) / dpcm->rate; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 226 | add_timer(&dpcm->timer); |
| 227 | } |
| 228 | |
| 229 | static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm) |
| 230 | { |
| 231 | unsigned long delta; |
| 232 | |
| 233 | delta = jiffies - dpcm->base_time; |
| 234 | if (!delta) |
| 235 | return; |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 236 | dpcm->base_time += delta; |
| 237 | delta *= dpcm->rate; |
| 238 | dpcm->frac_pos += delta; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 239 | while (dpcm->frac_pos >= dpcm->frac_buffer_size) |
| 240 | dpcm->frac_pos -= dpcm->frac_buffer_size; |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 241 | while (dpcm->frac_period_rest <= delta) { |
| 242 | dpcm->elapsed++; |
| 243 | dpcm->frac_period_rest += dpcm->frac_period_size; |
| 244 | } |
| 245 | dpcm->frac_period_rest -= delta; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 248 | static int dummy_systimer_start(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 250 | struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; |
| 251 | spin_lock(&dpcm->lock); |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 252 | dpcm->base_time = jiffies; |
| 253 | dummy_systimer_rearm(dpcm); |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 254 | spin_unlock(&dpcm->lock); |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 255 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 258 | static int dummy_systimer_stop(struct snd_pcm_substream *substream) |
| 259 | { |
| 260 | struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; |
| 261 | spin_lock(&dpcm->lock); |
| 262 | del_timer(&dpcm->timer); |
| 263 | spin_unlock(&dpcm->lock); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int dummy_systimer_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 269 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 270 | struct dummy_systimer_pcm *dpcm = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 272 | dpcm->frac_pos = 0; |
| 273 | dpcm->rate = runtime->rate; |
| 274 | dpcm->frac_buffer_size = runtime->buffer_size * HZ; |
| 275 | dpcm->frac_period_size = runtime->period_size * HZ; |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 276 | dpcm->frac_period_rest = dpcm->frac_period_size; |
| 277 | dpcm->elapsed = 0; |
Ahmet Ä°nan | 53463a83 | 2008-02-21 07:55:30 +0100 | [diff] [blame] | 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 282 | static void dummy_systimer_callback(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 284 | struct dummy_systimer_pcm *dpcm = (struct dummy_systimer_pcm *)data; |
Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 285 | unsigned long flags; |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 286 | int elapsed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Takashi Iwai | b32425a | 2005-11-18 18:52:14 +0100 | [diff] [blame] | 288 | spin_lock_irqsave(&dpcm->lock, flags); |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 289 | dummy_systimer_update(dpcm); |
| 290 | dummy_systimer_rearm(dpcm); |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 291 | elapsed = dpcm->elapsed; |
| 292 | dpcm->elapsed = 0; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 293 | spin_unlock_irqrestore(&dpcm->lock, flags); |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 294 | if (elapsed) |
| 295 | snd_pcm_period_elapsed(dpcm->substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 298 | static snd_pcm_uframes_t |
| 299 | dummy_systimer_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 301 | struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 302 | snd_pcm_uframes_t pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 304 | spin_lock(&dpcm->lock); |
| 305 | dummy_systimer_update(dpcm); |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 306 | pos = dpcm->frac_pos / HZ; |
Takashi Iwai | b142037 | 2009-09-03 16:01:06 +0200 | [diff] [blame] | 307 | spin_unlock(&dpcm->lock); |
Takashi Iwai | b5d1078 | 2009-09-04 08:45:11 +0200 | [diff] [blame] | 308 | return pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 311 | static int dummy_systimer_create(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 313 | struct dummy_systimer_pcm *dpcm; |
| 314 | |
| 315 | dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); |
| 316 | if (!dpcm) |
| 317 | return -ENOMEM; |
| 318 | substream->runtime->private_data = dpcm; |
| 319 | init_timer(&dpcm->timer); |
| 320 | dpcm->timer.data = (unsigned long) dpcm; |
| 321 | dpcm->timer.function = dummy_systimer_callback; |
| 322 | spin_lock_init(&dpcm->lock); |
| 323 | dpcm->substream = substream; |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static void dummy_systimer_free(struct snd_pcm_substream *substream) |
| 328 | { |
| 329 | kfree(substream->runtime->private_data); |
| 330 | } |
| 331 | |
| 332 | static struct dummy_timer_ops dummy_systimer_ops = { |
| 333 | .create = dummy_systimer_create, |
| 334 | .free = dummy_systimer_free, |
| 335 | .prepare = dummy_systimer_prepare, |
| 336 | .start = dummy_systimer_start, |
| 337 | .stop = dummy_systimer_stop, |
| 338 | .pointer = dummy_systimer_pointer, |
| 339 | }; |
| 340 | |
| 341 | #ifdef CONFIG_HIGH_RES_TIMERS |
| 342 | /* |
| 343 | * hrtimer interface |
| 344 | */ |
| 345 | |
| 346 | struct dummy_hrtimer_pcm { |
| 347 | ktime_t base_time; |
| 348 | ktime_t period_time; |
| 349 | atomic_t running; |
| 350 | struct hrtimer timer; |
| 351 | struct tasklet_struct tasklet; |
| 352 | struct snd_pcm_substream *substream; |
| 353 | }; |
| 354 | |
| 355 | static void dummy_hrtimer_pcm_elapsed(unsigned long priv) |
| 356 | { |
| 357 | struct dummy_hrtimer_pcm *dpcm = (struct dummy_hrtimer_pcm *)priv; |
| 358 | if (atomic_read(&dpcm->running)) |
| 359 | snd_pcm_period_elapsed(dpcm->substream); |
| 360 | } |
| 361 | |
| 362 | static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer) |
| 363 | { |
| 364 | struct dummy_hrtimer_pcm *dpcm; |
| 365 | |
| 366 | dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer); |
| 367 | if (!atomic_read(&dpcm->running)) |
| 368 | return HRTIMER_NORESTART; |
| 369 | tasklet_schedule(&dpcm->tasklet); |
| 370 | hrtimer_forward_now(timer, dpcm->period_time); |
| 371 | return HRTIMER_RESTART; |
| 372 | } |
| 373 | |
| 374 | static int dummy_hrtimer_start(struct snd_pcm_substream *substream) |
| 375 | { |
| 376 | struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; |
| 377 | |
| 378 | dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer); |
| 379 | hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL); |
| 380 | atomic_set(&dpcm->running, 1); |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static int dummy_hrtimer_stop(struct snd_pcm_substream *substream) |
| 385 | { |
| 386 | struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; |
| 387 | |
| 388 | atomic_set(&dpcm->running, 0); |
| 389 | hrtimer_cancel(&dpcm->timer); |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm) |
| 394 | { |
| 395 | tasklet_kill(&dpcm->tasklet); |
| 396 | } |
| 397 | |
| 398 | static snd_pcm_uframes_t |
| 399 | dummy_hrtimer_pointer(struct snd_pcm_substream *substream) |
| 400 | { |
| 401 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 402 | struct dummy_hrtimer_pcm *dpcm = runtime->private_data; |
| 403 | u64 delta; |
| 404 | u32 pos; |
| 405 | |
| 406 | delta = ktime_us_delta(hrtimer_cb_get_time(&dpcm->timer), |
| 407 | dpcm->base_time); |
| 408 | delta = div_u64(delta * runtime->rate + 999999, 1000000); |
| 409 | div_u64_rem(delta, runtime->buffer_size, &pos); |
| 410 | return pos; |
| 411 | } |
| 412 | |
| 413 | static int dummy_hrtimer_prepare(struct snd_pcm_substream *substream) |
| 414 | { |
| 415 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 416 | struct dummy_hrtimer_pcm *dpcm = runtime->private_data; |
| 417 | unsigned int period, rate; |
| 418 | long sec; |
| 419 | unsigned long nsecs; |
| 420 | |
| 421 | dummy_hrtimer_sync(dpcm); |
| 422 | period = runtime->period_size; |
| 423 | rate = runtime->rate; |
| 424 | sec = period / rate; |
| 425 | period %= rate; |
| 426 | nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate); |
| 427 | dpcm->period_time = ktime_set(sec, nsecs); |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int dummy_hrtimer_create(struct snd_pcm_substream *substream) |
| 433 | { |
| 434 | struct dummy_hrtimer_pcm *dpcm; |
| 435 | |
| 436 | dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); |
| 437 | if (!dpcm) |
| 438 | return -ENOMEM; |
| 439 | substream->runtime->private_data = dpcm; |
| 440 | hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 441 | dpcm->timer.function = dummy_hrtimer_callback; |
| 442 | dpcm->substream = substream; |
| 443 | atomic_set(&dpcm->running, 0); |
| 444 | tasklet_init(&dpcm->tasklet, dummy_hrtimer_pcm_elapsed, |
| 445 | (unsigned long)dpcm); |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static void dummy_hrtimer_free(struct snd_pcm_substream *substream) |
| 450 | { |
| 451 | struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; |
| 452 | dummy_hrtimer_sync(dpcm); |
| 453 | kfree(dpcm); |
| 454 | } |
| 455 | |
| 456 | static struct dummy_timer_ops dummy_hrtimer_ops = { |
| 457 | .create = dummy_hrtimer_create, |
| 458 | .free = dummy_hrtimer_free, |
| 459 | .prepare = dummy_hrtimer_prepare, |
| 460 | .start = dummy_hrtimer_start, |
| 461 | .stop = dummy_hrtimer_stop, |
| 462 | .pointer = dummy_hrtimer_pointer, |
| 463 | }; |
| 464 | |
| 465 | #endif /* CONFIG_HIGH_RES_TIMERS */ |
| 466 | |
| 467 | /* |
| 468 | * PCM interface |
| 469 | */ |
| 470 | |
| 471 | static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 472 | { |
| 473 | struct snd_dummy *dummy = snd_pcm_substream_chip(substream); |
| 474 | |
| 475 | switch (cmd) { |
| 476 | case SNDRV_PCM_TRIGGER_START: |
| 477 | case SNDRV_PCM_TRIGGER_RESUME: |
| 478 | return dummy->timer_ops->start(substream); |
| 479 | case SNDRV_PCM_TRIGGER_STOP: |
| 480 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 481 | return dummy->timer_ops->stop(substream); |
| 482 | } |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | |
| 486 | static int dummy_pcm_prepare(struct snd_pcm_substream *substream) |
| 487 | { |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 488 | struct snd_dummy *dummy = snd_pcm_substream_chip(substream); |
| 489 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 490 | return dummy->timer_ops->prepare(substream); |
| 491 | } |
| 492 | |
| 493 | static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream) |
| 494 | { |
| 495 | struct snd_dummy *dummy = snd_pcm_substream_chip(substream); |
| 496 | |
| 497 | return dummy->timer_ops->pointer(substream); |
| 498 | } |
| 499 | |
| 500 | static struct snd_pcm_hardware dummy_pcm_hardware = { |
| 501 | .info = (SNDRV_PCM_INFO_MMAP | |
| 502 | SNDRV_PCM_INFO_INTERLEAVED | |
| 503 | SNDRV_PCM_INFO_RESUME | |
| 504 | SNDRV_PCM_INFO_MMAP_VALID), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | .formats = USE_FORMATS, |
| 506 | .rates = USE_RATE, |
| 507 | .rate_min = USE_RATE_MIN, |
| 508 | .rate_max = USE_RATE_MAX, |
| 509 | .channels_min = USE_CHANNELS_MIN, |
| 510 | .channels_max = USE_CHANNELS_MAX, |
| 511 | .buffer_bytes_max = MAX_BUFFER_SIZE, |
| 512 | .period_bytes_min = 64, |
Takashi Iwai | e05d696 | 2006-08-17 17:12:19 +0200 | [diff] [blame] | 513 | .period_bytes_max = MAX_PERIOD_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | .periods_min = USE_PERIODS_MIN, |
| 515 | .periods_max = USE_PERIODS_MAX, |
| 516 | .fifo_size = 0, |
| 517 | }; |
| 518 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 519 | static int dummy_pcm_hw_params(struct snd_pcm_substream *substream, |
| 520 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 522 | if (fake_buffer) { |
| 523 | /* runtime->dma_bytes has to be set manually to allow mmap */ |
| 524 | substream->runtime->dma_bytes = params_buffer_bytes(hw_params); |
| 525 | return 0; |
| 526 | } |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 527 | return snd_pcm_lib_malloc_pages(substream, |
| 528 | params_buffer_bytes(hw_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 531 | static int dummy_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 533 | if (fake_buffer) |
| 534 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return snd_pcm_lib_free_pages(substream); |
| 536 | } |
| 537 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 538 | static int dummy_pcm_open(struct snd_pcm_substream *substream) |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 539 | { |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 540 | struct snd_dummy *dummy = snd_pcm_substream_chip(substream); |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 541 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | int err; |
| 543 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 544 | dummy->timer_ops = &dummy_systimer_ops; |
| 545 | #ifdef CONFIG_HIGH_RES_TIMERS |
| 546 | if (hrtimer) |
| 547 | dummy->timer_ops = &dummy_hrtimer_ops; |
| 548 | #endif |
| 549 | |
| 550 | err = dummy->timer_ops->create(substream); |
| 551 | if (err < 0) |
| 552 | return err; |
| 553 | |
| 554 | runtime->hw = dummy_pcm_hardware; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | if (substream->pcm->device & 1) { |
| 556 | runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; |
| 557 | runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; |
| 558 | } |
| 559 | if (substream->pcm->device & 2) |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 560 | runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | |
| 561 | SNDRV_PCM_INFO_MMAP_VALID); |
| 562 | |
| 563 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 564 | err = add_playback_constraints(substream->runtime); |
| 565 | else |
| 566 | err = add_capture_constraints(substream->runtime); |
| 567 | if (err < 0) { |
| 568 | dummy->timer_ops->free(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 574 | static int dummy_pcm_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 576 | struct snd_dummy *dummy = snd_pcm_substream_chip(substream); |
| 577 | dummy->timer_ops->free(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 581 | /* |
| 582 | * dummy buffer handling |
| 583 | */ |
| 584 | |
| 585 | static void *dummy_page[2]; |
| 586 | |
| 587 | static void free_fake_buffer(void) |
| 588 | { |
| 589 | if (fake_buffer) { |
| 590 | int i; |
| 591 | for (i = 0; i < 2; i++) |
| 592 | if (dummy_page[i]) { |
| 593 | free_page((unsigned long)dummy_page[i]); |
| 594 | dummy_page[i] = NULL; |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | static int alloc_fake_buffer(void) |
| 600 | { |
| 601 | int i; |
| 602 | |
| 603 | if (!fake_buffer) |
| 604 | return 0; |
| 605 | for (i = 0; i < 2; i++) { |
| 606 | dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL); |
| 607 | if (!dummy_page[i]) { |
| 608 | free_fake_buffer(); |
| 609 | return -ENOMEM; |
| 610 | } |
| 611 | } |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static int dummy_pcm_copy(struct snd_pcm_substream *substream, |
| 616 | int channel, snd_pcm_uframes_t pos, |
| 617 | void __user *dst, snd_pcm_uframes_t count) |
| 618 | { |
| 619 | return 0; /* do nothing */ |
| 620 | } |
| 621 | |
| 622 | static int dummy_pcm_silence(struct snd_pcm_substream *substream, |
| 623 | int channel, snd_pcm_uframes_t pos, |
| 624 | snd_pcm_uframes_t count) |
| 625 | { |
| 626 | return 0; /* do nothing */ |
| 627 | } |
| 628 | |
| 629 | static struct page *dummy_pcm_page(struct snd_pcm_substream *substream, |
| 630 | unsigned long offset) |
| 631 | { |
| 632 | return virt_to_page(dummy_page[substream->stream]); /* the same page */ |
| 633 | } |
| 634 | |
Takashi Iwai | c631d03 | 2009-09-03 15:59:26 +0200 | [diff] [blame] | 635 | static struct snd_pcm_ops dummy_pcm_ops = { |
| 636 | .open = dummy_pcm_open, |
| 637 | .close = dummy_pcm_close, |
| 638 | .ioctl = snd_pcm_lib_ioctl, |
| 639 | .hw_params = dummy_pcm_hw_params, |
| 640 | .hw_free = dummy_pcm_hw_free, |
| 641 | .prepare = dummy_pcm_prepare, |
| 642 | .trigger = dummy_pcm_trigger, |
| 643 | .pointer = dummy_pcm_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | }; |
| 645 | |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 646 | static struct snd_pcm_ops dummy_pcm_ops_no_buf = { |
| 647 | .open = dummy_pcm_open, |
| 648 | .close = dummy_pcm_close, |
| 649 | .ioctl = snd_pcm_lib_ioctl, |
| 650 | .hw_params = dummy_pcm_hw_params, |
| 651 | .hw_free = dummy_pcm_hw_free, |
| 652 | .prepare = dummy_pcm_prepare, |
| 653 | .trigger = dummy_pcm_trigger, |
| 654 | .pointer = dummy_pcm_pointer, |
| 655 | .copy = dummy_pcm_copy, |
| 656 | .silence = dummy_pcm_silence, |
| 657 | .page = dummy_pcm_page, |
| 658 | }; |
| 659 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 660 | static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device, |
| 661 | int substreams) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 663 | struct snd_pcm *pcm; |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 664 | struct snd_pcm_ops *ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | int err; |
| 666 | |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 667 | err = snd_pcm_new(dummy->card, "Dummy PCM", device, |
| 668 | substreams, substreams, &pcm); |
| 669 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return err; |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 671 | dummy->pcm = pcm; |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 672 | if (fake_buffer) |
| 673 | ops = &dummy_pcm_ops_no_buf; |
| 674 | else |
| 675 | ops = &dummy_pcm_ops; |
| 676 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops); |
| 677 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | pcm->private_data = dummy; |
| 679 | pcm->info_flags = 0; |
| 680 | strcpy(pcm->name, "Dummy PCM"); |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 681 | if (!fake_buffer) { |
| 682 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 683 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 684 | snd_dma_continuous_data(GFP_KERNEL), |
| 685 | 0, 64*1024); |
| 686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return 0; |
| 688 | } |
| 689 | |
Takashi Iwai | 9b151fe | 2009-09-08 14:30:49 +0200 | [diff] [blame] | 690 | /* |
| 691 | * mixer interface |
| 692 | */ |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | #define DUMMY_VOLUME(xname, xindex, addr) \ |
Takashi Iwai | fb567a8 | 2006-08-23 13:07:19 +0200 | [diff] [blame] | 695 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 696 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
| 697 | .name = xname, .index = xindex, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | .info = snd_dummy_volume_info, \ |
| 699 | .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ |
Takashi Iwai | fb567a8 | 2006-08-23 13:07:19 +0200 | [diff] [blame] | 700 | .private_value = addr, \ |
| 701 | .tlv = { .p = db_scale_dummy } } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 703 | static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, |
| 704 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
| 706 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 707 | uinfo->count = 2; |
| 708 | uinfo->value.integer.min = -50; |
| 709 | uinfo->value.integer.max = 100; |
| 710 | return 0; |
| 711 | } |
| 712 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 713 | static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, |
| 714 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 716 | struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | int addr = kcontrol->private_value; |
| 718 | |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 719 | spin_lock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; |
| 721 | ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 722 | spin_unlock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 726 | static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, |
| 727 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 729 | struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | int change, addr = kcontrol->private_value; |
| 731 | int left, right; |
| 732 | |
| 733 | left = ucontrol->value.integer.value[0]; |
| 734 | if (left < -50) |
| 735 | left = -50; |
| 736 | if (left > 100) |
| 737 | left = 100; |
| 738 | right = ucontrol->value.integer.value[1]; |
| 739 | if (right < -50) |
| 740 | right = -50; |
| 741 | if (right > 100) |
| 742 | right = 100; |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 743 | spin_lock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | change = dummy->mixer_volume[addr][0] != left || |
| 745 | dummy->mixer_volume[addr][1] != right; |
| 746 | dummy->mixer_volume[addr][0] = left; |
| 747 | dummy->mixer_volume[addr][1] = right; |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 748 | spin_unlock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | return change; |
| 750 | } |
| 751 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 752 | static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0); |
Takashi Iwai | fb567a8 | 2006-08-23 13:07:19 +0200 | [diff] [blame] | 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | #define DUMMY_CAPSRC(xname, xindex, addr) \ |
| 755 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 756 | .info = snd_dummy_capsrc_info, \ |
| 757 | .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ |
| 758 | .private_value = addr } |
| 759 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 760 | #define snd_dummy_capsrc_info snd_ctl_boolean_stereo_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 762 | static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, |
| 763 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 765 | struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | int addr = kcontrol->private_value; |
| 767 | |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 768 | spin_lock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; |
| 770 | ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 771 | spin_unlock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return 0; |
| 773 | } |
| 774 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 775 | 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] | 776 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 777 | struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | int change, addr = kcontrol->private_value; |
| 779 | int left, right; |
| 780 | |
| 781 | left = ucontrol->value.integer.value[0] & 1; |
| 782 | right = ucontrol->value.integer.value[1] & 1; |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 783 | spin_lock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | change = dummy->capture_source[addr][0] != left && |
| 785 | dummy->capture_source[addr][1] != right; |
| 786 | dummy->capture_source[addr][0] = left; |
| 787 | dummy->capture_source[addr][1] = right; |
Takashi Iwai | c8eb6ba | 2005-11-17 10:20:23 +0100 | [diff] [blame] | 788 | spin_unlock_irq(&dummy->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | return change; |
| 790 | } |
| 791 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 792 | static struct snd_kcontrol_new snd_dummy_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), |
| 794 | DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), |
| 795 | DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), |
Takashi Iwai | e05d696 | 2006-08-17 17:12:19 +0200 | [diff] [blame] | 796 | DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), |
Takashi Iwai | e05d696 | 2006-08-17 17:12:19 +0200 | [diff] [blame] | 798 | DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), |
Takashi Iwai | e05d696 | 2006-08-17 17:12:19 +0200 | [diff] [blame] | 800 | DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), |
Takashi Iwai | e05d696 | 2006-08-17 17:12:19 +0200 | [diff] [blame] | 802 | DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | }; |
| 804 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 805 | static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 807 | struct snd_card *card = dummy->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | unsigned int idx; |
| 809 | int err; |
| 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | spin_lock_init(&dummy->mixer_lock); |
| 812 | strcpy(card->mixername, "Dummy Mixer"); |
| 813 | |
| 814 | for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 815 | err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy)); |
| 816 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return err; |
| 818 | } |
| 819 | return 0; |
| 820 | } |
| 821 | |
Takashi Iwai | 9b151fe | 2009-09-08 14:30:49 +0200 | [diff] [blame] | 822 | #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_PROC_FS) |
| 823 | /* |
| 824 | * proc interface |
| 825 | */ |
| 826 | static void print_formats(struct snd_info_buffer *buffer) |
| 827 | { |
| 828 | int i; |
| 829 | |
| 830 | for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) { |
| 831 | if (dummy_pcm_hardware.formats & (1ULL << i)) |
| 832 | snd_iprintf(buffer, " %s", snd_pcm_format_name(i)); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | static void print_rates(struct snd_info_buffer *buffer) |
| 837 | { |
| 838 | static int rates[] = { |
| 839 | 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, |
| 840 | 64000, 88200, 96000, 176400, 192000, |
| 841 | }; |
| 842 | int i; |
| 843 | |
| 844 | if (dummy_pcm_hardware.rates & SNDRV_PCM_RATE_CONTINUOUS) |
| 845 | snd_iprintf(buffer, " continuous"); |
| 846 | if (dummy_pcm_hardware.rates & SNDRV_PCM_RATE_KNOT) |
| 847 | snd_iprintf(buffer, " knot"); |
| 848 | for (i = 0; i < ARRAY_SIZE(rates); i++) |
| 849 | if (dummy_pcm_hardware.rates & (1 << i)) |
| 850 | snd_iprintf(buffer, " %d", rates[i]); |
| 851 | } |
| 852 | |
| 853 | #define get_dummy_int_ptr(ofs) \ |
| 854 | (unsigned int *)((char *)&dummy_pcm_hardware + (ofs)) |
| 855 | #define get_dummy_ll_ptr(ofs) \ |
| 856 | (unsigned long long *)((char *)&dummy_pcm_hardware + (ofs)) |
| 857 | |
| 858 | struct dummy_hw_field { |
| 859 | const char *name; |
| 860 | const char *format; |
| 861 | unsigned int offset; |
| 862 | unsigned int size; |
| 863 | }; |
| 864 | #define FIELD_ENTRY(item, fmt) { \ |
| 865 | .name = #item, \ |
| 866 | .format = fmt, \ |
| 867 | .offset = offsetof(struct snd_pcm_hardware, item), \ |
| 868 | .size = sizeof(dummy_pcm_hardware.item) } |
| 869 | |
| 870 | static struct dummy_hw_field fields[] = { |
| 871 | FIELD_ENTRY(formats, "%#llx"), |
| 872 | FIELD_ENTRY(rates, "%#x"), |
| 873 | FIELD_ENTRY(rate_min, "%d"), |
| 874 | FIELD_ENTRY(rate_max, "%d"), |
| 875 | FIELD_ENTRY(channels_min, "%d"), |
| 876 | FIELD_ENTRY(channels_max, "%d"), |
| 877 | FIELD_ENTRY(buffer_bytes_max, "%ld"), |
| 878 | FIELD_ENTRY(period_bytes_min, "%ld"), |
| 879 | FIELD_ENTRY(period_bytes_max, "%ld"), |
| 880 | FIELD_ENTRY(periods_min, "%d"), |
| 881 | FIELD_ENTRY(periods_max, "%d"), |
| 882 | }; |
| 883 | |
| 884 | static void dummy_proc_read(struct snd_info_entry *entry, |
| 885 | struct snd_info_buffer *buffer) |
| 886 | { |
| 887 | int i; |
| 888 | |
| 889 | for (i = 0; i < ARRAY_SIZE(fields); i++) { |
| 890 | snd_iprintf(buffer, "%s ", fields[i].name); |
| 891 | if (fields[i].size == sizeof(int)) |
| 892 | snd_iprintf(buffer, fields[i].format, |
| 893 | *get_dummy_int_ptr(fields[i].offset)); |
| 894 | else |
| 895 | snd_iprintf(buffer, fields[i].format, |
| 896 | *get_dummy_ll_ptr(fields[i].offset)); |
| 897 | if (!strcmp(fields[i].name, "formats")) |
| 898 | print_formats(buffer); |
| 899 | else if (!strcmp(fields[i].name, "rates")) |
| 900 | print_rates(buffer); |
| 901 | snd_iprintf(buffer, "\n"); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | static void dummy_proc_write(struct snd_info_entry *entry, |
| 906 | struct snd_info_buffer *buffer) |
| 907 | { |
| 908 | char line[64]; |
| 909 | |
| 910 | while (!snd_info_get_line(buffer, line, sizeof(line))) { |
| 911 | char item[20]; |
| 912 | const char *ptr; |
| 913 | unsigned long long val; |
| 914 | int i; |
| 915 | |
| 916 | ptr = snd_info_get_str(item, line, sizeof(item)); |
| 917 | for (i = 0; i < ARRAY_SIZE(fields); i++) { |
| 918 | if (!strcmp(item, fields[i].name)) |
| 919 | break; |
| 920 | } |
| 921 | if (i >= ARRAY_SIZE(fields)) |
| 922 | continue; |
| 923 | snd_info_get_str(item, ptr, sizeof(item)); |
| 924 | if (strict_strtoull(item, 0, &val)) |
| 925 | continue; |
| 926 | if (fields[i].size == sizeof(int)) |
| 927 | *get_dummy_int_ptr(fields[i].offset) = val; |
| 928 | else |
| 929 | *get_dummy_ll_ptr(fields[i].offset) = val; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | static void __devinit dummy_proc_init(struct snd_dummy *chip) |
| 934 | { |
| 935 | struct snd_info_entry *entry; |
| 936 | |
| 937 | if (!snd_card_proc_new(chip->card, "dummy_pcm", &entry)) { |
| 938 | snd_info_set_text_ops(entry, chip, dummy_proc_read); |
| 939 | entry->c.text.write = dummy_proc_write; |
| 940 | entry->mode |= S_IWUSR; |
| 941 | } |
| 942 | } |
| 943 | #else |
| 944 | #define dummy_proc_init(x) |
| 945 | #endif /* CONFIG_SND_DEBUG && CONFIG_PROC_FS */ |
| 946 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 947 | static int __devinit snd_dummy_probe(struct platform_device *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 949 | struct snd_card *card; |
| 950 | struct snd_dummy *dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | int idx, err; |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 952 | int dev = devptr->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 954 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, |
| 955 | sizeof(struct snd_dummy), &card); |
| 956 | if (err < 0) |
| 957 | return err; |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 958 | dummy = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | dummy->card = card; |
| 960 | for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { |
| 961 | if (pcm_substreams[dev] < 1) |
| 962 | pcm_substreams[dev] = 1; |
| 963 | if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) |
| 964 | pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 965 | err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev]); |
| 966 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | goto __nodev; |
| 968 | } |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 969 | err = snd_card_dummy_new_mixer(dummy); |
| 970 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | goto __nodev; |
| 972 | strcpy(card->driver, "Dummy"); |
| 973 | strcpy(card->shortname, "Dummy"); |
| 974 | sprintf(card->longname, "Dummy %i", dev + 1); |
Takashi Iwai | 16dab54 | 2005-09-05 17:17:58 +0200 | [diff] [blame] | 975 | |
Takashi Iwai | 9b151fe | 2009-09-08 14:30:49 +0200 | [diff] [blame] | 976 | dummy_proc_init(dummy); |
| 977 | |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 978 | snd_card_set_dev(card, &devptr->dev); |
Takashi Iwai | 16dab54 | 2005-09-05 17:17:58 +0200 | [diff] [blame] | 979 | |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 980 | err = snd_card_register(card); |
| 981 | if (err == 0) { |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 982 | platform_set_drvdata(devptr, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | return 0; |
| 984 | } |
| 985 | __nodev: |
| 986 | snd_card_free(card); |
| 987 | return err; |
| 988 | } |
| 989 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 990 | static int __devexit snd_dummy_remove(struct platform_device *devptr) |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 991 | { |
| 992 | snd_card_free(platform_get_drvdata(devptr)); |
| 993 | platform_set_drvdata(devptr, NULL); |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | #ifdef CONFIG_PM |
| 998 | static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state) |
| 999 | { |
| 1000 | struct snd_card *card = platform_get_drvdata(pdev); |
| 1001 | struct snd_dummy *dummy = card->private_data; |
| 1002 | |
| 1003 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 1004 | snd_pcm_suspend_all(dummy->pcm); |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | static int snd_dummy_resume(struct platform_device *pdev) |
| 1009 | { |
| 1010 | struct snd_card *card = platform_get_drvdata(pdev); |
| 1011 | |
| 1012 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | #endif |
| 1016 | |
| 1017 | #define SND_DUMMY_DRIVER "snd_dummy" |
| 1018 | |
| 1019 | static struct platform_driver snd_dummy_driver = { |
| 1020 | .probe = snd_dummy_probe, |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 1021 | .remove = __devexit_p(snd_dummy_remove), |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 1022 | #ifdef CONFIG_PM |
| 1023 | .suspend = snd_dummy_suspend, |
| 1024 | .resume = snd_dummy_resume, |
| 1025 | #endif |
| 1026 | .driver = { |
| 1027 | .name = SND_DUMMY_DRIVER |
| 1028 | }, |
| 1029 | }; |
| 1030 | |
Randy Dunlap | c12aad6 | 2007-06-25 12:08:01 +0200 | [diff] [blame] | 1031 | static void snd_dummy_unregister_all(void) |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 1032 | { |
| 1033 | int i; |
| 1034 | |
| 1035 | for (i = 0; i < ARRAY_SIZE(devices); ++i) |
| 1036 | platform_device_unregister(devices[i]); |
| 1037 | platform_driver_unregister(&snd_dummy_driver); |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 1038 | free_fake_buffer(); |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | static int __init alsa_card_dummy_init(void) |
| 1042 | { |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 1043 | int i, cards, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Jaroslav Kysela | 1a11cb6 | 2008-08-15 12:59:02 +0200 | [diff] [blame] | 1045 | err = platform_driver_register(&snd_dummy_driver); |
| 1046 | if (err < 0) |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 1047 | return err; |
| 1048 | |
Takashi Iwai | a68c4d1 | 2009-09-04 12:19:36 +0200 | [diff] [blame] | 1049 | err = alloc_fake_buffer(); |
| 1050 | if (err < 0) { |
| 1051 | platform_driver_unregister(&snd_dummy_driver); |
| 1052 | return err; |
| 1053 | } |
| 1054 | |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 1055 | cards = 0; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 1056 | for (i = 0; i < SNDRV_CARDS; i++) { |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 1057 | struct platform_device *device; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 1058 | if (! enable[i]) |
| 1059 | continue; |
Takashi Iwai | 6e65c1c | 2005-11-17 16:01:56 +0100 | [diff] [blame] | 1060 | device = platform_device_register_simple(SND_DUMMY_DRIVER, |
| 1061 | i, NULL, 0); |
Rene Herman | a182ee9 | 2006-04-13 12:57:11 +0200 | [diff] [blame] | 1062 | if (IS_ERR(device)) |
| 1063 | continue; |
Rene Herman | 7152447 | 2006-04-13 12:58:06 +0200 | [diff] [blame] | 1064 | if (!platform_get_drvdata(device)) { |
| 1065 | platform_device_unregister(device); |
| 1066 | continue; |
| 1067 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 1068 | devices[i] = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | cards++; |
| 1070 | } |
| 1071 | if (!cards) { |
| 1072 | #ifdef MODULE |
| 1073 | printk(KERN_ERR "Dummy soundcard not found or device busy\n"); |
| 1074 | #endif |
Rene Herman | a182ee9 | 2006-04-13 12:57:11 +0200 | [diff] [blame] | 1075 | snd_dummy_unregister_all(); |
| 1076 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | static void __exit alsa_card_dummy_exit(void) |
| 1082 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 1083 | snd_dummy_unregister_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | module_init(alsa_card_dummy_init) |
| 1087 | module_exit(alsa_card_dummy_exit) |