em28xx-audio.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. * Empiatech em28x1 audio extension
  3. *
  4. * Copyright (C) 2006 Markus Rechberger <mrechberger@gmail.com>
  5. *
  6. * Copyright (C) 2007-2011 Mauro Carvalho Chehab <mchehab@redhat.com>
  7. * - Port to work with the in-kernel driver
  8. * - Cleanups, fixes, alsa-controls, etc.
  9. *
  10. * This driver is based on my previous au600 usb pstn audio driver
  11. * and inherits all the copyrights
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/usb.h>
  29. #include <linux/init.h>
  30. #include <linux/sound.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/soundcard.h>
  33. #include <linux/slab.h>
  34. #include <linux/vmalloc.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/module.h>
  37. #include <sound/core.h>
  38. #include <sound/pcm.h>
  39. #include <sound/pcm_params.h>
  40. #include <sound/info.h>
  41. #include <sound/initval.h>
  42. #include <sound/control.h>
  43. #include <sound/tlv.h>
  44. #include <sound/ac97_codec.h>
  45. #include <media/v4l2-common.h>
  46. #include "em28xx.h"
  47. static int debug;
  48. module_param(debug, int, 0644);
  49. MODULE_PARM_DESC(debug, "activates debug info");
  50. #define dprintk(fmt, arg...) do { \
  51. if (debug) \
  52. printk(KERN_INFO "em28xx-audio %s: " fmt, \
  53. __func__, ##arg); \
  54. } while (0)
  55. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  56. static int em28xx_deinit_isoc_audio(struct em28xx *dev)
  57. {
  58. int i;
  59. dprintk("Stopping isoc\n");
  60. for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
  61. if (!irqs_disabled())
  62. usb_kill_urb(dev->adev.urb[i]);
  63. else
  64. usb_unlink_urb(dev->adev.urb[i]);
  65. usb_free_urb(dev->adev.urb[i]);
  66. dev->adev.urb[i] = NULL;
  67. kfree(dev->adev.transfer_buffer[i]);
  68. dev->adev.transfer_buffer[i] = NULL;
  69. }
  70. return 0;
  71. }
  72. static void em28xx_audio_isocirq(struct urb *urb)
  73. {
  74. struct em28xx *dev = urb->context;
  75. int i;
  76. unsigned int oldptr;
  77. int period_elapsed = 0;
  78. int status;
  79. unsigned char *cp;
  80. unsigned int stride;
  81. struct snd_pcm_substream *substream;
  82. struct snd_pcm_runtime *runtime;
  83. switch (urb->status) {
  84. case 0: /* success */
  85. case -ETIMEDOUT: /* NAK */
  86. break;
  87. case -ECONNRESET: /* kill */
  88. case -ENOENT:
  89. case -ESHUTDOWN:
  90. return;
  91. default: /* error */
  92. dprintk("urb completition error %d.\n", urb->status);
  93. break;
  94. }
  95. if (atomic_read(&dev->stream_started) == 0)
  96. return;
  97. if (dev->adev.capture_pcm_substream) {
  98. substream = dev->adev.capture_pcm_substream;
  99. runtime = substream->runtime;
  100. stride = runtime->frame_bits >> 3;
  101. for (i = 0; i < urb->number_of_packets; i++) {
  102. int length =
  103. urb->iso_frame_desc[i].actual_length / stride;
  104. cp = (unsigned char *)urb->transfer_buffer +
  105. urb->iso_frame_desc[i].offset;
  106. if (!length)
  107. continue;
  108. oldptr = dev->adev.hwptr_done_capture;
  109. if (oldptr + length >= runtime->buffer_size) {
  110. unsigned int cnt =
  111. runtime->buffer_size - oldptr;
  112. memcpy(runtime->dma_area + oldptr * stride, cp,
  113. cnt * stride);
  114. memcpy(runtime->dma_area, cp + cnt * stride,
  115. length * stride - cnt * stride);
  116. } else {
  117. memcpy(runtime->dma_area + oldptr * stride, cp,
  118. length * stride);
  119. }
  120. snd_pcm_stream_lock(substream);
  121. dev->adev.hwptr_done_capture += length;
  122. if (dev->adev.hwptr_done_capture >=
  123. runtime->buffer_size)
  124. dev->adev.hwptr_done_capture -=
  125. runtime->buffer_size;
  126. dev->adev.capture_transfer_done += length;
  127. if (dev->adev.capture_transfer_done >=
  128. runtime->period_size) {
  129. dev->adev.capture_transfer_done -=
  130. runtime->period_size;
  131. period_elapsed = 1;
  132. }
  133. snd_pcm_stream_unlock(substream);
  134. }
  135. if (period_elapsed)
  136. snd_pcm_period_elapsed(substream);
  137. }
  138. urb->status = 0;
  139. status = usb_submit_urb(urb, GFP_ATOMIC);
  140. if (status < 0) {
  141. em28xx_errdev("resubmit of audio urb failed (error=%i)\n",
  142. status);
  143. }
  144. return;
  145. }
  146. static int em28xx_init_audio_isoc(struct em28xx *dev)
  147. {
  148. int i, errCode;
  149. const int sb_size = EM28XX_NUM_AUDIO_PACKETS *
  150. EM28XX_AUDIO_MAX_PACKET_SIZE;
  151. dprintk("Starting isoc transfers\n");
  152. for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
  153. struct urb *urb;
  154. int j, k;
  155. dev->adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC);
  156. if (!dev->adev.transfer_buffer[i])
  157. return -ENOMEM;
  158. memset(dev->adev.transfer_buffer[i], 0x80, sb_size);
  159. urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
  160. if (!urb) {
  161. em28xx_errdev("usb_alloc_urb failed!\n");
  162. for (j = 0; j < i; j++) {
  163. usb_free_urb(dev->adev.urb[j]);
  164. kfree(dev->adev.transfer_buffer[j]);
  165. }
  166. return -ENOMEM;
  167. }
  168. urb->dev = dev->udev;
  169. urb->context = dev;
  170. urb->pipe = usb_rcvisocpipe(dev->udev, EM28XX_EP_AUDIO);
  171. urb->transfer_flags = URB_ISO_ASAP;
  172. urb->transfer_buffer = dev->adev.transfer_buffer[i];
  173. urb->interval = 1;
  174. urb->complete = em28xx_audio_isocirq;
  175. urb->number_of_packets = EM28XX_NUM_AUDIO_PACKETS;
  176. urb->transfer_buffer_length = sb_size;
  177. for (j = k = 0; j < EM28XX_NUM_AUDIO_PACKETS;
  178. j++, k += EM28XX_AUDIO_MAX_PACKET_SIZE) {
  179. urb->iso_frame_desc[j].offset = k;
  180. urb->iso_frame_desc[j].length =
  181. EM28XX_AUDIO_MAX_PACKET_SIZE;
  182. }
  183. dev->adev.urb[i] = urb;
  184. }
  185. for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
  186. errCode = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC);
  187. if (errCode) {
  188. em28xx_errdev("submit of audio urb failed\n");
  189. em28xx_deinit_isoc_audio(dev);
  190. atomic_set(&dev->stream_started, 0);
  191. return errCode;
  192. }
  193. }
  194. return 0;
  195. }
  196. static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
  197. size_t size)
  198. {
  199. struct snd_pcm_runtime *runtime = subs->runtime;
  200. dprintk("Allocating vbuffer\n");
  201. if (runtime->dma_area) {
  202. if (runtime->dma_bytes > size)
  203. return 0;
  204. vfree(runtime->dma_area);
  205. }
  206. runtime->dma_area = vmalloc(size);
  207. if (!runtime->dma_area)
  208. return -ENOMEM;
  209. runtime->dma_bytes = size;
  210. return 0;
  211. }
  212. static struct snd_pcm_hardware snd_em28xx_hw_capture = {
  213. .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
  214. SNDRV_PCM_INFO_MMAP |
  215. SNDRV_PCM_INFO_INTERLEAVED |
  216. SNDRV_PCM_INFO_BATCH |
  217. SNDRV_PCM_INFO_MMAP_VALID,
  218. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  219. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_KNOT,
  220. .rate_min = 48000,
  221. .rate_max = 48000,
  222. .channels_min = 2,
  223. .channels_max = 2,
  224. .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
  225. .period_bytes_min = 64, /* 12544/2, */
  226. .period_bytes_max = 12544,
  227. .periods_min = 2,
  228. .periods_max = 98, /* 12544, */
  229. };
  230. static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
  231. {
  232. struct em28xx *dev = snd_pcm_substream_chip(substream);
  233. struct snd_pcm_runtime *runtime = substream->runtime;
  234. int ret = 0;
  235. dprintk("opening device and trying to acquire exclusive lock\n");
  236. if (!dev) {
  237. em28xx_err("BUG: em28xx can't find device struct."
  238. " Can't proceed with open\n");
  239. return -ENODEV;
  240. }
  241. runtime->hw = snd_em28xx_hw_capture;
  242. if ((dev->alt == 0 || dev->audio_ifnum) && dev->adev.users == 0) {
  243. if (dev->audio_ifnum)
  244. dev->alt = 1;
  245. else
  246. dev->alt = 7;
  247. dprintk("changing alternate number on interface %d to %d\n",
  248. dev->audio_ifnum, dev->alt);
  249. usb_set_interface(dev->udev, dev->audio_ifnum, dev->alt);
  250. /* Sets volume, mute, etc */
  251. dev->mute = 0;
  252. mutex_lock(&dev->lock);
  253. ret = em28xx_audio_analog_set(dev);
  254. if (ret < 0)
  255. goto err;
  256. dev->adev.users++;
  257. mutex_unlock(&dev->lock);
  258. }
  259. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  260. dev->adev.capture_pcm_substream = substream;
  261. runtime->private_data = dev;
  262. return 0;
  263. err:
  264. mutex_unlock(&dev->lock);
  265. em28xx_err("Error while configuring em28xx mixer\n");
  266. return ret;
  267. }
  268. static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream)
  269. {
  270. struct em28xx *dev = snd_pcm_substream_chip(substream);
  271. dprintk("closing device\n");
  272. dev->mute = 1;
  273. mutex_lock(&dev->lock);
  274. dev->adev.users--;
  275. if (atomic_read(&dev->stream_started) > 0) {
  276. atomic_set(&dev->stream_started, 0);
  277. schedule_work(&dev->wq_trigger);
  278. }
  279. em28xx_audio_analog_set(dev);
  280. if (substream->runtime->dma_area) {
  281. dprintk("freeing\n");
  282. vfree(substream->runtime->dma_area);
  283. substream->runtime->dma_area = NULL;
  284. }
  285. mutex_unlock(&dev->lock);
  286. return 0;
  287. }
  288. static int snd_em28xx_hw_capture_params(struct snd_pcm_substream *substream,
  289. struct snd_pcm_hw_params *hw_params)
  290. {
  291. int ret;
  292. dprintk("Setting capture parameters\n");
  293. ret = snd_pcm_alloc_vmalloc_buffer(substream,
  294. params_buffer_bytes(hw_params));
  295. if (ret < 0)
  296. return ret;
  297. #if 0
  298. /* TODO: set up em28xx audio chip to deliver the correct audio format,
  299. current default is 48000hz multiplexed => 96000hz mono
  300. which shouldn't matter since analogue TV only supports mono */
  301. unsigned int channels, rate, format;
  302. format = params_format(hw_params);
  303. rate = params_rate(hw_params);
  304. channels = params_channels(hw_params);
  305. #endif
  306. return 0;
  307. }
  308. static int snd_em28xx_hw_capture_free(struct snd_pcm_substream *substream)
  309. {
  310. struct em28xx *dev = snd_pcm_substream_chip(substream);
  311. dprintk("Stop capture, if needed\n");
  312. if (atomic_read(&dev->stream_started) > 0) {
  313. atomic_set(&dev->stream_started, 0);
  314. schedule_work(&dev->wq_trigger);
  315. }
  316. return 0;
  317. }
  318. static int snd_em28xx_prepare(struct snd_pcm_substream *substream)
  319. {
  320. struct em28xx *dev = snd_pcm_substream_chip(substream);
  321. dev->adev.hwptr_done_capture = 0;
  322. dev->adev.capture_transfer_done = 0;
  323. return 0;
  324. }
  325. static void audio_trigger(struct work_struct *work)
  326. {
  327. struct em28xx *dev = container_of(work, struct em28xx, wq_trigger);
  328. if (atomic_read(&dev->stream_started)) {
  329. dprintk("starting capture");
  330. em28xx_init_audio_isoc(dev);
  331. } else {
  332. dprintk("stopping capture");
  333. em28xx_deinit_isoc_audio(dev);
  334. }
  335. }
  336. static int snd_em28xx_capture_trigger(struct snd_pcm_substream *substream,
  337. int cmd)
  338. {
  339. struct em28xx *dev = snd_pcm_substream_chip(substream);
  340. int retval = 0;
  341. switch (cmd) {
  342. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
  343. case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
  344. case SNDRV_PCM_TRIGGER_START:
  345. atomic_set(&dev->stream_started, 1);
  346. break;
  347. case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
  348. case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
  349. case SNDRV_PCM_TRIGGER_STOP:
  350. atomic_set(&dev->stream_started, 0);
  351. break;
  352. default:
  353. retval = -EINVAL;
  354. }
  355. schedule_work(&dev->wq_trigger);
  356. return retval;
  357. }
  358. static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream
  359. *substream)
  360. {
  361. unsigned long flags;
  362. struct em28xx *dev;
  363. snd_pcm_uframes_t hwptr_done;
  364. dev = snd_pcm_substream_chip(substream);
  365. spin_lock_irqsave(&dev->adev.slock, flags);
  366. hwptr_done = dev->adev.hwptr_done_capture;
  367. spin_unlock_irqrestore(&dev->adev.slock, flags);
  368. return hwptr_done;
  369. }
  370. static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
  371. unsigned long offset)
  372. {
  373. void *pageptr = subs->runtime->dma_area + offset;
  374. return vmalloc_to_page(pageptr);
  375. }
  376. /*
  377. * AC97 volume control support
  378. */
  379. static int em28xx_vol_info(struct snd_kcontrol *kcontrol,
  380. struct snd_ctl_elem_info *info)
  381. {
  382. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  383. info->count = 2;
  384. info->value.integer.min = 0;
  385. info->value.integer.max = 0x1f;
  386. return 0;
  387. }
  388. static int em28xx_vol_put(struct snd_kcontrol *kcontrol,
  389. struct snd_ctl_elem_value *value)
  390. {
  391. struct em28xx *dev = snd_kcontrol_chip(kcontrol);
  392. u16 val = (0x1f - (value->value.integer.value[0] & 0x1f)) |
  393. (0x1f - (value->value.integer.value[1] & 0x1f)) << 8;
  394. int rc;
  395. mutex_lock(&dev->lock);
  396. rc = em28xx_read_ac97(dev, kcontrol->private_value);
  397. if (rc < 0)
  398. goto err;
  399. val |= rc & 0x8000; /* Preserve the mute flag */
  400. rc = em28xx_write_ac97(dev, kcontrol->private_value, val);
  401. if (rc < 0)
  402. goto err;
  403. dprintk("%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
  404. (val & 0x8000) ? "muted " : "",
  405. 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
  406. val, (int)kcontrol->private_value);
  407. err:
  408. mutex_unlock(&dev->lock);
  409. return rc;
  410. }
  411. static int em28xx_vol_get(struct snd_kcontrol *kcontrol,
  412. struct snd_ctl_elem_value *value)
  413. {
  414. struct em28xx *dev = snd_kcontrol_chip(kcontrol);
  415. int val;
  416. mutex_lock(&dev->lock);
  417. val = em28xx_read_ac97(dev, kcontrol->private_value);
  418. mutex_unlock(&dev->lock);
  419. if (val < 0)
  420. return val;
  421. dprintk("%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
  422. (val & 0x8000) ? "muted " : "",
  423. 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
  424. val, (int)kcontrol->private_value);
  425. value->value.integer.value[0] = 0x1f - (val & 0x1f);
  426. value->value.integer.value[1] = 0x1f - ((val << 8) & 0x1f);
  427. return 0;
  428. }
  429. static int em28xx_vol_put_mute(struct snd_kcontrol *kcontrol,
  430. struct snd_ctl_elem_value *value)
  431. {
  432. struct em28xx *dev = snd_kcontrol_chip(kcontrol);
  433. u16 val = value->value.integer.value[0];
  434. int rc;
  435. mutex_lock(&dev->lock);
  436. rc = em28xx_read_ac97(dev, kcontrol->private_value);
  437. if (rc < 0)
  438. goto err;
  439. if (val)
  440. rc &= 0x1f1f;
  441. else
  442. rc |= 0x8000;
  443. rc = em28xx_write_ac97(dev, kcontrol->private_value, rc);
  444. if (rc < 0)
  445. goto err;
  446. dprintk("%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
  447. (val & 0x8000) ? "muted " : "",
  448. 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
  449. val, (int)kcontrol->private_value);
  450. err:
  451. mutex_unlock(&dev->lock);
  452. return rc;
  453. }
  454. static int em28xx_vol_get_mute(struct snd_kcontrol *kcontrol,
  455. struct snd_ctl_elem_value *value)
  456. {
  457. struct em28xx *dev = snd_kcontrol_chip(kcontrol);
  458. int val;
  459. mutex_lock(&dev->lock);
  460. val = em28xx_read_ac97(dev, kcontrol->private_value);
  461. mutex_unlock(&dev->lock);
  462. if (val < 0)
  463. return val;
  464. if (val & 0x8000)
  465. value->value.integer.value[0] = 0;
  466. else
  467. value->value.integer.value[0] = 1;
  468. dprintk("%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
  469. (val & 0x8000) ? "muted " : "",
  470. 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
  471. val, (int)kcontrol->private_value);
  472. return 0;
  473. }
  474. static const DECLARE_TLV_DB_SCALE(em28xx_db_scale, -3450, 150, 0);
  475. static int em28xx_cvol_new(struct snd_card *card, struct em28xx *dev,
  476. char *name, int id)
  477. {
  478. int err;
  479. char ctl_name[44];
  480. struct snd_kcontrol *kctl;
  481. struct snd_kcontrol_new tmp;
  482. memset (&tmp, 0, sizeof(tmp));
  483. tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  484. tmp.private_value = id,
  485. tmp.name = ctl_name,
  486. /* Add Mute Control */
  487. sprintf(ctl_name, "%s Switch", name);
  488. tmp.get = em28xx_vol_get_mute;
  489. tmp.put = em28xx_vol_put_mute;
  490. tmp.info = snd_ctl_boolean_mono_info;
  491. kctl = snd_ctl_new1(&tmp, dev);
  492. err = snd_ctl_add(card, kctl);
  493. if (err < 0)
  494. return err;
  495. dprintk("Added control %s for ac97 volume control 0x%04x\n",
  496. ctl_name, id);
  497. memset (&tmp, 0, sizeof(tmp));
  498. tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  499. tmp.private_value = id,
  500. tmp.name = ctl_name,
  501. /* Add Volume Control */
  502. sprintf(ctl_name, "%s Volume", name);
  503. tmp.get = em28xx_vol_get;
  504. tmp.put = em28xx_vol_put;
  505. tmp.info = em28xx_vol_info;
  506. tmp.tlv.p = em28xx_db_scale,
  507. kctl = snd_ctl_new1(&tmp, dev);
  508. err = snd_ctl_add(card, kctl);
  509. if (err < 0)
  510. return err;
  511. dprintk("Added control %s for ac97 volume control 0x%04x\n",
  512. ctl_name, id);
  513. return 0;
  514. }
  515. /*
  516. * register/unregister code and data
  517. */
  518. static struct snd_pcm_ops snd_em28xx_pcm_capture = {
  519. .open = snd_em28xx_capture_open,
  520. .close = snd_em28xx_pcm_close,
  521. .ioctl = snd_pcm_lib_ioctl,
  522. .hw_params = snd_em28xx_hw_capture_params,
  523. .hw_free = snd_em28xx_hw_capture_free,
  524. .prepare = snd_em28xx_prepare,
  525. .trigger = snd_em28xx_capture_trigger,
  526. .pointer = snd_em28xx_capture_pointer,
  527. .page = snd_pcm_get_vmalloc_page,
  528. };
  529. static int em28xx_audio_init(struct em28xx *dev)
  530. {
  531. struct em28xx_audio *adev = &dev->adev;
  532. struct snd_pcm *pcm;
  533. struct snd_card *card;
  534. static int devnr;
  535. int err;
  536. if (!dev->has_alsa_audio || dev->audio_ifnum < 0) {
  537. /* This device does not support the extension (in this case
  538. the device is expecting the snd-usb-audio module or
  539. doesn't have analog audio support at all) */
  540. return 0;
  541. }
  542. printk(KERN_INFO "em28xx-audio.c: probing for em28xx Audio Vendor Class\n");
  543. printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
  544. "Rechberger\n");
  545. printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2007-2011 Mauro Carvalho Chehab\n");
  546. err = snd_card_create(index[devnr], "Em28xx Audio", THIS_MODULE, 0,
  547. &card);
  548. if (err < 0)
  549. return err;
  550. spin_lock_init(&adev->slock);
  551. err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
  552. if (err < 0) {
  553. snd_card_free(card);
  554. return err;
  555. }
  556. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
  557. pcm->info_flags = 0;
  558. pcm->private_data = dev;
  559. strcpy(pcm->name, "Empia 28xx Capture");
  560. snd_card_set_dev(card, &dev->udev->dev);
  561. strcpy(card->driver, "Em28xx-Audio");
  562. strcpy(card->shortname, "Em28xx Audio");
  563. strcpy(card->longname, "Empia Em28xx Audio");
  564. INIT_WORK(&dev->wq_trigger, audio_trigger);
  565. if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
  566. em28xx_cvol_new(card, dev, "Video", AC97_VIDEO);
  567. em28xx_cvol_new(card, dev, "Line In", AC97_LINE);
  568. em28xx_cvol_new(card, dev, "Phone", AC97_PHONE);
  569. em28xx_cvol_new(card, dev, "Microphone", AC97_MIC);
  570. em28xx_cvol_new(card, dev, "CD", AC97_CD);
  571. em28xx_cvol_new(card, dev, "AUX", AC97_AUX);
  572. em28xx_cvol_new(card, dev, "PCM", AC97_PCM);
  573. em28xx_cvol_new(card, dev, "Master", AC97_MASTER);
  574. em28xx_cvol_new(card, dev, "Line", AC97_HEADPHONE);
  575. em28xx_cvol_new(card, dev, "Mono", AC97_MASTER_MONO);
  576. em28xx_cvol_new(card, dev, "LFE", AC97_CENTER_LFE_MASTER);
  577. em28xx_cvol_new(card, dev, "Surround", AC97_SURROUND_MASTER);
  578. }
  579. err = snd_card_register(card);
  580. if (err < 0) {
  581. snd_card_free(card);
  582. return err;
  583. }
  584. adev->sndcard = card;
  585. adev->udev = dev->udev;
  586. return 0;
  587. }
  588. static int em28xx_audio_fini(struct em28xx *dev)
  589. {
  590. if (dev == NULL)
  591. return 0;
  592. if (dev->has_alsa_audio != 1) {
  593. /* This device does not support the extension (in this case
  594. the device is expecting the snd-usb-audio module or
  595. doesn't have analog audio support at all) */
  596. return 0;
  597. }
  598. if (dev->adev.sndcard) {
  599. snd_card_free(dev->adev.sndcard);
  600. dev->adev.sndcard = NULL;
  601. }
  602. return 0;
  603. }
  604. static struct em28xx_ops audio_ops = {
  605. .id = EM28XX_AUDIO,
  606. .name = "Em28xx Audio Extension",
  607. .init = em28xx_audio_init,
  608. .fini = em28xx_audio_fini,
  609. };
  610. static int __init em28xx_alsa_register(void)
  611. {
  612. return em28xx_register_extension(&audio_ops);
  613. }
  614. static void __exit em28xx_alsa_unregister(void)
  615. {
  616. em28xx_unregister_extension(&audio_ops);
  617. }
  618. MODULE_LICENSE("GPL");
  619. MODULE_AUTHOR("Markus Rechberger <mrechberger@gmail.com>");
  620. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  621. MODULE_DESCRIPTION("Em28xx Audio driver");
  622. module_init(em28xx_alsa_register);
  623. module_exit(em28xx_alsa_unregister);