aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/stream.c')
-rw-r--r--sound/usb/stream.c693
1 files changed, 412 insertions, 281 deletions
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 5ed334575fc7..729afd808cc4 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -106,6 +106,8 @@ static void snd_usb_init_substream(struct snd_usb_stream *as,
106 subs->ep_num = fp->endpoint; 106 subs->ep_num = fp->endpoint;
107 if (fp->channels > subs->channels_max) 107 if (fp->channels > subs->channels_max)
108 subs->channels_max = fp->channels; 108 subs->channels_max = fp->channels;
109
110 snd_usb_preallocate_buffer(subs);
109} 111}
110 112
111/* kctl callbacks for usb-audio channel maps */ 113/* kctl callbacks for usb-audio channel maps */
@@ -633,6 +635,395 @@ snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface,
633 return NULL; 635 return NULL;
634} 636}
635 637
638static struct audioformat *
639audio_format_alloc_init(struct snd_usb_audio *chip,
640 struct usb_host_interface *alts,
641 int protocol, int iface_no, int altset_idx,
642 int altno, int num_channels, int clock)
643{
644 struct audioformat *fp;
645
646 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
647 if (!fp)
648 return NULL;
649
650 fp->iface = iface_no;
651 fp->altsetting = altno;
652 fp->altset_idx = altset_idx;
653 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
654 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
655 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
656 fp->protocol = protocol;
657 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
658 fp->channels = num_channels;
659 if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH)
660 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
661 * (fp->maxpacksize & 0x7ff);
662 fp->clock = clock;
663 INIT_LIST_HEAD(&fp->list);
664
665 return fp;
666}
667
668static struct audioformat *
669snd_usb_get_audioformat_uac12(struct snd_usb_audio *chip,
670 struct usb_host_interface *alts,
671 int protocol, int iface_no, int altset_idx,
672 int altno, int stream, int bm_quirk)
673{
674 struct usb_device *dev = chip->dev;
675 struct uac_format_type_i_continuous_descriptor *fmt;
676 unsigned int num_channels = 0, chconfig = 0;
677 struct audioformat *fp;
678 int clock = 0;
679 u64 format;
680
681 /* get audio formats */
682 if (protocol == UAC_VERSION_1) {
683 struct uac1_as_header_descriptor *as =
684 snd_usb_find_csint_desc(alts->extra, alts->extralen,
685 NULL, UAC_AS_GENERAL);
686 struct uac_input_terminal_descriptor *iterm;
687
688 if (!as) {
689 dev_err(&dev->dev,
690 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
691 iface_no, altno);
692 return NULL;
693 }
694
695 if (as->bLength < sizeof(*as)) {
696 dev_err(&dev->dev,
697 "%u:%d : invalid UAC_AS_GENERAL desc\n",
698 iface_no, altno);
699 return NULL;
700 }
701
702 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
703
704 iterm = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
705 as->bTerminalLink);
706 if (iterm) {
707 num_channels = iterm->bNrChannels;
708 chconfig = le16_to_cpu(iterm->wChannelConfig);
709 }
710 } else { /* UAC_VERSION_2 */
711 struct uac2_input_terminal_descriptor *input_term;
712 struct uac2_output_terminal_descriptor *output_term;
713 struct uac2_as_header_descriptor *as =
714 snd_usb_find_csint_desc(alts->extra, alts->extralen,
715 NULL, UAC_AS_GENERAL);
716
717 if (!as) {
718 dev_err(&dev->dev,
719 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
720 iface_no, altno);
721 return NULL;
722 }
723
724 if (as->bLength < sizeof(*as)) {
725 dev_err(&dev->dev,
726 "%u:%d : invalid UAC_AS_GENERAL desc\n",
727 iface_no, altno);
728 return NULL;
729 }
730
731 num_channels = as->bNrChannels;
732 format = le32_to_cpu(as->bmFormats);
733 chconfig = le32_to_cpu(as->bmChannelConfig);
734
735 /*
736 * lookup the terminal associated to this interface
737 * to extract the clock
738 */
739 input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
740 as->bTerminalLink);
741 if (input_term) {
742 clock = input_term->bCSourceID;
743 if (!chconfig && (num_channels == input_term->bNrChannels))
744 chconfig = le32_to_cpu(input_term->bmChannelConfig);
745 goto found_clock;
746 }
747
748 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
749 as->bTerminalLink);
750 if (output_term) {
751 clock = output_term->bCSourceID;
752 goto found_clock;
753 }
754
755 dev_err(&dev->dev,
756 "%u:%d : bogus bTerminalLink %d\n",
757 iface_no, altno, as->bTerminalLink);
758 return NULL;
759 }
760
761found_clock:
762 /* get format type */
763 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen,
764 NULL, UAC_FORMAT_TYPE);
765 if (!fmt) {
766 dev_err(&dev->dev,
767 "%u:%d : no UAC_FORMAT_TYPE desc\n",
768 iface_no, altno);
769 return NULL;
770 }
771 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8))
772 || ((protocol == UAC_VERSION_2) &&
773 (fmt->bLength < 6))) {
774 dev_err(&dev->dev,
775 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
776 iface_no, altno);
777 return NULL;
778 }
779
780 /*
781 * Blue Microphones workaround: The last altsetting is
782 * identical with the previous one, except for a larger
783 * packet size, but is actually a mislabeled two-channel
784 * setting; ignore it.
785 *
786 * Part 2: analyze quirk flag and format
787 */
788 if (bm_quirk && fmt->bNrChannels == 1 && fmt->bSubframeSize == 2)
789 return NULL;
790
791 fp = audio_format_alloc_init(chip, alts, protocol, iface_no,
792 altset_idx, altno, num_channels, clock);
793 if (!fp)
794 return ERR_PTR(-ENOMEM);
795
796 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol,
797 iface_no);
798
799 /* some quirks for attributes here */
800 snd_usb_audioformat_attributes_quirk(chip, fp, stream);
801
802 /* ok, let's parse further... */
803 if (snd_usb_parse_audio_format(chip, fp, format,
804 fmt, stream) < 0) {
805 kfree(fp->rate_table);
806 kfree(fp);
807 return NULL;
808 }
809
810 /* Create chmap */
811 if (fp->channels != num_channels)
812 chconfig = 0;
813
814 fp->chmap = convert_chmap(fp->channels, chconfig, protocol);
815
816 return fp;
817}
818
819static struct audioformat *
820snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,
821 struct usb_host_interface *alts,
822 int iface_no, int altset_idx,
823 int altno, int stream)
824{
825 struct usb_device *dev = chip->dev;
826 struct uac3_input_terminal_descriptor *input_term;
827 struct uac3_output_terminal_descriptor *output_term;
828 struct uac3_cluster_header_descriptor *cluster;
829 struct uac3_as_header_descriptor *as = NULL;
830 struct uac3_hc_descriptor_header hc_header;
831 struct snd_pcm_chmap_elem *chmap;
832 unsigned char badd_profile;
833 u64 badd_formats = 0;
834 unsigned int num_channels;
835 struct audioformat *fp;
836 u16 cluster_id, wLength;
837 int clock = 0;
838 int err;
839
840 badd_profile = chip->badd_profile;
841
842 if (badd_profile >= UAC3_FUNCTION_SUBCLASS_GENERIC_IO) {
843 unsigned int maxpacksize =
844 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
845
846 switch (maxpacksize) {
847 default:
848 dev_err(&dev->dev,
849 "%u:%d : incorrect wMaxPacketSize for BADD profile\n",
850 iface_no, altno);
851 return NULL;
852 case UAC3_BADD_EP_MAXPSIZE_SYNC_MONO_16:
853 case UAC3_BADD_EP_MAXPSIZE_ASYNC_MONO_16:
854 badd_formats = SNDRV_PCM_FMTBIT_S16_LE;
855 num_channels = 1;
856 break;
857 case UAC3_BADD_EP_MAXPSIZE_SYNC_MONO_24:
858 case UAC3_BADD_EP_MAXPSIZE_ASYNC_MONO_24:
859 badd_formats = SNDRV_PCM_FMTBIT_S24_3LE;
860 num_channels = 1;
861 break;
862 case UAC3_BADD_EP_MAXPSIZE_SYNC_STEREO_16:
863 case UAC3_BADD_EP_MAXPSIZE_ASYNC_STEREO_16:
864 badd_formats = SNDRV_PCM_FMTBIT_S16_LE;
865 num_channels = 2;
866 break;
867 case UAC3_BADD_EP_MAXPSIZE_SYNC_STEREO_24:
868 case UAC3_BADD_EP_MAXPSIZE_ASYNC_STEREO_24:
869 badd_formats = SNDRV_PCM_FMTBIT_S24_3LE;
870 num_channels = 2;
871 break;
872 }
873
874 chmap = kzalloc(sizeof(*chmap), GFP_KERNEL);
875 if (!chmap)
876 return ERR_PTR(-ENOMEM);
877
878 if (num_channels == 1) {
879 chmap->map[0] = SNDRV_CHMAP_MONO;
880 } else {
881 chmap->map[0] = SNDRV_CHMAP_FL;
882 chmap->map[1] = SNDRV_CHMAP_FR;
883 }
884
885 chmap->channels = num_channels;
886 clock = UAC3_BADD_CS_ID9;
887 goto found_clock;
888 }
889
890 as = snd_usb_find_csint_desc(alts->extra, alts->extralen,
891 NULL, UAC_AS_GENERAL);
892 if (!as) {
893 dev_err(&dev->dev,
894 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
895 iface_no, altno);
896 return NULL;
897 }
898
899 if (as->bLength < sizeof(*as)) {
900 dev_err(&dev->dev,
901 "%u:%d : invalid UAC_AS_GENERAL desc\n",
902 iface_no, altno);
903 return NULL;
904 }
905
906 cluster_id = le16_to_cpu(as->wClusterDescrID);
907 if (!cluster_id) {
908 dev_err(&dev->dev,
909 "%u:%d : no cluster descriptor\n",
910 iface_no, altno);
911 return NULL;
912 }
913
914 /*
915 * Get number of channels and channel map through
916 * High Capability Cluster Descriptor
917 *
918 * First step: get High Capability header and
919 * read size of Cluster Descriptor
920 */
921 err = snd_usb_ctl_msg(chip->dev,
922 usb_rcvctrlpipe(chip->dev, 0),
923 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
924 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
925 cluster_id,
926 snd_usb_ctrl_intf(chip),
927 &hc_header, sizeof(hc_header));
928 if (err < 0)
929 return ERR_PTR(err);
930 else if (err != sizeof(hc_header)) {
931 dev_err(&dev->dev,
932 "%u:%d : can't get High Capability descriptor\n",
933 iface_no, altno);
934 return ERR_PTR(-EIO);
935 }
936
937 /*
938 * Second step: allocate needed amount of memory
939 * and request Cluster Descriptor
940 */
941 wLength = le16_to_cpu(hc_header.wLength);
942 cluster = kzalloc(wLength, GFP_KERNEL);
943 if (!cluster)
944 return ERR_PTR(-ENOMEM);
945 err = snd_usb_ctl_msg(chip->dev,
946 usb_rcvctrlpipe(chip->dev, 0),
947 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
948 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
949 cluster_id,
950 snd_usb_ctrl_intf(chip),
951 cluster, wLength);
952 if (err < 0) {
953 kfree(cluster);
954 return ERR_PTR(err);
955 } else if (err != wLength) {
956 dev_err(&dev->dev,
957 "%u:%d : can't get Cluster Descriptor\n",
958 iface_no, altno);
959 kfree(cluster);
960 return ERR_PTR(-EIO);
961 }
962
963 num_channels = cluster->bNrChannels;
964 chmap = convert_chmap_v3(cluster);
965 kfree(cluster);
966
967 /*
968 * lookup the terminal associated to this interface
969 * to extract the clock
970 */
971 input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
972 as->bTerminalLink);
973 if (input_term) {
974 clock = input_term->bCSourceID;
975 goto found_clock;
976 }
977
978 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
979 as->bTerminalLink);
980 if (output_term) {
981 clock = output_term->bCSourceID;
982 goto found_clock;
983 }
984
985 dev_err(&dev->dev, "%u:%d : bogus bTerminalLink %d\n",
986 iface_no, altno, as->bTerminalLink);
987 kfree(chmap);
988 return NULL;
989
990found_clock:
991 fp = audio_format_alloc_init(chip, alts, UAC_VERSION_3, iface_no,
992 altset_idx, altno, num_channels, clock);
993 if (!fp) {
994 kfree(chmap);
995 return ERR_PTR(-ENOMEM);
996 }
997
998 fp->chmap = chmap;
999
1000 if (badd_profile >= UAC3_FUNCTION_SUBCLASS_GENERIC_IO) {
1001 fp->attributes = 0; /* No attributes */
1002
1003 fp->fmt_type = UAC_FORMAT_TYPE_I;
1004 fp->formats = badd_formats;
1005
1006 fp->nr_rates = 0; /* SNDRV_PCM_RATE_CONTINUOUS */
1007 fp->rate_min = UAC3_BADD_SAMPLING_RATE;
1008 fp->rate_max = UAC3_BADD_SAMPLING_RATE;
1009 fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
1010
1011 } else {
1012 fp->attributes = parse_uac_endpoint_attributes(chip, alts,
1013 UAC_VERSION_3,
1014 iface_no);
1015 /* ok, let's parse further... */
1016 if (snd_usb_parse_audio_format_v3(chip, fp, as, stream) < 0) {
1017 kfree(fp->chmap);
1018 kfree(fp->rate_table);
1019 kfree(fp);
1020 return NULL;
1021 }
1022 }
1023
1024 return fp;
1025}
1026
636int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) 1027int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
637{ 1028{
638 struct usb_device *dev; 1029 struct usb_device *dev;
@@ -640,13 +1031,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
640 struct usb_host_interface *alts; 1031 struct usb_host_interface *alts;
641 struct usb_interface_descriptor *altsd; 1032 struct usb_interface_descriptor *altsd;
642 int i, altno, err, stream; 1033 int i, altno, err, stream;
643 u64 format = 0;
644 unsigned int num_channels = 0;
645 struct audioformat *fp = NULL; 1034 struct audioformat *fp = NULL;
646 int num, protocol, clock = 0; 1035 int num, protocol;
647 struct uac_format_type_i_continuous_descriptor *fmt = NULL;
648 struct snd_pcm_chmap_elem *chmap_v3 = NULL;
649 unsigned int chconfig;
650 1036
651 dev = chip->dev; 1037 dev = chip->dev;
652 1038
@@ -695,303 +1081,48 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
695 protocol <= 2) 1081 protocol <= 2)
696 protocol = UAC_VERSION_1; 1082 protocol = UAC_VERSION_1;
697 1083
698 chconfig = 0;
699 /* get audio formats */
700 switch (protocol) { 1084 switch (protocol) {
701 default: 1085 default:
702 dev_dbg(&dev->dev, "%u:%d: unknown interface protocol %#02x, assuming v1\n", 1086 dev_dbg(&dev->dev, "%u:%d: unknown interface protocol %#02x, assuming v1\n",
703 iface_no, altno, protocol); 1087 iface_no, altno, protocol);
704 protocol = UAC_VERSION_1; 1088 protocol = UAC_VERSION_1;
705 /* fall through */ 1089 /* fall through */
706 1090 case UAC_VERSION_1:
707 case UAC_VERSION_1: { 1091 /* fall through */
708 struct uac1_as_header_descriptor *as =
709 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
710 struct uac_input_terminal_descriptor *iterm;
711
712 if (!as) {
713 dev_err(&dev->dev,
714 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
715 iface_no, altno);
716 continue;
717 }
718
719 if (as->bLength < sizeof(*as)) {
720 dev_err(&dev->dev,
721 "%u:%d : invalid UAC_AS_GENERAL desc\n",
722 iface_no, altno);
723 continue;
724 }
725
726 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
727
728 iterm = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
729 as->bTerminalLink);
730 if (iterm) {
731 num_channels = iterm->bNrChannels;
732 chconfig = le16_to_cpu(iterm->wChannelConfig);
733 }
734
735 break;
736 }
737
738 case UAC_VERSION_2: { 1092 case UAC_VERSION_2: {
739 struct uac2_input_terminal_descriptor *input_term; 1093 int bm_quirk = 0;
740 struct uac2_output_terminal_descriptor *output_term;
741 struct uac2_as_header_descriptor *as =
742 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
743
744 if (!as) {
745 dev_err(&dev->dev,
746 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
747 iface_no, altno);
748 continue;
749 }
750
751 if (as->bLength < sizeof(*as)) {
752 dev_err(&dev->dev,
753 "%u:%d : invalid UAC_AS_GENERAL desc\n",
754 iface_no, altno);
755 continue;
756 }
757
758 num_channels = as->bNrChannels;
759 format = le32_to_cpu(as->bmFormats);
760 chconfig = le32_to_cpu(as->bmChannelConfig);
761
762 /* lookup the terminal associated to this interface
763 * to extract the clock */
764 input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
765 as->bTerminalLink);
766 if (input_term) {
767 clock = input_term->bCSourceID;
768 if (!chconfig && (num_channels == input_term->bNrChannels))
769 chconfig = le32_to_cpu(input_term->bmChannelConfig);
770 break;
771 }
772
773 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
774 as->bTerminalLink);
775 if (output_term) {
776 clock = output_term->bCSourceID;
777 break;
778 }
779
780 dev_err(&dev->dev,
781 "%u:%d : bogus bTerminalLink %d\n",
782 iface_no, altno, as->bTerminalLink);
783 continue;
784 }
785
786 case UAC_VERSION_3: {
787 struct uac3_input_terminal_descriptor *input_term;
788 struct uac3_output_terminal_descriptor *output_term;
789 struct uac3_as_header_descriptor *as;
790 struct uac3_cluster_header_descriptor *cluster;
791 struct uac3_hc_descriptor_header hc_header;
792 u16 cluster_id, wLength;
793
794 as = snd_usb_find_csint_desc(alts->extra,
795 alts->extralen,
796 NULL, UAC_AS_GENERAL);
797
798 if (!as) {
799 dev_err(&dev->dev,
800 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
801 iface_no, altno);
802 continue;
803 }
804
805 if (as->bLength < sizeof(*as)) {
806 dev_err(&dev->dev,
807 "%u:%d : invalid UAC_AS_GENERAL desc\n",
808 iface_no, altno);
809 continue;
810 }
811
812 cluster_id = le16_to_cpu(as->wClusterDescrID);
813 if (!cluster_id) {
814 dev_err(&dev->dev,
815 "%u:%d : no cluster descriptor\n",
816 iface_no, altno);
817 continue;
818 }
819
820 /*
821 * Get number of channels and channel map through
822 * High Capability Cluster Descriptor
823 *
824 * First step: get High Capability header and
825 * read size of Cluster Descriptor
826 */
827 err = snd_usb_ctl_msg(chip->dev,
828 usb_rcvctrlpipe(chip->dev, 0),
829 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
830 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
831 cluster_id,
832 snd_usb_ctrl_intf(chip),
833 &hc_header, sizeof(hc_header));
834 if (err < 0)
835 return err;
836 else if (err != sizeof(hc_header)) {
837 dev_err(&dev->dev,
838 "%u:%d : can't get High Capability descriptor\n",
839 iface_no, altno);
840 return -EIO;
841 }
842
843 /*
844 * Second step: allocate needed amount of memory
845 * and request Cluster Descriptor
846 */
847 wLength = le16_to_cpu(hc_header.wLength);
848 cluster = kzalloc(wLength, GFP_KERNEL);
849 if (!cluster)
850 return -ENOMEM;
851 err = snd_usb_ctl_msg(chip->dev,
852 usb_rcvctrlpipe(chip->dev, 0),
853 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
854 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
855 cluster_id,
856 snd_usb_ctrl_intf(chip),
857 cluster, wLength);
858 if (err < 0) {
859 kfree(cluster);
860 return err;
861 } else if (err != wLength) {
862 dev_err(&dev->dev,
863 "%u:%d : can't get Cluster Descriptor\n",
864 iface_no, altno);
865 kfree(cluster);
866 return -EIO;
867 }
868
869 num_channels = cluster->bNrChannels;
870 chmap_v3 = convert_chmap_v3(cluster);
871
872 kfree(cluster);
873
874 format = le64_to_cpu(as->bmFormats);
875
876 /* lookup the terminal associated to this interface
877 * to extract the clock */
878 input_term = snd_usb_find_input_terminal_descriptor(
879 chip->ctrl_intf,
880 as->bTerminalLink);
881
882 if (input_term) {
883 clock = input_term->bCSourceID;
884 break;
885 }
886
887 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
888 as->bTerminalLink);
889 if (output_term) {
890 clock = output_term->bCSourceID;
891 break;
892 }
893
894 dev_err(&dev->dev,
895 "%u:%d : bogus bTerminalLink %d\n",
896 iface_no, altno, as->bTerminalLink);
897 continue;
898 }
899 }
900
901 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
902 /* get format type */
903 fmt = snd_usb_find_csint_desc(alts->extra,
904 alts->extralen,
905 NULL, UAC_FORMAT_TYPE);
906 if (!fmt) {
907 dev_err(&dev->dev,
908 "%u:%d : no UAC_FORMAT_TYPE desc\n",
909 iface_no, altno);
910 continue;
911 }
912 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8))
913 || ((protocol == UAC_VERSION_2) &&
914 (fmt->bLength < 6))) {
915 dev_err(&dev->dev,
916 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
917 iface_no, altno);
918 continue;
919 }
920 1094
921 /* 1095 /*
922 * Blue Microphones workaround: The last altsetting is 1096 * Blue Microphones workaround: The last altsetting is
923 * identical with the previous one, except for a larger 1097 * identical with the previous one, except for a larger
924 * packet size, but is actually a mislabeled two-channel 1098 * packet size, but is actually a mislabeled two-channel
925 * setting; ignore it. 1099 * setting; ignore it.
1100 *
1101 * Part 1: prepare quirk flag
926 */ 1102 */
927 if (fmt->bNrChannels == 1 && 1103 if (altno == 2 && num == 3 &&
928 fmt->bSubframeSize == 2 &&
929 altno == 2 && num == 3 &&
930 fp && fp->altsetting == 1 && fp->channels == 1 && 1104 fp && fp->altsetting == 1 && fp->channels == 1 &&
931 fp->formats == SNDRV_PCM_FMTBIT_S16_LE && 1105 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
932 protocol == UAC_VERSION_1 && 1106 protocol == UAC_VERSION_1 &&
933 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 1107 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
934 fp->maxpacksize * 2) 1108 fp->maxpacksize * 2)
935 continue; 1109 bm_quirk = 1;
936 }
937
938 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
939 if (!fp)
940 return -ENOMEM;
941 1110
942 fp->iface = iface_no; 1111 fp = snd_usb_get_audioformat_uac12(chip, alts, protocol,
943 fp->altsetting = altno; 1112 iface_no, i, altno,
944 fp->altset_idx = i; 1113 stream, bm_quirk);
945 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; 1114 break;
946 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 1115 }
947 fp->datainterval = snd_usb_parse_datainterval(chip, alts); 1116 case UAC_VERSION_3:
948 fp->protocol = protocol; 1117 fp = snd_usb_get_audioformat_uac3(chip, alts,
949 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 1118 iface_no, i, altno, stream);
950 fp->channels = num_channels; 1119 break;
951 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
952 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
953 * (fp->maxpacksize & 0x7ff);
954 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
955 fp->clock = clock;
956 INIT_LIST_HEAD(&fp->list);
957
958 /* some quirks for attributes here */
959 snd_usb_audioformat_attributes_quirk(chip, fp, stream);
960
961 /* ok, let's parse further... */
962 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
963 if (snd_usb_parse_audio_format(chip, fp, format,
964 fmt, stream) < 0) {
965 kfree(fp->rate_table);
966 kfree(fp);
967 fp = NULL;
968 continue;
969 }
970 } else {
971 struct uac3_as_header_descriptor *as;
972
973 as = snd_usb_find_csint_desc(alts->extra,
974 alts->extralen,
975 NULL, UAC_AS_GENERAL);
976
977 if (snd_usb_parse_audio_format_v3(chip, fp, as,
978 stream) < 0) {
979 kfree(fp->rate_table);
980 kfree(fp);
981 fp = NULL;
982 continue;
983 }
984 } 1120 }
985 1121
986 /* Create chmap */ 1122 if (!fp)
987 if (fp->channels != num_channels) 1123 continue;
988 chconfig = 0; 1124 else if (IS_ERR(fp))
989 1125 return PTR_ERR(fp);
990 if (protocol == UAC_VERSION_3)
991 fp->chmap = chmap_v3;
992 else
993 fp->chmap = convert_chmap(fp->channels, chconfig,
994 protocol);
995 1126
996 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint); 1127 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint);
997 err = snd_usb_add_audio_stream(chip, stream, fp); 1128 err = snd_usb_add_audio_stream(chip, stream, fp);