aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/usbaudio.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/usbaudio.c')
-rw-r--r--sound/usb/usbaudio.c841
1 files changed, 564 insertions, 277 deletions
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index 9edef4684978..c539f7fe292f 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 */
739static 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 */
747static 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 */
763static 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 */
942static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) 919static 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 */
1290static 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 */
1312static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) 1330static 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
1979static struct snd_pcm_ops snd_usb_capture_ops = { 2006static 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,68 @@ 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 */
2397static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audioformat *fp, 2426static 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 printk(" XXXXX SAMPLE BYTES %d\n", sample_bytes);
2487 switch (sample_bytes) {
2420 case 1: 2488 case 1:
2421 pcm_format = SNDRV_PCM_FORMAT_S8; 2489 pcm_format = SNDRV_PCM_FORMAT_S8;
2422 break; 2490 break;
@@ -2437,12 +2505,12 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2437 break; 2505 break;
2438 default: 2506 default:
2439 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", 2507 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n",
2440 chip->dev->devnum, fp->iface, 2508 chip->dev->devnum, fp->iface, fp->altsetting,
2441 fp->altsetting, sample_width, sample_bytes); 2509 sample_width, sample_bytes);
2442 break; 2510 break;
2443 } 2511 }
2444 break; 2512 break;
2445 case USB_AUDIO_FORMAT_PCM8: 2513 case UAC_FORMAT_TYPE_I_PCM8:
2446 pcm_format = SNDRV_PCM_FORMAT_U8; 2514 pcm_format = SNDRV_PCM_FORMAT_U8;
2447 2515
2448 /* Dallas DS4201 workaround: it advertises U8 format, but really 2516 /* Dallas DS4201 workaround: it advertises U8 format, but really
@@ -2450,13 +2518,13 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2450 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 2518 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2451 pcm_format = SNDRV_PCM_FORMAT_S8; 2519 pcm_format = SNDRV_PCM_FORMAT_S8;
2452 break; 2520 break;
2453 case USB_AUDIO_FORMAT_IEEE_FLOAT: 2521 case UAC_FORMAT_TYPE_I_IEEE_FLOAT:
2454 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; 2522 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE;
2455 break; 2523 break;
2456 case USB_AUDIO_FORMAT_ALAW: 2524 case UAC_FORMAT_TYPE_I_ALAW:
2457 pcm_format = SNDRV_PCM_FORMAT_A_LAW; 2525 pcm_format = SNDRV_PCM_FORMAT_A_LAW;
2458 break; 2526 break;
2459 case USB_AUDIO_FORMAT_MU_LAW: 2527 case UAC_FORMAT_TYPE_I_MULAW:
2460 pcm_format = SNDRV_PCM_FORMAT_MU_LAW; 2528 pcm_format = SNDRV_PCM_FORMAT_MU_LAW;
2461 break; 2529 break;
2462 default: 2530 default:
@@ -2470,7 +2538,7 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2470 2538
2471/* 2539/*
2472 * parse the format descriptor and stores the possible sample rates 2540 * parse the format descriptor and stores the possible sample rates
2473 * on the audioformat table. 2541 * on the audioformat table (audio class v1).
2474 * 2542 *
2475 * @dev: usb device 2543 * @dev: usb device
2476 * @fp: audioformat record 2544 * @fp: audioformat record
@@ -2478,13 +2546,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 2546 * @offset: the start offset of descriptor pointing the rate type
2479 * (7 for type I and II, 8 for type II) 2547 * (7 for type I and II, 8 for type II)
2480 */ 2548 */
2481static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioformat *fp, 2549static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
2482 unsigned char *fmt, int offset) 2550 unsigned char *fmt, int offset)
2483{ 2551{
2484 int nr_rates = fmt[offset]; 2552 int nr_rates = fmt[offset];
2485 2553
2486 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { 2554 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
2487 snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n", 2555 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
2488 chip->dev->devnum, fp->iface, fp->altsetting); 2556 chip->dev->devnum, fp->iface, fp->altsetting);
2489 return -1; 2557 return -1;
2490 } 2558 }
@@ -2535,14 +2603,87 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
2535} 2603}
2536 2604
2537/* 2605/*
2606 * parse the format descriptor and stores the possible sample rates
2607 * on the audioformat table (audio class v2).
2608 */
2609static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
2610 struct audioformat *fp,
2611 struct usb_host_interface *iface)
2612{
2613 struct usb_device *dev = chip->dev;
2614 unsigned char tmp[2], *data;
2615 int i, nr_rates, data_size, ret = 0;
2616
2617 /* get the number of sample rates first by only fetching 2 bytes */
2618 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
2619 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
2620 0x0100, chip->clock_id << 8, tmp, sizeof(tmp), 1000);
2621
2622 if (ret < 0) {
2623 snd_printk(KERN_ERR "unable to retrieve number of sample rates\n");
2624 goto err;
2625 }
2626
2627 nr_rates = (tmp[1] << 8) | tmp[0];
2628 data_size = 2 + 12 * nr_rates;
2629 data = kzalloc(data_size, GFP_KERNEL);
2630 if (!data) {
2631 ret = -ENOMEM;
2632 goto err;
2633 }
2634
2635 /* now get the full information */
2636 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
2637 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
2638 0x0100, chip->clock_id << 8, data, data_size, 1000);
2639
2640 if (ret < 0) {
2641 snd_printk(KERN_ERR "unable to retrieve sample rate range\n");
2642 ret = -EINVAL;
2643 goto err_free;
2644 }
2645
2646 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
2647 if (!fp->rate_table) {
2648 ret = -ENOMEM;
2649 goto err_free;
2650 }
2651
2652 fp->nr_rates = 0;
2653 fp->rate_min = fp->rate_max = 0;
2654
2655 for (i = 0; i < nr_rates; i++) {
2656 int rate = combine_quad(&data[2 + 12 * i]);
2657
2658 fp->rate_table[fp->nr_rates] = rate;
2659 if (!fp->rate_min || rate < fp->rate_min)
2660 fp->rate_min = rate;
2661 if (!fp->rate_max || rate > fp->rate_max)
2662 fp->rate_max = rate;
2663 fp->rates |= snd_pcm_rate_to_rate_bit(rate);
2664 fp->nr_rates++;
2665 }
2666
2667err_free:
2668 kfree(data);
2669err:
2670 return ret;
2671}
2672
2673/*
2538 * parse the format type I and III descriptors 2674 * parse the format type I and III descriptors
2539 */ 2675 */
2540static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat *fp, 2676static int parse_audio_format_i(struct snd_usb_audio *chip,
2541 int format, unsigned char *fmt) 2677 struct audioformat *fp,
2678 int format, void *_fmt,
2679 struct usb_host_interface *iface)
2542{ 2680{
2543 int pcm_format; 2681 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
2682 struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
2683 int protocol = altsd->bInterfaceProtocol;
2684 int pcm_format, ret;
2544 2685
2545 if (fmt[3] == USB_FORMAT_TYPE_III) { 2686 if (fmt->bFormatType == UAC_FORMAT_TYPE_III) {
2546 /* FIXME: the format type is really IECxxx 2687 /* FIXME: the format type is really IECxxx
2547 * but we give normal PCM format to get the existing 2688 * but we give normal PCM format to get the existing
2548 * apps working... 2689 * apps working...
@@ -2560,34 +2701,57 @@ static int parse_audio_format_i(struct snd_usb_audio *chip, struct audioformat *
2560 pcm_format = SNDRV_PCM_FORMAT_S16_LE; 2701 pcm_format = SNDRV_PCM_FORMAT_S16_LE;
2561 } 2702 }
2562 } else { 2703 } else {
2563 pcm_format = parse_audio_format_i_type(chip, fp, format, fmt); 2704 pcm_format = parse_audio_format_i_type(chip, fp, format, fmt, protocol);
2564 if (pcm_format < 0) 2705 if (pcm_format < 0)
2565 return -1; 2706 return -1;
2566 } 2707 }
2708
2567 fp->format = pcm_format; 2709 fp->format = pcm_format;
2568 fp->channels = fmt[4]; 2710
2711 /* gather possible sample rates */
2712 /* audio class v1 reports possible sample rates as part of the
2713 * proprietary class specific descriptor.
2714 * audio class v2 uses class specific EP0 range requests for that.
2715 */
2716 switch (protocol) {
2717 case UAC_VERSION_1:
2718 fp->channels = fmt->bNrChannels;
2719 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7);
2720 break;
2721 case UAC_VERSION_2:
2722 /* fp->channels is already set in this case */
2723 ret = parse_audio_format_rates_v2(chip, fp, iface);
2724 break;
2725 }
2726
2569 if (fp->channels < 1) { 2727 if (fp->channels < 1) {
2570 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", 2728 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n",
2571 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); 2729 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels);
2572 return -1; 2730 return -1;
2573 } 2731 }
2574 return parse_audio_format_rates(chip, fp, fmt, 7); 2732
2733 return ret;
2575} 2734}
2576 2735
2577/* 2736/*
2578 * prase the format type II descriptor 2737 * parse the format type II descriptor
2579 */ 2738 */
2580static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat *fp, 2739static int parse_audio_format_ii(struct snd_usb_audio *chip,
2581 int format, unsigned char *fmt) 2740 struct audioformat *fp,
2741 int format, void *_fmt,
2742 struct usb_host_interface *iface)
2582{ 2743{
2583 int brate, framesize; 2744 int brate, framesize, ret;
2745 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
2746 int protocol = altsd->bInterfaceProtocol;
2747
2584 switch (format) { 2748 switch (format) {
2585 case USB_AUDIO_FORMAT_AC3: 2749 case UAC_FORMAT_TYPE_II_AC3:
2586 /* FIXME: there is no AC3 format defined yet */ 2750 /* FIXME: there is no AC3 format defined yet */
2587 // fp->format = SNDRV_PCM_FORMAT_AC3; 2751 // fp->format = SNDRV_PCM_FORMAT_AC3;
2588 fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */ 2752 fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */
2589 break; 2753 break;
2590 case USB_AUDIO_FORMAT_MPEG: 2754 case UAC_FORMAT_TYPE_II_MPEG:
2591 fp->format = SNDRV_PCM_FORMAT_MPEG; 2755 fp->format = SNDRV_PCM_FORMAT_MPEG;
2592 break; 2756 break;
2593 default: 2757 default:
@@ -2596,26 +2760,46 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat
2596 fp->format = SNDRV_PCM_FORMAT_MPEG; 2760 fp->format = SNDRV_PCM_FORMAT_MPEG;
2597 break; 2761 break;
2598 } 2762 }
2763
2599 fp->channels = 1; 2764 fp->channels = 1;
2600 brate = combine_word(&fmt[4]); /* fmt[4,5] : wMaxBitRate (in kbps) */ 2765
2601 framesize = combine_word(&fmt[6]); /* fmt[6,7]: wSamplesPerFrame */ 2766 switch (protocol) {
2602 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 2767 case UAC_VERSION_1: {
2603 fp->frame_size = framesize; 2768 struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
2604 return parse_audio_format_rates(chip, fp, fmt, 8); /* fmt[8..] sample rates */ 2769 brate = le16_to_cpu(fmt->wMaxBitRate);
2770 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
2771 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
2772 fp->frame_size = framesize;
2773 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
2774 break;
2775 }
2776 case UAC_VERSION_2: {
2777 struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
2778 brate = le16_to_cpu(fmt->wMaxBitRate);
2779 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
2780 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
2781 fp->frame_size = framesize;
2782 ret = parse_audio_format_rates_v2(chip, fp, iface);
2783 break;
2784 }
2785 }
2786
2787 return ret;
2605} 2788}
2606 2789
2607static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp, 2790static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
2608 int format, unsigned char *fmt, int stream) 2791 int format, unsigned char *fmt, int stream,
2792 struct usb_host_interface *iface)
2609{ 2793{
2610 int err; 2794 int err;
2611 2795
2612 switch (fmt[3]) { 2796 switch (fmt[3]) {
2613 case USB_FORMAT_TYPE_I: 2797 case UAC_FORMAT_TYPE_I:
2614 case USB_FORMAT_TYPE_III: 2798 case UAC_FORMAT_TYPE_III:
2615 err = parse_audio_format_i(chip, fp, format, fmt); 2799 err = parse_audio_format_i(chip, fp, format, fmt, iface);
2616 break; 2800 break;
2617 case USB_FORMAT_TYPE_II: 2801 case UAC_FORMAT_TYPE_II:
2618 err = parse_audio_format_ii(chip, fp, format, fmt); 2802 err = parse_audio_format_ii(chip, fp, format, fmt, iface);
2619 break; 2803 break;
2620 default: 2804 default:
2621 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", 2805 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
@@ -2633,7 +2817,7 @@ static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp
2633 if (chip->usb_id == USB_ID(0x041e, 0x3000) || 2817 if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
2634 chip->usb_id == USB_ID(0x041e, 0x3020) || 2818 chip->usb_id == USB_ID(0x041e, 0x3020) ||
2635 chip->usb_id == USB_ID(0x041e, 0x3061)) { 2819 chip->usb_id == USB_ID(0x041e, 0x3061)) {
2636 if (fmt[3] == USB_FORMAT_TYPE_I && 2820 if (fmt[3] == UAC_FORMAT_TYPE_I &&
2637 fp->rates != SNDRV_PCM_RATE_48000 && 2821 fp->rates != SNDRV_PCM_RATE_48000 &&
2638 fp->rates != SNDRV_PCM_RATE_96000) 2822 fp->rates != SNDRV_PCM_RATE_96000)
2639 return -1; 2823 return -1;
@@ -2662,10 +2846,10 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2662 struct usb_host_interface *alts; 2846 struct usb_host_interface *alts;
2663 struct usb_interface_descriptor *altsd; 2847 struct usb_interface_descriptor *altsd;
2664 int i, altno, err, stream; 2848 int i, altno, err, stream;
2665 int format; 2849 int format = 0, num_channels = 0;
2666 struct audioformat *fp = NULL; 2850 struct audioformat *fp = NULL;
2667 unsigned char *fmt, *csep; 2851 unsigned char *fmt, *csep;
2668 int num; 2852 int num, protocol;
2669 2853
2670 dev = chip->dev; 2854 dev = chip->dev;
2671 2855
@@ -2684,10 +2868,11 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2684 for (i = 0; i < num; i++) { 2868 for (i = 0; i < num; i++) {
2685 alts = &iface->altsetting[i]; 2869 alts = &iface->altsetting[i];
2686 altsd = get_iface_desc(alts); 2870 altsd = get_iface_desc(alts);
2871 protocol = altsd->bInterfaceProtocol;
2687 /* skip invalid one */ 2872 /* skip invalid one */
2688 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && 2873 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
2689 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || 2874 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
2690 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING && 2875 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
2691 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) || 2876 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
2692 altsd->bNumEndpoints < 1 || 2877 altsd->bNumEndpoints < 1 ||
2693 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0) 2878 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
@@ -2708,30 +2893,65 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2708 continue; 2893 continue;
2709 2894
2710 /* get audio formats */ 2895 /* get audio formats */
2711 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, AS_GENERAL); 2896 switch (protocol) {
2712 if (!fmt) { 2897 case UAC_VERSION_1: {
2713 snd_printk(KERN_ERR "%d:%u:%d : AS_GENERAL descriptor not found\n", 2898 struct uac_as_header_descriptor_v1 *as =
2714 dev->devnum, iface_no, altno); 2899 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
2715 continue; 2900
2901 if (!as) {
2902 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
2903 dev->devnum, iface_no, altno);
2904 continue;
2905 }
2906
2907 if (as->bLength < sizeof(*as)) {
2908 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
2909 dev->devnum, iface_no, altno);
2910 continue;
2911 }
2912
2913 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
2914 break;
2716 } 2915 }
2717 2916
2718 if (fmt[0] < 7) { 2917 case UAC_VERSION_2: {
2719 snd_printk(KERN_ERR "%d:%u:%d : invalid AS_GENERAL desc\n", 2918 struct uac_as_header_descriptor_v2 *as =
2720 dev->devnum, iface_no, altno); 2919 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
2721 continue; 2920
2921 if (!as) {
2922 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
2923 dev->devnum, iface_no, altno);
2924 continue;
2925 }
2926
2927 if (as->bLength < sizeof(*as)) {
2928 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
2929 dev->devnum, iface_no, altno);
2930 continue;
2931 }
2932
2933 num_channels = as->bNrChannels;
2934 format = le32_to_cpu(as->bmFormats);
2935
2936 break;
2722 } 2937 }
2723 2938
2724 format = (fmt[6] << 8) | fmt[5]; /* remember the format value */ 2939 default:
2940 snd_printk(KERN_ERR "%d:%u:%d : unknown interface protocol %04x\n",
2941 dev->devnum, iface_no, altno, protocol);
2942 continue;
2943 }
2725 2944
2726 /* get format type */ 2945 /* get format type */
2727 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, FORMAT_TYPE); 2946 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
2728 if (!fmt) { 2947 if (!fmt) {
2729 snd_printk(KERN_ERR "%d:%u:%d : no FORMAT_TYPE desc\n", 2948 snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
2730 dev->devnum, iface_no, altno); 2949 dev->devnum, iface_no, altno);
2731 continue; 2950 continue;
2732 } 2951 }
2733 if (fmt[0] < 8) { 2952 if (((protocol == UAC_VERSION_1) && (fmt[0] < 8)) ||
2734 snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n", 2953 ((protocol == UAC_VERSION_2) && (fmt[0] != 6))) {
2954 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
2735 dev->devnum, iface_no, altno); 2955 dev->devnum, iface_no, altno);
2736 continue; 2956 continue;
2737 } 2957 }
@@ -2744,6 +2964,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 && 2964 if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 &&
2745 fp && fp->altsetting == 1 && fp->channels == 1 && 2965 fp && fp->altsetting == 1 && fp->channels == 1 &&
2746 fp->format == SNDRV_PCM_FORMAT_S16_LE && 2966 fp->format == SNDRV_PCM_FORMAT_S16_LE &&
2967 protocol == UAC_VERSION_1 &&
2747 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 2968 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
2748 fp->maxpacksize * 2) 2969 fp->maxpacksize * 2)
2749 continue; 2970 continue;
@@ -2752,7 +2973,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2752 /* Creamware Noah has this descriptor after the 2nd endpoint */ 2973 /* Creamware Noah has this descriptor after the 2nd endpoint */
2753 if (!csep && altsd->bNumEndpoints >= 2) 2974 if (!csep && altsd->bNumEndpoints >= 2)
2754 csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); 2975 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) { 2976 if (!csep || csep[0] < 7 || csep[2] != UAC_EP_GENERAL) {
2756 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" 2977 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
2757 " class specific endpoint descriptor\n", 2978 " class specific endpoint descriptor\n",
2758 dev->devnum, iface_no, altno); 2979 dev->devnum, iface_no, altno);
@@ -2772,6 +2993,8 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2772 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 2993 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
2773 fp->datainterval = parse_datainterval(chip, alts); 2994 fp->datainterval = parse_datainterval(chip, alts);
2774 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 2995 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
2996 /* num_channels is only set for v2 interfaces */
2997 fp->channels = num_channels;
2775 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) 2998 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
2776 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) 2999 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
2777 * (fp->maxpacksize & 0x7ff); 3000 * (fp->maxpacksize & 0x7ff);
@@ -2784,12 +3007,12 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2784 /* Optoplay sets the sample rate attribute although 3007 /* Optoplay sets the sample rate attribute although
2785 * it seems not supporting it in fact. 3008 * it seems not supporting it in fact.
2786 */ 3009 */
2787 fp->attributes &= ~EP_CS_ATTR_SAMPLE_RATE; 3010 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
2788 break; 3011 break;
2789 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ 3012 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
2790 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ 3013 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
2791 /* doesn't set the sample rate attribute, but supports it */ 3014 /* doesn't set the sample rate attribute, but supports it */
2792 fp->attributes |= EP_CS_ATTR_SAMPLE_RATE; 3015 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
2793 break; 3016 break;
2794 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ 3017 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
2795 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is 3018 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
@@ -2798,16 +3021,16 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2798 * plantronics headset and Griffin iMic have set adaptive-in 3021 * plantronics headset and Griffin iMic have set adaptive-in
2799 * although it's really not... 3022 * although it's really not...
2800 */ 3023 */
2801 fp->ep_attr &= ~EP_ATTR_MASK; 3024 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
2802 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 3025 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
2803 fp->ep_attr |= EP_ATTR_ADAPTIVE; 3026 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
2804 else 3027 else
2805 fp->ep_attr |= EP_ATTR_SYNC; 3028 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
2806 break; 3029 break;
2807 } 3030 }
2808 3031
2809 /* ok, let's parse further... */ 3032 /* ok, let's parse further... */
2810 if (parse_audio_format(chip, fp, format, fmt, stream) < 0) { 3033 if (parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
2811 kfree(fp->rate_table); 3034 kfree(fp->rate_table);
2812 kfree(fp); 3035 kfree(fp);
2813 continue; 3036 continue;
@@ -2849,6 +3072,65 @@ static void snd_usb_stream_disconnect(struct list_head *head)
2849 } 3072 }
2850} 3073}
2851 3074
3075static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
3076{
3077 struct usb_device *dev = chip->dev;
3078 struct usb_host_interface *alts;
3079 struct usb_interface_descriptor *altsd;
3080 struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
3081
3082 if (!iface) {
3083 snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
3084 dev->devnum, ctrlif, interface);
3085 return -EINVAL;
3086 }
3087
3088 if (usb_interface_claimed(iface)) {
3089 snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
3090 dev->devnum, ctrlif, interface);
3091 return -EINVAL;
3092 }
3093
3094 alts = &iface->altsetting[0];
3095 altsd = get_iface_desc(alts);
3096 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
3097 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
3098 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
3099 int err = snd_usbmidi_create(chip->card, iface,
3100 &chip->midi_list, NULL);
3101 if (err < 0) {
3102 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
3103 dev->devnum, ctrlif, interface);
3104 return -EINVAL;
3105 }
3106 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
3107
3108 return 0;
3109 }
3110
3111 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
3112 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
3113 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
3114 snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
3115 dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
3116 /* skip non-supported classes */
3117 return -EINVAL;
3118 }
3119
3120 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
3121 snd_printk(KERN_ERR "low speed audio streaming not supported\n");
3122 return -EINVAL;
3123 }
3124
3125 if (! parse_audio_endpoints(chip, interface)) {
3126 usb_set_interface(dev, interface, 0); /* reset the current interface */
3127 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
3128 return -EINVAL;
3129 }
3130
3131 return 0;
3132}
3133
2852/* 3134/*
2853 * parse audio control descriptor and create pcm/midi streams 3135 * parse audio control descriptor and create pcm/midi streams
2854 */ 3136 */
@@ -2856,67 +3138,81 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
2856{ 3138{
2857 struct usb_device *dev = chip->dev; 3139 struct usb_device *dev = chip->dev;
2858 struct usb_host_interface *host_iface; 3140 struct usb_host_interface *host_iface;
2859 struct usb_interface *iface; 3141 struct usb_interface_descriptor *altsd;
2860 unsigned char *p1; 3142 void *control_header;
2861 int i, j; 3143 int i, protocol;
2862 3144
2863 /* find audiocontrol interface */ 3145 /* find audiocontrol interface */
2864 host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0]; 3146 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))) { 3147 control_header = snd_usb_find_csint_desc(host_iface->extra,
2866 snd_printk(KERN_ERR "cannot find HEADER\n"); 3148 host_iface->extralen,
2867 return -EINVAL; 3149 NULL, UAC_HEADER);
2868 } 3150 altsd = get_iface_desc(host_iface);
2869 if (! p1[7] || p1[0] < 8 + p1[7]) { 3151 protocol = altsd->bInterfaceProtocol;
2870 snd_printk(KERN_ERR "invalid HEADER\n"); 3152
3153 if (!control_header) {
3154 snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
2871 return -EINVAL; 3155 return -EINVAL;
2872 } 3156 }
2873 3157
2874 /* 3158 switch (protocol) {
2875 * parse all USB audio streaming interfaces 3159 case UAC_VERSION_1: {
2876 */ 3160 struct uac_ac_header_descriptor_v1 *h1 = control_header;
2877 for (i = 0; i < p1[7]; i++) { 3161
2878 struct usb_host_interface *alts; 3162 if (!h1->bInCollection) {
2879 struct usb_interface_descriptor *altsd; 3163 snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
2880 j = p1[8 + i]; 3164 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 } 3165 }
2891 alts = &iface->altsetting[0]; 3166
2892 altsd = get_iface_desc(alts); 3167 if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
2893 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO || 3168 snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
2894 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && 3169 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 } 3170 }
2905 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && 3171
2906 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || 3172 for (i = 0; i < h1->bInCollection; i++)
2907 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING) { 3173 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); 3174
2909 /* skip non-supported classes */ 3175 break;
2910 continue; 3176 }
3177
3178 case UAC_VERSION_2: {
3179 struct uac_clock_source_descriptor *cs;
3180 struct usb_interface_assoc_descriptor *assoc =
3181 usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
3182
3183 if (!assoc) {
3184 snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
3185 return -EINVAL;
2911 } 3186 }
2912 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) { 3187
2913 snd_printk(KERN_ERR "low speed audio streaming not supported\n"); 3188 /* FIXME: for now, we expect there is at least one clock source
2914 continue; 3189 * descriptor and we always take the first one.
3190 * We should properly support devices with multiple clock sources,
3191 * clock selectors and sample rate conversion units. */
3192
3193 cs = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen,
3194 NULL, UAC_CLOCK_SOURCE);
3195
3196 if (!cs) {
3197 snd_printk(KERN_ERR "CLOCK_SOURCE descriptor not found\n");
3198 return -EINVAL;
2915 } 3199 }
2916 if (! parse_audio_endpoints(chip, j)) { 3200
2917 usb_set_interface(dev, j, 0); /* reset the current interface */ 3201 chip->clock_id = cs->bClockID;
2918 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); 3202
3203 for (i = 0; i < assoc->bInterfaceCount; i++) {
3204 int intf = assoc->bFirstInterface + i;
3205
3206 if (intf != ctrlif)
3207 snd_usb_create_stream(chip, ctrlif, intf);
2919 } 3208 }
3209
3210 break;
3211 }
3212
3213 default:
3214 snd_printk(KERN_ERR "unknown protocol version 0x%02x\n", protocol);
3215 return -EINVAL;
2920 } 3216 }
2921 3217
2922 return 0; 3218 return 0;
@@ -3007,7 +3303,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
3007 static const struct audioformat ua_format = { 3303 static const struct audioformat ua_format = {
3008 .format = SNDRV_PCM_FORMAT_S24_3LE, 3304 .format = SNDRV_PCM_FORMAT_S24_3LE,
3009 .channels = 2, 3305 .channels = 2,
3010 .fmt_type = USB_FORMAT_TYPE_I, 3306 .fmt_type = UAC_FORMAT_TYPE_I,
3011 .altsetting = 1, 3307 .altsetting = 1,
3012 .altset_idx = 1, 3308 .altset_idx = 1,
3013 .rates = SNDRV_PCM_RATE_CONTINUOUS, 3309 .rates = SNDRV_PCM_RATE_CONTINUOUS,
@@ -3099,7 +3395,7 @@ static int create_ua1000_quirk(struct snd_usb_audio *chip,
3099{ 3395{
3100 static const struct audioformat ua1000_format = { 3396 static const struct audioformat ua1000_format = {
3101 .format = SNDRV_PCM_FORMAT_S32_LE, 3397 .format = SNDRV_PCM_FORMAT_S32_LE,
3102 .fmt_type = USB_FORMAT_TYPE_I, 3398 .fmt_type = UAC_FORMAT_TYPE_I,
3103 .altsetting = 1, 3399 .altsetting = 1,
3104 .altset_idx = 1, 3400 .altset_idx = 1,
3105 .attributes = 0, 3401 .attributes = 0,
@@ -3142,59 +3438,6 @@ static int create_ua1000_quirk(struct snd_usb_audio *chip,
3142 return 0; 3438 return 0;
3143} 3439}
3144 3440
3145/*
3146 * Create a stream for an Edirol UA-101 interface.
3147 * Copy, paste and modify from Edirol UA-1000
3148 */
3149static 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
3198static int snd_usb_create_quirk(struct snd_usb_audio *chip, 3441static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3199 struct usb_interface *iface, 3442 struct usb_interface *iface,
3200 const struct snd_usb_audio_quirk *quirk); 3443 const struct snd_usb_audio_quirk *quirk);
@@ -3232,6 +3475,18 @@ static int ignore_interface_quirk(struct snd_usb_audio *chip,
3232 return 0; 3475 return 0;
3233} 3476}
3234 3477
3478/*
3479 * Allow alignment on audio sub-slot (channel samples) rather than
3480 * on audio slots (audio frames)
3481 */
3482static int create_align_transfer_quirk(struct snd_usb_audio *chip,
3483 struct usb_interface *iface,
3484 const struct snd_usb_audio_quirk *quirk)
3485{
3486 chip->txfr_quirk = 1;
3487 return 1; /* Continue with creating streams and mixer */
3488}
3489
3235 3490
3236/* 3491/*
3237 * boot quirks 3492 * boot quirks
@@ -3327,6 +3582,32 @@ static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
3327} 3582}
3328 3583
3329/* 3584/*
3585 * This call will put the synth in "USB send" mode, i.e it will send MIDI
3586 * messages through USB (this is disabled at startup). The synth will
3587 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
3588 * sign on its LCD. Values here are chosen based on sniffing USB traffic
3589 * under Windows.
3590 */
3591static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
3592{
3593 int err, actual_length;
3594
3595 /* "midi send" enable */
3596 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
3597
3598 void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
3599 if (!buf)
3600 return -ENOMEM;
3601 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
3602 ARRAY_SIZE(seq), &actual_length, 1000);
3603 kfree(buf);
3604 if (err < 0)
3605 return err;
3606
3607 return 0;
3608}
3609
3610/*
3330 * Setup quirks 3611 * Setup quirks
3331 */ 3612 */
3332#define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */ 3613#define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */
@@ -3406,8 +3687,8 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3406 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 3687 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
3407 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 3688 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
3408 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, 3689 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
3409 [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk, 3690 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
3410 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk 3691 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk
3411 }; 3692 };
3412 3693
3413 if (quirk->type < QUIRK_TYPE_COUNT) { 3694 if (quirk->type < QUIRK_TYPE_COUNT) {
@@ -3596,7 +3877,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3596 ifnum = get_iface_desc(alts)->bInterfaceNumber; 3877 ifnum = get_iface_desc(alts)->bInterfaceNumber;
3597 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 3878 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
3598 le16_to_cpu(dev->descriptor.idProduct)); 3879 le16_to_cpu(dev->descriptor.idProduct));
3599
3600 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) 3880 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
3601 goto __err_val; 3881 goto __err_val;
3602 3882
@@ -3624,6 +3904,12 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3624 goto __err_val; 3904 goto __err_val;
3625 } 3905 }
3626 3906
3907 /* Access Music VirusTI Desktop */
3908 if (id == USB_ID(0x133e, 0x0815)) {
3909 if (snd_usb_accessmusic_boot_quirk(dev) < 0)
3910 goto __err_val;
3911 }
3912
3627 /* 3913 /*
3628 * found a config. now register to ALSA 3914 * found a config. now register to ALSA
3629 */ 3915 */
@@ -3661,6 +3947,7 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3661 } 3947 }
3662 } 3948 }
3663 3949
3950 chip->txfr_quirk = 0;
3664 err = 1; /* continue */ 3951 err = 1; /* continue */
3665 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { 3952 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
3666 /* need some special handlings */ 3953 /* need some special handlings */