dummy.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. #include <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/slab.h>
  24. #include <linux/time.h>
  25. #include <linux/wait.h>
  26. #include <linux/moduleparam.h>
  27. #include <sound/core.h>
  28. #include <sound/control.h>
  29. #include <sound/pcm.h>
  30. #include <sound/rawmidi.h>
  31. #include <sound/initval.h>
  32. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  33. MODULE_DESCRIPTION("Dummy soundcard (/dev/null)");
  34. MODULE_LICENSE("GPL");
  35. MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
  36. #define MAX_PCM_DEVICES 4
  37. #define MAX_PCM_SUBSTREAMS 16
  38. #define MAX_MIDI_DEVICES 2
  39. #if 0 /* emu10k1 emulation */
  40. #define MAX_BUFFER_SIZE (128 * 1024)
  41. static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
  42. {
  43. int err;
  44. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  45. return err;
  46. if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0)
  47. return err;
  48. return 0;
  49. }
  50. #define add_playback_constraints emu10k1_playback_constraints
  51. #endif
  52. #if 0 /* RME9652 emulation */
  53. #define MAX_BUFFER_SIZE (26 * 64 * 1024)
  54. #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
  55. #define USE_CHANNELS_MIN 26
  56. #define USE_CHANNELS_MAX 26
  57. #define USE_PERIODS_MIN 2
  58. #define USE_PERIODS_MAX 2
  59. #endif
  60. #if 0 /* ICE1712 emulation */
  61. #define MAX_BUFFER_SIZE (256 * 1024)
  62. #define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
  63. #define USE_CHANNELS_MIN 10
  64. #define USE_CHANNELS_MAX 10
  65. #define USE_PERIODS_MIN 1
  66. #define USE_PERIODS_MAX 1024
  67. #endif
  68. #if 0 /* UDA1341 emulation */
  69. #define MAX_BUFFER_SIZE (16380)
  70. #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  71. #define USE_CHANNELS_MIN 2
  72. #define USE_CHANNELS_MAX 2
  73. #define USE_PERIODS_MIN 2
  74. #define USE_PERIODS_MAX 255
  75. #endif
  76. #if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */
  77. #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  78. #define USE_CHANNELS_MIN 2
  79. #define USE_CHANNELS_MAX 2
  80. #define USE_RATE SNDRV_PCM_RATE_48000
  81. #define USE_RATE_MIN 48000
  82. #define USE_RATE_MAX 48000
  83. #endif
  84. /* defaults */
  85. #ifndef MAX_BUFFER_SIZE
  86. #define MAX_BUFFER_SIZE (64*1024)
  87. #endif
  88. #ifndef USE_FORMATS
  89. #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
  90. #endif
  91. #ifndef USE_RATE
  92. #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000
  93. #define USE_RATE_MIN 5500
  94. #define USE_RATE_MAX 48000
  95. #endif
  96. #ifndef USE_CHANNELS_MIN
  97. #define USE_CHANNELS_MIN 1
  98. #endif
  99. #ifndef USE_CHANNELS_MAX
  100. #define USE_CHANNELS_MAX 2
  101. #endif
  102. #ifndef USE_PERIODS_MIN
  103. #define USE_PERIODS_MIN 1
  104. #endif
  105. #ifndef USE_PERIODS_MAX
  106. #define USE_PERIODS_MAX 1024
  107. #endif
  108. #ifndef add_playback_constraints
  109. #define add_playback_constraints(x) 0
  110. #endif
  111. #ifndef add_capture_constraints
  112. #define add_capture_constraints(x) 0
  113. #endif
  114. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  115. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  116. static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
  117. static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  118. static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
  119. //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
  120. module_param_array(index, int, NULL, 0444);
  121. MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
  122. module_param_array(id, charp, NULL, 0444);
  123. MODULE_PARM_DESC(id, "ID string for dummy soundcard.");
  124. module_param_array(enable, bool, NULL, 0444);
  125. MODULE_PARM_DESC(enable, "Enable this dummy soundcard.");
  126. module_param_array(pcm_devs, int, NULL, 0444);
  127. MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
  128. module_param_array(pcm_substreams, int, NULL, 0444);
  129. MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
  130. //module_param_array(midi_devs, int, NULL, 0444);
  131. //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
  132. #define MIXER_ADDR_MASTER 0
  133. #define MIXER_ADDR_LINE 1
  134. #define MIXER_ADDR_MIC 2
  135. #define MIXER_ADDR_SYNTH 3
  136. #define MIXER_ADDR_CD 4
  137. #define MIXER_ADDR_LAST 4
  138. struct snd_dummy {
  139. struct snd_card *card;
  140. spinlock_t mixer_lock;
  141. int mixer_volume[MIXER_ADDR_LAST+1][2];
  142. int capture_source[MIXER_ADDR_LAST+1][2];
  143. };
  144. struct snd_dummy_pcm {
  145. struct snd_dummy *dummy;
  146. spinlock_t lock;
  147. struct timer_list timer;
  148. unsigned int pcm_size;
  149. unsigned int pcm_count;
  150. unsigned int pcm_bps; /* bytes per second */
  151. unsigned int pcm_jiffie; /* bytes per one jiffie */
  152. unsigned int pcm_irq_pos; /* IRQ position */
  153. unsigned int pcm_buf_pos; /* position in buffer */
  154. struct snd_pcm_substream *substream;
  155. };
  156. static struct snd_card *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
  157. static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
  158. {
  159. dpcm->timer.expires = 1 + jiffies;
  160. add_timer(&dpcm->timer);
  161. }
  162. static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm)
  163. {
  164. del_timer(&dpcm->timer);
  165. }
  166. static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  167. {
  168. struct snd_pcm_runtime *runtime = substream->runtime;
  169. struct snd_dummy_pcm *dpcm = runtime->private_data;
  170. int err = 0;
  171. spin_lock(&dpcm->lock);
  172. if (cmd == SNDRV_PCM_TRIGGER_START) {
  173. snd_card_dummy_pcm_timer_start(dpcm);
  174. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  175. snd_card_dummy_pcm_timer_stop(dpcm);
  176. } else {
  177. err = -EINVAL;
  178. }
  179. spin_unlock(&dpcm->lock);
  180. return err;
  181. }
  182. static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
  183. {
  184. struct snd_pcm_runtime *runtime = substream->runtime;
  185. struct snd_dummy_pcm *dpcm = runtime->private_data;
  186. unsigned int bps;
  187. bps = runtime->rate * runtime->channels;
  188. bps *= snd_pcm_format_width(runtime->format);
  189. bps /= 8;
  190. if (bps <= 0)
  191. return -EINVAL;
  192. dpcm->pcm_bps = bps;
  193. dpcm->pcm_jiffie = bps / HZ;
  194. dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);
  195. dpcm->pcm_count = snd_pcm_lib_period_bytes(substream);
  196. dpcm->pcm_irq_pos = 0;
  197. dpcm->pcm_buf_pos = 0;
  198. return 0;
  199. }
  200. static void snd_card_dummy_pcm_timer_function(unsigned long data)
  201. {
  202. struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data;
  203. spin_lock(&dpcm->lock);
  204. dpcm->timer.expires = 1 + jiffies;
  205. add_timer(&dpcm->timer);
  206. dpcm->pcm_irq_pos += dpcm->pcm_jiffie;
  207. dpcm->pcm_buf_pos += dpcm->pcm_jiffie;
  208. dpcm->pcm_buf_pos %= dpcm->pcm_size;
  209. if (dpcm->pcm_irq_pos >= dpcm->pcm_count) {
  210. dpcm->pcm_irq_pos %= dpcm->pcm_count;
  211. spin_unlock(&dpcm->lock);
  212. snd_pcm_period_elapsed(dpcm->substream);
  213. spin_lock(&dpcm->lock);
  214. }
  215. spin_unlock(&dpcm->lock);
  216. }
  217. static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream)
  218. {
  219. struct snd_pcm_runtime *runtime = substream->runtime;
  220. struct snd_dummy_pcm *dpcm = runtime->private_data;
  221. return bytes_to_frames(runtime, dpcm->pcm_buf_pos);
  222. }
  223. static struct snd_pcm_hardware snd_card_dummy_playback =
  224. {
  225. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  226. SNDRV_PCM_INFO_MMAP_VALID),
  227. .formats = USE_FORMATS,
  228. .rates = USE_RATE,
  229. .rate_min = USE_RATE_MIN,
  230. .rate_max = USE_RATE_MAX,
  231. .channels_min = USE_CHANNELS_MIN,
  232. .channels_max = USE_CHANNELS_MAX,
  233. .buffer_bytes_max = MAX_BUFFER_SIZE,
  234. .period_bytes_min = 64,
  235. .period_bytes_max = MAX_BUFFER_SIZE,
  236. .periods_min = USE_PERIODS_MIN,
  237. .periods_max = USE_PERIODS_MAX,
  238. .fifo_size = 0,
  239. };
  240. static struct snd_pcm_hardware snd_card_dummy_capture =
  241. {
  242. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  243. SNDRV_PCM_INFO_MMAP_VALID),
  244. .formats = USE_FORMATS,
  245. .rates = USE_RATE,
  246. .rate_min = USE_RATE_MIN,
  247. .rate_max = USE_RATE_MAX,
  248. .channels_min = USE_CHANNELS_MIN,
  249. .channels_max = USE_CHANNELS_MAX,
  250. .buffer_bytes_max = MAX_BUFFER_SIZE,
  251. .period_bytes_min = 64,
  252. .period_bytes_max = MAX_BUFFER_SIZE,
  253. .periods_min = USE_PERIODS_MIN,
  254. .periods_max = USE_PERIODS_MAX,
  255. .fifo_size = 0,
  256. };
  257. static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime)
  258. {
  259. kfree(runtime->private_data);
  260. }
  261. static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
  262. struct snd_pcm_hw_params *hw_params)
  263. {
  264. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  265. }
  266. static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream)
  267. {
  268. return snd_pcm_lib_free_pages(substream);
  269. }
  270. static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream)
  271. {
  272. struct snd_dummy_pcm *dpcm;
  273. dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
  274. if (! dpcm)
  275. return dpcm;
  276. init_timer(&dpcm->timer);
  277. dpcm->timer.data = (unsigned long) dpcm;
  278. dpcm->timer.function = snd_card_dummy_pcm_timer_function;
  279. spin_lock_init(&dpcm->lock);
  280. dpcm->substream = substream;
  281. return dpcm;
  282. }
  283. static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
  284. {
  285. struct snd_pcm_runtime *runtime = substream->runtime;
  286. struct snd_dummy_pcm *dpcm;
  287. int err;
  288. if ((dpcm = new_pcm_stream(substream)) == NULL)
  289. return -ENOMEM;
  290. runtime->private_data = dpcm;
  291. runtime->private_free = snd_card_dummy_runtime_free;
  292. runtime->hw = snd_card_dummy_playback;
  293. if (substream->pcm->device & 1) {
  294. runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
  295. runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
  296. }
  297. if (substream->pcm->device & 2)
  298. runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
  299. if ((err = add_playback_constraints(runtime)) < 0) {
  300. kfree(dpcm);
  301. return err;
  302. }
  303. return 0;
  304. }
  305. static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream)
  306. {
  307. struct snd_pcm_runtime *runtime = substream->runtime;
  308. struct snd_dummy_pcm *dpcm;
  309. int err;
  310. if ((dpcm = new_pcm_stream(substream)) == NULL)
  311. return -ENOMEM;
  312. runtime->private_data = dpcm;
  313. runtime->private_free = snd_card_dummy_runtime_free;
  314. runtime->hw = snd_card_dummy_capture;
  315. if (substream->pcm->device == 1) {
  316. runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
  317. runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
  318. }
  319. if (substream->pcm->device & 2)
  320. runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
  321. if ((err = add_capture_constraints(runtime)) < 0) {
  322. kfree(dpcm);
  323. return err;
  324. }
  325. return 0;
  326. }
  327. static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream)
  328. {
  329. return 0;
  330. }
  331. static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream)
  332. {
  333. return 0;
  334. }
  335. static struct snd_pcm_ops snd_card_dummy_playback_ops = {
  336. .open = snd_card_dummy_playback_open,
  337. .close = snd_card_dummy_playback_close,
  338. .ioctl = snd_pcm_lib_ioctl,
  339. .hw_params = snd_card_dummy_hw_params,
  340. .hw_free = snd_card_dummy_hw_free,
  341. .prepare = snd_card_dummy_pcm_prepare,
  342. .trigger = snd_card_dummy_pcm_trigger,
  343. .pointer = snd_card_dummy_pcm_pointer,
  344. };
  345. static struct snd_pcm_ops snd_card_dummy_capture_ops = {
  346. .open = snd_card_dummy_capture_open,
  347. .close = snd_card_dummy_capture_close,
  348. .ioctl = snd_pcm_lib_ioctl,
  349. .hw_params = snd_card_dummy_hw_params,
  350. .hw_free = snd_card_dummy_hw_free,
  351. .prepare = snd_card_dummy_pcm_prepare,
  352. .trigger = snd_card_dummy_pcm_trigger,
  353. .pointer = snd_card_dummy_pcm_pointer,
  354. };
  355. static int __init snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams)
  356. {
  357. struct snd_pcm *pcm;
  358. int err;
  359. if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device,
  360. substreams, substreams, &pcm)) < 0)
  361. return err;
  362. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops);
  363. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops);
  364. pcm->private_data = dummy;
  365. pcm->info_flags = 0;
  366. strcpy(pcm->name, "Dummy PCM");
  367. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  368. snd_dma_continuous_data(GFP_KERNEL),
  369. 0, 64*1024);
  370. return 0;
  371. }
  372. #define DUMMY_VOLUME(xname, xindex, addr) \
  373. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  374. .info = snd_dummy_volume_info, \
  375. .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \
  376. .private_value = addr }
  377. static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol,
  378. struct snd_ctl_elem_info *uinfo)
  379. {
  380. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  381. uinfo->count = 2;
  382. uinfo->value.integer.min = -50;
  383. uinfo->value.integer.max = 100;
  384. return 0;
  385. }
  386. static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol,
  387. struct snd_ctl_elem_value *ucontrol)
  388. {
  389. struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
  390. int addr = kcontrol->private_value;
  391. spin_lock_irq(&dummy->mixer_lock);
  392. ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0];
  393. ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1];
  394. spin_unlock_irq(&dummy->mixer_lock);
  395. return 0;
  396. }
  397. static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol,
  398. struct snd_ctl_elem_value *ucontrol)
  399. {
  400. struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
  401. int change, addr = kcontrol->private_value;
  402. int left, right;
  403. left = ucontrol->value.integer.value[0];
  404. if (left < -50)
  405. left = -50;
  406. if (left > 100)
  407. left = 100;
  408. right = ucontrol->value.integer.value[1];
  409. if (right < -50)
  410. right = -50;
  411. if (right > 100)
  412. right = 100;
  413. spin_lock_irq(&dummy->mixer_lock);
  414. change = dummy->mixer_volume[addr][0] != left ||
  415. dummy->mixer_volume[addr][1] != right;
  416. dummy->mixer_volume[addr][0] = left;
  417. dummy->mixer_volume[addr][1] = right;
  418. spin_unlock_irq(&dummy->mixer_lock);
  419. return change;
  420. }
  421. #define DUMMY_CAPSRC(xname, xindex, addr) \
  422. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  423. .info = snd_dummy_capsrc_info, \
  424. .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \
  425. .private_value = addr }
  426. static int snd_dummy_capsrc_info(struct snd_kcontrol *kcontrol,
  427. struct snd_ctl_elem_info *uinfo)
  428. {
  429. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  430. uinfo->count = 2;
  431. uinfo->value.integer.min = 0;
  432. uinfo->value.integer.max = 1;
  433. return 0;
  434. }
  435. static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol,
  436. struct snd_ctl_elem_value *ucontrol)
  437. {
  438. struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
  439. int addr = kcontrol->private_value;
  440. spin_lock_irq(&dummy->mixer_lock);
  441. ucontrol->value.integer.value[0] = dummy->capture_source[addr][0];
  442. ucontrol->value.integer.value[1] = dummy->capture_source[addr][1];
  443. spin_unlock_irq(&dummy->mixer_lock);
  444. return 0;
  445. }
  446. static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  447. {
  448. struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
  449. int change, addr = kcontrol->private_value;
  450. int left, right;
  451. left = ucontrol->value.integer.value[0] & 1;
  452. right = ucontrol->value.integer.value[1] & 1;
  453. spin_lock_irq(&dummy->mixer_lock);
  454. change = dummy->capture_source[addr][0] != left &&
  455. dummy->capture_source[addr][1] != right;
  456. dummy->capture_source[addr][0] = left;
  457. dummy->capture_source[addr][1] = right;
  458. spin_unlock_irq(&dummy->mixer_lock);
  459. return change;
  460. }
  461. static struct snd_kcontrol_new snd_dummy_controls[] = {
  462. DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
  463. DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
  464. DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
  465. DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_MASTER),
  466. DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE),
  467. DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_MASTER),
  468. DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
  469. DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MASTER),
  470. DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
  471. DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER)
  472. };
  473. static int __init snd_card_dummy_new_mixer(struct snd_dummy *dummy)
  474. {
  475. struct snd_card *card = dummy->card;
  476. unsigned int idx;
  477. int err;
  478. snd_assert(dummy != NULL, return -EINVAL);
  479. spin_lock_init(&dummy->mixer_lock);
  480. strcpy(card->mixername, "Dummy Mixer");
  481. for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
  482. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0)
  483. return err;
  484. }
  485. return 0;
  486. }
  487. static int __init snd_card_dummy_probe(int dev)
  488. {
  489. struct snd_card *card;
  490. struct snd_dummy *dummy;
  491. int idx, err;
  492. if (!enable[dev])
  493. return -ENODEV;
  494. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  495. sizeof(struct snd_dummy));
  496. if (card == NULL)
  497. return -ENOMEM;
  498. dummy = card->private_data;
  499. dummy->card = card;
  500. for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
  501. if (pcm_substreams[dev] < 1)
  502. pcm_substreams[dev] = 1;
  503. if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS)
  504. pcm_substreams[dev] = MAX_PCM_SUBSTREAMS;
  505. if ((err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev])) < 0)
  506. goto __nodev;
  507. }
  508. if ((err = snd_card_dummy_new_mixer(dummy)) < 0)
  509. goto __nodev;
  510. strcpy(card->driver, "Dummy");
  511. strcpy(card->shortname, "Dummy");
  512. sprintf(card->longname, "Dummy %i", dev + 1);
  513. if ((err = snd_card_set_generic_dev(card)) < 0)
  514. goto __nodev;
  515. if ((err = snd_card_register(card)) == 0) {
  516. snd_dummy_cards[dev] = card;
  517. return 0;
  518. }
  519. __nodev:
  520. snd_card_free(card);
  521. return err;
  522. }
  523. static int __init alsa_card_dummy_init(void)
  524. {
  525. int dev, cards;
  526. for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
  527. if (snd_card_dummy_probe(dev) < 0) {
  528. #ifdef MODULE
  529. printk(KERN_ERR "Dummy soundcard #%i not found or device busy\n", dev + 1);
  530. #endif
  531. break;
  532. }
  533. cards++;
  534. }
  535. if (!cards) {
  536. #ifdef MODULE
  537. printk(KERN_ERR "Dummy soundcard not found or device busy\n");
  538. #endif
  539. return -ENODEV;
  540. }
  541. return 0;
  542. }
  543. static void __exit alsa_card_dummy_exit(void)
  544. {
  545. int idx;
  546. for (idx = 0; idx < SNDRV_CARDS; idx++)
  547. snd_card_free(snd_dummy_cards[idx]);
  548. }
  549. module_init(alsa_card_dummy_init)
  550. module_exit(alsa_card_dummy_exit)