28 #include <linux/kernel.h>
31 #include <linux/sound.h>
33 #include <linux/soundcard.h>
34 #include <linux/slab.h>
37 #include <linux/module.h>
53 #define dprintk(fmt, arg...) do { \
55 printk(KERN_INFO "em28xx-audio %s: " fmt, \
61 static int em28xx_deinit_isoc_audio(
struct em28xx *
dev)
82 static void em28xx_audio_isocirq(
struct urb *
urb)
87 int period_elapsed = 0;
94 switch (urb->status) {
103 dprintk(
"urb completition error %d.\n", urb->status);
110 if (dev->
adev.capture_pcm_substream) {
111 substream = dev->
adev.capture_pcm_substream;
115 for (i = 0; i < urb->number_of_packets; i++) {
117 urb->iso_frame_desc[
i].actual_length / stride;
118 cp = (
unsigned char *)urb->transfer_buffer +
119 urb->iso_frame_desc[i].offset;
124 oldptr = dev->
adev.hwptr_done_capture;
131 length * stride - cnt * stride);
137 snd_pcm_stream_lock(substream);
140 if (dev->
adev.hwptr_done_capture >=
142 dev->
adev.hwptr_done_capture -=
146 if (dev->
adev.capture_transfer_done >=
148 dev->
adev.capture_transfer_done -=
153 snd_pcm_stream_unlock(substream);
168 static int em28xx_init_audio_isoc(
struct em28xx *dev)
174 dprintk(
"Starting isoc transfers\n");
181 if (!dev->
adev.transfer_buffer[i])
184 memset(dev->
adev.transfer_buffer[i], 0x80, sb_size);
188 for (j = 0; j <
i; j++) {
195 urb->dev = dev->
udev;
198 urb->transfer_flags = URB_ISO_ASAP;
199 urb->transfer_buffer = dev->
adev.transfer_buffer[
i];
201 urb->complete = em28xx_audio_isocirq;
203 urb->transfer_buffer_length = sb_size;
207 urb->iso_frame_desc[
j].offset =
k;
208 urb->iso_frame_desc[
j].length =
218 em28xx_deinit_isoc_audio(dev);
233 dprintk(
"Allocating vbuffer\n");
264 .buffer_bytes_max = 62720 * 8,
265 .period_bytes_min = 64,
266 .period_bytes_max = 12544,
277 dprintk(
"opening device and trying to acquire exclusive lock\n");
280 em28xx_err(
"BUG: em28xx can't find device struct."
281 " Can't proceed with open\n");
285 runtime->
hw = snd_em28xx_hw_capture;
292 dprintk(
"changing alternate number on interface %d to %d\n",
308 dev->
adev.capture_pcm_substream = substream;
314 em28xx_err(
"Error while configuring em28xx mixer\n");
333 if (substream->
runtime->dma_area) {
348 dprintk(
"Setting capture parameters\n");
350 ret = snd_pcm_alloc_vmalloc_buffer(substream,
372 dprintk(
"Stop capture, if needed\n");
386 dev->
adev.hwptr_done_capture = 0;
387 dev->
adev.capture_transfer_done = 0;
398 em28xx_init_audio_isoc(dev);
401 em28xx_deinit_isoc_audio(dev);
438 hwptr_done = dev->
adev.hwptr_done_capture;
439 spin_unlock_irqrestore(&dev->
adev.slock, flags);
455 static int em28xx_vol_info(
struct snd_kcontrol *kcontrol,
466 static int em28xx_vol_put(
struct snd_kcontrol *kcontrol,
470 u16 val = (0x1f - (value->
value.integer.value[0] & 0x1f)) |
471 (0x1f - (value->
value.integer.value[1] & 0x1f)) << 8;
485 dprintk(
"%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
486 (val & 0x8000) ?
"muted " :
"",
487 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
495 static int em28xx_vol_get(
struct snd_kcontrol *kcontrol,
507 dprintk(
"%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
508 (val & 0x8000) ?
"muted " :
"",
509 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
512 value->
value.integer.value[0] = 0x1f - (val & 0x1f);
513 value->
value.integer.value[1] = 0x1f - ((val << 8) & 0x1f);
518 static int em28xx_vol_put_mute(
struct snd_kcontrol *kcontrol,
522 u16 val = value->
value.integer.value[0];
539 dprintk(
"%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
540 (val & 0x8000) ?
"muted " :
"",
541 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
549 static int em28xx_vol_get_mute(
struct snd_kcontrol *kcontrol,
562 value->
value.integer.value[0] = 0;
564 value->
value.integer.value[0] = 1;
566 dprintk(
"%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
567 (val & 0x8000) ?
"muted " :
"",
568 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
586 tmp.private_value =
id,
590 sprintf(ctl_name,
"%s Switch", name);
591 tmp.get = em28xx_vol_get_mute;
592 tmp.put = em28xx_vol_put_mute;
598 dprintk(
"Added control %s for ac97 volume control 0x%04x\n",
603 tmp.private_value =
id,
607 sprintf(ctl_name,
"%s Volume", name);
608 tmp.get = em28xx_vol_get;
609 tmp.put = em28xx_vol_put;
610 tmp.info = em28xx_vol_info;
611 tmp.tlv.p = em28xx_db_scale,
616 dprintk(
"Added control %s for ac97 volume control 0x%04x\n",
625 static struct snd_pcm_ops snd_em28xx_pcm_capture = {
626 .open = snd_em28xx_capture_open,
627 .close = snd_em28xx_pcm_close,
629 .hw_params = snd_em28xx_hw_capture_params,
630 .hw_free = snd_em28xx_hw_capture_free,
631 .prepare = snd_em28xx_prepare,
632 .trigger = snd_em28xx_capture_trigger,
633 .pointer = snd_em28xx_capture_pointer,
634 .page = snd_pcm_get_vmalloc_page,
637 static int em28xx_audio_init(
struct em28xx *dev)
652 printk(
KERN_INFO "em28xx-audio.c: probing for em28xx Audio Vendor Class\n");
655 printk(
KERN_INFO "em28xx-audio.c: Copyright (C) 2007-2011 Mauro Carvalho Chehab\n");
663 err =
snd_pcm_new(card,
"Em28xx Audio", 0, 0, 1, &pcm);
682 em28xx_cvol_new(card, dev,
"Video",
AC97_VIDEO);
683 em28xx_cvol_new(card, dev,
"Line In",
AC97_LINE);
684 em28xx_cvol_new(card, dev,
"Phone",
AC97_PHONE);
685 em28xx_cvol_new(card, dev,
"Microphone",
AC97_MIC);
686 em28xx_cvol_new(card, dev,
"CD",
AC97_CD);
687 em28xx_cvol_new(card, dev,
"AUX",
AC97_AUX);
688 em28xx_cvol_new(card, dev,
"PCM",
AC97_PCM);
708 static int em28xx_audio_fini(
struct em28xx *dev)
720 if (dev->
adev.sndcard) {
730 .name =
"Em28xx Audio Extension",
731 .init = em28xx_audio_init,
732 .fini = em28xx_audio_fini,
735 static int __init em28xx_alsa_register(
void)
740 static void __exit em28xx_alsa_unregister(
void)