stream.c (825e587af2e90e9b953849f3347a01d8f383d577) stream.c (0ba41d917eeb87f608cf147f870ff2f4c1056bab)
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of

--- 397 unchanged lines hidden (view full) ---

406 * bytes after the first endpoint, go search the entire interface.
407 * Some devices have it directly *before* the standard endpoint.
408 */
409 if (!csep)
410 csep = snd_usb_find_desc(alts->extra, alts->extralen, NULL, USB_DT_CS_ENDPOINT);
411
412 if (!csep || csep->bLength < 7 ||
413 csep->bDescriptorSubtype != UAC_EP_GENERAL) {
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of

--- 397 unchanged lines hidden (view full) ---

406 * bytes after the first endpoint, go search the entire interface.
407 * Some devices have it directly *before* the standard endpoint.
408 */
409 if (!csep)
410 csep = snd_usb_find_desc(alts->extra, alts->extralen, NULL, USB_DT_CS_ENDPOINT);
411
412 if (!csep || csep->bLength < 7 ||
413 csep->bDescriptorSubtype != UAC_EP_GENERAL) {
414 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
415 " class specific endpoint descriptor\n",
416 chip->dev->devnum, iface_no,
417 altsd->bAlternateSetting);
414 usb_audio_warn(chip,
415 "%u:%d : no or invalid class specific endpoint descriptor\n",
416 iface_no, altsd->bAlternateSetting);
418 return 0;
419 }
420
421 if (protocol == UAC_VERSION_1) {
422 attributes = csep->bmAttributes;
423 } else {
424 struct uac2_iso_endpoint_descriptor *csep2 =
425 (struct uac2_iso_endpoint_descriptor *) csep;

--- 102 unchanged lines hidden (view full) ---

528 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
529 protocol <= 2)
530 protocol = UAC_VERSION_1;
531
532 chconfig = 0;
533 /* get audio formats */
534 switch (protocol) {
535 default:
417 return 0;
418 }
419
420 if (protocol == UAC_VERSION_1) {
421 attributes = csep->bmAttributes;
422 } else {
423 struct uac2_iso_endpoint_descriptor *csep2 =
424 (struct uac2_iso_endpoint_descriptor *) csep;

--- 102 unchanged lines hidden (view full) ---

527 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
528 protocol <= 2)
529 protocol = UAC_VERSION_1;
530
531 chconfig = 0;
532 /* get audio formats */
533 switch (protocol) {
534 default:
536 snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n",
537 dev->devnum, iface_no, altno, protocol);
535 dev_dbg(&dev->dev, "%u:%d: unknown interface protocol %#02x, assuming v1\n",
536 iface_no, altno, protocol);
538 protocol = UAC_VERSION_1;
539 /* fall through */
540
541 case UAC_VERSION_1: {
542 struct uac1_as_header_descriptor *as =
543 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
544 struct uac_input_terminal_descriptor *iterm;
545
546 if (!as) {
537 protocol = UAC_VERSION_1;
538 /* fall through */
539
540 case UAC_VERSION_1: {
541 struct uac1_as_header_descriptor *as =
542 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
543 struct uac_input_terminal_descriptor *iterm;
544
545 if (!as) {
547 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
548 dev->devnum, iface_no, altno);
546 dev_err(&dev->dev,
547 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
548 iface_no, altno);
549 continue;
550 }
551
552 if (as->bLength < sizeof(*as)) {
549 continue;
550 }
551
552 if (as->bLength < sizeof(*as)) {
553 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
554 dev->devnum, iface_no, altno);
553 dev_err(&dev->dev,
554 "%u:%d : invalid UAC_AS_GENERAL desc\n",
555 iface_no, altno);
555 continue;
556 }
557
558 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
559
560 iterm = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
561 as->bTerminalLink);
562 if (iterm) {

--- 6 unchanged lines hidden (view full) ---

569
570 case UAC_VERSION_2: {
571 struct uac2_input_terminal_descriptor *input_term;
572 struct uac2_output_terminal_descriptor *output_term;
573 struct uac2_as_header_descriptor *as =
574 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
575
576 if (!as) {
556 continue;
557 }
558
559 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
560
561 iterm = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
562 as->bTerminalLink);
563 if (iterm) {

--- 6 unchanged lines hidden (view full) ---

570
571 case UAC_VERSION_2: {
572 struct uac2_input_terminal_descriptor *input_term;
573 struct uac2_output_terminal_descriptor *output_term;
574 struct uac2_as_header_descriptor *as =
575 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
576
577 if (!as) {
577 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
578 dev->devnum, iface_no, altno);
578 dev_err(&dev->dev,
579 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
580 iface_no, altno);
579 continue;
580 }
581
582 if (as->bLength < sizeof(*as)) {
581 continue;
582 }
583
584 if (as->bLength < sizeof(*as)) {
583 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
584 dev->devnum, iface_no, altno);
585 dev_err(&dev->dev,
586 "%u:%d : invalid UAC_AS_GENERAL desc\n",
587 iface_no, altno);
585 continue;
586 }
587
588 num_channels = as->bNrChannels;
589 format = le32_to_cpu(as->bmFormats);
590 chconfig = le32_to_cpu(as->bmChannelConfig);
591
592 /* lookup the terminal associated to this interface

--- 9 unchanged lines hidden (view full) ---

602
603 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
604 as->bTerminalLink);
605 if (output_term) {
606 clock = output_term->bCSourceID;
607 break;
608 }
609
588 continue;
589 }
590
591 num_channels = as->bNrChannels;
592 format = le32_to_cpu(as->bmFormats);
593 chconfig = le32_to_cpu(as->bmChannelConfig);
594
595 /* lookup the terminal associated to this interface

--- 9 unchanged lines hidden (view full) ---

605
606 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
607 as->bTerminalLink);
608 if (output_term) {
609 clock = output_term->bCSourceID;
610 break;
611 }
612
610 snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n",
611 dev->devnum, iface_no, altno, as->bTerminalLink);
613 dev_err(&dev->dev,
614 "%u:%d : bogus bTerminalLink %d\n",
615 iface_no, altno, as->bTerminalLink);
612 continue;
613 }
614 }
615
616 /* get format type */
617 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
618 if (!fmt) {
616 continue;
617 }
618 }
619
620 /* get format type */
621 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
622 if (!fmt) {
619 snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
620 dev->devnum, iface_no, altno);
623 dev_err(&dev->dev,
624 "%u:%d : no UAC_FORMAT_TYPE desc\n",
625 iface_no, altno);
621 continue;
622 }
623 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
624 ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
626 continue;
627 }
628 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
629 ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
625 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
626 dev->devnum, iface_no, altno);
630 dev_err(&dev->dev,
631 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
632 iface_no, altno);
627 continue;
628 }
629
630 /*
631 * Blue Microphones workaround: The last altsetting is identical
632 * with the previous one, except for a larger packet size, but
633 * is actually a mislabeled two-channel setting; ignore it.
634 */

