dummy.c 30 KB

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