^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "device.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "audio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define N_URBS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define CLOCK_DRIFT_TOLERANCE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define FRAMES_PER_URB 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define BYTES_PER_FRAME 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define CHANNELS_PER_STREAM 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define BYTES_PER_SAMPLE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define BYTES_PER_SAMPLE_USB 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define MAX_BUFFER_SIZE (128*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define MAX_ENDPOINT_SIZE 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define ENDPOINT_CAPTURE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define ENDPOINT_PLAYBACK 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define MAKE_CHECKBYTE(cdev,stream,i) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) (stream << 1) | (~(i / (cdev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static const struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) SNDRV_PCM_INFO_BLOCK_TRANSFER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .formats = SNDRV_PCM_FMTBIT_S24_3BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) SNDRV_PCM_RATE_96000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .rate_min = 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .rate_max = 0, /* will overwrite later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .channels_min = CHANNELS_PER_STREAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .channels_max = CHANNELS_PER_STREAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .buffer_bytes_max = MAX_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .period_bytes_min = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .period_bytes_max = MAX_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .periods_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .periods_max = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) activate_substream(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct snd_pcm_substream *sub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) spin_lock(&cdev->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) cdev->sub_playback[sub->number] = sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) cdev->sub_capture[sub->number] = sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) spin_unlock(&cdev->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) deactivate_substream(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct snd_pcm_substream *sub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) spin_lock_irqsave(&cdev->spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cdev->sub_playback[sub->number] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) cdev->sub_capture[sub->number] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spin_unlock_irqrestore(&cdev->spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) all_substreams_zero(struct snd_pcm_substream **subs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) for (i = 0; i < MAX_STREAMS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (subs[i] != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static int stream_start(struct snd_usb_caiaqdev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) dev_dbg(dev, "%s(%p)\n", __func__, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (cdev->streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) cdev->input_panic = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) cdev->output_panic = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) cdev->first_packet = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) cdev->streaming = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) cdev->warned = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) for (i = 0; i < N_URBS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = usb_submit_urb(cdev->data_urbs_in[i], GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) dev_err(dev, "unable to trigger read #%d! (ret %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) cdev->streaming = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void stream_stop(struct snd_usb_caiaqdev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dev_dbg(dev, "%s(%p)\n", __func__, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (!cdev->streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) cdev->streaming = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) for (i = 0; i < N_URBS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) usb_kill_urb(cdev->data_urbs_in[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (test_bit(i, &cdev->outurb_active_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) usb_kill_urb(cdev->data_urbs_out[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) cdev->outurb_active_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dev_dbg(dev, "%s(%p)\n", __func__, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) substream->runtime->hw = cdev->pcm_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) snd_pcm_limit_hw_rates(substream->runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) dev_dbg(dev, "%s(%p)\n", __func__, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (all_substreams_zero(cdev->sub_playback) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) all_substreams_zero(cdev->sub_capture)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* when the last client has stopped streaming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * all sample rates are allowed again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) stream_stop(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) cdev->pcm_info.rates = cdev->samplerates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) deactivate_substream(cdev, sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* this should probably go upstream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #error "Change this table"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 48000, 64000, 88200, 96000, 176400, 192000 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int bytes_per_sample, bpp, ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int index = substream->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) dev_dbg(dev, "%s(%p)\n", __func__, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int out_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) switch (cdev->spec.data_alignment) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) out_pos = BYTES_PER_SAMPLE + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) out_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) cdev->period_out_count[index] = out_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) cdev->audio_out_buf_pos[index] = out_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int in_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) switch (cdev->spec.data_alignment) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) in_pos = BYTES_PER_SAMPLE + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) in_pos = BYTES_PER_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) in_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) cdev->period_in_count[index] = in_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) cdev->audio_in_buf_pos[index] = in_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (cdev->streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* the first client that opens a stream defines the sample rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * setting for all subsequent calls, until the last client closed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) for (i=0; i < ARRAY_SIZE(rates); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (runtime->rate == rates[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) cdev->pcm_info.rates = 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) snd_pcm_limit_hw_rates(runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) bytes_per_sample = BYTES_PER_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (cdev->spec.data_alignment >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) bytes_per_sample++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * bytes_per_sample * CHANNELS_PER_STREAM * cdev->n_streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (bpp > MAX_ENDPOINT_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) bpp = MAX_ENDPOINT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ret = snd_usb_caiaq_set_audio_params(cdev, runtime->rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) runtime->sample_bits, bpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ret = stream_start(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) cdev->output_running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) wait_event_timeout(cdev->prepare_wait_queue, cdev->output_running, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (!cdev->output_running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) stream_stop(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) dev_dbg(dev, "%s(%p) cmd %d\n", __func__, sub, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) activate_substream(cdev, sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) deactivate_substream(cdev, sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int index = sub->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) snd_pcm_uframes_t ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) spin_lock(&cdev->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (cdev->input_panic || cdev->output_panic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ptr = SNDRV_PCM_POS_XRUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ptr = bytes_to_frames(sub->runtime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) cdev->audio_out_buf_pos[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ptr = bytes_to_frames(sub->runtime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) cdev->audio_in_buf_pos[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_unlock(&cdev->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return ptr;
^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) /* operators for both playback and capture */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static const struct snd_pcm_ops snd_usb_caiaq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .open = snd_usb_caiaq_substream_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .close = snd_usb_caiaq_substream_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .hw_free = snd_usb_caiaq_pcm_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .prepare = snd_usb_caiaq_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .trigger = snd_usb_caiaq_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .pointer = snd_usb_caiaq_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static void check_for_elapsed_periods(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct snd_pcm_substream **subs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int stream, pb, *cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct snd_pcm_substream *sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) for (stream = 0; stream < cdev->n_streams; stream++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) sub = subs[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!sub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pb = snd_pcm_lib_period_bytes(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) &cdev->period_out_count[stream] :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) &cdev->period_in_count[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (*cnt >= pb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) snd_pcm_period_elapsed(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) *cnt %= pb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static void read_in_urb_mode0(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) const struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct snd_pcm_substream *sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) int stream, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (all_substreams_zero(cdev->sub_capture))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) for (i = 0; i < iso->actual_length;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) for (stream = 0; stream < cdev->n_streams; stream++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) sub = cdev->sub_capture[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (sub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct snd_pcm_runtime *rt = sub->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) char *audio_buf = rt->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int sz = frames_to_bytes(rt, rt->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) audio_buf[cdev->audio_in_buf_pos[stream]++]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) = usb_buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) cdev->period_in_count[stream]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (cdev->audio_in_buf_pos[stream] == sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) cdev->audio_in_buf_pos[stream] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void read_in_urb_mode2(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) const struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) unsigned char check_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct snd_pcm_substream *sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int stream, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) for (i = 0; i < iso->actual_length;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) for (stream = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) stream < cdev->n_streams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) stream++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (cdev->first_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) check_byte = MAKE_CHECKBYTE(cdev, stream, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if ((usb_buf[i] & 0x3f) != check_byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) cdev->input_panic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (usb_buf[i] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) cdev->output_panic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) cdev->first_packet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) for (stream = 0; stream < cdev->n_streams; stream++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) sub = cdev->sub_capture[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (cdev->input_panic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) usb_buf[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (sub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct snd_pcm_runtime *rt = sub->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) char *audio_buf = rt->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) int sz = frames_to_bytes(rt, rt->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) audio_buf[cdev->audio_in_buf_pos[stream]++] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) usb_buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) cdev->period_in_count[stream]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (cdev->audio_in_buf_pos[stream] == sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) cdev->audio_in_buf_pos[stream] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static void read_in_urb_mode3(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) const struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) int stream, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /* paranoia check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (iso->actual_length % (BYTES_PER_SAMPLE_USB * CHANNELS_PER_STREAM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) for (i = 0; i < iso->actual_length;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) for (stream = 0; stream < cdev->n_streams; stream++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct snd_pcm_substream *sub = cdev->sub_capture[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) char *audio_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int c, n, sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (sub && !cdev->input_panic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct snd_pcm_runtime *rt = sub->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) audio_buf = rt->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) sz = frames_to_bytes(rt, rt->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) for (c = 0; c < CHANNELS_PER_STREAM; c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* 3 audio data bytes, followed by 1 check byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (audio_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) for (n = 0; n < BYTES_PER_SAMPLE; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) audio_buf[cdev->audio_in_buf_pos[stream]++] = usb_buf[i+n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (cdev->audio_in_buf_pos[stream] == sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) cdev->audio_in_buf_pos[stream] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) cdev->period_in_count[stream] += BYTES_PER_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) i += BYTES_PER_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (usb_buf[i] != ((stream << 1) | c) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) !cdev->first_packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (!cdev->input_panic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) dev_warn(dev, " EXPECTED: %02x got %02x, c %d, stream %d, i %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ((stream << 1) | c), usb_buf[i], c, stream, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) cdev->input_panic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (cdev->first_packet > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) cdev->first_packet--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static void read_in_urb(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) const struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (!cdev->streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (iso->actual_length < cdev->bpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) switch (cdev->spec.data_alignment) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) read_in_urb_mode0(cdev, urb, iso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) read_in_urb_mode2(cdev, urb, iso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) read_in_urb_mode3(cdev, urb, iso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if ((cdev->input_panic || cdev->output_panic) && !cdev->warned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) dev_warn(dev, "streaming error detected %s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) cdev->input_panic ? "(input)" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) cdev->output_panic ? "(output)" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) cdev->warned = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct snd_pcm_substream *sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int stream, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) for (i = 0; i < iso->length;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) for (stream = 0; stream < cdev->n_streams; stream++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) sub = cdev->sub_playback[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (sub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct snd_pcm_runtime *rt = sub->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) char *audio_buf = rt->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) int sz = frames_to_bytes(rt, rt->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) usb_buf[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) audio_buf[cdev->audio_out_buf_pos[stream]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) cdev->period_out_count[stream]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) cdev->audio_out_buf_pos[stream]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (cdev->audio_out_buf_pos[stream] == sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) cdev->audio_out_buf_pos[stream] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) usb_buf[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* fill in the check bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (cdev->spec.data_alignment == 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) (cdev->n_streams * CHANNELS_PER_STREAM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) for (stream = 0; stream < cdev->n_streams; stream++, i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) usb_buf[i] = MAKE_CHECKBYTE(cdev, stream, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) int stream, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) for (i = 0; i < iso->length;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) for (stream = 0; stream < cdev->n_streams; stream++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct snd_pcm_substream *sub = cdev->sub_playback[stream];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) char *audio_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) int c, n, sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (sub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct snd_pcm_runtime *rt = sub->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) audio_buf = rt->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) sz = frames_to_bytes(rt, rt->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) for (c = 0; c < CHANNELS_PER_STREAM; c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) for (n = 0; n < BYTES_PER_SAMPLE; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (audio_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) usb_buf[i+n] = audio_buf[cdev->audio_out_buf_pos[stream]++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (cdev->audio_out_buf_pos[stream] == sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) cdev->audio_out_buf_pos[stream] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) usb_buf[i+n] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (audio_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) cdev->period_out_count[stream] += BYTES_PER_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) i += BYTES_PER_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* fill in the check byte pattern */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) usb_buf[i++] = (stream << 1) | c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static inline void fill_out_urb(struct snd_usb_caiaqdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct urb *urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) const struct usb_iso_packet_descriptor *iso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) switch (cdev->spec.data_alignment) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) fill_out_urb_mode_0(cdev, urb, iso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) fill_out_urb_mode_3(cdev, urb, iso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static void read_completed(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct snd_usb_caiaq_cb_info *info = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct snd_usb_caiaqdev *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct urb *out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) int i, frame, len, send_it = 0, outframe = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) size_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (urb->status || !info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) cdev = info->cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (!cdev->streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* find an unused output urb that is unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) for (i = 0; i < N_URBS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (test_and_set_bit(i, &cdev->outurb_active_mask) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) out = cdev->data_urbs_out[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) break;
^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) if (!out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) dev_err(dev, "Unable to find an output urb to use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) goto requeue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* read the recently received packet and send back one which has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * the same layout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) for (frame = 0; frame < FRAMES_PER_URB; frame++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (urb->iso_frame_desc[frame].status)
^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) len = urb->iso_frame_desc[outframe].actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) out->iso_frame_desc[outframe].length = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) out->iso_frame_desc[outframe].actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) out->iso_frame_desc[outframe].offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) offset += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) spin_lock_irqsave(&cdev->spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) spin_unlock_irqrestore(&cdev->spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) check_for_elapsed_periods(cdev, cdev->sub_playback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) check_for_elapsed_periods(cdev, cdev->sub_capture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) send_it = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) outframe++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (send_it) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) out->number_of_packets = outframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) usb_submit_urb(out, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) struct snd_usb_caiaq_cb_info *oinfo = out->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) clear_bit(oinfo->index, &cdev->outurb_active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) requeue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* re-submit inbound urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) for (frame = 0; frame < FRAMES_PER_URB; frame++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) urb->iso_frame_desc[frame].length = BYTES_PER_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) urb->iso_frame_desc[frame].actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) urb->number_of_packets = FRAMES_PER_URB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static void write_completed(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) struct snd_usb_caiaq_cb_info *info = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) struct snd_usb_caiaqdev *cdev = info->cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (!cdev->output_running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) cdev->output_running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) wake_up(&cdev->prepare_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) clear_bit(info->index, &cdev->outurb_active_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) int i, frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct urb **urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct usb_device *usb_dev = cdev->chip.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) urbs = kmalloc_array(N_URBS, sizeof(*urbs), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (!urbs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) *ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) for (i = 0; i < N_URBS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (!urbs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) *ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) urbs[i]->transfer_buffer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!urbs[i]->transfer_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) *ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) for (frame = 0; frame < FRAMES_PER_URB; frame++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) struct usb_iso_packet_descriptor *iso =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) &urbs[i]->iso_frame_desc[frame];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) iso->offset = BYTES_PER_FRAME * frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) iso->length = BYTES_PER_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) urbs[i]->dev = usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) urbs[i]->pipe = pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) urbs[i]->transfer_buffer_length = FRAMES_PER_URB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) * BYTES_PER_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) urbs[i]->context = &cdev->data_cb_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) urbs[i]->interval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) urbs[i]->number_of_packets = FRAMES_PER_URB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) urbs[i]->complete = (dir == SNDRV_PCM_STREAM_CAPTURE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) read_completed : write_completed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) *ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) static void free_urbs(struct urb **urbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (!urbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) for (i = 0; i < N_URBS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (!urbs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) usb_kill_urb(urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) kfree(urbs[i]->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) usb_free_urb(urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) kfree(urbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) cdev->n_audio_in = max(cdev->spec.num_analog_audio_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) cdev->spec.num_digital_audio_in) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) CHANNELS_PER_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) cdev->n_audio_out = max(cdev->spec.num_analog_audio_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) cdev->spec.num_digital_audio_out) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) CHANNELS_PER_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) cdev->n_streams = max(cdev->n_audio_in, cdev->n_audio_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) dev_dbg(dev, "cdev->n_audio_in = %d\n", cdev->n_audio_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) dev_dbg(dev, "cdev->n_audio_out = %d\n", cdev->n_audio_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) dev_dbg(dev, "cdev->n_streams = %d\n", cdev->n_streams);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (cdev->n_streams > MAX_STREAMS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) dev_err(dev, "unable to initialize device, too many streams.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (cdev->n_streams < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) dev_err(dev, "bogus number of streams: %d\n", cdev->n_streams);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) ret = snd_pcm_new(cdev->chip.card, cdev->product_name, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) cdev->n_audio_out, cdev->n_audio_in, &cdev->pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) dev_err(dev, "snd_pcm_new() returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) cdev->pcm->private_data = cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) strlcpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) memcpy(&cdev->pcm_info, &snd_usb_caiaq_pcm_hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) sizeof(snd_usb_caiaq_pcm_hardware));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) /* setup samplerates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) cdev->samplerates = cdev->pcm_info.rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) switch (cdev->chip.usb_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) cdev->samplerates |= SNDRV_PCM_RATE_192000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) cdev->samplerates |= SNDRV_PCM_RATE_88200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) &snd_usb_caiaq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) &snd_usb_caiaq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) snd_pcm_set_managed_buffer_all(cdev->pcm, SNDRV_DMA_TYPE_VMALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) cdev->data_cb_info =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) kmalloc_array(N_URBS, sizeof(struct snd_usb_caiaq_cb_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (!cdev->data_cb_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) cdev->outurb_active_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) BUILD_BUG_ON(N_URBS > (sizeof(cdev->outurb_active_mask) * 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) for (i = 0; i < N_URBS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) cdev->data_cb_info[i].cdev = cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) cdev->data_cb_info[i].index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) cdev->data_urbs_in = alloc_urbs(cdev, SNDRV_PCM_STREAM_CAPTURE, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) kfree(cdev->data_cb_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) free_urbs(cdev->data_urbs_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) cdev->data_urbs_out = alloc_urbs(cdev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) kfree(cdev->data_cb_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) free_urbs(cdev->data_urbs_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) free_urbs(cdev->data_urbs_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) struct device *dev = caiaqdev_to_dev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) dev_dbg(dev, "%s(%p)\n", __func__, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) stream_stop(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) free_urbs(cdev->data_urbs_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) free_urbs(cdev->data_urbs_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) kfree(cdev->data_cb_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)