diff options
Diffstat (limited to 'sound/usb/usbaudio.c')
| -rw-r--r-- | sound/usb/usbaudio.c | 894 |
1 files changed, 565 insertions, 329 deletions
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index 9edef4684978..11b0826b8fe6 100644 --- a/sound/usb/usbaudio.c +++ b/sound/usb/usbaudio.c | |||
| @@ -44,9 +44,11 @@ | |||
| 44 | #include <linux/slab.h> | 44 | #include <linux/slab.h> |
| 45 | #include <linux/string.h> | 45 | #include <linux/string.h> |
| 46 | #include <linux/usb.h> | 46 | #include <linux/usb.h> |
| 47 | #include <linux/vmalloc.h> | ||
| 48 | #include <linux/moduleparam.h> | 47 | #include <linux/moduleparam.h> |
| 49 | #include <linux/mutex.h> | 48 | #include <linux/mutex.h> |
| 49 | #include <linux/usb/audio.h> | ||
| 50 | #include <linux/usb/ch9.h> | ||
| 51 | |||
| 50 | #include <sound/core.h> | 52 | #include <sound/core.h> |
| 51 | #include <sound/info.h> | 53 | #include <sound/info.h> |
| 52 | #include <sound/pcm.h> | 54 | #include <sound/pcm.h> |
| @@ -170,11 +172,12 @@ struct snd_usb_substream { | |||
| 170 | unsigned int curpacksize; /* current packet size in bytes (for capture) */ | 172 | unsigned int curpacksize; /* current packet size in bytes (for capture) */ |
| 171 | unsigned int curframesize; /* current packet size in frames (for capture) */ | 173 | unsigned int curframesize; /* current packet size in frames (for capture) */ |
| 172 | unsigned int fill_max: 1; /* fill max packet size always */ | 174 | unsigned int fill_max: 1; /* fill max packet size always */ |
| 175 | unsigned int txfr_quirk:1; /* allow sub-frame alignment */ | ||
| 173 | unsigned int fmt_type; /* USB audio format type (1-3) */ | 176 | unsigned int fmt_type; /* USB audio format type (1-3) */ |
| 174 | 177 | ||
| 175 | unsigned int running: 1; /* running status */ | 178 | unsigned int running: 1; /* running status */ |
| 176 | 179 | ||
| 177 | unsigned int hwptr_done; /* processed frame position in the buffer */ | 180 | unsigned int hwptr_done; /* processed byte position in the buffer */ |
| 178 | unsigned int transfer_done; /* processed frames since last period update */ | 181 | unsigned int transfer_done; /* processed frames since last period update */ |
| 179 | unsigned long active_mask; /* bitmask of active urbs */ | 182 | unsigned long active_mask; /* bitmask of active urbs */ |
| 180 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ | 183 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ |
| @@ -343,7 +346,7 @@ static int retire_capture_urb(struct snd_usb_substream *subs, | |||
| 343 | unsigned long flags; | 346 | unsigned long flags; |
| 344 | unsigned char *cp; | 347 | unsigned char *cp; |
| 345 | int i; | 348 | int i; |
| 346 | unsigned int stride, len, oldptr; | 349 | unsigned int stride, frames, bytes, oldptr; |
| 347 | int period_elapsed = 0; | 350 | int period_elapsed = 0; |
| 348 | 351 | ||
| 349 | stride = runtime->frame_bits >> 3; | 352 | stride = runtime->frame_bits >> 3; |
| @@ -354,29 +357,39 @@ static int retire_capture_urb(struct snd_usb_substream *subs, | |||
| 354 | snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); | 357 | snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); |
| 355 | // continue; | 358 | // continue; |
| 356 | } | 359 | } |
| 357 | len = urb->iso_frame_desc[i].actual_length / stride; | 360 | bytes = urb->iso_frame_desc[i].actual_length; |
| 358 | if (! len) | 361 | frames = bytes / stride; |
| 359 | continue; | 362 | if (!subs->txfr_quirk) |
| 363 | bytes = frames * stride; | ||
| 364 | if (bytes % (runtime->sample_bits >> 3) != 0) { | ||
| 365 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
| 366 | int oldbytes = bytes; | ||
| 367 | #endif | ||
| 368 | bytes = frames * stride; | ||
| 369 | snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", | ||
| 370 | oldbytes, bytes); | ||
| 371 | } | ||
| 360 | /* update the current pointer */ | 372 | /* update the current pointer */ |
| 361 | spin_lock_irqsave(&subs->lock, flags); | 373 | spin_lock_irqsave(&subs->lock, flags); |
| 362 | oldptr = subs->hwptr_done; | 374 | oldptr = subs->hwptr_done; |
| 363 | subs->hwptr_done += len; | 375 | subs->hwptr_done += bytes; |
| 364 | if (subs->hwptr_done >= runtime->buffer_size) | 376 | if (subs->hwptr_done >= runtime->buffer_size * stride) |
| 365 | subs->hwptr_done -= runtime->buffer_size; | 377 | subs->hwptr_done -= runtime->buffer_size * stride; |
| 366 | subs->transfer_done += len; | 378 | frames = (bytes + (oldptr % stride)) / stride; |
| 379 | subs->transfer_done += frames; | ||
| 367 | if (subs->transfer_done >= runtime->period_size) { | 380 | if (subs->transfer_done >= runtime->period_size) { |
| 368 | subs->transfer_done -= runtime->period_size; | 381 | subs->transfer_done -= runtime->period_size; |
| 369 | period_elapsed = 1; | 382 | period_elapsed = 1; |
| 370 | } | 383 | } |
| 371 | spin_unlock_irqrestore(&subs->lock, flags); | 384 | spin_unlock_irqrestore(&subs->lock, flags); |
| 372 | /* copy a data chunk */ | 385 | /* copy a data chunk */ |
| 373 | if (oldptr + len > runtime->buffer_size) { | 386 | if (oldptr + bytes > runtime->buffer_size * stride) { |
| 374 | unsigned int cnt = runtime->buffer_size - oldptr; | 387 | unsigned int bytes1 = |
| 375 | unsigned int blen = cnt * stride; | 388 | runtime->buffer_size * stride - oldptr; |
| 376 | memcpy(runtime->dma_area + oldptr * stride, cp, blen); | 389 | memcpy(runtime->dma_area + oldptr, cp, bytes1); |
| 377 | memcpy(runtime->dma_area, cp + blen, len * stride - blen); | 390 | memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); |
| 378 | } else { | 391 | } else { |
| 379 | memcpy(runtime->dma_area + oldptr * stride, cp, len * stride); | 392 | memcpy(runtime->dma_area + oldptr, cp, bytes); |
| 380 | } | 393 | } |
| 381 | } | 394 | } |
| 382 | if (period_elapsed) | 395 | if (period_elapsed) |
| @@ -563,34 +576,34 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
| 563 | struct snd_pcm_runtime *runtime, | 576 | struct snd_pcm_runtime *runtime, |
| 564 | struct urb *urb) | 577 | struct urb *urb) |
| 565 | { | 578 | { |
| 566 | int i, stride, offs; | 579 | int i, stride; |
| 567 | unsigned int counts; | 580 | unsigned int counts, frames, bytes; |
| 568 | unsigned long flags; | 581 | unsigned long flags; |
| 569 | int period_elapsed = 0; | 582 | int period_elapsed = 0; |
| 570 | struct snd_urb_ctx *ctx = urb->context; | 583 | struct snd_urb_ctx *ctx = urb->context; |
| 571 | 584 | ||
| 572 | stride = runtime->frame_bits >> 3; | 585 | stride = runtime->frame_bits >> 3; |
| 573 | 586 | ||
| 574 | offs = 0; | 587 | frames = 0; |
| 575 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | 588 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ |
| 576 | urb->number_of_packets = 0; | 589 | urb->number_of_packets = 0; |
| 577 | spin_lock_irqsave(&subs->lock, flags); | 590 | spin_lock_irqsave(&subs->lock, flags); |
| 578 | for (i = 0; i < ctx->packets; i++) { | 591 | for (i = 0; i < ctx->packets; i++) { |
| 579 | counts = snd_usb_audio_next_packet_size(subs); | 592 | counts = snd_usb_audio_next_packet_size(subs); |
| 580 | /* set up descriptor */ | 593 | /* set up descriptor */ |
| 581 | urb->iso_frame_desc[i].offset = offs * stride; | 594 | urb->iso_frame_desc[i].offset = frames * stride; |
| 582 | urb->iso_frame_desc[i].length = counts * stride; | 595 | urb->iso_frame_desc[i].length = counts * stride; |
| 583 | offs += counts; | 596 | frames += counts; |
| 584 | urb->number_of_packets++; | 597 | urb->number_of_packets++; |
| 585 | subs->transfer_done += counts; | 598 | subs->transfer_done += counts; |
| 586 | if (subs->transfer_done >= runtime->period_size) { | 599 | if (subs->transfer_done >= runtime->period_size) { |
| 587 | subs->transfer_done -= runtime->period_size; | 600 | subs->transfer_done -= runtime->period_size; |
| 588 | period_elapsed = 1; | 601 | period_elapsed = 1; |
| 589 | if (subs->fmt_type == USB_FORMAT_TYPE_II) { | 602 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) { |
| 590 | if (subs->transfer_done > 0) { | 603 | if (subs->transfer_done > 0) { |
| 591 | /* FIXME: fill-max mode is not | 604 | /* FIXME: fill-max mode is not |
| 592 | * supported yet */ | 605 | * supported yet */ |
| 593 | offs -= subs->transfer_done; | 606 | frames -= subs->transfer_done; |
| 594 | counts -= subs->transfer_done; | 607 | counts -= subs->transfer_done; |
| 595 | urb->iso_frame_desc[i].length = | 608 | urb->iso_frame_desc[i].length = |
| 596 | counts * stride; | 609 | counts * stride; |
| @@ -600,7 +613,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
| 600 | if (i < ctx->packets) { | 613 | if (i < ctx->packets) { |
| 601 | /* add a transfer delimiter */ | 614 | /* add a transfer delimiter */ |
| 602 | urb->iso_frame_desc[i].offset = | 615 | urb->iso_frame_desc[i].offset = |
| 603 | offs * stride; | 616 | frames * stride; |
| 604 | urb->iso_frame_desc[i].length = 0; | 617 | urb->iso_frame_desc[i].length = 0; |
| 605 | urb->number_of_packets++; | 618 | urb->number_of_packets++; |
| 606 | } | 619 | } |
| @@ -610,26 +623,25 @@ static int prepare_playback_urb(struct snd_usb_substream *subs, | |||
| 610 | if (period_elapsed) /* finish at the period boundary */ | 623 | if (period_elapsed) /* finish at the period boundary */ |
| 611 | break; | 624 | break; |
| 612 | } | 625 | } |
| 613 | if (subs->hwptr_done + offs > runtime->buffer_size) { | 626 | bytes = frames * stride; |
| 627 | if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { | ||
| 614 | /* err, the transferred area goes over buffer boundary. */ | 628 | /* err, the transferred area goes over buffer boundary. */ |
| 615 | unsigned int len = runtime->buffer_size - subs->hwptr_done; | 629 | unsigned int bytes1 = |
| 630 | runtime->buffer_size * stride - subs->hwptr_done; | ||
| 616 | memcpy(urb->transfer_buffer, | 631 | memcpy(urb->transfer_buffer, |
| 617 | runtime->dma_area + subs->hwptr_done * stride, | 632 | runtime->dma_area + subs->hwptr_done, bytes1); |
| 618 | len * stride); | 633 | memcpy(urb->transfer_buffer + bytes1, |
| 619 | memcpy(urb->transfer_buffer + len * stride, | 634 | runtime->dma_area, bytes - bytes1); |
| 620 | runtime->dma_area, | ||
| 621 | (offs - len) * stride); | ||
| 622 | } else { | 635 | } else { |
| 623 | memcpy(urb->transfer_buffer, | 636 | memcpy(urb->transfer_buffer, |
| 624 | runtime->dma_area + subs->hwptr_done * stride, | 637 | runtime->dma_area + subs->hwptr_done, bytes); |
| 625 | offs * stride); | ||
| 626 | } | 638 | } |
| 627 | subs->hwptr_done += offs; | 639 | subs->hwptr_done += bytes; |
| 628 | if (subs->hwptr_done >= runtime->buffer_size) | 640 | if (subs->hwptr_done >= runtime->buffer_size * stride) |
| 629 | subs->hwptr_done -= runtime->buffer_size; | 641 | subs->hwptr_done -= runtime->buffer_size * stride; |
| 630 | runtime->delay += offs; | 642 | runtime->delay += frames; |
| 631 | spin_unlock_irqrestore(&subs->lock, flags); | 643 | spin_unlock_irqrestore(&subs->lock, flags); |
| 632 | urb->transfer_buffer_length = offs * stride; | 644 | urb->transfer_buffer_length = bytes; |
| 633 | if (period_elapsed) | 645 | if (period_elapsed) |
| 634 | snd_pcm_period_elapsed(subs->pcm_substream); | 646 | snd_pcm_period_elapsed(subs->pcm_substream); |
| 635 | return 0; | 647 | return 0; |
| @@ -735,41 +747,6 @@ static void snd_complete_sync_urb(struct urb *urb) | |||
| 735 | } | 747 | } |
| 736 | 748 | ||
| 737 | 749 | ||
| 738 | /* get the physical page pointer at the given offset */ | ||
| 739 | static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs, | ||
| 740 | unsigned long offset) | ||
| 741 | { | ||
| 742 | void *pageptr = subs->runtime->dma_area + offset; | ||
| 743 | return vmalloc_to_page(pageptr); | ||
| 744 | } | ||
| 745 | |||
| 746 | /* allocate virtual buffer; may be called more than once */ | ||
| 747 | static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size) | ||
| 748 | { | ||
| 749 | struct snd_pcm_runtime *runtime = subs->runtime; | ||
| 750 | if (runtime->dma_area) { | ||
| 751 | if (runtime->dma_bytes >= size) | ||
| 752 | return 0; /* already large enough */ | ||
| 753 | vfree(runtime->dma_area); | ||
| 754 | } | ||
| 755 | runtime->dma_area = vmalloc_user(size); | ||
| 756 | if (!runtime->dma_area) | ||
| 757 | return -ENOMEM; | ||
| 758 | runtime->dma_bytes = size; | ||
| 759 | return 0; | ||
| 760 | } | ||
| 761 | |||
| 762 | /* free virtual buffer; may be called more than once */ | ||
| 763 | static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs) | ||
| 764 | { | ||
| 765 | struct snd_pcm_runtime *runtime = subs->runtime; | ||
| 766 | |||
| 767 | vfree(runtime->dma_area); | ||
| 768 | runtime->dma_area = NULL; | ||
| 769 | return 0; | ||
| 770 | } | ||
| 771 | |||
| 772 | |||
| 773 | /* | 750 | /* |
| 774 | * unlink active urbs. | 751 | * unlink active urbs. |
| 775 | */ | 752 | */ |
| @@ -937,18 +914,18 @@ static int wait_clear_urbs(struct snd_usb_substream *subs) | |||
| 937 | 914 | ||
| 938 | 915 | ||
| 939 | /* | 916 | /* |
| 940 | * return the current pcm pointer. just return the hwptr_done value. | 917 | * return the current pcm pointer. just based on the hwptr_done value. |
| 941 | */ | 918 | */ |
| 942 | static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) | 919 | static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) |
| 943 | { | 920 | { |
| 944 | struct snd_usb_substream *subs; | 921 | struct snd_usb_substream *subs; |
| 945 | snd_pcm_uframes_t hwptr_done; | 922 | unsigned int hwptr_done; |
| 946 | 923 | ||
| 947 | subs = (struct snd_usb_substream *)substream->runtime->private_data; | 924 | subs = (struct snd_usb_substream *)substream->runtime->private_data; |
| 948 | spin_lock(&subs->lock); | 925 | spin_lock(&subs->lock); |
| 949 | hwptr_done = subs->hwptr_done; | 926 | hwptr_done = subs->hwptr_done; |
| 950 | spin_unlock(&subs->lock); | 927 | spin_unlock(&subs->lock); |
| 951 | return hwptr_done; | 928 | return hwptr_done / (substream->runtime->frame_bits >> 3); |
| 952 | } | 929 | } |
| 953 | 930 | ||
| 954 | 931 | ||
| @@ -1130,7 +1107,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri | |||
| 1130 | u->packets = (i + 1) * total_packs / subs->nurbs | 1107 | u->packets = (i + 1) * total_packs / subs->nurbs |
| 1131 | - i * total_packs / subs->nurbs; | 1108 | - i * total_packs / subs->nurbs; |
| 1132 | u->buffer_size = maxsize * u->packets; | 1109 | u->buffer_size = maxsize * u->packets; |
| 1133 | if (subs->fmt_type == USB_FORMAT_TYPE_II) | 1110 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) |
| 1134 | u->packets++; /* for transfer delimiter */ | 1111 | u->packets++; /* for transfer delimiter */ |
| 1135 | u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); | 1112 | u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); |
| 1136 | if (!u->urb) | 1113 | if (!u->urb) |
| @@ -1206,7 +1183,7 @@ static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned | |||
| 1206 | if (i >= fp->nr_rates) | 1183 | if (i >= fp->nr_rates) |
| 1207 | continue; | 1184 | continue; |
| 1208 | } | 1185 | } |
| 1209 | attr = fp->ep_attr & EP_ATTR_MASK; | 1186 | attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE; |
| 1210 | if (! found) { | 1187 | if (! found) { |
| 1211 | found = fp; | 1188 | found = fp; |
| 1212 | cur_attr = attr; | 1189 | cur_attr = attr; |
| @@ -1218,14 +1195,14 @@ static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned | |||
| 1218 | * M-audio audiophile USB. | 1195 | * M-audio audiophile USB. |
| 1219 | */ | 1196 | */ |
| 1220 | if (attr != cur_attr) { | 1197 | if (attr != cur_attr) { |
| 1221 | if ((attr == EP_ATTR_ASYNC && | 1198 | if ((attr == USB_ENDPOINT_SYNC_ASYNC && |
| 1222 | subs->direction == SNDRV_PCM_STREAM_PLAYBACK) || | 1199 | subs->direction == SNDRV_PCM_STREAM_PLAYBACK) || |
| 1223 | (attr == EP_ATTR_ADAPTIVE && | 1200 | (attr == USB_ENDPOINT_SYNC_ADAPTIVE && |
| 1224 | subs->direction == SNDRV_PCM_STREAM_CAPTURE)) | 1201 | subs->direction == SNDRV_PCM_STREAM_CAPTURE)) |
| 1225 | continue; | 1202 | continue; |
| 1226 | if ((cur_attr == EP_ATTR_ASYNC && | 1203 | if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC && |
| 1227 | subs->direction == SNDRV_PCM_STREAM_PLAYBACK) || | 1204 | subs->direction == SNDRV_PCM_STREAM_PLAYBACK) || |
| 1228 | (cur_attr == EP_ATTR_ADAPTIVE && | 1205 | (cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE && |
| 1229 | subs->direction == SNDRV_PCM_STREAM_CAPTURE)) { | 1206 | subs->direction == SNDRV_PCM_STREAM_CAPTURE)) { |
| 1230 | found = fp; | 1207 | found = fp; |
| 1231 | cur_attr = attr; | 1208 | cur_attr = attr; |
| @@ -1255,11 +1232,11 @@ static int init_usb_pitch(struct usb_device *dev, int iface, | |||
| 1255 | 1232 | ||
| 1256 | ep = get_endpoint(alts, 0)->bEndpointAddress; | 1233 | ep = get_endpoint(alts, 0)->bEndpointAddress; |
| 1257 | /* if endpoint has pitch control, enable it */ | 1234 | /* if endpoint has pitch control, enable it */ |
| 1258 | if (fmt->attributes & EP_CS_ATTR_PITCH_CONTROL) { | 1235 | if (fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL) { |
| 1259 | data[0] = 1; | 1236 | data[0] = 1; |
| 1260 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, | 1237 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, |
| 1261 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, | 1238 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, |
| 1262 | PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) { | 1239 | UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) { |
| 1263 | snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", | 1240 | snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", |
| 1264 | dev->devnum, iface, ep); | 1241 | dev->devnum, iface, ep); |
| 1265 | return err; | 1242 | return err; |
| @@ -1278,21 +1255,21 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface, | |||
| 1278 | 1255 | ||
| 1279 | ep = get_endpoint(alts, 0)->bEndpointAddress; | 1256 | ep = get_endpoint(alts, 0)->bEndpointAddress; |
| 1280 | /* if endpoint has sampling rate control, set it */ | 1257 | /* if endpoint has sampling rate control, set it */ |
| 1281 | if (fmt->attributes & EP_CS_ATTR_SAMPLE_RATE) { | 1258 | if (fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE) { |
| 1282 | int crate; | 1259 | int crate; |
| 1283 | data[0] = rate; | 1260 | data[0] = rate; |
| 1284 | data[1] = rate >> 8; | 1261 | data[1] = rate >> 8; |
| 1285 | data[2] = rate >> 16; | 1262 | data[2] = rate >> 16; |
| 1286 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, | 1263 | if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, |
| 1287 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, | 1264 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, |
| 1288 | SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) { | 1265 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000)) < 0) { |
| 1289 | snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", | 1266 | snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", |
| 1290 | dev->devnum, iface, fmt->altsetting, rate, ep); | 1267 | dev->devnum, iface, fmt->altsetting, rate, ep); |
| 1291 | return err; | 1268 | return err; |
| 1292 | } | 1269 | } |
| 1293 | if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, | 1270 | if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, |
| 1294 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN, | 1271 | USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN, |
| 1295 | SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) { | 1272 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000)) < 0) { |
| 1296 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", | 1273 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", |
| 1297 | dev->devnum, iface, fmt->altsetting, ep); | 1274 | dev->devnum, iface, fmt->altsetting, ep); |
| 1298 | return 0; /* some devices don't support reading */ | 1275 | return 0; /* some devices don't support reading */ |
| @@ -1307,6 +1284,47 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface, | |||
| 1307 | } | 1284 | } |
| 1308 | 1285 | ||
| 1309 | /* | 1286 | /* |
| 1287 | * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device, | ||
| 1288 | * not for interface. | ||
| 1289 | */ | ||
| 1290 | static void set_format_emu_quirk(struct snd_usb_substream *subs, | ||
| 1291 | struct audioformat *fmt) | ||
| 1292 | { | ||
| 1293 | unsigned char emu_samplerate_id = 0; | ||
| 1294 | |||
| 1295 | /* When capture is active | ||
| 1296 | * sample rate shouldn't be changed | ||
| 1297 | * by playback substream | ||
| 1298 | */ | ||
| 1299 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { | ||
| 1300 | if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1) | ||
| 1301 | return; | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | switch (fmt->rate_min) { | ||
| 1305 | case 48000: | ||
| 1306 | emu_samplerate_id = EMU_QUIRK_SR_48000HZ; | ||
| 1307 | break; | ||
| 1308 | case 88200: | ||
| 1309 | emu_samplerate_id = EMU_QUIRK_SR_88200HZ; | ||
| 1310 | break; | ||
| 1311 | case 96000: | ||
| 1312 | emu_samplerate_id = EMU_QUIRK_SR_96000HZ; | ||
| 1313 | break; | ||
| 1314 | case 176400: | ||
| 1315 | emu_samplerate_id = EMU_QUIRK_SR_176400HZ; | ||
| 1316 | break; | ||
| 1317 | case 192000: | ||
| 1318 | emu_samplerate_id = EMU_QUIRK_SR_192000HZ; | ||
| 1319 | break; | ||
| 1320 | default: | ||
| 1321 | emu_samplerate_id = EMU_QUIRK_SR_44100HZ; | ||
| 1322 | break; | ||
| 1323 | } | ||
| 1324 | snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id); | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | /* | ||
| 1310 | * find a matching format and set up the interface | 1328 | * find a matching format and set up the interface |
| 1311 | */ | 1329 | */ |
| 1312 | static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | 1330 | static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) |
| @@ -1369,9 +1387,9 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
| 1369 | * descriptors which fool us. if it has only one EP, | 1387 | * descriptors which fool us. if it has only one EP, |
| 1370 | * assume it as adaptive-out or sync-in. | 1388 | * assume it as adaptive-out or sync-in. |
| 1371 | */ | 1389 | */ |
| 1372 | attr = fmt->ep_attr & EP_ATTR_MASK; | 1390 | attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE; |
| 1373 | if (((is_playback && attr == EP_ATTR_ASYNC) || | 1391 | if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) || |
| 1374 | (! is_playback && attr == EP_ATTR_ADAPTIVE)) && | 1392 | (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) && |
| 1375 | altsd->bNumEndpoints >= 2) { | 1393 | altsd->bNumEndpoints >= 2) { |
| 1376 | /* check sync-pipe endpoint */ | 1394 | /* check sync-pipe endpoint */ |
| 1377 | /* ... and check descriptor size before accessing bSynchAddress | 1395 | /* ... and check descriptor size before accessing bSynchAddress |
| @@ -1411,7 +1429,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
| 1411 | } | 1429 | } |
| 1412 | 1430 | ||
| 1413 | /* always fill max packet size */ | 1431 | /* always fill max packet size */ |
| 1414 | if (fmt->attributes & EP_CS_ATTR_FILL_MAX) | 1432 | if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX) |
| 1415 | subs->fill_max = 1; | 1433 | subs->fill_max = 1; |
| 1416 | 1434 | ||
| 1417 | if ((err = init_usb_pitch(dev, subs->interface, alts, fmt)) < 0) | 1435 | if ((err = init_usb_pitch(dev, subs->interface, alts, fmt)) < 0) |
| @@ -1419,6 +1437,14 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
| 1419 | 1437 | ||
| 1420 | subs->cur_audiofmt = fmt; | 1438 | subs->cur_audiofmt = fmt; |
| 1421 | 1439 | ||
| 1440 | switch (subs->stream->chip->usb_id) { | ||
| 1441 | case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ | ||
| 1442 | case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */ | ||
| 1443 | case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */ | ||
| 1444 | set_format_emu_quirk(subs, fmt); | ||
| 1445 | break; | ||
| 1446 | } | ||
| 1447 | |||
| 1422 | #if 0 | 1448 | #if 0 |
| 1423 | printk(KERN_DEBUG | 1449 | printk(KERN_DEBUG |
| 1424 | "setting done: format = %d, rate = %d..%d, channels = %d\n", | 1450 | "setting done: format = %d, rate = %d..%d, channels = %d\n", |
| @@ -1449,8 +1475,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, | |||
| 1449 | unsigned int channels, rate, format; | 1475 | unsigned int channels, rate, format; |
| 1450 | int ret, changed; | 1476 | int ret, changed; |
| 1451 | 1477 | ||
| 1452 | ret = snd_pcm_alloc_vmalloc_buffer(substream, | 1478 | ret = snd_pcm_lib_alloc_vmalloc_buffer(substream, |
| 1453 | params_buffer_bytes(hw_params)); | 1479 | params_buffer_bytes(hw_params)); |
| 1454 | if (ret < 0) | 1480 | if (ret < 0) |
| 1455 | return ret; | 1481 | return ret; |
| 1456 | 1482 | ||
| @@ -1507,7 +1533,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream) | |||
| 1507 | subs->period_bytes = 0; | 1533 | subs->period_bytes = 0; |
| 1508 | if (!subs->stream->chip->shutdown) | 1534 | if (!subs->stream->chip->shutdown) |
| 1509 | release_substream_urbs(subs, 0); | 1535 | release_substream_urbs(subs, 0); |
| 1510 | return snd_pcm_free_vmalloc_buffer(substream); | 1536 | return snd_pcm_lib_free_vmalloc_buffer(substream); |
| 1511 | } | 1537 | } |
| 1512 | 1538 | ||
| 1513 | /* | 1539 | /* |
| @@ -1861,7 +1887,7 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre | |||
| 1861 | runtime->hw.channels_min = fp->channels; | 1887 | runtime->hw.channels_min = fp->channels; |
| 1862 | if (runtime->hw.channels_max < fp->channels) | 1888 | if (runtime->hw.channels_max < fp->channels) |
| 1863 | runtime->hw.channels_max = fp->channels; | 1889 | runtime->hw.channels_max = fp->channels; |
| 1864 | if (fp->fmt_type == USB_FORMAT_TYPE_II && fp->frame_size > 0) { | 1890 | if (fp->fmt_type == UAC_FORMAT_TYPE_II && fp->frame_size > 0) { |
| 1865 | /* FIXME: there might be more than one audio formats... */ | 1891 | /* FIXME: there might be more than one audio formats... */ |
| 1866 | runtime->hw.period_bytes_min = runtime->hw.period_bytes_max = | 1892 | runtime->hw.period_bytes_min = runtime->hw.period_bytes_max = |
| 1867 | fp->frame_size; | 1893 | fp->frame_size; |
| @@ -1973,7 +1999,8 @@ static struct snd_pcm_ops snd_usb_playback_ops = { | |||
| 1973 | .prepare = snd_usb_pcm_prepare, | 1999 | .prepare = snd_usb_pcm_prepare, |
| 1974 | .trigger = snd_usb_pcm_playback_trigger, | 2000 | .trigger = snd_usb_pcm_playback_trigger, |
| 1975 | .pointer = snd_usb_pcm_pointer, | 2001 | .pointer = snd_usb_pcm_pointer, |
| 1976 | .page = snd_pcm_get_vmalloc_page, | 2002 | .page = snd_pcm_lib_get_vmalloc_page, |
| 2003 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
| 1977 | }; | 2004 | }; |
| 1978 | 2005 | ||
| 1979 | static struct snd_pcm_ops snd_usb_capture_ops = { | 2006 | static struct snd_pcm_ops snd_usb_capture_ops = { |
| @@ -1985,7 +2012,8 @@ static struct snd_pcm_ops snd_usb_capture_ops = { | |||
| 1985 | .prepare = snd_usb_pcm_prepare, | 2012 | .prepare = snd_usb_pcm_prepare, |
| 1986 | .trigger = snd_usb_pcm_capture_trigger, | 2013 | .trigger = snd_usb_pcm_capture_trigger, |
| 1987 | .pointer = snd_usb_pcm_pointer, | 2014 | .pointer = snd_usb_pcm_pointer, |
| 1988 | .page = snd_pcm_get_vmalloc_page, | 2015 | .page = snd_pcm_lib_get_vmalloc_page, |
| 2016 | .mmap = snd_pcm_lib_mmap_vmalloc, | ||
| 1989 | }; | 2017 | }; |
| 1990 | 2018 | ||
| 1991 | 2019 | ||
| @@ -2093,7 +2121,7 @@ static struct usb_device_id usb_audio_ids [] = { | |||
| 2093 | #include "usbquirks.h" | 2121 | #include "usbquirks.h" |
| 2094 | { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS), | 2122 | { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS), |
| 2095 | .bInterfaceClass = USB_CLASS_AUDIO, | 2123 | .bInterfaceClass = USB_CLASS_AUDIO, |
| 2096 | .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL }, | 2124 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL }, |
| 2097 | { } /* Terminating entry */ | 2125 | { } /* Terminating entry */ |
| 2098 | }; | 2126 | }; |
| 2099 | 2127 | ||
| @@ -2132,7 +2160,7 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s | |||
| 2132 | snd_iprintf(buffer, " Endpoint: %d %s (%s)\n", | 2160 | snd_iprintf(buffer, " Endpoint: %d %s (%s)\n", |
| 2133 | fp->endpoint & USB_ENDPOINT_NUMBER_MASK, | 2161 | fp->endpoint & USB_ENDPOINT_NUMBER_MASK, |
| 2134 | fp->endpoint & USB_DIR_IN ? "IN" : "OUT", | 2162 | fp->endpoint & USB_DIR_IN ? "IN" : "OUT", |
| 2135 | sync_types[(fp->ep_attr & EP_ATTR_MASK) >> 2]); | 2163 | sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]); |
| 2136 | if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) { | 2164 | if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) { |
| 2137 | snd_iprintf(buffer, " Rates: %d - %d (continuous)\n", | 2165 | snd_iprintf(buffer, " Rates: %d - %d (continuous)\n", |
| 2138 | fp->rate_min, fp->rate_max); | 2166 | fp->rate_min, fp->rate_max); |
| @@ -2227,6 +2255,7 @@ static void init_substream(struct snd_usb_stream *as, int stream, struct audiofo | |||
| 2227 | subs->stream = as; | 2255 | subs->stream = as; |
| 2228 | subs->direction = stream; | 2256 | subs->direction = stream; |
| 2229 | subs->dev = as->chip->dev; | 2257 | subs->dev = as->chip->dev; |
| 2258 | subs->txfr_quirk = as->chip->txfr_quirk; | ||
| 2230 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { | 2259 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { |
| 2231 | subs->ops = audio_urb_ops[stream]; | 2260 | subs->ops = audio_urb_ops[stream]; |
| 2232 | } else { | 2261 | } else { |
| @@ -2394,29 +2423,67 @@ static int is_big_endian_format(struct snd_usb_audio *chip, struct audioformat * | |||
| 2394 | * @format: the format tag (wFormatTag) | 2423 | * @format: the format tag (wFormatTag) |
| 2395 | * @fmt: the format type descriptor | 2424 | * @fmt: the format type descriptor |
| 2396 | */ | 2425 | */ |
| 2397 | static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audioformat *fp, | 2426 | static int parse_audio_format_i_type(struct snd_usb_audio *chip, |
| 2398 | int format, unsigned char *fmt) | 2427 | struct audioformat *fp, |
| 2428 | int format, void *_fmt, | ||
| 2429 | int protocol) | ||
| 2399 | { | 2430 | { |
| 2400 | int pcm_format; | 2431 | int pcm_format, i; |
| 2401 | int sample_width, sample_bytes; | 2432 | int sample_width, sample_bytes; |
| 2402 | 2433 | ||
| 2434 | switch (protocol) { | ||
| 2435 | case UAC_VERSION_1: { | ||
| 2436 | struct uac_format_type_i_discrete_descriptor *fmt = _fmt; | ||
| 2437 | sample_width = fmt->bBitResolution; | ||
| 2438 | sample_bytes = fmt->bSubframeSize; | ||
| 2439 | break; | ||
| 2440 | } | ||
| 2441 | |||
| 2442 | case UAC_VERSION_2: { | ||
| 2443 | struct uac_format_type_i_ext_descriptor *fmt = _fmt; | ||
| 2444 | sample_width = fmt->bBitResolution; | ||
| 2445 | sample_bytes = fmt->bSubslotSize; | ||
| 2446 | |||
| 2447 | /* | ||
| 2448 | * FIXME | ||
| 2449 | * USB audio class v2 devices specify a bitmap of possible | ||
| 2450 | * audio formats rather than one fix value. For now, we just | ||
| 2451 | * pick one of them and report that as the only possible | ||
| 2452 | * value for this setting. | ||
| 2453 | * The bit allocation map is in fact compatible to the | ||
| 2454 | * wFormatTag of the v1 AS streaming descriptors, which is why | ||
| 2455 | * we can simply map the matrix. | ||
| 2456 | */ | ||
| 2457 | |||
| 2458 | for (i = 0; i < 5; i++) | ||
| 2459 | if (format & (1UL << i)) { | ||
| 2460 | format = i + 1; | ||
| 2461 | break; | ||
| 2462 | } | ||
| 2463 | |||
| 2464 | break; | ||
| 2465 | } | ||
| 2466 | |||
| 2467 | default: | ||
| 2468 | return -EINVAL; | ||
| 2469 | } | ||
| 2470 | |||
| 2403 | /* FIXME: correct endianess and sign? */ | 2471 | /* FIXME: correct endianess and sign? */ |
| 2404 | pcm_format = -1; | 2472 | pcm_format = -1; |
| 2405 | sample_width = fmt[6]; | 2473 | |
| 2406 | sample_bytes = fmt[5]; | ||
| 2407 | switch (format) { | 2474 | switch (format) { |
| 2408 | case 0: /* some devices don't define this correctly... */ | 2475 | case UAC_FORMAT_TYPE_I_UNDEFINED: /* some devices don't define this correctly... */ |
| 2409 | snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", | 2476 | snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", |
| 2410 | chip->dev->devnum, fp->iface, fp->altsetting); | 2477 | chip->dev->devnum, fp->iface, fp->altsetting); |
| 2411 | /* fall-through */ | 2478 | /* fall-through */ |
| 2412 | case USB_AUDIO_FORMAT_PCM: | 2479 | case UAC_FORMAT_TYPE_I_PCM: |
| 2413 | if (sample_width > sample_bytes * 8) { | 2480 | if (sample_width > sample_bytes * 8) { |
| 2414 | snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", | 2481 | snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", |
| 2415 | chip->dev->devnum, fp->iface, fp->altsetting, | 2482 | chip->dev->devnum, fp->iface, fp->altsetting, |
| 2416 | sample_width, sample_bytes); | 2483 | sample_width, sample_bytes); |
| 2417 | } | 2484 | } |
| 2418 | /* check the format byte size */ | 2485 | /* check the format byte size */ |
| 2419 | switch (fmt[5]) { | 2486 | switch (sample_bytes) { |
| 2420 | case 1: | 2487 | case 1: |
| 2421 | pcm_format = SNDRV_PCM_FORMAT_S8; | 2488 | pcm_format = SNDRV_PCM_FORMAT_S8; |
| 2422 | break; | 2489 | break; |
| @@ -2437,12 +2504,12 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor | |||
| 2437 | break; | 2504 | break; |
| 2438 | default: | 2505 | default: |
| 2439 | snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", | 2506 | snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", |
| 2440 | chip->dev->devnum, fp->iface, | 2507 | chip->dev->devnum, fp->iface, fp->altsetting, |
| 2441 | fp->altsetting, sample_width, sample_bytes); | 2508 | sample_width, sample_bytes); |
| 2442 | break; | 2509 | break; |
| 2443 | } | 2510 | } |
| 2444 | break; | 2511 | break; |
| 2445 | case USB_AUDIO_FORMAT_PCM8: | 2512 | case UAC_FORMAT_TYPE_I_PCM8: |
| 2446 | pcm_format = SNDRV_PCM_FORMAT_U8; | 2513 | pcm_format = SNDRV_PCM_FORMAT_U8; |
| 2447 | 2514 | ||
| 2448 | /* Dallas DS4201 workaround: it advertises U8 format, but really | 2515 | /* Dallas DS4201 workaround: it advertises U8 format, but really |
| @@ -2450,13 +2517,13 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor | |||
| 2450 | if (chip->usb_id == USB_ID(0x04fa, 0x4201)) | 2517 | if (chip->usb_id == USB_ID(0x04fa, 0x4201)) |
| 2451 | pcm_format = SNDRV_PCM_FORMAT_S8; | 2518 | pcm_format = SNDRV_PCM_FORMAT_S8; |
| 2452 | break; | 2519 | break; |
| 2453 | case USB_AUDIO_FORMAT_IEEE_FLOAT: | 2520 | case UAC_FORMAT_TYPE_I_IEEE_FLOAT: |
| 2454 | pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; | 2521 | pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; |
| 2455 | break; | 2522 | break; |
| 2456 | case USB_AUDIO_FORMAT_ALAW: | 2523 | case UAC_FORMAT_TYPE_I_ALAW: |
| 2457 | pcm_format = SNDRV_PCM_FORMAT_A_LAW; | 2524 | pcm_format = SNDRV_PCM_FORMAT_A_LAW; |
| 2458 | break; | 2525 | break; |
| 2459 | case USB_AUDIO_FORMAT_MU_LAW: | 2526 | case UAC_FORMAT_TYPE_I_MULAW: |
| 2460 | pcm_format = SNDRV_PCM_FORMAT_MU_LAW; | 2527 | pcm_format = SNDRV_PCM_FORMAT_MU_LAW; |
| 2461 | break; | 2528 | break; |
| 2462 | default: | 2529 | default: |
| @@ -2470,7 +2537,7 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor | |||
| 2470 | 2537 | ||
| 2471 | /* | 2538 | /* |
| 2472 | * parse the format descriptor and stores the possible sample rates | 2539 | * parse the format descriptor and stores the possible sample rates |
| 2473 | * on the audioformat table. | 2540 | * on the audioformat table (audio class v1). |
| 2474 | * | 2541 | * |
| 2475 | * @dev: usb device | 2542 | * @dev: usb device |
| 2476 | * @fp: audioformat record | 2543 | * @fp: audioformat record |
| @@ -2478,13 +2545,13 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor | |||
| 2478 | * @offset: the start offset of descriptor pointing the rate type | 2545 | * @offset: the start offset of descriptor pointing the rate type |
| 2479 | * (7 for type I and II, 8 for type II) | 2546 | * (7 for type I and II, 8 for type II) |
| 2480 | */ | 2547 | */ |
| 2481 | static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioformat *fp, | 2548 | static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp, |
| 2482 | unsigned char *fmt, int offset) | 2549 | unsigned char *fmt, int offset) |
| 2483 | { | 2550 | { |
| 2484 | int nr_rates = fmt[offset]; | 2551 | int nr_rates = fmt[offset]; |
| 2485 | 2552 | ||
| 2486 | if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { | 2553 | if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { |
| 2487 | snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n", | 2554 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", |
| 2488 | chip->dev->devnum, fp->iface, fp->altsetting); | 2555 | chip->dev->devnum, fp->iface, fp->altsetting); |
| 2489 | return -1; | 2556 | return -1; |
| 2490 | } | 2557 | } |
| @@ -2513,6 +2580,9 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform | |||
| 2513 | chip->usb_id == USB_ID(0x0d8c, 0x0102)) && | 2580 | chip->usb_id == USB_ID(0x0d8c, 0x0102)) && |
| 2514 | fp->altsetting == 5 && fp->maxpacksize == 392) | 2581 | fp->altsetting == 5 && fp->maxpacksize == 392) |
| 2515 | rate = 96000; | 2582 | rate = 96000; |
| 2583 | /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */ | ||
| 2584 | if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068)) | ||
| 2585 | rate = 8000; | ||
| 2516 | fp->rate_table[fp->nr_rates] = rate; | 2586 | fp->rate_table[fp->nr_rates] = rate; |
| 2517 | if (!fp->rate_min || rate < fp->rate_min) | 2587 | if (!fp->rate_min || rate < fp->rate_min) |
| 2518 | fp->rate_min = rate; | 2588 | fp->rate_min = rate; |
| @@ -2535,14 +2605,87 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform | |||
| 2535 | } | 2605 | } |
| 2536 | 2606 | ||
| 2537 | /* | 2607 | /* |
| 2608 | * parse the format descriptor and stores the possible sample rates | ||
| 2609 | * on the audioformat table (audio class v2). | ||
| 2610 | */ | ||
| 2611 | static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, | ||
| 2612 | struct audioformat *fp, | ||
| 2613 | struct usb_host_interface *iface) | ||
| 2614 | { | ||
| 2615 | struct usb_device *dev = chip->dev; | ||
| 2616 | unsigned char tmp[2], *data; | ||
| 2617 | int i, nr_rates, data_size, ret = 0; | ||
| 2618 | |||
| 2619 | /* get the number of sample rates first by only fetching 2 bytes */ | ||
| 2620 | ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, | ||
| 2621 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
| 2622 | 0x0100, chip->clock_id << 8, tmp, sizeof(tmp), 1000); | ||
| 2623 | |||
| 2624 | if (ret < 0) { | ||
| 2625 | snd_printk(KERN_ERR "unable to retrieve number of sample rates\n"); | ||
| 2626 | goto err; | ||
| 2627 | } | ||
| 2628 | |||
| 2629 | nr_rates = (tmp[1] << 8) | tmp[0]; | ||
| 2630 | data_size = 2 + 12 * nr_rates; | ||
| 2631 | data = kzalloc(data_size, GFP_KERNEL); | ||
| 2632 | if (!data) { | ||
| 2633 | ret = -ENOMEM; | ||
| 2634 | goto err; | ||
| 2635 | } | ||
| 2636 | |||
| 2637 | /* now get the full information */ | ||
| 2638 | ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, | ||
| 2639 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
| 2640 | 0x0100, chip->clock_id << 8, data, data_size, 1000); | ||
| 2641 | |||
| 2642 | if (ret < 0) { | ||
| 2643 | snd_printk(KERN_ERR "unable to retrieve sample rate range\n"); | ||
| 2644 | ret = -EINVAL; | ||
| 2645 | goto err_free; | ||
| 2646 | } | ||
| 2647 | |||
| 2648 | fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); | ||
| 2649 | if (!fp->rate_table) { | ||
| 2650 | ret = -ENOMEM; | ||
| 2651 | goto err_free; | ||
| 2652 | } | ||
| 2653 | |||
| 2654 | fp->nr_rates = 0; | ||
| 2655 | fp->rate_min = fp->rate_max = 0; | ||
| 2656 | |||
| 2657 | for (i = 0; i < nr_rates; i++) { | ||
| 2658 | int rate = combine_quad(&data[2 + 12 * i]); | ||
| 2659 | |||
| 2660 | fp->rate_table[fp->nr_rates] = rate; | ||
| 2661 | if (!fp->rate_min || rate < fp->rate_min) | ||
| 2662 | fp->rate_min = rate; | ||
| 2663 | if (!fp->rate_max || rate > fp->rate_max) | ||
| 2664 | fp->rate_max = rate; | ||
| 2665 | fp->rates |= snd_pcm_rate_to_rate_bit(rate); | ||
| 2666 | fp->nr_rates++; | ||
| 2667 | } | ||
| 2668 | |||
| 2669 | err_free: | ||
| 2670 | kfree(data); | ||
| 2671 | err: | ||
| 2672 | return ret; | ||
| 2673 | } | ||
| 2674 | |||
| 2675 | /* | ||
| 2538 | * parse the format type I and III descriptors | 2676 | * parse the format type I and III descriptors |
| 2539 | */ | 2677 | */ |
| 2540 | static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat *fp, | 2678 | static int parse_audio_format_i(struct snd_usb_audio *chip, |
| 2541 | int format, unsigned char *fmt) | 2679 | struct audioformat *fp, |
| 2680 | int format, void *_fmt, | ||
| 2681 | struct usb_host_interface *iface) | ||
| 2542 | { | 2682 | { |
| 2543 | int pcm_format; | 2683 | struct usb_interface_descriptor *altsd = get_iface_desc(iface); |
| 2684 | struct uac_format_type_i_discrete_descriptor *fmt = _fmt; | ||
| 2685 | int protocol = altsd->bInterfaceProtocol; | ||
| 2686 | int pcm_format, ret; | ||
| 2544 | 2687 | ||
| 2545 | if (fmt[3] == USB_FORMAT_TYPE_III) { | 2688 | if (fmt->bFormatType == UAC_FORMAT_TYPE_III) { |
| 2546 | /* FIXME: the format type is really IECxxx | 2689 | /* FIXME: the format type is really IECxxx |
| 2547 | * but we give normal PCM format to get the existing | 2690 | * but we give normal PCM format to get the existing |
| 2548 | * apps working... | 2691 | * apps working... |
| @@ -2560,34 +2703,57 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat * | |||
| 2560 | pcm_format = SNDRV_PCM_FORMAT_S16_LE; | 2703 | pcm_format = SNDRV_PCM_FORMAT_S16_LE; |
| 2561 | } | 2704 | } |
| 2562 | } else { | 2705 | } else { |
| 2563 | pcm_format = parse_audio_format_i_type(chip, fp, format, fmt); | 2706 | pcm_format = parse_audio_format_i_type(chip, fp, format, fmt, protocol); |
| 2564 | if (pcm_format < 0) | 2707 | if (pcm_format < 0) |
| 2565 | return -1; | 2708 | return -1; |
| 2566 | } | 2709 | } |
| 2710 | |||
| 2567 | fp->format = pcm_format; | 2711 | fp->format = pcm_format; |
| 2568 | fp->channels = fmt[4]; | 2712 | |
| 2713 | /* gather possible sample rates */ | ||
| 2714 | /* audio class v1 reports possible sample rates as part of the | ||
| 2715 | * proprietary class specific descriptor. | ||
| 2716 | * audio class v2 uses class specific EP0 range requests for that. | ||
| 2717 | */ | ||
| 2718 | switch (protocol) { | ||
| 2719 | case UAC_VERSION_1: | ||
| 2720 | fp->channels = fmt->bNrChannels; | ||
| 2721 | ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7); | ||
| 2722 | break; | ||
| 2723 | case UAC_VERSION_2: | ||
| 2724 | /* fp->channels is already set in this case */ | ||
| 2725 | ret = parse_audio_format_rates_v2(chip, fp, iface); | ||
| 2726 | break; | ||
| 2727 | } | ||
| 2728 | |||
| 2569 | if (fp->channels < 1) { | 2729 | if (fp->channels < 1) { |
| 2570 | snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", | 2730 | snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", |
| 2571 | chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); | 2731 | chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); |
| 2572 | return -1; | 2732 | return -1; |
| 2573 | } | 2733 | } |
| 2574 | return parse_audio_format_rates(chip, fp, fmt, 7); | 2734 | |
| 2735 | return ret; | ||
| 2575 | } | 2736 | } |
| 2576 | 2737 | ||
| 2577 | /* | 2738 | /* |
| 2578 | * prase the format type II descriptor | 2739 | * parse the format type II descriptor |
| 2579 | */ | 2740 | */ |
| 2580 | static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat *fp, | 2741 | static int parse_audio_format_ii(struct snd_usb_audio *chip, |
| 2581 | int format, unsigned char *fmt) | 2742 | struct audioformat *fp, |
| 2743 | int format, void *_fmt, | ||
| 2744 | struct usb_host_interface *iface) | ||
| 2582 | { | 2745 | { |
| 2583 | int brate, framesize; | 2746 | int brate, framesize, ret; |
| 2747 | struct usb_interface_descriptor *altsd = get_iface_desc(iface); | ||
| 2748 | int protocol = altsd->bInterfaceProtocol; | ||
| 2749 | |||
| 2584 | switch (format) { | 2750 | switch (format) { |
| 2585 | case USB_AUDIO_FORMAT_AC3: | 2751 | case UAC_FORMAT_TYPE_II_AC3: |
| 2586 | /* FIXME: there is no AC3 format defined yet */ | 2752 | /* FIXME: there is no AC3 format defined yet */ |
| 2587 | // fp->format = SNDRV_PCM_FORMAT_AC3; | 2753 | // fp->format = SNDRV_PCM_FORMAT_AC3; |
| 2588 | fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */ | 2754 | fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */ |
| 2589 | break; | 2755 | break; |
| 2590 | case USB_AUDIO_FORMAT_MPEG: | 2756 | case UAC_FORMAT_TYPE_II_MPEG: |
| 2591 | fp->format = SNDRV_PCM_FORMAT_MPEG; | 2757 | fp->format = SNDRV_PCM_FORMAT_MPEG; |
| 2592 | break; | 2758 | break; |
| 2593 | default: | 2759 | default: |
| @@ -2596,26 +2762,46 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat | |||
| 2596 | fp->format = SNDRV_PCM_FORMAT_MPEG; | 2762 | fp->format = SNDRV_PCM_FORMAT_MPEG; |
| 2597 | break; | 2763 | break; |
| 2598 | } | 2764 | } |
| 2765 | |||
| 2599 | fp->channels = 1; | 2766 | fp->channels = 1; |
| 2600 | brate = combine_word(&fmt[4]); /* fmt[4,5] : wMaxBitRate (in kbps) */ | 2767 | |
| 2601 | framesize = combine_word(&fmt[6]); /* fmt[6,7]: wSamplesPerFrame */ | 2768 | switch (protocol) { |
| 2602 | snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); | 2769 | case UAC_VERSION_1: { |
| 2603 | fp->frame_size = framesize; | 2770 | struct uac_format_type_ii_discrete_descriptor *fmt = _fmt; |
| 2604 | return parse_audio_format_rates(chip, fp, fmt, 8); /* fmt[8..] sample rates */ | 2771 | brate = le16_to_cpu(fmt->wMaxBitRate); |
| 2772 | framesize = le16_to_cpu(fmt->wSamplesPerFrame); | ||
| 2773 | snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); | ||
| 2774 | fp->frame_size = framesize; | ||
| 2775 | ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */ | ||
| 2776 | break; | ||
| 2777 | } | ||
| 2778 | case UAC_VERSION_2: { | ||
| 2779 | struct uac_format_type_ii_ext_descriptor *fmt = _fmt; | ||
| 2780 | brate = le16_to_cpu(fmt->wMaxBitRate); | ||
| 2781 | framesize = le16_to_cpu(fmt->wSamplesPerFrame); | ||
| 2782 | snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); | ||
| 2783 | fp->frame_size = framesize; | ||
| 2784 | ret = parse_audio_format_rates_v2(chip, fp, iface); | ||
| 2785 | break; | ||
| 2786 | } | ||
| 2787 | } | ||
| 2788 | |||
| 2789 | return ret; | ||
| 2605 | } | 2790 | } |
| 2606 | 2791 | ||
| 2607 | static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, | 2792 | static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, |
| 2608 | int format, unsigned char *fmt, int stream) | 2793 | int format, unsigned char *fmt, int stream, |
| 2794 | struct usb_host_interface *iface) | ||
| 2609 | { | 2795 | { |
| 2610 | int err; | 2796 | int err; |
| 2611 | 2797 | ||
| 2612 | switch (fmt[3]) { | 2798 | switch (fmt[3]) { |
| 2613 | case USB_FORMAT_TYPE_I: | 2799 | case UAC_FORMAT_TYPE_I: |
| 2614 | case USB_FORMAT_TYPE_III: | 2800 | case UAC_FORMAT_TYPE_III: |
| 2615 | err = parse_audio_format_i(chip, fp, format, fmt); | 2801 | err = parse_audio_format_i(chip, fp, format, fmt, iface); |
| 2616 | break; | 2802 | break; |
| 2617 | case USB_FORMAT_TYPE_II: | 2803 | case UAC_FORMAT_TYPE_II: |
| 2618 | err = parse_audio_format_ii(chip, fp, format, fmt); | 2804 | err = parse_audio_format_ii(chip, fp, format, fmt, iface); |
| 2619 | break; | 2805 | break; |
| 2620 | default: | 2806 | default: |
| 2621 | snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", | 2807 | snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", |
| @@ -2633,7 +2819,7 @@ static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp | |||
| 2633 | if (chip->usb_id == USB_ID(0x041e, 0x3000) || | 2819 | if (chip->usb_id == USB_ID(0x041e, 0x3000) || |
| 2634 | chip->usb_id == USB_ID(0x041e, 0x3020) || | 2820 | chip->usb_id == USB_ID(0x041e, 0x3020) || |
| 2635 | chip->usb_id == USB_ID(0x041e, 0x3061)) { | 2821 | chip->usb_id == USB_ID(0x041e, 0x3061)) { |
| 2636 | if (fmt[3] == USB_FORMAT_TYPE_I && | 2822 | if (fmt[3] == UAC_FORMAT_TYPE_I && |
| 2637 | fp->rates != SNDRV_PCM_RATE_48000 && | 2823 | fp->rates != SNDRV_PCM_RATE_48000 && |
| 2638 | fp->rates != SNDRV_PCM_RATE_96000) | 2824 | fp->rates != SNDRV_PCM_RATE_96000) |
| 2639 | return -1; | 2825 | return -1; |
| @@ -2662,10 +2848,10 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2662 | struct usb_host_interface *alts; | 2848 | struct usb_host_interface *alts; |
| 2663 | struct usb_interface_descriptor *altsd; | 2849 | struct usb_interface_descriptor *altsd; |
| 2664 | int i, altno, err, stream; | 2850 | int i, altno, err, stream; |
| 2665 | int format; | 2851 | int format = 0, num_channels = 0; |
| 2666 | struct audioformat *fp = NULL; | 2852 | struct audioformat *fp = NULL; |
| 2667 | unsigned char *fmt, *csep; | 2853 | unsigned char *fmt, *csep; |
| 2668 | int num; | 2854 | int num, protocol; |
| 2669 | 2855 | ||
| 2670 | dev = chip->dev; | 2856 | dev = chip->dev; |
| 2671 | 2857 | ||
| @@ -2684,10 +2870,11 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2684 | for (i = 0; i < num; i++) { | 2870 | for (i = 0; i < num; i++) { |
| 2685 | alts = &iface->altsetting[i]; | 2871 | alts = &iface->altsetting[i]; |
| 2686 | altsd = get_iface_desc(alts); | 2872 | altsd = get_iface_desc(alts); |
| 2873 | protocol = altsd->bInterfaceProtocol; | ||
| 2687 | /* skip invalid one */ | 2874 | /* skip invalid one */ |
| 2688 | if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && | 2875 | if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && |
| 2689 | altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || | 2876 | altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || |
| 2690 | (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING && | 2877 | (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING && |
| 2691 | altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) || | 2878 | altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) || |
| 2692 | altsd->bNumEndpoints < 1 || | 2879 | altsd->bNumEndpoints < 1 || |
| 2693 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0) | 2880 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0) |
| @@ -2708,30 +2895,65 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2708 | continue; | 2895 | continue; |
| 2709 | 2896 | ||
| 2710 | /* get audio formats */ | 2897 | /* get audio formats */ |
| 2711 | fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, AS_GENERAL); | 2898 | switch (protocol) { |
| 2712 | if (!fmt) { | 2899 | case UAC_VERSION_1: { |
| 2713 | snd_printk(KERN_ERR "%d:%u:%d : AS_GENERAL descriptor not found\n", | 2900 | struct uac_as_header_descriptor_v1 *as = |
| 2714 | dev->devnum, iface_no, altno); | 2901 | snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); |
| 2715 | continue; | 2902 | |
| 2903 | if (!as) { | ||
| 2904 | snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", | ||
| 2905 | dev->devnum, iface_no, altno); | ||
| 2906 | continue; | ||
| 2907 | } | ||
| 2908 | |||
| 2909 | if (as->bLength < sizeof(*as)) { | ||
| 2910 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", | ||
| 2911 | dev->devnum, iface_no, altno); | ||
| 2912 | continue; | ||
| 2913 | } | ||
| 2914 | |||
| 2915 | format = le16_to_cpu(as->wFormatTag); /* remember the format value */ | ||
| 2916 | break; | ||
| 2716 | } | 2917 | } |
| 2717 | 2918 | ||
| 2718 | if (fmt[0] < 7) { | 2919 | case UAC_VERSION_2: { |
| 2719 | snd_printk(KERN_ERR "%d:%u:%d : invalid AS_GENERAL desc\n", | 2920 | struct uac_as_header_descriptor_v2 *as = |
| 2720 | dev->devnum, iface_no, altno); | 2921 | snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); |
| 2721 | continue; | 2922 | |
| 2923 | if (!as) { | ||
| 2924 | snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", | ||
| 2925 | dev->devnum, iface_no, altno); | ||
| 2926 | continue; | ||
| 2927 | } | ||
| 2928 | |||
| 2929 | if (as->bLength < sizeof(*as)) { | ||
| 2930 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", | ||
| 2931 | dev->devnum, iface_no, altno); | ||
| 2932 | continue; | ||
| 2933 | } | ||
| 2934 | |||
| 2935 | num_channels = as->bNrChannels; | ||
| 2936 | format = le32_to_cpu(as->bmFormats); | ||
| 2937 | |||
| 2938 | break; | ||
| 2722 | } | 2939 | } |
| 2723 | 2940 | ||
| 2724 | format = (fmt[6] << 8) | fmt[5]; /* remember the format value */ | 2941 | default: |
| 2942 | snd_printk(KERN_ERR "%d:%u:%d : unknown interface protocol %04x\n", | ||
| 2943 | dev->devnum, iface_no, altno, protocol); | ||
| 2944 | continue; | ||
| 2945 | } | ||
| 2725 | 2946 | ||
| 2726 | /* get format type */ | 2947 | /* get format type */ |
| 2727 | fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, FORMAT_TYPE); | 2948 | fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); |
| 2728 | if (!fmt) { | 2949 | if (!fmt) { |
| 2729 | snd_printk(KERN_ERR "%d:%u:%d : no FORMAT_TYPE desc\n", | 2950 | snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n", |
| 2730 | dev->devnum, iface_no, altno); | 2951 | dev->devnum, iface_no, altno); |
| 2731 | continue; | 2952 | continue; |
| 2732 | } | 2953 | } |
| 2733 | if (fmt[0] < 8) { | 2954 | if (((protocol == UAC_VERSION_1) && (fmt[0] < 8)) || |
| 2734 | snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n", | 2955 | ((protocol == UAC_VERSION_2) && (fmt[0] != 6))) { |
| 2956 | snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", | ||
| 2735 | dev->devnum, iface_no, altno); | 2957 | dev->devnum, iface_no, altno); |
| 2736 | continue; | 2958 | continue; |
| 2737 | } | 2959 | } |
| @@ -2744,6 +2966,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2744 | if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 && | 2966 | if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 && |
| 2745 | fp && fp->altsetting == 1 && fp->channels == 1 && | 2967 | fp && fp->altsetting == 1 && fp->channels == 1 && |
| 2746 | fp->format == SNDRV_PCM_FORMAT_S16_LE && | 2968 | fp->format == SNDRV_PCM_FORMAT_S16_LE && |
| 2969 | protocol == UAC_VERSION_1 && | ||
| 2747 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == | 2970 | le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == |
| 2748 | fp->maxpacksize * 2) | 2971 | fp->maxpacksize * 2) |
| 2749 | continue; | 2972 | continue; |
| @@ -2752,7 +2975,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2752 | /* Creamware Noah has this descriptor after the 2nd endpoint */ | 2975 | /* Creamware Noah has this descriptor after the 2nd endpoint */ |
| 2753 | if (!csep && altsd->bNumEndpoints >= 2) | 2976 | if (!csep && altsd->bNumEndpoints >= 2) |
| 2754 | csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); | 2977 | csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); |
| 2755 | if (!csep || csep[0] < 7 || csep[2] != EP_GENERAL) { | 2978 | if (!csep || csep[0] < 7 || csep[2] != UAC_EP_GENERAL) { |
| 2756 | snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" | 2979 | snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" |
| 2757 | " class specific endpoint descriptor\n", | 2980 | " class specific endpoint descriptor\n", |
| 2758 | dev->devnum, iface_no, altno); | 2981 | dev->devnum, iface_no, altno); |
| @@ -2772,6 +2995,8 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2772 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | 2995 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; |
| 2773 | fp->datainterval = parse_datainterval(chip, alts); | 2996 | fp->datainterval = parse_datainterval(chip, alts); |
| 2774 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | 2997 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); |
| 2998 | /* num_channels is only set for v2 interfaces */ | ||
| 2999 | fp->channels = num_channels; | ||
| 2775 | if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) | 3000 | if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) |
| 2776 | fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) | 3001 | fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) |
| 2777 | * (fp->maxpacksize & 0x7ff); | 3002 | * (fp->maxpacksize & 0x7ff); |
| @@ -2784,12 +3009,12 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2784 | /* Optoplay sets the sample rate attribute although | 3009 | /* Optoplay sets the sample rate attribute although |
| 2785 | * it seems not supporting it in fact. | 3010 | * it seems not supporting it in fact. |
| 2786 | */ | 3011 | */ |
| 2787 | fp->attributes &= ~EP_CS_ATTR_SAMPLE_RATE; | 3012 | fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE; |
| 2788 | break; | 3013 | break; |
| 2789 | case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ | 3014 | case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ |
| 2790 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ | 3015 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ |
| 2791 | /* doesn't set the sample rate attribute, but supports it */ | 3016 | /* doesn't set the sample rate attribute, but supports it */ |
| 2792 | fp->attributes |= EP_CS_ATTR_SAMPLE_RATE; | 3017 | fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; |
| 2793 | break; | 3018 | break; |
| 2794 | case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ | 3019 | case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ |
| 2795 | case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is | 3020 | case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is |
| @@ -2798,16 +3023,16 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) | |||
| 2798 | * plantronics headset and Griffin iMic have set adaptive-in | 3023 | * plantronics headset and Griffin iMic have set adaptive-in |
| 2799 | * although it's really not... | 3024 | * although it's really not... |
| 2800 | */ | 3025 | */ |
| 2801 | fp->ep_attr &= ~EP_ATTR_MASK; | 3026 | fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE; |
| 2802 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | 3027 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 2803 | fp->ep_attr |= EP_ATTR_ADAPTIVE; | 3028 | fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE; |
| 2804 | else | 3029 | else |
| 2805 | fp->ep_attr |= EP_ATTR_SYNC; | 3030 | fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC; |
| 2806 | break; | 3031 | break; |
| 2807 | } | 3032 | } |
| 2808 | 3033 | ||
| 2809 | /* ok, let's parse further... */ | 3034 | /* ok, let's parse further... */ |
| 2810 | if (parse_audio_format(chip, fp, format, fmt, stream) < 0) { | 3035 | if (parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) { |
| 2811 | kfree(fp->rate_table); | 3036 | kfree(fp->rate_table); |
| 2812 | kfree(fp); | 3037 | kfree(fp); |
| 2813 | continue; | 3038 | continue; |
| @@ -2849,6 +3074,65 @@ static void snd_usb_stream_disconnect(struct list_head *head) | |||
| 2849 | } | 3074 | } |
| 2850 | } | 3075 | } |
| 2851 | 3076 | ||
| 3077 | static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface) | ||
| 3078 | { | ||
| 3079 | struct usb_device *dev = chip->dev; | ||
| 3080 | struct usb_host_interface *alts; | ||
| 3081 | struct usb_interface_descriptor *altsd; | ||
| 3082 | struct usb_interface *iface = usb_ifnum_to_if(dev, interface); | ||
| 3083 | |||
| 3084 | if (!iface) { | ||
| 3085 | snd_printk(KERN_ERR "%d:%u:%d : does not exist\n", | ||
| 3086 | dev->devnum, ctrlif, interface); | ||
| 3087 | return -EINVAL; | ||
| 3088 | } | ||
| 3089 | |||
| 3090 | if (usb_interface_claimed(iface)) { | ||
| 3091 | snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n", | ||
| 3092 | dev->devnum, ctrlif, interface); | ||
| 3093 | return -EINVAL; | ||
| 3094 | } | ||
| 3095 | |||
| 3096 | alts = &iface->altsetting[0]; | ||
| 3097 | altsd = get_iface_desc(alts); | ||
| 3098 | if ((altsd->bInterfaceClass == USB_CLASS_AUDIO || | ||
| 3099 | altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && | ||
| 3100 | altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) { | ||
| 3101 | int err = snd_usbmidi_create(chip->card, iface, | ||
| 3102 | &chip->midi_list, NULL); | ||
| 3103 | if (err < 0) { | ||
| 3104 | snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", | ||
| 3105 | dev->devnum, ctrlif, interface); | ||
| 3106 | return -EINVAL; | ||
| 3107 | } | ||
| 3108 | usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | ||
| 3109 | |||
| 3110 | return 0; | ||
| 3111 | } | ||
| 3112 | |||
| 3113 | if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && | ||
| 3114 | altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || | ||
| 3115 | altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) { | ||
| 3116 | snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n", | ||
| 3117 | dev->devnum, ctrlif, interface, altsd->bInterfaceClass); | ||
| 3118 | /* skip non-supported classes */ | ||
| 3119 | return -EINVAL; | ||
| 3120 | } | ||
| 3121 | |||
| 3122 | if (snd_usb_get_speed(dev) == USB_SPEED_LOW) { | ||
| 3123 | snd_printk(KERN_ERR "low speed audio streaming not supported\n"); | ||
| 3124 | return -EINVAL; | ||
| 3125 | } | ||
| 3126 | |||
| 3127 | if (! parse_audio_endpoints(chip, interface)) { | ||
| 3128 | usb_set_interface(dev, interface, 0); /* reset the current interface */ | ||
| 3129 | usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | ||
| 3130 | return -EINVAL; | ||
| 3131 | } | ||
| 3132 | |||
| 3133 | return 0; | ||
| 3134 | } | ||
| 3135 | |||
| 2852 | /* | 3136 | /* |
| 2853 | * parse audio control descriptor and create pcm/midi streams | 3137 | * parse audio control descriptor and create pcm/midi streams |
| 2854 | */ | 3138 | */ |
| @@ -2856,67 +3140,81 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif) | |||
| 2856 | { | 3140 | { |
| 2857 | struct usb_device *dev = chip->dev; | 3141 | struct usb_device *dev = chip->dev; |
| 2858 | struct usb_host_interface *host_iface; | 3142 | struct usb_host_interface *host_iface; |
| 2859 | struct usb_interface *iface; | 3143 | struct usb_interface_descriptor *altsd; |
| 2860 | unsigned char *p1; | 3144 | void *control_header; |
| 2861 | int i, j; | 3145 | int i, protocol; |
| 2862 | 3146 | ||
| 2863 | /* find audiocontrol interface */ | 3147 | /* find audiocontrol interface */ |
| 2864 | host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0]; | 3148 | host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0]; |
| 2865 | if (!(p1 = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen, NULL, HEADER))) { | 3149 | control_header = snd_usb_find_csint_desc(host_iface->extra, |
| 2866 | snd_printk(KERN_ERR "cannot find HEADER\n"); | 3150 | host_iface->extralen, |
| 2867 | return -EINVAL; | 3151 | NULL, UAC_HEADER); |
| 2868 | } | 3152 | altsd = get_iface_desc(host_iface); |
| 2869 | if (! p1[7] || p1[0] < 8 + p1[7]) { | 3153 | protocol = altsd->bInterfaceProtocol; |
| 2870 | snd_printk(KERN_ERR "invalid HEADER\n"); | 3154 | |
| 3155 | if (!control_header) { | ||
| 3156 | snd_printk(KERN_ERR "cannot find UAC_HEADER\n"); | ||
| 2871 | return -EINVAL; | 3157 | return -EINVAL; |
| 2872 | } | 3158 | } |
| 2873 | 3159 | ||
| 2874 | /* | 3160 | switch (protocol) { |
| 2875 | * parse all USB audio streaming interfaces | 3161 | case UAC_VERSION_1: { |
| 2876 | */ | 3162 | struct uac_ac_header_descriptor_v1 *h1 = control_header; |
| 2877 | for (i = 0; i < p1[7]; i++) { | 3163 | |
| 2878 | struct usb_host_interface *alts; | 3164 | if (!h1->bInCollection) { |
| 2879 | struct usb_interface_descriptor *altsd; | 3165 | snd_printk(KERN_INFO "skipping empty audio interface (v1)\n"); |
| 2880 | j = p1[8 + i]; | 3166 | return -EINVAL; |
| 2881 | iface = usb_ifnum_to_if(dev, j); | ||
| 2882 | if (!iface) { | ||
| 2883 | snd_printk(KERN_ERR "%d:%u:%d : does not exist\n", | ||
| 2884 | dev->devnum, ctrlif, j); | ||
| 2885 | continue; | ||
| 2886 | } | ||
| 2887 | if (usb_interface_claimed(iface)) { | ||
| 2888 | snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n", dev->devnum, ctrlif, j); | ||
| 2889 | continue; | ||
| 2890 | } | 3167 | } |
| 2891 | alts = &iface->altsetting[0]; | 3168 | |
| 2892 | altsd = get_iface_desc(alts); | 3169 | if (h1->bLength < sizeof(*h1) + h1->bInCollection) { |
| 2893 | if ((altsd->bInterfaceClass == USB_CLASS_AUDIO || | 3170 | snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n"); |
| 2894 | altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && | 3171 | return -EINVAL; |
| 2895 | altsd->bInterfaceSubClass == USB_SUBCLASS_MIDI_STREAMING) { | ||
| 2896 | int err = snd_usbmidi_create(chip->card, iface, | ||
| 2897 | &chip->midi_list, NULL); | ||
| 2898 | if (err < 0) { | ||
| 2899 | snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", dev->devnum, ctrlif, j); | ||
| 2900 | continue; | ||
| 2901 | } | ||
| 2902 | usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | ||
| 2903 | continue; | ||
| 2904 | } | 3172 | } |
| 2905 | if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && | 3173 | |
| 2906 | altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || | 3174 | for (i = 0; i < h1->bInCollection; i++) |
| 2907 | altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING) { | 3175 | snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]); |
| 2908 | snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n", dev->devnum, ctrlif, j, altsd->bInterfaceClass); | 3176 | |
| 2909 | /* skip non-supported classes */ | 3177 | break; |
| 2910 | continue; | 3178 | } |
| 3179 | |||
| 3180 | case UAC_VERSION_2: { | ||
| 3181 | struct uac_clock_source_descriptor *cs; | ||
| 3182 | struct usb_interface_assoc_descriptor *assoc = | ||
| 3183 | usb_ifnum_to_if(dev, ctrlif)->intf_assoc; | ||
| 3184 | |||
| 3185 | if (!assoc) { | ||
| 3186 | snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n"); | ||
| 3187 | return -EINVAL; | ||
| 2911 | } | 3188 | } |
| 2912 | if (snd_usb_get_speed(dev) == USB_SPEED_LOW) { | 3189 | |
| 2913 | snd_printk(KERN_ERR "low speed audio streaming not supported\n"); | 3190 | /* FIXME: for now, we expect there is at least one clock source |
| 2914 | continue; | 3191 | * descriptor and we always take the first one. |
| 3192 | * We should properly support devices with multiple clock sources, | ||
| 3193 | * clock selectors and sample rate conversion units. */ | ||
| 3194 | |||
| 3195 | cs = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen, | ||
| 3196 | NULL, UAC_CLOCK_SOURCE); | ||
| 3197 | |||
| 3198 | if (!cs) { | ||
| 3199 | snd_printk(KERN_ERR "CLOCK_SOURCE descriptor not found\n"); | ||
| 3200 | return -EINVAL; | ||
| 2915 | } | 3201 | } |
| 2916 | if (! parse_audio_endpoints(chip, j)) { | 3202 | |
| 2917 | usb_set_interface(dev, j, 0); /* reset the current interface */ | 3203 | chip->clock_id = cs->bClockID; |
| 2918 | usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | 3204 | |
| 3205 | for (i = 0; i < assoc->bInterfaceCount; i++) { | ||
| 3206 | int intf = assoc->bFirstInterface + i; | ||
| 3207 | |||
| 3208 | if (intf != ctrlif) | ||
| 3209 | snd_usb_create_stream(chip, ctrlif, intf); | ||
| 2919 | } | 3210 | } |
| 3211 | |||
| 3212 | break; | ||
| 3213 | } | ||
| 3214 | |||
| 3215 | default: | ||
| 3216 | snd_printk(KERN_ERR "unknown protocol version 0x%02x\n", protocol); | ||
| 3217 | return -EINVAL; | ||
| 2920 | } | 3218 | } |
| 2921 | 3219 | ||
| 2922 | return 0; | 3220 | return 0; |
| @@ -3007,7 +3305,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip, | |||
| 3007 | static const struct audioformat ua_format = { | 3305 | static const struct audioformat ua_format = { |
| 3008 | .format = SNDRV_PCM_FORMAT_S24_3LE, | 3306 | .format = SNDRV_PCM_FORMAT_S24_3LE, |
| 3009 | .channels = 2, | 3307 | .channels = 2, |
| 3010 | .fmt_type = USB_FORMAT_TYPE_I, | 3308 | .fmt_type = UAC_FORMAT_TYPE_I, |
| 3011 | .altsetting = 1, | 3309 | .altsetting = 1, |
| 3012 | .altset_idx = 1, | 3310 | .altset_idx = 1, |
| 3013 | .rates = SNDRV_PCM_RATE_CONTINUOUS, | 3311 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| @@ -3090,111 +3388,6 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip, | |||
| 3090 | return 0; | 3388 | return 0; |
| 3091 | } | 3389 | } |
| 3092 | 3390 | ||
| 3093 | /* | ||
| 3094 | * Create a stream for an Edirol UA-1000 interface. | ||
| 3095 | */ | ||
| 3096 | static int create_ua1000_quirk(struct snd_usb_audio *chip, | ||
| 3097 | struct usb_interface *iface, | ||
| 3098 | const struct snd_usb_audio_quirk *quirk) | ||
| 3099 | { | ||
| 3100 | static const struct audioformat ua1000_format = { | ||
| 3101 | .format = SNDRV_PCM_FORMAT_S32_LE, | ||
| 3102 | .fmt_type = USB_FORMAT_TYPE_I, | ||
| 3103 | .altsetting = 1, | ||
| 3104 | .altset_idx = 1, | ||
| 3105 | .attributes = 0, | ||
| 3106 | .rates = SNDRV_PCM_RATE_CONTINUOUS, | ||
| 3107 | }; | ||
| 3108 | struct usb_host_interface *alts; | ||
| 3109 | struct usb_interface_descriptor *altsd; | ||
| 3110 | struct audioformat *fp; | ||
| 3111 | int stream, err; | ||
| 3112 | |||
| 3113 | if (iface->num_altsetting != 2) | ||
| 3114 | return -ENXIO; | ||
| 3115 | alts = &iface->altsetting[1]; | ||
| 3116 | altsd = get_iface_desc(alts); | ||
| 3117 | if (alts->extralen != 11 || alts->extra[1] != USB_DT_CS_INTERFACE || | ||
| 3118 | altsd->bNumEndpoints != 1) | ||
| 3119 | return -ENXIO; | ||
| 3120 | |||
| 3121 | fp = kmemdup(&ua1000_format, sizeof(*fp), GFP_KERNEL); | ||
| 3122 | if (!fp) | ||
| 3123 | return -ENOMEM; | ||
| 3124 | |||
| 3125 | fp->channels = alts->extra[4]; | ||
| 3126 | fp->iface = altsd->bInterfaceNumber; | ||
| 3127 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | ||
| 3128 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | ||
| 3129 | fp->datainterval = parse_datainterval(chip, alts); | ||
| 3130 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | ||
| 3131 | fp->rate_max = fp->rate_min = combine_triple(&alts->extra[8]); | ||
| 3132 | |||
| 3133 | stream = (fp->endpoint & USB_DIR_IN) | ||
| 3134 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | ||
| 3135 | err = add_audio_endpoint(chip, stream, fp); | ||
| 3136 | if (err < 0) { | ||
| 3137 | kfree(fp); | ||
| 3138 | return err; | ||
| 3139 | } | ||
| 3140 | /* FIXME: playback must be synchronized to capture */ | ||
| 3141 | usb_set_interface(chip->dev, fp->iface, 0); | ||
| 3142 | return 0; | ||
| 3143 | } | ||
| 3144 | |||
| 3145 | /* | ||
| 3146 | * Create a stream for an Edirol UA-101 interface. | ||
| 3147 | * Copy, paste and modify from Edirol UA-1000 | ||
| 3148 | */ | ||
| 3149 | static int create_ua101_quirk(struct snd_usb_audio *chip, | ||
| 3150 | struct usb_interface *iface, | ||
| 3151 | const struct snd_usb_audio_quirk *quirk) | ||
| 3152 | { | ||
| 3153 | static const struct audioformat ua101_format = { | ||
| 3154 | .format = SNDRV_PCM_FORMAT_S32_LE, | ||
| 3155 | .fmt_type = USB_FORMAT_TYPE_I, | ||
| 3156 | .altsetting = 1, | ||
| 3157 | .altset_idx = 1, | ||
| 3158 | .attributes = 0, | ||
| 3159 | .rates = SNDRV_PCM_RATE_CONTINUOUS, | ||
| 3160 | }; | ||
| 3161 | struct usb_host_interface *alts; | ||
| 3162 | struct usb_interface_descriptor *altsd; | ||
| 3163 | struct audioformat *fp; | ||
| 3164 | int stream, err; | ||
| 3165 | |||
| 3166 | if (iface->num_altsetting != 2) | ||
| 3167 | return -ENXIO; | ||
| 3168 | alts = &iface->altsetting[1]; | ||
| 3169 | altsd = get_iface_desc(alts); | ||
| 3170 | if (alts->extralen != 18 || alts->extra[1] != USB_DT_CS_INTERFACE || | ||
| 3171 | altsd->bNumEndpoints != 1) | ||
| 3172 | return -ENXIO; | ||
| 3173 | |||
| 3174 | fp = kmemdup(&ua101_format, sizeof(*fp), GFP_KERNEL); | ||
| 3175 | if (!fp) | ||
| 3176 | return -ENOMEM; | ||
| 3177 | |||
| 3178 | fp->channels = alts->extra[11]; | ||
| 3179 | fp->iface = altsd->bInterfaceNumber; | ||
| 3180 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | ||
| 3181 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | ||
| 3182 | fp->datainterval = parse_datainterval(chip, alts); | ||
| 3183 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | ||
| 3184 | fp->rate_max = fp->rate_min = combine_triple(&alts->extra[15]); | ||
| 3185 | |||
| 3186 | stream = (fp->endpoint & USB_DIR_IN) | ||
| 3187 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | ||
| 3188 | err = add_audio_endpoint(chip, stream, fp); | ||
| 3189 | if (err < 0) { | ||
| 3190 | kfree(fp); | ||
| 3191 | return err; | ||
| 3192 | } | ||
| 3193 | /* FIXME: playback must be synchronized to capture */ | ||
| 3194 | usb_set_interface(chip->dev, fp->iface, 0); | ||
| 3195 | return 0; | ||
| 3196 | } | ||
| 3197 | |||
| 3198 | static int snd_usb_create_quirk(struct snd_usb_audio *chip, | 3391 | static int snd_usb_create_quirk(struct snd_usb_audio *chip, |
| 3199 | struct usb_interface *iface, | 3392 | struct usb_interface *iface, |
| 3200 | const struct snd_usb_audio_quirk *quirk); | 3393 | const struct snd_usb_audio_quirk *quirk); |
| @@ -3232,6 +3425,18 @@ static int ignore_interface_quirk(struct snd_usb_audio *chip, | |||
| 3232 | return 0; | 3425 | return 0; |
| 3233 | } | 3426 | } |
| 3234 | 3427 | ||
| 3428 | /* | ||
| 3429 | * Allow alignment on audio sub-slot (channel samples) rather than | ||
| 3430 | * on audio slots (audio frames) | ||
| 3431 | */ | ||
| 3432 | static int create_align_transfer_quirk(struct snd_usb_audio *chip, | ||
| 3433 | struct usb_interface *iface, | ||
| 3434 | const struct snd_usb_audio_quirk *quirk) | ||
| 3435 | { | ||
| 3436 | chip->txfr_quirk = 1; | ||
| 3437 | return 1; /* Continue with creating streams and mixer */ | ||
| 3438 | } | ||
| 3439 | |||
| 3235 | 3440 | ||
| 3236 | /* | 3441 | /* |
| 3237 | * boot quirks | 3442 | * boot quirks |
| @@ -3327,6 +3532,32 @@ static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) | |||
| 3327 | } | 3532 | } |
| 3328 | 3533 | ||
| 3329 | /* | 3534 | /* |
| 3535 | * This call will put the synth in "USB send" mode, i.e it will send MIDI | ||
| 3536 | * messages through USB (this is disabled at startup). The synth will | ||
| 3537 | * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB | ||
| 3538 | * sign on its LCD. Values here are chosen based on sniffing USB traffic | ||
| 3539 | * under Windows. | ||
| 3540 | */ | ||
| 3541 | static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev) | ||
| 3542 | { | ||
| 3543 | int err, actual_length; | ||
| 3544 | |||
| 3545 | /* "midi send" enable */ | ||
| 3546 | static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 }; | ||
| 3547 | |||
| 3548 | void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL); | ||
| 3549 | if (!buf) | ||
| 3550 | return -ENOMEM; | ||
| 3551 | err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf, | ||
| 3552 | ARRAY_SIZE(seq), &actual_length, 1000); | ||
| 3553 | kfree(buf); | ||
| 3554 | if (err < 0) | ||
| 3555 | return err; | ||
| 3556 | |||
| 3557 | return 0; | ||
| 3558 | } | ||
| 3559 | |||
| 3560 | /* | ||
| 3330 | * Setup quirks | 3561 | * Setup quirks |
| 3331 | */ | 3562 | */ |
| 3332 | #define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */ | 3563 | #define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */ |
| @@ -3405,9 +3636,8 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip, | |||
| 3405 | [QUIRK_MIDI_CME] = create_any_midi_quirk, | 3636 | [QUIRK_MIDI_CME] = create_any_midi_quirk, |
| 3406 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, | 3637 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, |
| 3407 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, | 3638 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, |
| 3408 | [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, | 3639 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, |
| 3409 | [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk, | 3640 | [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk |
| 3410 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk | ||
| 3411 | }; | 3641 | }; |
| 3412 | 3642 | ||
| 3413 | if (quirk->type < QUIRK_TYPE_COUNT) { | 3643 | if (quirk->type < QUIRK_TYPE_COUNT) { |
| @@ -3596,7 +3826,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev, | |||
| 3596 | ifnum = get_iface_desc(alts)->bInterfaceNumber; | 3826 | ifnum = get_iface_desc(alts)->bInterfaceNumber; |
| 3597 | id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), | 3827 | id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), |
| 3598 | le16_to_cpu(dev->descriptor.idProduct)); | 3828 | le16_to_cpu(dev->descriptor.idProduct)); |
| 3599 | |||
| 3600 | if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) | 3829 | if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) |
| 3601 | goto __err_val; | 3830 | goto __err_val; |
| 3602 | 3831 | ||
| @@ -3624,6 +3853,12 @@ static void *snd_usb_audio_probe(struct usb_device *dev, | |||
| 3624 | goto __err_val; | 3853 | goto __err_val; |
| 3625 | } | 3854 | } |
| 3626 | 3855 | ||
| 3856 | /* Access Music VirusTI Desktop */ | ||
| 3857 | if (id == USB_ID(0x133e, 0x0815)) { | ||
| 3858 | if (snd_usb_accessmusic_boot_quirk(dev) < 0) | ||
| 3859 | goto __err_val; | ||
| 3860 | } | ||
| 3861 | |||
| 3627 | /* | 3862 | /* |
| 3628 | * found a config. now register to ALSA | 3863 | * found a config. now register to ALSA |
| 3629 | */ | 3864 | */ |
| @@ -3661,6 +3896,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev, | |||
| 3661 | } | 3896 | } |
| 3662 | } | 3897 | } |
| 3663 | 3898 | ||
| 3899 | chip->txfr_quirk = 0; | ||
| 3664 | err = 1; /* continue */ | 3900 | err = 1; /* continue */ |
| 3665 | if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { | 3901 | if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { |
| 3666 | /* need some special handlings */ | 3902 | /* need some special handlings */ |
