aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/caiaq/audio.c88
-rw-r--r--sound/usb/caiaq/device.c109
-rw-r--r--sound/usb/caiaq/device.h1
-rw-r--r--sound/usb/caiaq/midi.c24
-rw-r--r--sound/usb/usbaudio.c14
5 files changed, 126 insertions, 110 deletions
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index b13ce767ac72..b14451342166 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -42,10 +42,10 @@
42 (stream << 1) | (~(i / (dev->n_streams * BYTES_PER_SAMPLE_USB)) & 1) 42 (stream << 1) | (~(i / (dev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
43 43
44static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = { 44static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
45 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 45 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
46 SNDRV_PCM_INFO_BLOCK_TRANSFER), 46 SNDRV_PCM_INFO_BLOCK_TRANSFER),
47 .formats = SNDRV_PCM_FMTBIT_S24_3BE, 47 .formats = SNDRV_PCM_FMTBIT_S24_3BE,
48 .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 48 .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
49 SNDRV_PCM_RATE_96000), 49 SNDRV_PCM_RATE_96000),
50 .rate_min = 44100, 50 .rate_min = 44100,
51 .rate_max = 0, /* will overwrite later */ 51 .rate_max = 0, /* will overwrite later */
@@ -68,7 +68,7 @@ activate_substream(struct snd_usb_caiaqdev *dev,
68 dev->sub_capture[sub->number] = sub; 68 dev->sub_capture[sub->number] = sub;
69} 69}
70 70
71static void 71static void
72deactivate_substream(struct snd_usb_caiaqdev *dev, 72deactivate_substream(struct snd_usb_caiaqdev *dev,
73 struct snd_pcm_substream *sub) 73 struct snd_pcm_substream *sub)
74{ 74{
@@ -118,7 +118,7 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
118 return -EPIPE; 118 return -EPIPE;
119 } 119 }
120 } 120 }
121 121
122 return 0; 122 return 0;
123} 123}
124 124
@@ -129,7 +129,7 @@ static void stream_stop(struct snd_usb_caiaqdev *dev)
129 debug("%s(%p)\n", __func__, dev); 129 debug("%s(%p)\n", __func__, dev);
130 if (!dev->streaming) 130 if (!dev->streaming)
131 return; 131 return;
132 132
133 dev->streaming = 0; 133 dev->streaming = 0;
134 134
135 for (i = 0; i < N_URBS; i++) { 135 for (i = 0; i < N_URBS; i++) {
@@ -154,7 +154,7 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
154 debug("%s(%p)\n", __func__, substream); 154 debug("%s(%p)\n", __func__, substream);
155 if (all_substreams_zero(dev->sub_playback) && 155 if (all_substreams_zero(dev->sub_playback) &&
156 all_substreams_zero(dev->sub_capture)) { 156 all_substreams_zero(dev->sub_capture)) {
157 /* when the last client has stopped streaming, 157 /* when the last client has stopped streaming,
158 * all sample rates are allowed again */ 158 * all sample rates are allowed again */
159 stream_stop(dev); 159 stream_stop(dev);
160 dev->pcm_info.rates = dev->samplerates; 160 dev->pcm_info.rates = dev->samplerates;
@@ -194,7 +194,7 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
194 struct snd_pcm_runtime *runtime = substream->runtime; 194 struct snd_pcm_runtime *runtime = substream->runtime;
195 195
196 debug("%s(%p)\n", __func__, substream); 196 debug("%s(%p)\n", __func__, substream);
197 197
198 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 198 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
199 dev->period_out_count[index] = BYTES_PER_SAMPLE + 1; 199 dev->period_out_count[index] = BYTES_PER_SAMPLE + 1;
200 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; 200 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
@@ -205,19 +205,19 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
205 205
206 if (dev->streaming) 206 if (dev->streaming)
207 return 0; 207 return 0;
208 208
209 /* the first client that opens a stream defines the sample rate 209 /* the first client that opens a stream defines the sample rate
210 * setting for all subsequent calls, until the last client closed. */ 210 * setting for all subsequent calls, until the last client closed. */
211 for (i=0; i < ARRAY_SIZE(rates); i++) 211 for (i=0; i < ARRAY_SIZE(rates); i++)
212 if (runtime->rate == rates[i]) 212 if (runtime->rate == rates[i])
213 dev->pcm_info.rates = 1 << i; 213 dev->pcm_info.rates = 1 << i;
214 214
215 snd_pcm_limit_hw_rates(runtime); 215 snd_pcm_limit_hw_rates(runtime);
216 216
217 bytes_per_sample = BYTES_PER_SAMPLE; 217 bytes_per_sample = BYTES_PER_SAMPLE;
218 if (dev->spec.data_alignment == 2) 218 if (dev->spec.data_alignment == 2)
219 bytes_per_sample++; 219 bytes_per_sample++;
220 220
221 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 221 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
222 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; 222 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams;
223 223
@@ -232,7 +232,7 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
232 ret = stream_start(dev); 232 ret = stream_start(dev);
233 if (ret) 233 if (ret)
234 return ret; 234 return ret;
235 235
236 dev->output_running = 0; 236 dev->output_running = 0;
237 wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ); 237 wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ);
238 if (!dev->output_running) { 238 if (!dev->output_running) {
@@ -273,7 +273,7 @@ snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
273 return SNDRV_PCM_POS_XRUN; 273 return SNDRV_PCM_POS_XRUN;
274 274
275 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 275 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
276 return bytes_to_frames(sub->runtime, 276 return bytes_to_frames(sub->runtime,
277 dev->audio_out_buf_pos[index]); 277 dev->audio_out_buf_pos[index]);
278 else 278 else
279 return bytes_to_frames(sub->runtime, 279 return bytes_to_frames(sub->runtime,
@@ -291,7 +291,7 @@ static struct snd_pcm_ops snd_usb_caiaq_ops = {
291 .trigger = snd_usb_caiaq_pcm_trigger, 291 .trigger = snd_usb_caiaq_pcm_trigger,
292 .pointer = snd_usb_caiaq_pcm_pointer 292 .pointer = snd_usb_caiaq_pcm_pointer
293}; 293};
294 294
295static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev, 295static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev,
296 struct snd_pcm_substream **subs) 296 struct snd_pcm_substream **subs)
297{ 297{
@@ -333,7 +333,7 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
333 struct snd_pcm_runtime *rt = sub->runtime; 333 struct snd_pcm_runtime *rt = sub->runtime;
334 char *audio_buf = rt->dma_area; 334 char *audio_buf = rt->dma_area;
335 int sz = frames_to_bytes(rt, rt->buffer_size); 335 int sz = frames_to_bytes(rt, rt->buffer_size);
336 audio_buf[dev->audio_in_buf_pos[stream]++] 336 audio_buf[dev->audio_in_buf_pos[stream]++]
337 = usb_buf[i]; 337 = usb_buf[i];
338 dev->period_in_count[stream]++; 338 dev->period_in_count[stream]++;
339 if (dev->audio_in_buf_pos[stream] == sz) 339 if (dev->audio_in_buf_pos[stream] == sz)
@@ -354,14 +354,14 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
354 354
355 for (i = 0; i < iso->actual_length;) { 355 for (i = 0; i < iso->actual_length;) {
356 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { 356 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
357 for (stream = 0; 357 for (stream = 0;
358 stream < dev->n_streams; 358 stream < dev->n_streams;
359 stream++, i++) { 359 stream++, i++) {
360 if (dev->first_packet) 360 if (dev->first_packet)
361 continue; 361 continue;
362 362
363 check_byte = MAKE_CHECKBYTE(dev, stream, i); 363 check_byte = MAKE_CHECKBYTE(dev, stream, i);
364 364
365 if ((usb_buf[i] & 0x3f) != check_byte) 365 if ((usb_buf[i] & 0x3f) != check_byte)
366 dev->input_panic = 1; 366 dev->input_panic = 1;
367 367
@@ -410,21 +410,21 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
410 } 410 }
411 411
412 if ((dev->input_panic || dev->output_panic) && !dev->warned) { 412 if ((dev->input_panic || dev->output_panic) && !dev->warned) {
413 debug("streaming error detected %s %s\n", 413 debug("streaming error detected %s %s\n",
414 dev->input_panic ? "(input)" : "", 414 dev->input_panic ? "(input)" : "",
415 dev->output_panic ? "(output)" : ""); 415 dev->output_panic ? "(output)" : "");
416 dev->warned = 1; 416 dev->warned = 1;
417 } 417 }
418} 418}
419 419
420static void fill_out_urb(struct snd_usb_caiaqdev *dev, 420static void fill_out_urb(struct snd_usb_caiaqdev *dev,
421 struct urb *urb, 421 struct urb *urb,
422 const struct usb_iso_packet_descriptor *iso) 422 const struct usb_iso_packet_descriptor *iso)
423{ 423{
424 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 424 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
425 struct snd_pcm_substream *sub; 425 struct snd_pcm_substream *sub;
426 int stream, i; 426 int stream, i;
427 427
428 for (i = 0; i < iso->length;) { 428 for (i = 0; i < iso->length;) {
429 for (stream = 0; stream < dev->n_streams; stream++, i++) { 429 for (stream = 0; stream < dev->n_streams; stream++, i++) {
430 sub = dev->sub_playback[stream]; 430 sub = dev->sub_playback[stream];
@@ -444,7 +444,7 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
444 444
445 /* fill in the check bytes */ 445 /* fill in the check bytes */
446 if (dev->spec.data_alignment == 2 && 446 if (dev->spec.data_alignment == 2 &&
447 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 447 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) ==
448 (dev->n_streams * CHANNELS_PER_STREAM)) 448 (dev->n_streams * CHANNELS_PER_STREAM))
449 for (stream = 0; stream < dev->n_streams; stream++, i++) 449 for (stream = 0; stream < dev->n_streams; stream++, i++)
450 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 450 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
@@ -453,7 +453,7 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
453 453
454static void read_completed(struct urb *urb) 454static void read_completed(struct urb *urb)
455{ 455{
456 struct snd_usb_caiaq_cb_info *info = urb->context; 456 struct snd_usb_caiaq_cb_info *info = urb->context;
457 struct snd_usb_caiaqdev *dev; 457 struct snd_usb_caiaqdev *dev;
458 struct urb *out; 458 struct urb *out;
459 int frame, len, send_it = 0, outframe = 0; 459 int frame, len, send_it = 0, outframe = 0;
@@ -478,7 +478,7 @@ static void read_completed(struct urb *urb)
478 out->iso_frame_desc[outframe].length = len; 478 out->iso_frame_desc[outframe].length = len;
479 out->iso_frame_desc[outframe].actual_length = 0; 479 out->iso_frame_desc[outframe].actual_length = 0;
480 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame; 480 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame;
481 481
482 if (len > 0) { 482 if (len > 0) {
483 spin_lock(&dev->spinlock); 483 spin_lock(&dev->spinlock);
484 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); 484 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]);
@@ -497,14 +497,14 @@ static void read_completed(struct urb *urb)
497 out->transfer_flags = URB_ISO_ASAP; 497 out->transfer_flags = URB_ISO_ASAP;
498 usb_submit_urb(out, GFP_ATOMIC); 498 usb_submit_urb(out, GFP_ATOMIC);
499 } 499 }
500 500
501 /* re-submit inbound urb */ 501 /* re-submit inbound urb */
502 for (frame = 0; frame < FRAMES_PER_URB; frame++) { 502 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
503 urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame; 503 urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame;
504 urb->iso_frame_desc[frame].length = BYTES_PER_FRAME; 504 urb->iso_frame_desc[frame].length = BYTES_PER_FRAME;
505 urb->iso_frame_desc[frame].actual_length = 0; 505 urb->iso_frame_desc[frame].actual_length = 0;
506 } 506 }
507 507
508 urb->number_of_packets = FRAMES_PER_URB; 508 urb->number_of_packets = FRAMES_PER_URB;
509 urb->transfer_flags = URB_ISO_ASAP; 509 urb->transfer_flags = URB_ISO_ASAP;
510 usb_submit_urb(urb, GFP_ATOMIC); 510 usb_submit_urb(urb, GFP_ATOMIC);
@@ -528,7 +528,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
528 struct usb_device *usb_dev = dev->chip.dev; 528 struct usb_device *usb_dev = dev->chip.dev;
529 unsigned int pipe; 529 unsigned int pipe;
530 530
531 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ? 531 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
532 usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) : 532 usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) :
533 usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE); 533 usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE);
534 534
@@ -547,25 +547,25 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
547 return urbs; 547 return urbs;
548 } 548 }
549 549
550 urbs[i]->transfer_buffer = 550 urbs[i]->transfer_buffer =
551 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL); 551 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL);
552 if (!urbs[i]->transfer_buffer) { 552 if (!urbs[i]->transfer_buffer) {
553 log("unable to kmalloc() transfer buffer, OOM!?\n"); 553 log("unable to kmalloc() transfer buffer, OOM!?\n");
554 *ret = -ENOMEM; 554 *ret = -ENOMEM;
555 return urbs; 555 return urbs;
556 } 556 }
557 557
558 for (frame = 0; frame < FRAMES_PER_URB; frame++) { 558 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
559 struct usb_iso_packet_descriptor *iso = 559 struct usb_iso_packet_descriptor *iso =
560 &urbs[i]->iso_frame_desc[frame]; 560 &urbs[i]->iso_frame_desc[frame];
561 561
562 iso->offset = BYTES_PER_FRAME * frame; 562 iso->offset = BYTES_PER_FRAME * frame;
563 iso->length = BYTES_PER_FRAME; 563 iso->length = BYTES_PER_FRAME;
564 } 564 }
565 565
566 urbs[i]->dev = usb_dev; 566 urbs[i]->dev = usb_dev;
567 urbs[i]->pipe = pipe; 567 urbs[i]->pipe = pipe;
568 urbs[i]->transfer_buffer_length = FRAMES_PER_URB 568 urbs[i]->transfer_buffer_length = FRAMES_PER_URB
569 * BYTES_PER_FRAME; 569 * BYTES_PER_FRAME;
570 urbs[i]->context = &dev->data_cb_info[i]; 570 urbs[i]->context = &dev->data_cb_info[i];
571 urbs[i]->interval = 1; 571 urbs[i]->interval = 1;
@@ -589,7 +589,7 @@ static void free_urbs(struct urb **urbs)
589 for (i = 0; i < N_URBS; i++) { 589 for (i = 0; i < N_URBS; i++) {
590 if (!urbs[i]) 590 if (!urbs[i])
591 continue; 591 continue;
592 592
593 usb_kill_urb(urbs[i]); 593 usb_kill_urb(urbs[i]);
594 kfree(urbs[i]->transfer_buffer); 594 kfree(urbs[i]->transfer_buffer);
595 usb_free_urb(urbs[i]); 595 usb_free_urb(urbs[i]);
@@ -602,11 +602,11 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
602{ 602{
603 int i, ret; 603 int i, ret;
604 604
605 dev->n_audio_in = max(dev->spec.num_analog_audio_in, 605 dev->n_audio_in = max(dev->spec.num_analog_audio_in,
606 dev->spec.num_digital_audio_in) / 606 dev->spec.num_digital_audio_in) /
607 CHANNELS_PER_STREAM; 607 CHANNELS_PER_STREAM;
608 dev->n_audio_out = max(dev->spec.num_analog_audio_out, 608 dev->n_audio_out = max(dev->spec.num_analog_audio_out,
609 dev->spec.num_digital_audio_out) / 609 dev->spec.num_digital_audio_out) /
610 CHANNELS_PER_STREAM; 610 CHANNELS_PER_STREAM;
611 dev->n_streams = max(dev->n_audio_in, dev->n_audio_out); 611 dev->n_streams = max(dev->n_audio_in, dev->n_audio_out);
612 612
@@ -619,7 +619,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
619 return -EINVAL; 619 return -EINVAL;
620 } 620 }
621 621
622 ret = snd_pcm_new(dev->chip.card, dev->product_name, 0, 622 ret = snd_pcm_new(dev->chip.card, dev->product_name, 0,
623 dev->n_audio_out, dev->n_audio_in, &dev->pcm); 623 dev->n_audio_out, dev->n_audio_in, &dev->pcm);
624 624
625 if (ret < 0) { 625 if (ret < 0) {
@@ -632,7 +632,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
632 632
633 memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); 633 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
634 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 634 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
635 635
636 memcpy(&dev->pcm_info, &snd_usb_caiaq_pcm_hardware, 636 memcpy(&dev->pcm_info, &snd_usb_caiaq_pcm_hardware,
637 sizeof(snd_usb_caiaq_pcm_hardware)); 637 sizeof(snd_usb_caiaq_pcm_hardware));
638 638
@@ -651,9 +651,9 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
651 break; 651 break;
652 } 652 }
653 653
654 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 654 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
655 &snd_usb_caiaq_ops); 655 &snd_usb_caiaq_ops);
656 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 656 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE,
657 &snd_usb_caiaq_ops); 657 &snd_usb_caiaq_ops);
658 658
659 snd_pcm_lib_preallocate_pages_for_all(dev->pcm, 659 snd_pcm_lib_preallocate_pages_for_all(dev->pcm,
@@ -662,7 +662,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
662 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE); 662 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);
663 663
664 dev->data_cb_info = 664 dev->data_cb_info =
665 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS, 665 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS,
666 GFP_KERNEL); 666 GFP_KERNEL);
667 667
668 if (!dev->data_cb_info) 668 if (!dev->data_cb_info)
@@ -672,14 +672,14 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
672 dev->data_cb_info[i].dev = dev; 672 dev->data_cb_info[i].dev = dev;
673 dev->data_cb_info[i].index = i; 673 dev->data_cb_info[i].index = i;
674 } 674 }
675 675
676 dev->data_urbs_in = alloc_urbs(dev, SNDRV_PCM_STREAM_CAPTURE, &ret); 676 dev->data_urbs_in = alloc_urbs(dev, SNDRV_PCM_STREAM_CAPTURE, &ret);
677 if (ret < 0) { 677 if (ret < 0) {
678 kfree(dev->data_cb_info); 678 kfree(dev->data_cb_info);
679 free_urbs(dev->data_urbs_in); 679 free_urbs(dev->data_urbs_in);
680 return ret; 680 return ret;
681 } 681 }
682 682
683 dev->data_urbs_out = alloc_urbs(dev, SNDRV_PCM_STREAM_PLAYBACK, &ret); 683 dev->data_urbs_out = alloc_urbs(dev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
684 if (ret < 0) { 684 if (ret < 0) {
685 kfree(dev->data_cb_info); 685 kfree(dev->data_cb_info);
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 515de1cd2a3e..22406245a98b 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -35,7 +35,7 @@
35#include "input.h" 35#include "input.h"
36 36
37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.14"); 38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.16");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
41 "{Native Instruments, RigKontrol3}," 41 "{Native Instruments, RigKontrol3},"
@@ -79,7 +79,7 @@ static struct usb_device_id snd_usb_id_table[] = {
79 { 79 {
80 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, 80 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
81 .idVendor = USB_VID_NATIVEINSTRUMENTS, 81 .idVendor = USB_VID_NATIVEINSTRUMENTS,
82 .idProduct = USB_PID_RIGKONTROL2 82 .idProduct = USB_PID_RIGKONTROL2
83 }, 83 },
84 { 84 {
85 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, 85 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
@@ -197,7 +197,7 @@ int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *dev,
197 197
198 if (buffer && len > 0) 198 if (buffer && len > 0)
199 memcpy(dev->ep1_out_buf+1, buffer, len); 199 memcpy(dev->ep1_out_buf+1, buffer, len);
200 200
201 dev->ep1_out_buf[0] = command; 201 dev->ep1_out_buf[0] = command;
202 return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1), 202 return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1),
203 dev->ep1_out_buf, len+1, &actual_len, 200); 203 dev->ep1_out_buf, len+1, &actual_len, 200);
@@ -208,7 +208,7 @@ int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev,
208{ 208{
209 int ret; 209 int ret;
210 char tmp[5]; 210 char tmp[5];
211 211
212 switch (rate) { 212 switch (rate) {
213 case 44100: tmp[0] = SAMPLERATE_44100; break; 213 case 44100: tmp[0] = SAMPLERATE_44100; break;
214 case 48000: tmp[0] = SAMPLERATE_48000; break; 214 case 48000: tmp[0] = SAMPLERATE_48000; break;
@@ -237,12 +237,12 @@ int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev,
237 237
238 if (ret) 238 if (ret)
239 return ret; 239 return ret;
240 240
241 if (!wait_event_timeout(dev->ep1_wait_queue, 241 if (!wait_event_timeout(dev->ep1_wait_queue,
242 dev->audio_parm_answer >= 0, HZ)) 242 dev->audio_parm_answer >= 0, HZ))
243 return -EPIPE; 243 return -EPIPE;
244 244
245 if (dev->audio_parm_answer != 1) 245 if (dev->audio_parm_answer != 1)
246 debug("unable to set the device's audio params\n"); 246 debug("unable to set the device's audio params\n");
247 else 247 else
248 dev->bpp = bpp; 248 dev->bpp = bpp;
@@ -250,8 +250,8 @@ int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev,
250 return dev->audio_parm_answer == 1 ? 0 : -EINVAL; 250 return dev->audio_parm_answer == 1 ? 0 : -EINVAL;
251} 251}
252 252
253int snd_usb_caiaq_set_auto_msg (struct snd_usb_caiaqdev *dev, 253int snd_usb_caiaq_set_auto_msg(struct snd_usb_caiaqdev *dev,
254 int digital, int analog, int erp) 254 int digital, int analog, int erp)
255{ 255{
256 char tmp[3] = { digital, analog, erp }; 256 char tmp[3] = { digital, analog, erp };
257 return snd_usb_caiaq_send_command(dev, EP1_CMD_AUTO_MSG, 257 return snd_usb_caiaq_send_command(dev, EP1_CMD_AUTO_MSG,
@@ -262,7 +262,7 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
262{ 262{
263 int ret; 263 int ret;
264 char val[4]; 264 char val[4];
265 265
266 /* device-specific startup specials */ 266 /* device-specific startup specials */
267 switch (dev->chip.usb_id) { 267 switch (dev->chip.usb_id) {
268 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 268 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
@@ -314,7 +314,7 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
314 dev->control_state, 1); 314 dev->control_state, 1);
315 break; 315 break;
316 } 316 }
317 317
318 if (dev->spec.num_analog_audio_out + 318 if (dev->spec.num_analog_audio_out +
319 dev->spec.num_analog_audio_in + 319 dev->spec.num_analog_audio_in +
320 dev->spec.num_digital_audio_out + 320 dev->spec.num_digital_audio_out +
@@ -323,7 +323,7 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
323 if (ret < 0) 323 if (ret < 0)
324 log("Unable to set up audio system (ret=%d)\n", ret); 324 log("Unable to set up audio system (ret=%d)\n", ret);
325 } 325 }
326 326
327 if (dev->spec.num_midi_in + 327 if (dev->spec.num_midi_in +
328 dev->spec.num_midi_out > 0) { 328 dev->spec.num_midi_out > 0) {
329 ret = snd_usb_caiaq_midi_init(dev); 329 ret = snd_usb_caiaq_midi_init(dev);
@@ -363,7 +363,7 @@ static int create_card(struct usb_device* usb_dev, struct snd_card **cardp)
363 if (devnum >= SNDRV_CARDS) 363 if (devnum >= SNDRV_CARDS)
364 return -ENODEV; 364 return -ENODEV;
365 365
366 err = snd_card_create(index[devnum], id[devnum], THIS_MODULE, 366 err = snd_card_create(index[devnum], id[devnum], THIS_MODULE,
367 sizeof(struct snd_usb_caiaqdev), &card); 367 sizeof(struct snd_usb_caiaqdev), &card);
368 if (err < 0) 368 if (err < 0)
369 return err; 369 return err;
@@ -382,11 +382,11 @@ static int create_card(struct usb_device* usb_dev, struct snd_card **cardp)
382 382
383static int __devinit init_card(struct snd_usb_caiaqdev *dev) 383static int __devinit init_card(struct snd_usb_caiaqdev *dev)
384{ 384{
385 char *c; 385 char *c, usbpath[32];
386 struct usb_device *usb_dev = dev->chip.dev; 386 struct usb_device *usb_dev = dev->chip.dev;
387 struct snd_card *card = dev->chip.card; 387 struct snd_card *card = dev->chip.card;
388 int err, len; 388 int err, len;
389 389
390 if (usb_set_interface(usb_dev, 0, 1) != 0) { 390 if (usb_set_interface(usb_dev, 0, 1) != 0) {
391 log("can't set alt interface.\n"); 391 log("can't set alt interface.\n");
392 return -EIO; 392 return -EIO;
@@ -395,19 +395,19 @@ static int __devinit init_card(struct snd_usb_caiaqdev *dev)
395 usb_init_urb(&dev->ep1_in_urb); 395 usb_init_urb(&dev->ep1_in_urb);
396 usb_init_urb(&dev->midi_out_urb); 396 usb_init_urb(&dev->midi_out_urb);
397 397
398 usb_fill_bulk_urb(&dev->ep1_in_urb, usb_dev, 398 usb_fill_bulk_urb(&dev->ep1_in_urb, usb_dev,
399 usb_rcvbulkpipe(usb_dev, 0x1), 399 usb_rcvbulkpipe(usb_dev, 0x1),
400 dev->ep1_in_buf, EP1_BUFSIZE, 400 dev->ep1_in_buf, EP1_BUFSIZE,
401 usb_ep1_command_reply_dispatch, dev); 401 usb_ep1_command_reply_dispatch, dev);
402 402
403 usb_fill_bulk_urb(&dev->midi_out_urb, usb_dev, 403 usb_fill_bulk_urb(&dev->midi_out_urb, usb_dev,
404 usb_sndbulkpipe(usb_dev, 0x1), 404 usb_sndbulkpipe(usb_dev, 0x1),
405 dev->midi_out_buf, EP1_BUFSIZE, 405 dev->midi_out_buf, EP1_BUFSIZE,
406 snd_usb_caiaq_midi_output_done, dev); 406 snd_usb_caiaq_midi_output_done, dev);
407 407
408 init_waitqueue_head(&dev->ep1_wait_queue); 408 init_waitqueue_head(&dev->ep1_wait_queue);
409 init_waitqueue_head(&dev->prepare_wait_queue); 409 init_waitqueue_head(&dev->prepare_wait_queue);
410 410
411 if (usb_submit_urb(&dev->ep1_in_urb, GFP_KERNEL) != 0) 411 if (usb_submit_urb(&dev->ep1_in_urb, GFP_KERNEL) != 0)
412 return -EIO; 412 return -EIO;
413 413
@@ -420,47 +420,52 @@ static int __devinit init_card(struct snd_usb_caiaqdev *dev)
420 420
421 usb_string(usb_dev, usb_dev->descriptor.iManufacturer, 421 usb_string(usb_dev, usb_dev->descriptor.iManufacturer,
422 dev->vendor_name, CAIAQ_USB_STR_LEN); 422 dev->vendor_name, CAIAQ_USB_STR_LEN);
423 423
424 usb_string(usb_dev, usb_dev->descriptor.iProduct, 424 usb_string(usb_dev, usb_dev->descriptor.iProduct,
425 dev->product_name, CAIAQ_USB_STR_LEN); 425 dev->product_name, CAIAQ_USB_STR_LEN);
426 426
427 usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, 427 strlcpy(card->driver, MODNAME, sizeof(card->driver));
428 dev->serial, CAIAQ_USB_STR_LEN); 428 strlcpy(card->shortname, dev->product_name, sizeof(card->shortname));
429 429 strlcpy(card->mixername, dev->product_name, sizeof(card->mixername));
430 /* terminate serial string at first white space occurence */ 430
431 c = strchr(dev->serial, ' '); 431 /* if the id was not passed as module option, fill it with a shortened
432 if (c) 432 * version of the product string which does not contain any
433 *c = '\0'; 433 * whitespaces */
434 434
435 strcpy(card->driver, MODNAME); 435 if (*card->id == '\0') {
436 strcpy(card->shortname, dev->product_name); 436 char id[sizeof(card->id)];
437 437
438 len = snprintf(card->longname, sizeof(card->longname), 438 memset(id, 0, sizeof(id));
439 "%s %s (serial %s, ", 439
440 dev->vendor_name, dev->product_name, dev->serial); 440 for (c = card->shortname, len = 0;
441 441 *c && len < sizeof(card->id); c++)
442 if (len < sizeof(card->longname) - 2) 442 if (*c != ' ')
443 len += usb_make_path(usb_dev, card->longname + len, 443 id[len++] = *c;
444 sizeof(card->longname) - len); 444
445 445 snd_card_set_id(card, id);
446 card->longname[len++] = ')'; 446 }
447 card->longname[len] = '\0'; 447
448 usb_make_path(usb_dev, usbpath, sizeof(usbpath));
449 snprintf(card->longname, sizeof(card->longname),
450 "%s %s (%s)",
451 dev->vendor_name, dev->product_name, usbpath);
452
448 setup_card(dev); 453 setup_card(dev);
449 return 0; 454 return 0;
450} 455}
451 456
452static int __devinit snd_probe(struct usb_interface *intf, 457static int __devinit snd_probe(struct usb_interface *intf,
453 const struct usb_device_id *id) 458 const struct usb_device_id *id)
454{ 459{
455 int ret; 460 int ret;
456 struct snd_card *card; 461 struct snd_card *card;
457 struct usb_device *device = interface_to_usbdev(intf); 462 struct usb_device *device = interface_to_usbdev(intf);
458 463
459 ret = create_card(device, &card); 464 ret = create_card(device, &card);
460 465
461 if (ret < 0) 466 if (ret < 0)
462 return ret; 467 return ret;
463 468
464 usb_set_intfdata(intf, card); 469 usb_set_intfdata(intf, card);
465 ret = init_card(caiaqdev(card)); 470 ret = init_card(caiaqdev(card));
466 if (ret < 0) { 471 if (ret < 0) {
@@ -468,7 +473,7 @@ static int __devinit snd_probe(struct usb_interface *intf,
468 snd_card_free(card); 473 snd_card_free(card);
469 return ret; 474 return ret;
470 } 475 }
471 476
472 return 0; 477 return 0;
473} 478}
474 479
@@ -489,10 +494,10 @@ static void snd_disconnect(struct usb_interface *intf)
489 snd_usb_caiaq_input_free(dev); 494 snd_usb_caiaq_input_free(dev);
490#endif 495#endif
491 snd_usb_caiaq_audio_free(dev); 496 snd_usb_caiaq_audio_free(dev);
492 497
493 usb_kill_urb(&dev->ep1_in_urb); 498 usb_kill_urb(&dev->ep1_in_urb);
494 usb_kill_urb(&dev->midi_out_urb); 499 usb_kill_urb(&dev->midi_out_urb);
495 500
496 snd_card_free(card); 501 snd_card_free(card);
497 usb_reset_device(interface_to_usbdev(intf)); 502 usb_reset_device(interface_to_usbdev(intf));
498} 503}
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index 4cce1ad7493d..ece73514854e 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -81,7 +81,6 @@ struct snd_usb_caiaqdev {
81 81
82 char vendor_name[CAIAQ_USB_STR_LEN]; 82 char vendor_name[CAIAQ_USB_STR_LEN];
83 char product_name[CAIAQ_USB_STR_LEN]; 83 char product_name[CAIAQ_USB_STR_LEN];
84 char serial[CAIAQ_USB_STR_LEN];
85 84
86 int n_streams, n_audio_in, n_audio_out; 85 int n_streams, n_audio_in, n_audio_out;
87 int streaming, first_packet, output_running; 86 int streaming, first_packet, output_running;
diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c
index 8fa8cd88d763..538e8c00d31a 100644
--- a/sound/usb/caiaq/midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -40,7 +40,7 @@ static void snd_usb_caiaq_midi_input_trigger(struct snd_rawmidi_substream *subst
40 40
41 if (!dev) 41 if (!dev)
42 return; 42 return;
43 43
44 dev->midi_receive_substream = up ? substream : NULL; 44 dev->midi_receive_substream = up ? substream : NULL;
45} 45}
46 46
@@ -64,18 +64,18 @@ static void snd_usb_caiaq_midi_send(struct snd_usb_caiaqdev *dev,
64 struct snd_rawmidi_substream *substream) 64 struct snd_rawmidi_substream *substream)
65{ 65{
66 int len, ret; 66 int len, ret;
67 67
68 dev->midi_out_buf[0] = EP1_CMD_MIDI_WRITE; 68 dev->midi_out_buf[0] = EP1_CMD_MIDI_WRITE;
69 dev->midi_out_buf[1] = 0; /* port */ 69 dev->midi_out_buf[1] = 0; /* port */
70 len = snd_rawmidi_transmit(substream, dev->midi_out_buf + 3, 70 len = snd_rawmidi_transmit(substream, dev->midi_out_buf + 3,
71 EP1_BUFSIZE - 3); 71 EP1_BUFSIZE - 3);
72 72
73 if (len <= 0) 73 if (len <= 0)
74 return; 74 return;
75 75
76 dev->midi_out_buf[2] = len; 76 dev->midi_out_buf[2] = len;
77 dev->midi_out_urb.transfer_buffer_length = len+3; 77 dev->midi_out_urb.transfer_buffer_length = len+3;
78 78
79 ret = usb_submit_urb(&dev->midi_out_urb, GFP_ATOMIC); 79 ret = usb_submit_urb(&dev->midi_out_urb, GFP_ATOMIC);
80 if (ret < 0) 80 if (ret < 0)
81 log("snd_usb_caiaq_midi_send(%p): usb_submit_urb() failed," 81 log("snd_usb_caiaq_midi_send(%p): usb_submit_urb() failed,"
@@ -88,7 +88,7 @@ static void snd_usb_caiaq_midi_send(struct snd_usb_caiaqdev *dev,
88static void snd_usb_caiaq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) 88static void snd_usb_caiaq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
89{ 89{
90 struct snd_usb_caiaqdev *dev = substream->rmidi->private_data; 90 struct snd_usb_caiaqdev *dev = substream->rmidi->private_data;
91 91
92 if (up) { 92 if (up) {
93 dev->midi_out_substream = substream; 93 dev->midi_out_substream = substream;
94 if (!dev->midi_out_active) 94 if (!dev->midi_out_active)
@@ -113,12 +113,12 @@ static struct snd_rawmidi_ops snd_usb_caiaq_midi_input =
113 .trigger = snd_usb_caiaq_midi_input_trigger, 113 .trigger = snd_usb_caiaq_midi_input_trigger,
114}; 114};
115 115
116void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *dev, 116void snd_usb_caiaq_midi_handle_input(struct snd_usb_caiaqdev *dev,
117 int port, const char *buf, int len) 117 int port, const char *buf, int len)
118{ 118{
119 if (!dev->midi_receive_substream) 119 if (!dev->midi_receive_substream)
120 return; 120 return;
121 121
122 snd_rawmidi_receive(dev->midi_receive_substream, buf, len); 122 snd_rawmidi_receive(dev->midi_receive_substream, buf, len);
123} 123}
124 124
@@ -142,16 +142,16 @@ int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device)
142 142
143 if (device->spec.num_midi_out > 0) { 143 if (device->spec.num_midi_out > 0) {
144 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT; 144 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
145 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, 145 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
146 &snd_usb_caiaq_midi_output); 146 &snd_usb_caiaq_midi_output);
147 } 147 }
148 148
149 if (device->spec.num_midi_in > 0) { 149 if (device->spec.num_midi_in > 0) {
150 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT; 150 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
151 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, 151 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
152 &snd_usb_caiaq_midi_input); 152 &snd_usb_caiaq_midi_input);
153 } 153 }
154 154
155 device->rmidi = rmidi; 155 device->rmidi = rmidi;
156 156
157 return 0; 157 return 0;
@@ -160,7 +160,7 @@ int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device)
160void snd_usb_caiaq_midi_output_done(struct urb* urb) 160void snd_usb_caiaq_midi_output_done(struct urb* urb)
161{ 161{
162 struct snd_usb_caiaqdev *dev = urb->context; 162 struct snd_usb_caiaqdev *dev = urb->context;
163 163
164 dev->midi_out_active = 0; 164 dev->midi_out_active = 0;
165 if (urb->status != 0) 165 if (urb->status != 0)
166 return; 166 return;
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index e87121751dd0..c7b902358b7b 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -627,6 +627,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
627 subs->hwptr_done += offs; 627 subs->hwptr_done += offs;
628 if (subs->hwptr_done >= runtime->buffer_size) 628 if (subs->hwptr_done >= runtime->buffer_size)
629 subs->hwptr_done -= runtime->buffer_size; 629 subs->hwptr_done -= runtime->buffer_size;
630 runtime->delay += offs;
630 spin_unlock_irqrestore(&subs->lock, flags); 631 spin_unlock_irqrestore(&subs->lock, flags);
631 urb->transfer_buffer_length = offs * stride; 632 urb->transfer_buffer_length = offs * stride;
632 if (period_elapsed) 633 if (period_elapsed)
@@ -636,12 +637,22 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
636 637
637/* 638/*
638 * process after playback data complete 639 * process after playback data complete
639 * - nothing to do 640 * - decrease the delay count again
640 */ 641 */
641static int retire_playback_urb(struct snd_usb_substream *subs, 642static int retire_playback_urb(struct snd_usb_substream *subs,
642 struct snd_pcm_runtime *runtime, 643 struct snd_pcm_runtime *runtime,
643 struct urb *urb) 644 struct urb *urb)
644{ 645{
646 unsigned long flags;
647 int stride = runtime->frame_bits >> 3;
648 int processed = urb->transfer_buffer_length / stride;
649
650 spin_lock_irqsave(&subs->lock, flags);
651 if (processed > runtime->delay)
652 runtime->delay = 0;
653 else
654 runtime->delay -= processed;
655 spin_unlock_irqrestore(&subs->lock, flags);
645 return 0; 656 return 0;
646} 657}
647 658
@@ -1520,6 +1531,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
1520 subs->hwptr_done = 0; 1531 subs->hwptr_done = 0;
1521 subs->transfer_done = 0; 1532 subs->transfer_done = 0;
1522 subs->phase = 0; 1533 subs->phase = 0;
1534 runtime->delay = 0;
1523 1535
1524 /* clear urbs (to be sure) */ 1536 /* clear urbs (to be sure) */
1525 deactivate_urbs(subs, 0, 1); 1537 deactivate_urbs(subs, 0, 1);