^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Empiatech em28x1 audio extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright (C) 2006 Markus Rechberger <mrechberger@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Copyright (C) 2007-2016 Mauro Carvalho Chehab
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // - Port to work with the in-kernel driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // - Cleanups, fixes, alsa-controls, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) // This driver is based on my previous au600 usb pstn audio driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) // and inherits all the copyrights
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) // This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) // it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) // the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) // (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) // This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) // but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) // GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "em28xx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/sound.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/soundcard.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <sound/info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <sound/ac97_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <media/v4l2-common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) module_param(debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) MODULE_PARM_DESC(debug, "activates debug info");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define EM28XX_MAX_AUDIO_BUFS 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define EM28XX_MIN_AUDIO_PACKETS 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define dprintk(fmt, arg...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (debug) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) dev_printk(KERN_DEBUG, &dev->intf->dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "video: %s: " fmt, __func__, ## arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static int em28xx_deinit_isoc_audio(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dprintk("Stopping isoc\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) for (i = 0; i < dev->adev.num_urb; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct urb *urb = dev->adev.urb[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (!irqs_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) usb_kill_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) usb_unlink_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void em28xx_audio_isocirq(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct em28xx *dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned int oldptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int period_elapsed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unsigned char *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned int stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (dev->disconnected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dprintk("device disconnected while streaming. URB status=%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) atomic_set(&dev->adev.stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) case 0: /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case -ETIMEDOUT: /* NAK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) case -ECONNRESET: /* kill */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) default: /* error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) dprintk("urb completion error %d.\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (atomic_read(&dev->adev.stream_started) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (dev->adev.capture_pcm_substream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) substream = dev->adev.capture_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) stride = runtime->frame_bits >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) for (i = 0; i < urb->number_of_packets; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) urb->iso_frame_desc[i].actual_length / stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) cp = (unsigned char *)urb->transfer_buffer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) urb->iso_frame_desc[i].offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) oldptr = dev->adev.hwptr_done_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (oldptr + length >= runtime->buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned int cnt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) runtime->buffer_size - oldptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) memcpy(runtime->dma_area + oldptr * stride, cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) cnt * stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) memcpy(runtime->dma_area, cp + cnt * stride,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) length * stride - cnt * stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) memcpy(runtime->dma_area + oldptr * stride, cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) length * stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) snd_pcm_stream_lock_irqsave(substream, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dev->adev.hwptr_done_capture += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (dev->adev.hwptr_done_capture >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) runtime->buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dev->adev.hwptr_done_capture -=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) dev->adev.capture_transfer_done += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (dev->adev.capture_transfer_done >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) runtime->period_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dev->adev.capture_transfer_done -=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) period_elapsed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) snd_pcm_stream_unlock_irqrestore(substream, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (period_elapsed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) snd_pcm_period_elapsed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) status = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) "resubmit of audio urb failed (error=%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int em28xx_init_audio_isoc(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) dprintk("Starting isoc transfers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Start streaming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (i = 0; i < dev->adev.num_urb; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) memset(dev->adev.transfer_buffer[i], 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) dev->adev.urb[i]->transfer_buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) err = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) "submit of audio urb failed (error=%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) em28xx_deinit_isoc_audio(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) atomic_set(&dev->adev.stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static const struct snd_pcm_hardware snd_em28xx_hw_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) SNDRV_PCM_INFO_BATCH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) SNDRV_PCM_INFO_MMAP_VALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .rates = SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .rate_min = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .rate_max = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * The period is 12.288 bytes. Allow a 10% of variation along its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * value, in order to avoid overruns/underruns due to some clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * drift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * FIXME: This period assumes 64 packets, and a 48000 PCM rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Calculate it dynamically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .period_bytes_min = 11059,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .period_bytes_max = 13516,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .periods_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .periods_max = 98, /* 12544, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct em28xx *dev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int nonblock, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) pr_err("em28xx-audio: BUG: em28xx can't find device struct. Can't proceed with open\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) dprintk("opening device and trying to acquire exclusive lock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) nonblock = !!(substream->f_flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!mutex_trylock(&dev->lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) mutex_lock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) runtime->hw = snd_em28xx_hw_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (dev->adev.users == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (!dev->alt || dev->is_audio_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) udev = interface_to_usbdev(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (dev->is_audio_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* audio is on a separate interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) dev->alt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* audio is on the same interface as video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dev->alt = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * FIXME: The intention seems to be to select
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * the alt setting with the largest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * wMaxPacketSize for the video endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * At least dev->alt should be used instead, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * we should probably not touch it at all if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * is already >0, because wMaxPacketSize of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * audio endpoints seems to be the same for all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dprintk("changing alternate number on interface %d to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dev->ifnum, dev->alt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) usb_set_interface(udev, dev->ifnum, dev->alt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Sets volume, mute, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) dev->mute = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ret = em28xx_audio_analog_set(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) kref_get(&dev->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev->adev.users++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* Dynamically adjust the period size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) dev->adev.period * 95 / 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dev->adev.period * 105 / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dev->adev.capture_pcm_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) "Error while configuring em28xx mixer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct em28xx *dev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) dprintk("closing device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) dev->mute = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) mutex_lock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) dev->adev.users--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (atomic_read(&dev->adev.stream_started) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) atomic_set(&dev->adev.stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) schedule_work(&dev->adev.wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) em28xx_audio_analog_set(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) kref_put(&dev->ref, em28xx_free_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int snd_em28xx_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct em28xx *dev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) dev->adev.hwptr_done_capture = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dev->adev.capture_transfer_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static void audio_trigger(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct em28xx_audio *adev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) container_of(work, struct em28xx_audio, wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct em28xx *dev = container_of(adev, struct em28xx, adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (atomic_read(&adev->stream_started)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) dprintk("starting capture");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) em28xx_init_audio_isoc(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) dprintk("stopping capture");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) em28xx_deinit_isoc_audio(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static int snd_em28xx_capture_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct em28xx *dev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) atomic_set(&dev->adev.stream_started, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) atomic_set(&dev->adev.stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) schedule_work(&dev->adev.wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct em28xx *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) snd_pcm_uframes_t hwptr_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) dev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return SNDRV_PCM_POS_XRUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) spin_lock_irqsave(&dev->adev.slock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) hwptr_done = dev->adev.hwptr_done_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) spin_unlock_irqrestore(&dev->adev.slock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return hwptr_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * AC97 volume control support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static int em28xx_vol_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct snd_ctl_elem_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct em28xx *dev = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) info->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) info->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) info->value.integer.max = 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static int em28xx_vol_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct em28xx *dev = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) u16 val = (0x1f - (value->value.integer.value[0] & 0x1f)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) (0x1f - (value->value.integer.value[1] & 0x1f)) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) int nonblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) nonblock = !!(substream->f_flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (!mutex_trylock(&dev->lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mutex_lock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) rc = em28xx_read_ac97(dev, kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) val |= rc & 0x8000; /* Preserve the mute flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) rc = em28xx_write_ac97(dev, kcontrol->private_value, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) dprintk("%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) (val & 0x8000) ? "muted " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) val, (int)kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static int em28xx_vol_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct em28xx *dev = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int nonblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) nonblock = !!(substream->f_flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (!mutex_trylock(&dev->lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) mutex_lock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) val = em28xx_read_ac97(dev, kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) dprintk("%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) (val & 0x8000) ? "muted " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) val, (int)kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) value->value.integer.value[0] = 0x1f - (val & 0x1f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) value->value.integer.value[1] = 0x1f - ((val >> 8) & 0x1f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static int em28xx_vol_put_mute(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct em28xx *dev = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) u16 val = value->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) int nonblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) nonblock = !!(substream->f_flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (!mutex_trylock(&dev->lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) mutex_lock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) rc = em28xx_read_ac97(dev, kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) rc &= 0x1f1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) rc |= 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) rc = em28xx_write_ac97(dev, kcontrol->private_value, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) dprintk("%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) (val & 0x8000) ? "muted " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) val, (int)kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int em28xx_vol_get_mute(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct em28xx *dev = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int nonblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (dev->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) nonblock = !!(substream->f_flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (!mutex_trylock(&dev->lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) mutex_lock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) val = em28xx_read_ac97(dev, kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) mutex_unlock(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (val & 0x8000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) value->value.integer.value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) value->value.integer.value[0] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) dprintk("%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) (val & 0x8000) ? "muted " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) val, (int)kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static const DECLARE_TLV_DB_SCALE(em28xx_db_scale, -3450, 150, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static int em28xx_cvol_new(struct snd_card *card, struct em28xx *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) char *name, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) char ctl_name[44];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct snd_kcontrol_new tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) memset(&tmp, 0, sizeof(tmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) tmp.private_value = id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) tmp.name = ctl_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /* Add Mute Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) sprintf(ctl_name, "%s Switch", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) tmp.get = em28xx_vol_get_mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) tmp.put = em28xx_vol_put_mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) tmp.info = snd_ctl_boolean_mono_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) kctl = snd_ctl_new1(&tmp, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) err = snd_ctl_add(card, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) dprintk("Added control %s for ac97 volume control 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) ctl_name, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) memset(&tmp, 0, sizeof(tmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) tmp.private_value = id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) tmp.name = ctl_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /* Add Volume Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) sprintf(ctl_name, "%s Volume", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) tmp.get = em28xx_vol_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) tmp.put = em28xx_vol_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) tmp.info = em28xx_vol_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) tmp.tlv.p = em28xx_db_scale,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) kctl = snd_ctl_new1(&tmp, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) err = snd_ctl_add(card, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) dprintk("Added control %s for ac97 volume control 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) ctl_name, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * register/unregister code and data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .open = snd_em28xx_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .close = snd_em28xx_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) .prepare = snd_em28xx_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .trigger = snd_em28xx_capture_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .pointer = snd_em28xx_capture_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static void em28xx_audio_free_urb(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct usb_device *udev = interface_to_usbdev(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) for (i = 0; i < dev->adev.num_urb; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct urb *urb = dev->adev.urb[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) usb_free_coherent(udev, urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) dev->adev.transfer_buffer[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) kfree(dev->adev.urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) kfree(dev->adev.transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) dev->adev.num_urb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static int em28xx_audio_ep_packet_size(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct usb_endpoint_descriptor *e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) int size = le16_to_cpu(e->wMaxPacketSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (udev->speed == USB_SPEED_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return (size & 0x7ff) * (1 + (((size) >> 11) & 0x03));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return size & 0x7ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static int em28xx_audio_urb_init(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct usb_endpoint_descriptor *e, *ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct usb_device *udev = interface_to_usbdev(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) int i, ep_size, interval, num_urb, npackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) int urb_size, bytes_per_transfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) u8 alt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (dev->ifnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) alt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) alt = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) intf = usb_ifnum_to_if(udev, dev->ifnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (intf->num_altsetting <= alt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) dev_err(&dev->intf->dev, "alt %d doesn't exist on interface %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) dev->ifnum, alt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) for (i = 0; i < intf->altsetting[alt].desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) e = &intf->altsetting[alt].endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (!usb_endpoint_dir_in(e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (e->bEndpointAddress == EM28XX_EP_AUDIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) ep = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) dev_err(&dev->intf->dev, "Couldn't find an audio endpoint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) ep_size = em28xx_audio_ep_packet_size(udev, ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) interval = 1 << (ep->bInterval - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) dev_info(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) "Endpoint 0x%02x %s on intf %d alt %d interval = %d, size %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) EM28XX_EP_AUDIO, usb_speed_string(udev->speed),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) dev->ifnum, alt, interval, ep_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /* Calculate the number and size of URBs to better fit the audio samples */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * Estimate the number of bytes per DMA transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) * This is given by the bit rate (for now, only 48000 Hz) multiplied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) * by 2 channels and 2 bytes/sample divided by the number of microframe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * intervals and by the microframe rate (125 us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) bytes_per_transfer = DIV_ROUND_UP(48000 * 2 * 2, 125 * interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * Estimate the number of transfer URBs. Don't let it go past the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * maximum number of URBs that is known to be supported by the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) num_urb = DIV_ROUND_UP(bytes_per_transfer, ep_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (num_urb > EM28XX_MAX_AUDIO_BUFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) num_urb = EM28XX_MAX_AUDIO_BUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * Now that we know the number of bytes per transfer and the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * URBs, estimate the typical size of an URB, in order to adjust the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * minimal number of packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) urb_size = bytes_per_transfer / num_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) * Now, calculate the amount of audio packets to be filled on each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * URB. In order to preserve the old behaviour, use a minimal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * threshold for this value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) npackets = EM28XX_MIN_AUDIO_PACKETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (urb_size > ep_size * npackets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) npackets = DIV_ROUND_UP(urb_size, ep_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) dev_info(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) "Number of URBs: %d, with %d packets and %d size\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) num_urb, npackets, urb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) /* Estimate the bytes per period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) dev->adev.period = urb_size * npackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /* Allocate space to store the number of URBs to be used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) dev->adev.transfer_buffer = kcalloc(num_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) sizeof(*dev->adev.transfer_buffer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (!dev->adev.transfer_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) dev->adev.urb = kcalloc(num_urb, sizeof(*dev->adev.urb), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (!dev->adev.urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) kfree(dev->adev.transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /* Alloc memory for each URB and for each transfer buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) dev->adev.num_urb = num_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) for (i = 0; i < num_urb; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) urb = usb_alloc_urb(npackets, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) em28xx_audio_free_urb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) dev->adev.urb[i] = urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) buf = usb_alloc_coherent(udev, npackets * ep_size, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) &urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) "usb_alloc_coherent failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) em28xx_audio_free_urb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) dev->adev.transfer_buffer[i] = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) urb->dev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) urb->context = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) urb->pipe = usb_rcvisocpipe(udev, EM28XX_EP_AUDIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) urb->transfer_buffer = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) urb->interval = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) urb->complete = em28xx_audio_isocirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) urb->number_of_packets = npackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) urb->transfer_buffer_length = ep_size * npackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) for (j = k = 0; j < npackets; j++, k += ep_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) urb->iso_frame_desc[j].offset = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) urb->iso_frame_desc[j].length = ep_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) static int em28xx_audio_init(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) struct em28xx_audio *adev = &dev->adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) struct usb_device *udev = interface_to_usbdev(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) static int devnr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * This device does not support the extension (in this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) * the device is expecting the snd-usb-audio module or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) * doesn't have analog audio support at all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) dev_info(&dev->intf->dev, "Binding audio extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) kref_get(&dev->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) dev_info(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) "em28xx-audio.c: Copyright (C) 2006 Markus Rechberger\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) dev_info(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) "em28xx-audio.c: Copyright (C) 2007-2016 Mauro Carvalho Chehab\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) err = snd_card_new(&dev->intf->dev, index[devnr], "Em28xx Audio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) THIS_MODULE, 0, &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) spin_lock_init(&adev->slock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) adev->sndcard = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) adev->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) goto card_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) pcm->private_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) strscpy(pcm->name, "Empia 28xx Capture", sizeof(pcm->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) strscpy(card->driver, "Em28xx-Audio", sizeof(card->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) strscpy(card->shortname, "Em28xx Audio", sizeof(card->shortname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) strscpy(card->longname, "Empia Em28xx Audio", sizeof(card->longname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) INIT_WORK(&adev->wq_trigger, audio_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) em28xx_cvol_new(card, dev, "Video", AC97_VIDEO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) em28xx_cvol_new(card, dev, "Line In", AC97_LINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) em28xx_cvol_new(card, dev, "Phone", AC97_PHONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) em28xx_cvol_new(card, dev, "Microphone", AC97_MIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) em28xx_cvol_new(card, dev, "CD", AC97_CD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) em28xx_cvol_new(card, dev, "AUX", AC97_AUX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) em28xx_cvol_new(card, dev, "PCM", AC97_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) em28xx_cvol_new(card, dev, "Master", AC97_MASTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) em28xx_cvol_new(card, dev, "Line", AC97_HEADPHONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) em28xx_cvol_new(card, dev, "Mono", AC97_MASTER_MONO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) em28xx_cvol_new(card, dev, "LFE", AC97_CENTER_LFE_MASTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) em28xx_cvol_new(card, dev, "Surround", AC97_SURROUND_MASTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) err = em28xx_audio_urb_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) goto card_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) goto urb_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) dev_info(&dev->intf->dev, "Audio extension successfully initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) urb_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) em28xx_audio_free_urb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) card_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) adev->sndcard = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) static int em28xx_audio_fini(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * This device does not support the extension (in this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * the device is expecting the snd-usb-audio module or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * doesn't have analog audio support at all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) dev_info(&dev->intf->dev, "Closing audio extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (dev->adev.sndcard) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) snd_card_disconnect(dev->adev.sndcard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) flush_work(&dev->adev.wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) em28xx_audio_free_urb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) snd_card_free(dev->adev.sndcard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) dev->adev.sndcard = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) kref_put(&dev->ref, em28xx_free_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) static int em28xx_audio_suspend(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) dev_info(&dev->intf->dev, "Suspending audio extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) em28xx_deinit_isoc_audio(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) atomic_set(&dev->adev.stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) static int em28xx_audio_resume(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) dev_info(&dev->intf->dev, "Resuming audio extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) /* Nothing to do other than schedule_work() ?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) schedule_work(&dev->adev.wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) static struct em28xx_ops audio_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) .id = EM28XX_AUDIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) .name = "Em28xx Audio Extension",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) .init = em28xx_audio_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .fini = em28xx_audio_fini,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) .suspend = em28xx_audio_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .resume = em28xx_audio_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) static int __init em28xx_alsa_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return em28xx_register_extension(&audio_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) static void __exit em28xx_alsa_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) em28xx_unregister_extension(&audio_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) MODULE_AUTHOR("Markus Rechberger <mrechberger@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) MODULE_AUTHOR("Mauro Carvalho Chehab");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) MODULE_DESCRIPTION(DRIVER_DESC " - audio interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) MODULE_VERSION(EM28XX_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) module_init(em28xx_alsa_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) module_exit(em28xx_alsa_unregister);