--- 4 unchanged lines hidden (view full) ---

639 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
640 protocol == UAC_VERSION_1 &&
641 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
642 fp->maxpacksize * 2)
643 continue;
644
645 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
646 if (! fp) {
633 continue;
634 }
635
636 /*
637 * Blue Microphones workaround: The last altsetting is identical
638 * with the previous one, except for a larger packet size, but
639 * is actually a mislabeled two-channel setting; ignore it.
640 */

--- 4 unchanged lines hidden (view full) ---

645 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
646 protocol == UAC_VERSION_1 &&
647 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
648 fp->maxpacksize * 2)
649 continue;
650
651 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
652 if (! fp) {
647 snd_printk(KERN_ERR "cannot malloc\n");
653 dev_err(&dev->dev, "cannot malloc\n");
648 return -ENOMEM;
649 }
650
651 fp->iface = iface_no;
652 fp->altsetting = altno;
653 fp->altset_idx = i;
654 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
655 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;

--- 46 unchanged lines hidden (view full) ---

702 continue;
703 }
704
705 /* Create chmap */
706 if (fp->channels != num_channels)
707 chconfig = 0;
708 fp->chmap = convert_chmap(fp->channels, chconfig, protocol);
709
654 return -ENOMEM;
655 }
656
657 fp->iface = iface_no;
658 fp->altsetting = altno;
659 fp->altset_idx = i;
660 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
661 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;

--- 46 unchanged lines hidden (view full) ---

708 continue;
709 }
710
711 /* Create chmap */
712 if (fp->channels != num_channels)
713 chconfig = 0;
714 fp->chmap = convert_chmap(fp->channels, chconfig, protocol);
715
710 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
716 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint);
711 err = snd_usb_add_audio_stream(chip, stream, fp);
712 if (err < 0) {
713 kfree(fp->rate_table);
714 kfree(fp->chmap);
715 kfree(fp);
716 return err;
717 }
718 /* try to set the interface... */
719 usb_set_interface(chip->dev, iface_no, altno);
720 snd_usb_init_pitch(chip, iface_no, alts, fp);
721 snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
722 }
723 return 0;
724}
725
717 err = snd_usb_add_audio_stream(chip, stream, fp);
718 if (err < 0) {
719 kfree(fp->rate_table);
720 kfree(fp->chmap);
721 kfree(fp);
722 return err;
723 }
724 /* try to set the interface... */
725 usb_set_interface(chip->dev, iface_no, altno);
726 snd_usb_init_pitch(chip, iface_no, alts, fp);
727 snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
728 }
729 return 0;
730}
731