1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese
6 #include <linux/device.h>
7 #include <linux/spinlock.h>
8 #include <linux/slab.h>
9 #include <linux/init.h>
10 #include <linux/usb.h>
11 #include <sound/core.h>
12 #include <sound/pcm.h>
18 #define CLOCK_DRIFT_TOLERANCE 5
19 #define FRAMES_PER_URB 8
20 #define BYTES_PER_FRAME 512
21 #define CHANNELS_PER_STREAM 2
22 #define BYTES_PER_SAMPLE 3
23 #define BYTES_PER_SAMPLE_USB 4
24 #define MAX_BUFFER_SIZE (128*1024)
25 #define MAX_ENDPOINT_SIZE 512
27 #define ENDPOINT_CAPTURE 2
28 #define ENDPOINT_PLAYBACK 6
30 #define MAKE_CHECKBYTE(cdev,stream,i) \
31 (stream << 1) | (~(i / (cdev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
33 static const struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
34 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
35 SNDRV_PCM_INFO_BLOCK_TRANSFER),
36 .formats = SNDRV_PCM_FMTBIT_S24_3BE,
37 .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
38 SNDRV_PCM_RATE_96000),
40 .rate_max = 0, /* will overwrite later */
41 .channels_min = CHANNELS_PER_STREAM,
42 .channels_max = CHANNELS_PER_STREAM,
43 .buffer_bytes_max = MAX_BUFFER_SIZE,
44 .period_bytes_min = 128,
45 .period_bytes_max = MAX_BUFFER_SIZE,
51 activate_substream(struct snd_usb_caiaqdev *cdev,
52 struct snd_pcm_substream *sub)
54 spin_lock(&cdev->spinlock);
56 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
57 cdev->sub_playback[sub->number] = sub;
59 cdev->sub_capture[sub->number] = sub;
61 spin_unlock(&cdev->spinlock);
65 deactivate_substream(struct snd_usb_caiaqdev *cdev,
66 struct snd_pcm_substream *sub)
69 spin_lock_irqsave(&cdev->spinlock, flags);
71 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
72 cdev->sub_playback[sub->number] = NULL;
74 cdev->sub_capture[sub->number] = NULL;
76 spin_unlock_irqrestore(&cdev->spinlock, flags);
80 all_substreams_zero(struct snd_pcm_substream **subs)
83 for (i = 0; i < MAX_STREAMS; i++)
89 static int stream_start(struct snd_usb_caiaqdev *cdev)
92 struct device *dev = caiaqdev_to_dev(cdev);
94 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
99 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
100 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
101 cdev->input_panic = 0;
102 cdev->output_panic = 0;
103 cdev->first_packet = 4;
107 for (i = 0; i < N_URBS; i++) {
108 ret = usb_submit_urb(cdev->data_urbs_in[i], GFP_ATOMIC);
110 dev_err(dev, "unable to trigger read #%d! (ret %d)\n",
120 static void stream_stop(struct snd_usb_caiaqdev *cdev)
123 struct device *dev = caiaqdev_to_dev(cdev);
125 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
126 if (!cdev->streaming)
131 for (i = 0; i < N_URBS; i++) {
132 usb_kill_urb(cdev->data_urbs_in[i]);
134 if (test_bit(i, &cdev->outurb_active_mask))
135 usb_kill_urb(cdev->data_urbs_out[i]);
138 cdev->outurb_active_mask = 0;
141 static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
143 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
144 struct device *dev = caiaqdev_to_dev(cdev);
146 dev_dbg(dev, "%s(%p)\n", __func__, substream);
147 substream->runtime->hw = cdev->pcm_info;
148 snd_pcm_limit_hw_rates(substream->runtime);
153 static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
155 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
156 struct device *dev = caiaqdev_to_dev(cdev);
158 dev_dbg(dev, "%s(%p)\n", __func__, substream);
159 if (all_substreams_zero(cdev->sub_playback) &&
160 all_substreams_zero(cdev->sub_capture)) {
161 /* when the last client has stopped streaming,
162 * all sample rates are allowed again */
164 cdev->pcm_info.rates = cdev->samplerates;
170 static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
172 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
173 deactivate_substream(cdev, sub);
177 /* this should probably go upstream */
178 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
179 #error "Change this table"
182 static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
183 48000, 64000, 88200, 96000, 176400, 192000 };
185 static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
187 int bytes_per_sample, bpp, ret, i;
188 int index = substream->number;
189 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
190 struct snd_pcm_runtime *runtime = substream->runtime;
191 struct device *dev = caiaqdev_to_dev(cdev);
193 dev_dbg(dev, "%s(%p)\n", __func__, substream);
195 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
198 switch (cdev->spec.data_alignment) {
201 out_pos = BYTES_PER_SAMPLE + 1;
209 cdev->period_out_count[index] = out_pos;
210 cdev->audio_out_buf_pos[index] = out_pos;
214 switch (cdev->spec.data_alignment) {
216 in_pos = BYTES_PER_SAMPLE + 2;
219 in_pos = BYTES_PER_SAMPLE;
227 cdev->period_in_count[index] = in_pos;
228 cdev->audio_in_buf_pos[index] = in_pos;
234 /* the first client that opens a stream defines the sample rate
235 * setting for all subsequent calls, until the last client closed. */
236 for (i=0; i < ARRAY_SIZE(rates); i++)
237 if (runtime->rate == rates[i])
238 cdev->pcm_info.rates = 1 << i;
240 snd_pcm_limit_hw_rates(runtime);
242 bytes_per_sample = BYTES_PER_SAMPLE;
243 if (cdev->spec.data_alignment >= 2)
246 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
247 * bytes_per_sample * CHANNELS_PER_STREAM * cdev->n_streams;
249 if (bpp > MAX_ENDPOINT_SIZE)
250 bpp = MAX_ENDPOINT_SIZE;
252 ret = snd_usb_caiaq_set_audio_params(cdev, runtime->rate,
253 runtime->sample_bits, bpp);
257 ret = stream_start(cdev);
261 cdev->output_running = 0;
262 wait_event_timeout(cdev->prepare_wait_queue, cdev->output_running, HZ);
263 if (!cdev->output_running) {
271 static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
273 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
274 struct device *dev = caiaqdev_to_dev(cdev);
276 dev_dbg(dev, "%s(%p) cmd %d\n", __func__, sub, cmd);
279 case SNDRV_PCM_TRIGGER_START:
280 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
281 activate_substream(cdev, sub);
283 case SNDRV_PCM_TRIGGER_STOP:
284 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
285 deactivate_substream(cdev, sub);
294 static snd_pcm_uframes_t
295 snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
297 int index = sub->number;
298 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
299 snd_pcm_uframes_t ptr;
301 spin_lock(&cdev->spinlock);
303 if (cdev->input_panic || cdev->output_panic) {
304 ptr = SNDRV_PCM_POS_XRUN;
308 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
309 ptr = bytes_to_frames(sub->runtime,
310 cdev->audio_out_buf_pos[index]);
312 ptr = bytes_to_frames(sub->runtime,
313 cdev->audio_in_buf_pos[index]);
316 spin_unlock(&cdev->spinlock);
320 /* operators for both playback and capture */
321 static const struct snd_pcm_ops snd_usb_caiaq_ops = {
322 .open = snd_usb_caiaq_substream_open,
323 .close = snd_usb_caiaq_substream_close,
324 .hw_free = snd_usb_caiaq_pcm_hw_free,
325 .prepare = snd_usb_caiaq_pcm_prepare,
326 .trigger = snd_usb_caiaq_pcm_trigger,
327 .pointer = snd_usb_caiaq_pcm_pointer,
330 static void check_for_elapsed_periods(struct snd_usb_caiaqdev *cdev,
331 struct snd_pcm_substream **subs)
333 int stream, pb, *cnt;
334 struct snd_pcm_substream *sub;
336 for (stream = 0; stream < cdev->n_streams; stream++) {
341 pb = snd_pcm_lib_period_bytes(sub);
342 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
343 &cdev->period_out_count[stream] :
344 &cdev->period_in_count[stream];
347 snd_pcm_period_elapsed(sub);
353 static void read_in_urb_mode0(struct snd_usb_caiaqdev *cdev,
354 const struct urb *urb,
355 const struct usb_iso_packet_descriptor *iso)
357 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
358 struct snd_pcm_substream *sub;
361 if (all_substreams_zero(cdev->sub_capture))
364 for (i = 0; i < iso->actual_length;) {
365 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
366 sub = cdev->sub_capture[stream];
368 struct snd_pcm_runtime *rt = sub->runtime;
369 char *audio_buf = rt->dma_area;
370 int sz = frames_to_bytes(rt, rt->buffer_size);
371 audio_buf[cdev->audio_in_buf_pos[stream]++]
373 cdev->period_in_count[stream]++;
374 if (cdev->audio_in_buf_pos[stream] == sz)
375 cdev->audio_in_buf_pos[stream] = 0;
381 static void read_in_urb_mode2(struct snd_usb_caiaqdev *cdev,
382 const struct urb *urb,
383 const struct usb_iso_packet_descriptor *iso)
385 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
386 unsigned char check_byte;
387 struct snd_pcm_substream *sub;
390 for (i = 0; i < iso->actual_length;) {
391 if (i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
393 stream < cdev->n_streams;
395 if (cdev->first_packet)
398 check_byte = MAKE_CHECKBYTE(cdev, stream, i);
400 if ((usb_buf[i] & 0x3f) != check_byte)
401 cdev->input_panic = 1;
403 if (usb_buf[i] & 0x80)
404 cdev->output_panic = 1;
407 cdev->first_packet = 0;
409 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
410 sub = cdev->sub_capture[stream];
411 if (cdev->input_panic)
415 struct snd_pcm_runtime *rt = sub->runtime;
416 char *audio_buf = rt->dma_area;
417 int sz = frames_to_bytes(rt, rt->buffer_size);
418 audio_buf[cdev->audio_in_buf_pos[stream]++] =
420 cdev->period_in_count[stream]++;
421 if (cdev->audio_in_buf_pos[stream] == sz)
422 cdev->audio_in_buf_pos[stream] = 0;
428 static void read_in_urb_mode3(struct snd_usb_caiaqdev *cdev,
429 const struct urb *urb,
430 const struct usb_iso_packet_descriptor *iso)
432 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
433 struct device *dev = caiaqdev_to_dev(cdev);
437 if (iso->actual_length % (BYTES_PER_SAMPLE_USB * CHANNELS_PER_STREAM))
440 for (i = 0; i < iso->actual_length;) {
441 for (stream = 0; stream < cdev->n_streams; stream++) {
442 struct snd_pcm_substream *sub = cdev->sub_capture[stream];
443 char *audio_buf = NULL;
446 if (sub && !cdev->input_panic) {
447 struct snd_pcm_runtime *rt = sub->runtime;
448 audio_buf = rt->dma_area;
449 sz = frames_to_bytes(rt, rt->buffer_size);
452 for (c = 0; c < CHANNELS_PER_STREAM; c++) {
453 /* 3 audio data bytes, followed by 1 check byte */
455 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
456 audio_buf[cdev->audio_in_buf_pos[stream]++] = usb_buf[i+n];
458 if (cdev->audio_in_buf_pos[stream] == sz)
459 cdev->audio_in_buf_pos[stream] = 0;
462 cdev->period_in_count[stream] += BYTES_PER_SAMPLE;
465 i += BYTES_PER_SAMPLE;
467 if (usb_buf[i] != ((stream << 1) | c) &&
468 !cdev->first_packet) {
469 if (!cdev->input_panic)
470 dev_warn(dev, " EXPECTED: %02x got %02x, c %d, stream %d, i %d\n",
471 ((stream << 1) | c), usb_buf[i], c, stream, i);
472 cdev->input_panic = 1;
480 if (cdev->first_packet > 0)
481 cdev->first_packet--;
484 static void read_in_urb(struct snd_usb_caiaqdev *cdev,
485 const struct urb *urb,
486 const struct usb_iso_packet_descriptor *iso)
488 struct device *dev = caiaqdev_to_dev(cdev);
490 if (!cdev->streaming)
493 if (iso->actual_length < cdev->bpp)
496 switch (cdev->spec.data_alignment) {
498 read_in_urb_mode0(cdev, urb, iso);
501 read_in_urb_mode2(cdev, urb, iso);
504 read_in_urb_mode3(cdev, urb, iso);
508 if ((cdev->input_panic || cdev->output_panic) && !cdev->warned) {
509 dev_warn(dev, "streaming error detected %s %s\n",
510 cdev->input_panic ? "(input)" : "",
511 cdev->output_panic ? "(output)" : "");
516 static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *cdev,
518 const struct usb_iso_packet_descriptor *iso)
520 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
521 struct snd_pcm_substream *sub;
524 for (i = 0; i < iso->length;) {
525 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
526 sub = cdev->sub_playback[stream];
528 struct snd_pcm_runtime *rt = sub->runtime;
529 char *audio_buf = rt->dma_area;
530 int sz = frames_to_bytes(rt, rt->buffer_size);
532 audio_buf[cdev->audio_out_buf_pos[stream]];
533 cdev->period_out_count[stream]++;
534 cdev->audio_out_buf_pos[stream]++;
535 if (cdev->audio_out_buf_pos[stream] == sz)
536 cdev->audio_out_buf_pos[stream] = 0;
541 /* fill in the check bytes */
542 if (cdev->spec.data_alignment == 2 &&
543 i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) ==
544 (cdev->n_streams * CHANNELS_PER_STREAM))
545 for (stream = 0; stream < cdev->n_streams; stream++, i++)
546 usb_buf[i] = MAKE_CHECKBYTE(cdev, stream, i);
550 static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *cdev,
552 const struct usb_iso_packet_descriptor *iso)
554 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
557 for (i = 0; i < iso->length;) {
558 for (stream = 0; stream < cdev->n_streams; stream++) {
559 struct snd_pcm_substream *sub = cdev->sub_playback[stream];
560 char *audio_buf = NULL;
564 struct snd_pcm_runtime *rt = sub->runtime;
565 audio_buf = rt->dma_area;
566 sz = frames_to_bytes(rt, rt->buffer_size);
569 for (c = 0; c < CHANNELS_PER_STREAM; c++) {
570 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
572 usb_buf[i+n] = audio_buf[cdev->audio_out_buf_pos[stream]++];
574 if (cdev->audio_out_buf_pos[stream] == sz)
575 cdev->audio_out_buf_pos[stream] = 0;
582 cdev->period_out_count[stream] += BYTES_PER_SAMPLE;
584 i += BYTES_PER_SAMPLE;
586 /* fill in the check byte pattern */
587 usb_buf[i++] = (stream << 1) | c;
593 static inline void fill_out_urb(struct snd_usb_caiaqdev *cdev,
595 const struct usb_iso_packet_descriptor *iso)
597 switch (cdev->spec.data_alignment) {
600 fill_out_urb_mode_0(cdev, urb, iso);
603 fill_out_urb_mode_3(cdev, urb, iso);
608 static void read_completed(struct urb *urb)
610 struct snd_usb_caiaq_cb_info *info = urb->context;
611 struct snd_usb_caiaqdev *cdev;
613 struct urb *out = NULL;
614 int i, frame, len, send_it = 0, outframe = 0;
618 if (urb->status || !info)
622 dev = caiaqdev_to_dev(cdev);
624 if (!cdev->streaming)
627 /* find an unused output urb that is unused */
628 for (i = 0; i < N_URBS; i++)
629 if (test_and_set_bit(i, &cdev->outurb_active_mask) == 0) {
630 out = cdev->data_urbs_out[i];
635 dev_err(dev, "Unable to find an output urb to use\n");
639 /* read the recently received packet and send back one which has
641 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
642 if (urb->iso_frame_desc[frame].status)
645 len = urb->iso_frame_desc[outframe].actual_length;
646 out->iso_frame_desc[outframe].length = len;
647 out->iso_frame_desc[outframe].actual_length = 0;
648 out->iso_frame_desc[outframe].offset = offset;
652 spin_lock_irqsave(&cdev->spinlock, flags);
653 fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]);
654 read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]);
655 spin_unlock_irqrestore(&cdev->spinlock, flags);
656 check_for_elapsed_periods(cdev, cdev->sub_playback);
657 check_for_elapsed_periods(cdev, cdev->sub_capture);
665 out->number_of_packets = outframe;
666 usb_submit_urb(out, GFP_ATOMIC);
668 struct snd_usb_caiaq_cb_info *oinfo = out->context;
669 clear_bit(oinfo->index, &cdev->outurb_active_mask);
673 /* re-submit inbound urb */
674 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
675 urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame;
676 urb->iso_frame_desc[frame].length = BYTES_PER_FRAME;
677 urb->iso_frame_desc[frame].actual_length = 0;
680 urb->number_of_packets = FRAMES_PER_URB;
681 usb_submit_urb(urb, GFP_ATOMIC);
684 static void write_completed(struct urb *urb)
686 struct snd_usb_caiaq_cb_info *info = urb->context;
687 struct snd_usb_caiaqdev *cdev = info->cdev;
689 if (!cdev->output_running) {
690 cdev->output_running = 1;
691 wake_up(&cdev->prepare_wait_queue);
694 clear_bit(info->index, &cdev->outurb_active_mask);
697 static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
701 struct usb_device *usb_dev = cdev->chip.dev;
704 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
705 usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) :
706 usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE);
708 urbs = kmalloc_array(N_URBS, sizeof(*urbs), GFP_KERNEL);
714 for (i = 0; i < N_URBS; i++) {
715 urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL);
721 urbs[i]->transfer_buffer =
722 kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB,
724 if (!urbs[i]->transfer_buffer) {
729 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
730 struct usb_iso_packet_descriptor *iso =
731 &urbs[i]->iso_frame_desc[frame];
733 iso->offset = BYTES_PER_FRAME * frame;
734 iso->length = BYTES_PER_FRAME;
737 urbs[i]->dev = usb_dev;
738 urbs[i]->pipe = pipe;
739 urbs[i]->transfer_buffer_length = FRAMES_PER_URB
741 urbs[i]->context = &cdev->data_cb_info[i];
742 urbs[i]->interval = 1;
743 urbs[i]->number_of_packets = FRAMES_PER_URB;
744 urbs[i]->complete = (dir == SNDRV_PCM_STREAM_CAPTURE) ?
745 read_completed : write_completed;
752 static void free_urbs(struct urb **urbs)
759 for (i = 0; i < N_URBS; i++) {
763 usb_kill_urb(urbs[i]);
764 kfree(urbs[i]->transfer_buffer);
765 usb_free_urb(urbs[i]);
771 int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
774 struct device *dev = caiaqdev_to_dev(cdev);
776 cdev->n_audio_in = max(cdev->spec.num_analog_audio_in,
777 cdev->spec.num_digital_audio_in) /
779 cdev->n_audio_out = max(cdev->spec.num_analog_audio_out,
780 cdev->spec.num_digital_audio_out) /
782 cdev->n_streams = max(cdev->n_audio_in, cdev->n_audio_out);
784 dev_dbg(dev, "cdev->n_audio_in = %d\n", cdev->n_audio_in);
785 dev_dbg(dev, "cdev->n_audio_out = %d\n", cdev->n_audio_out);
786 dev_dbg(dev, "cdev->n_streams = %d\n", cdev->n_streams);
788 if (cdev->n_streams > MAX_STREAMS) {
789 dev_err(dev, "unable to initialize device, too many streams.\n");
793 if (cdev->n_streams < 1) {
794 dev_err(dev, "bogus number of streams: %d\n", cdev->n_streams);
798 ret = snd_pcm_new(cdev->chip.card, cdev->product_name, 0,
799 cdev->n_audio_out, cdev->n_audio_in, &cdev->pcm);
802 dev_err(dev, "snd_pcm_new() returned %d\n", ret);
806 cdev->pcm->private_data = cdev;
807 strscpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name));
809 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
810 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
812 memcpy(&cdev->pcm_info, &snd_usb_caiaq_pcm_hardware,
813 sizeof(snd_usb_caiaq_pcm_hardware));
815 /* setup samplerates */
816 cdev->samplerates = cdev->pcm_info.rates;
817 switch (cdev->chip.usb_id) {
818 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
819 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
820 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
821 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
822 cdev->samplerates |= SNDRV_PCM_RATE_192000;
824 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
825 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
826 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
827 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2):
828 cdev->samplerates |= SNDRV_PCM_RATE_88200;
832 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
834 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_CAPTURE,
836 snd_pcm_set_managed_buffer_all(cdev->pcm, SNDRV_DMA_TYPE_VMALLOC,
840 kmalloc_array(N_URBS, sizeof(struct snd_usb_caiaq_cb_info),
843 if (!cdev->data_cb_info)
846 cdev->outurb_active_mask = 0;
847 BUILD_BUG_ON(N_URBS > (sizeof(cdev->outurb_active_mask) * 8));
849 for (i = 0; i < N_URBS; i++) {
850 cdev->data_cb_info[i].cdev = cdev;
851 cdev->data_cb_info[i].index = i;
854 cdev->data_urbs_in = alloc_urbs(cdev, SNDRV_PCM_STREAM_CAPTURE, &ret);
856 kfree(cdev->data_cb_info);
857 free_urbs(cdev->data_urbs_in);
861 cdev->data_urbs_out = alloc_urbs(cdev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
863 kfree(cdev->data_cb_info);
864 free_urbs(cdev->data_urbs_in);
865 free_urbs(cdev->data_urbs_out);
872 void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev)
874 struct device *dev = caiaqdev_to_dev(cdev);
876 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
878 free_urbs(cdev->data_urbs_in);
879 free_urbs(cdev->data_urbs_out);
880 kfree(cdev->data_cb_info);