sparc64: Fix hardirq tracing in trap return path.
[linux/fpc-iii.git] / sound / usb / caiaq / audio.c
blob86b2c3b92df53abafa8188560c4e034ce987ea97
1 /*
2 * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/spinlock.h>
20 #include <linux/init.h>
21 #include <linux/usb.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
25 #include "device.h"
26 #include "audio.h"
28 #define N_URBS 32
29 #define CLOCK_DRIFT_TOLERANCE 5
30 #define FRAMES_PER_URB 8
31 #define BYTES_PER_FRAME 512
32 #define CHANNELS_PER_STREAM 2
33 #define BYTES_PER_SAMPLE 3
34 #define BYTES_PER_SAMPLE_USB 4
35 #define MAX_BUFFER_SIZE (128*1024)
36 #define MAX_ENDPOINT_SIZE 512
38 #define ENDPOINT_CAPTURE 2
39 #define ENDPOINT_PLAYBACK 6
41 #define MAKE_CHECKBYTE(dev,stream,i) \
42 (stream << 1) | (~(i / (dev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
44 static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
45 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
46 SNDRV_PCM_INFO_BLOCK_TRANSFER),
47 .formats = SNDRV_PCM_FMTBIT_S24_3BE,
48 .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
49 SNDRV_PCM_RATE_96000),
50 .rate_min = 44100,
51 .rate_max = 0, /* will overwrite later */
52 .channels_min = CHANNELS_PER_STREAM,
53 .channels_max = CHANNELS_PER_STREAM,
54 .buffer_bytes_max = MAX_BUFFER_SIZE,
55 .period_bytes_min = 128,
56 .period_bytes_max = MAX_BUFFER_SIZE,
57 .periods_min = 1,
58 .periods_max = 1024,
61 static void
62 activate_substream(struct snd_usb_caiaqdev *dev,
63 struct snd_pcm_substream *sub)
65 spin_lock(&dev->spinlock);
67 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
68 dev->sub_playback[sub->number] = sub;
69 else
70 dev->sub_capture[sub->number] = sub;
72 spin_unlock(&dev->spinlock);
75 static void
76 deactivate_substream(struct snd_usb_caiaqdev *dev,
77 struct snd_pcm_substream *sub)
79 unsigned long flags;
80 spin_lock_irqsave(&dev->spinlock, flags);
82 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
83 dev->sub_playback[sub->number] = NULL;
84 else
85 dev->sub_capture[sub->number] = NULL;
87 spin_unlock_irqrestore(&dev->spinlock, flags);
90 static int
91 all_substreams_zero(struct snd_pcm_substream **subs)
93 int i;
94 for (i = 0; i < MAX_STREAMS; i++)
95 if (subs[i] != NULL)
96 return 0;
97 return 1;
100 static int stream_start(struct snd_usb_caiaqdev *dev)
102 int i, ret;
104 debug("%s(%p)\n", __func__, dev);
106 if (dev->streaming)
107 return -EINVAL;
109 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
110 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
111 dev->input_panic = 0;
112 dev->output_panic = 0;
113 dev->first_packet = 1;
114 dev->streaming = 1;
115 dev->warned = 0;
117 for (i = 0; i < N_URBS; i++) {
118 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC);
119 if (ret) {
120 log("unable to trigger read #%d! (ret %d)\n", i, ret);
121 dev->streaming = 0;
122 return -EPIPE;
126 return 0;
129 static void stream_stop(struct snd_usb_caiaqdev *dev)
131 int i;
133 debug("%s(%p)\n", __func__, dev);
134 if (!dev->streaming)
135 return;
137 dev->streaming = 0;
139 for (i = 0; i < N_URBS; i++) {
140 usb_kill_urb(dev->data_urbs_in[i]);
141 usb_kill_urb(dev->data_urbs_out[i]);
145 static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
147 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
148 debug("%s(%p)\n", __func__, substream);
149 substream->runtime->hw = dev->pcm_info;
150 snd_pcm_limit_hw_rates(substream->runtime);
151 return 0;
154 static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
156 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
158 debug("%s(%p)\n", __func__, substream);
159 if (all_substreams_zero(dev->sub_playback) &&
160 all_substreams_zero(dev->sub_capture)) {
161 /* when the last client has stopped streaming,
162 * all sample rates are allowed again */
163 stream_stop(dev);
164 dev->pcm_info.rates = dev->samplerates;
167 return 0;
170 static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
171 struct snd_pcm_hw_params *hw_params)
173 debug("%s(%p)\n", __func__, sub);
174 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
177 static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
179 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
180 debug("%s(%p)\n", __func__, sub);
181 deactivate_substream(dev, sub);
182 return snd_pcm_lib_free_pages(sub);
185 /* this should probably go upstream */
186 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
187 #error "Change this table"
188 #endif
190 static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
191 48000, 64000, 88200, 96000, 176400, 192000 };
193 static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
195 int bytes_per_sample, bpp, ret, i;
196 int index = substream->number;
197 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
198 struct snd_pcm_runtime *runtime = substream->runtime;
200 debug("%s(%p)\n", __func__, substream);
202 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
203 dev->period_out_count[index] = BYTES_PER_SAMPLE + 1;
204 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
205 } else {
206 int in_pos = (dev->spec.data_alignment == 2) ? 0 : 2;
207 dev->period_in_count[index] = BYTES_PER_SAMPLE + in_pos;
208 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE + in_pos;
211 if (dev->streaming)
212 return 0;
214 /* the first client that opens a stream defines the sample rate
215 * setting for all subsequent calls, until the last client closed. */
216 for (i=0; i < ARRAY_SIZE(rates); i++)
217 if (runtime->rate == rates[i])
218 dev->pcm_info.rates = 1 << i;
220 snd_pcm_limit_hw_rates(runtime);
222 bytes_per_sample = BYTES_PER_SAMPLE;
223 if (dev->spec.data_alignment == 2)
224 bytes_per_sample++;
226 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
227 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams;
229 if (bpp > MAX_ENDPOINT_SIZE)
230 bpp = MAX_ENDPOINT_SIZE;
232 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate,
233 runtime->sample_bits, bpp);
234 if (ret)
235 return ret;
237 ret = stream_start(dev);
238 if (ret)
239 return ret;
241 dev->output_running = 0;
242 wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ);
243 if (!dev->output_running) {
244 stream_stop(dev);
245 return -EPIPE;
248 return 0;
251 static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
253 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
255 switch (cmd) {
256 case SNDRV_PCM_TRIGGER_START:
257 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
258 activate_substream(dev, sub);
259 break;
260 case SNDRV_PCM_TRIGGER_STOP:
261 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
262 deactivate_substream(dev, sub);
263 break;
264 default:
265 return -EINVAL;
268 return 0;
271 static snd_pcm_uframes_t
272 snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
274 int index = sub->number;
275 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
276 snd_pcm_uframes_t ptr;
278 spin_lock(&dev->spinlock);
280 if (dev->input_panic || dev->output_panic)
281 ptr = SNDRV_PCM_POS_XRUN;
283 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
284 ptr = bytes_to_frames(sub->runtime,
285 dev->audio_out_buf_pos[index]);
286 else
287 ptr = bytes_to_frames(sub->runtime,
288 dev->audio_in_buf_pos[index]);
290 spin_unlock(&dev->spinlock);
291 return ptr;
294 /* operators for both playback and capture */
295 static struct snd_pcm_ops snd_usb_caiaq_ops = {
296 .open = snd_usb_caiaq_substream_open,
297 .close = snd_usb_caiaq_substream_close,
298 .ioctl = snd_pcm_lib_ioctl,
299 .hw_params = snd_usb_caiaq_pcm_hw_params,
300 .hw_free = snd_usb_caiaq_pcm_hw_free,
301 .prepare = snd_usb_caiaq_pcm_prepare,
302 .trigger = snd_usb_caiaq_pcm_trigger,
303 .pointer = snd_usb_caiaq_pcm_pointer
306 static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev,
307 struct snd_pcm_substream **subs)
309 int stream, pb, *cnt;
310 struct snd_pcm_substream *sub;
312 for (stream = 0; stream < dev->n_streams; stream++) {
313 sub = subs[stream];
314 if (!sub)
315 continue;
317 pb = snd_pcm_lib_period_bytes(sub);
318 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
319 &dev->period_out_count[stream] :
320 &dev->period_in_count[stream];
322 if (*cnt >= pb) {
323 snd_pcm_period_elapsed(sub);
324 *cnt %= pb;
329 static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
330 const struct urb *urb,
331 const struct usb_iso_packet_descriptor *iso)
333 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
334 struct snd_pcm_substream *sub;
335 int stream, i;
337 if (all_substreams_zero(dev->sub_capture))
338 return;
340 for (i = 0; i < iso->actual_length;) {
341 for (stream = 0; stream < dev->n_streams; stream++, i++) {
342 sub = dev->sub_capture[stream];
343 if (sub) {
344 struct snd_pcm_runtime *rt = sub->runtime;
345 char *audio_buf = rt->dma_area;
346 int sz = frames_to_bytes(rt, rt->buffer_size);
347 audio_buf[dev->audio_in_buf_pos[stream]++]
348 = usb_buf[i];
349 dev->period_in_count[stream]++;
350 if (dev->audio_in_buf_pos[stream] == sz)
351 dev->audio_in_buf_pos[stream] = 0;
357 static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
358 const struct urb *urb,
359 const struct usb_iso_packet_descriptor *iso)
361 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
362 unsigned char check_byte;
363 struct snd_pcm_substream *sub;
364 int stream, i;
366 for (i = 0; i < iso->actual_length;) {
367 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
368 for (stream = 0;
369 stream < dev->n_streams;
370 stream++, i++) {
371 if (dev->first_packet)
372 continue;
374 check_byte = MAKE_CHECKBYTE(dev, stream, i);
376 if ((usb_buf[i] & 0x3f) != check_byte)
377 dev->input_panic = 1;
379 if (usb_buf[i] & 0x80)
380 dev->output_panic = 1;
383 dev->first_packet = 0;
385 for (stream = 0; stream < dev->n_streams; stream++, i++) {
386 sub = dev->sub_capture[stream];
387 if (dev->input_panic)
388 usb_buf[i] = 0;
390 if (sub) {
391 struct snd_pcm_runtime *rt = sub->runtime;
392 char *audio_buf = rt->dma_area;
393 int sz = frames_to_bytes(rt, rt->buffer_size);
394 audio_buf[dev->audio_in_buf_pos[stream]++] =
395 usb_buf[i];
396 dev->period_in_count[stream]++;
397 if (dev->audio_in_buf_pos[stream] == sz)
398 dev->audio_in_buf_pos[stream] = 0;
404 static void read_in_urb(struct snd_usb_caiaqdev *dev,
405 const struct urb *urb,
406 const struct usb_iso_packet_descriptor *iso)
408 if (!dev->streaming)
409 return;
411 if (iso->actual_length < dev->bpp)
412 return;
414 switch (dev->spec.data_alignment) {
415 case 0:
416 read_in_urb_mode0(dev, urb, iso);
417 break;
418 case 2:
419 read_in_urb_mode2(dev, urb, iso);
420 break;
423 if ((dev->input_panic || dev->output_panic) && !dev->warned) {
424 debug("streaming error detected %s %s\n",
425 dev->input_panic ? "(input)" : "",
426 dev->output_panic ? "(output)" : "");
427 dev->warned = 1;
431 static void fill_out_urb(struct snd_usb_caiaqdev *dev,
432 struct urb *urb,
433 const struct usb_iso_packet_descriptor *iso)
435 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
436 struct snd_pcm_substream *sub;
437 int stream, i;
439 for (i = 0; i < iso->length;) {
440 for (stream = 0; stream < dev->n_streams; stream++, i++) {
441 sub = dev->sub_playback[stream];
442 if (sub) {
443 struct snd_pcm_runtime *rt = sub->runtime;
444 char *audio_buf = rt->dma_area;
445 int sz = frames_to_bytes(rt, rt->buffer_size);
446 usb_buf[i] =
447 audio_buf[dev->audio_out_buf_pos[stream]];
448 dev->period_out_count[stream]++;
449 dev->audio_out_buf_pos[stream]++;
450 if (dev->audio_out_buf_pos[stream] == sz)
451 dev->audio_out_buf_pos[stream] = 0;
452 } else
453 usb_buf[i] = 0;
456 /* fill in the check bytes */
457 if (dev->spec.data_alignment == 2 &&
458 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) ==
459 (dev->n_streams * CHANNELS_PER_STREAM))
460 for (stream = 0; stream < dev->n_streams; stream++, i++)
461 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
465 static void read_completed(struct urb *urb)
467 struct snd_usb_caiaq_cb_info *info = urb->context;
468 struct snd_usb_caiaqdev *dev;
469 struct urb *out;
470 int frame, len, send_it = 0, outframe = 0;
472 if (urb->status || !info)
473 return;
475 dev = info->dev;
477 if (!dev->streaming)
478 return;
480 out = dev->data_urbs_out[info->index];
482 /* read the recently received packet and send back one which has
483 * the same layout */
484 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
485 if (urb->iso_frame_desc[frame].status)
486 continue;
488 len = urb->iso_frame_desc[outframe].actual_length;
489 out->iso_frame_desc[outframe].length = len;
490 out->iso_frame_desc[outframe].actual_length = 0;
491 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame;
493 if (len > 0) {
494 spin_lock(&dev->spinlock);
495 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]);
496 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]);
497 spin_unlock(&dev->spinlock);
498 check_for_elapsed_periods(dev, dev->sub_playback);
499 check_for_elapsed_periods(dev, dev->sub_capture);
500 send_it = 1;
503 outframe++;
506 if (send_it) {
507 out->number_of_packets = FRAMES_PER_URB;
508 out->transfer_flags = URB_ISO_ASAP;
509 usb_submit_urb(out, GFP_ATOMIC);
512 /* re-submit inbound urb */
513 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
514 urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame;
515 urb->iso_frame_desc[frame].length = BYTES_PER_FRAME;
516 urb->iso_frame_desc[frame].actual_length = 0;
519 urb->number_of_packets = FRAMES_PER_URB;
520 urb->transfer_flags = URB_ISO_ASAP;
521 usb_submit_urb(urb, GFP_ATOMIC);
524 static void write_completed(struct urb *urb)
526 struct snd_usb_caiaq_cb_info *info = urb->context;
527 struct snd_usb_caiaqdev *dev = info->dev;
529 if (!dev->output_running) {
530 dev->output_running = 1;
531 wake_up(&dev->prepare_wait_queue);
535 static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
537 int i, frame;
538 struct urb **urbs;
539 struct usb_device *usb_dev = dev->chip.dev;
540 unsigned int pipe;
542 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
543 usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) :
544 usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE);
546 urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL);
547 if (!urbs) {
548 log("unable to kmalloc() urbs, OOM!?\n");
549 *ret = -ENOMEM;
550 return NULL;
553 for (i = 0; i < N_URBS; i++) {
554 urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL);
555 if (!urbs[i]) {
556 log("unable to usb_alloc_urb(), OOM!?\n");
557 *ret = -ENOMEM;
558 return urbs;
561 urbs[i]->transfer_buffer =
562 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL);
563 if (!urbs[i]->transfer_buffer) {
564 log("unable to kmalloc() transfer buffer, OOM!?\n");
565 *ret = -ENOMEM;
566 return urbs;
569 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
570 struct usb_iso_packet_descriptor *iso =
571 &urbs[i]->iso_frame_desc[frame];
573 iso->offset = BYTES_PER_FRAME * frame;
574 iso->length = BYTES_PER_FRAME;
577 urbs[i]->dev = usb_dev;
578 urbs[i]->pipe = pipe;
579 urbs[i]->transfer_buffer_length = FRAMES_PER_URB
580 * BYTES_PER_FRAME;
581 urbs[i]->context = &dev->data_cb_info[i];
582 urbs[i]->interval = 1;
583 urbs[i]->transfer_flags = URB_ISO_ASAP;
584 urbs[i]->number_of_packets = FRAMES_PER_URB;
585 urbs[i]->complete = (dir == SNDRV_PCM_STREAM_CAPTURE) ?
586 read_completed : write_completed;
589 *ret = 0;
590 return urbs;
593 static void free_urbs(struct urb **urbs)
595 int i;
597 if (!urbs)
598 return;
600 for (i = 0; i < N_URBS; i++) {
601 if (!urbs[i])
602 continue;
604 usb_kill_urb(urbs[i]);
605 kfree(urbs[i]->transfer_buffer);
606 usb_free_urb(urbs[i]);
609 kfree(urbs);
612 int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
614 int i, ret;
616 dev->n_audio_in = max(dev->spec.num_analog_audio_in,
617 dev->spec.num_digital_audio_in) /
618 CHANNELS_PER_STREAM;
619 dev->n_audio_out = max(dev->spec.num_analog_audio_out,
620 dev->spec.num_digital_audio_out) /
621 CHANNELS_PER_STREAM;
622 dev->n_streams = max(dev->n_audio_in, dev->n_audio_out);
624 debug("dev->n_audio_in = %d\n", dev->n_audio_in);
625 debug("dev->n_audio_out = %d\n", dev->n_audio_out);
626 debug("dev->n_streams = %d\n", dev->n_streams);
628 if (dev->n_streams > MAX_STREAMS) {
629 log("unable to initialize device, too many streams.\n");
630 return -EINVAL;
633 ret = snd_pcm_new(dev->chip.card, dev->product_name, 0,
634 dev->n_audio_out, dev->n_audio_in, &dev->pcm);
636 if (ret < 0) {
637 log("snd_pcm_new() returned %d\n", ret);
638 return ret;
641 dev->pcm->private_data = dev;
642 strcpy(dev->pcm->name, dev->product_name);
644 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
645 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
647 memcpy(&dev->pcm_info, &snd_usb_caiaq_pcm_hardware,
648 sizeof(snd_usb_caiaq_pcm_hardware));
650 /* setup samplerates */
651 dev->samplerates = dev->pcm_info.rates;
652 switch (dev->chip.usb_id) {
653 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
654 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
655 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
656 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
657 dev->samplerates |= SNDRV_PCM_RATE_192000;
658 /* fall thru */
659 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
660 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
661 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
662 dev->samplerates |= SNDRV_PCM_RATE_88200;
663 break;
666 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
667 &snd_usb_caiaq_ops);
668 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE,
669 &snd_usb_caiaq_ops);
671 snd_pcm_lib_preallocate_pages_for_all(dev->pcm,
672 SNDRV_DMA_TYPE_CONTINUOUS,
673 snd_dma_continuous_data(GFP_KERNEL),
674 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);
676 dev->data_cb_info =
677 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS,
678 GFP_KERNEL);
680 if (!dev->data_cb_info)
681 return -ENOMEM;
683 for (i = 0; i < N_URBS; i++) {
684 dev->data_cb_info[i].dev = dev;
685 dev->data_cb_info[i].index = i;
688 dev->data_urbs_in = alloc_urbs(dev, SNDRV_PCM_STREAM_CAPTURE, &ret);
689 if (ret < 0) {
690 kfree(dev->data_cb_info);
691 free_urbs(dev->data_urbs_in);
692 return ret;
695 dev->data_urbs_out = alloc_urbs(dev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
696 if (ret < 0) {
697 kfree(dev->data_cb_info);
698 free_urbs(dev->data_urbs_in);
699 free_urbs(dev->data_urbs_out);
700 return ret;
703 return 0;
706 void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev)
708 debug("%s(%p)\n", __func__, dev);
709 stream_stop(dev);
710 free_urbs(dev->data_urbs_in);
711 free_urbs(dev->data_urbs_out);
712 kfree(dev->data_cb_info);