Blame SOURCES/0008-lsusb-Add-support-for-audio-processing-unit-type-spe.patch

67abd2
From e5b6d24c5de9039606953bf8159f94ea6611e84d Mon Sep 17 00:00:00 2001
67abd2
From: Michael Drake <michael.drake@codethink.co.uk>
67abd2
Date: Thu, 7 Jun 2018 11:40:30 +0100
67abd2
Subject: [PATCH 8/9] lsusb: Add support for audio processing unit
67abd2
 type-specific fields.
67abd2
67abd2
Previously the data was rendered as hex as a "Process-specific"
67abd2
array type field.  Now the data is interpreted properly as
67abd2
descriptor fields.
67abd2
67abd2
Signed-off-by: Michael Drake <michael.drake@codethink.co.uk>
67abd2
---
67abd2
 desc-defs.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
67abd2
 1 file changed, 159 insertions(+), 18 deletions(-)
67abd2
67abd2
diff --git a/desc-defs.c b/desc-defs.c
67abd2
index 60cc603..d348abc 100644
67abd2
--- a/desc-defs.c
67abd2
+++ b/desc-defs.c
67abd2
@@ -16,6 +16,15 @@
67abd2
 /** Macro for computing number of elements in array. */
67abd2
 #define ARRAY_LEN(a) ((sizeof(a)) / (sizeof(a[0])))
67abd2
 
67abd2
+/**
67abd2
+ * Undefined descriptor
67abd2
+ *
67abd2
+ * Ensures remaining data is dumped as garbage at end of descriptor.
67abd2
+ */
67abd2
+const struct desc desc_undefined[] = {
67abd2
+	{ .field = NULL }
67abd2
+};
67abd2
+
67abd2
 /** USB Audio Device Class 1 Channel Names.  (Note: Order matters.) */
67abd2
 static const char * const uac1_channel_names[] = {
67abd2
 	"Left Front (L)", "Right Front (R)", "Center Front (C)",
67abd2
@@ -401,10 +410,38 @@ const struct desc * const desc_audio_ac_selector_unit[3] = {
67abd2
 	desc_audio_3_ac_selector_unit,
67abd2
 };
67abd2
 
67abd2
+/** UAC1: Table A-7: Processing Unit Process Types */
67abd2
+static const char * const uac1_proc_unit_types[] = {
67abd2
+	[0] = "Undefined",
67abd2
+	[1] = "Up/Down-mix",
67abd2
+	[2] = "Dolby Prologic",
67abd2
+	[3] = "3D Stereo Extender",
67abd2
+	[4] = "Reverberation",
67abd2
+	[5] = "Chorus",
67abd2
+	[6] = "Dyn Range Comp",
67abd2
+	[7] = NULL
67abd2
+};
67abd2
+
67abd2
+/** UAC1: Up/Down-mix and Dolby Prologic proc unit descriptor extensions Table 4-9, Table 4-10. */
67abd2
+static const struct desc desc_audio_1_ac_proc_unit_extended[] = {
67abd2
+	{ .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
67abd2
+	{ .field = "waModes",          .size = 2, .type = DESC_BITMAP,
67abd2
+			.array = { .array = true, .length_field1 = "bNrModes" } },
67abd2
+	{ .field = NULL }
67abd2
+};
67abd2
+
67abd2
+/** UAC1: Table A-7: Processing Unit Process Types */
67abd2
+static const struct desc_ext desc_audio_1_ac_proc_unit_specific[] = {
67abd2
+	{ .type = 1, .desc = desc_audio_1_ac_proc_unit_extended },
67abd2
+	{ .type = 2, .desc = desc_audio_1_ac_proc_unit_extended },
67abd2
+	{ .desc = NULL }
67abd2
+};
67abd2
+
67abd2
 /** UAC1: 4.3.2.6 Processing Unit Descriptor; Table 4-8. */
67abd2
 static const struct desc desc_audio_1_ac_processing_unit[] = {
67abd2
 	{ .field = "bUnitID",          .size = 1, .type = DESC_NUMBER },
67abd2
-	{ .field = "wProcessType",     .size = 2, .type = DESC_CONSTANT },
67abd2
+	{ .field = "wProcessType",     .size = 2, .type = DESC_NUMBER_STRINGS,
67abd2
+			.number_strings = uac1_proc_unit_types },
67abd2
 	{ .field = "bNrInPins",        .size = 1, .type = DESC_NUMBER },
67abd2
 	{ .field = "baSourceID",       .size = 1, .type = DESC_NUMBER,
67abd2
 			.array = { .array = true, .length_field1 = "bNrInPins" } },
67abd2
@@ -416,15 +453,48 @@ static const struct desc desc_audio_1_ac_processing_unit[] = {
67abd2
 	{ .field = "bmControls",       .size = 1, .type = DESC_BITMAP,
67abd2
 			.array = { .array = true, .length_field1 = "bControlSize" } },
67abd2
 	{ .field = "iProcessing",      .size = 1, .type = DESC_STR_DESC_INDEX },
67abd2
-	{ .field = "Process-specific", .size = 1, .type = DESC_BITMAP,
67abd2
-			.array = { .array = true } },
67abd2
+	{ .field = "Process-specific", .size = 1, .type = DESC_EXTENSION,
67abd2
+		.extension = { .type_field = "wProcessType", .d = desc_audio_1_ac_proc_unit_specific } },
67abd2
+	{ .field = NULL }
67abd2
+};
67abd2
+
67abd2
+/** UAC2: 4.7.2.11.1 Up/Down-mix Processing Unit Descriptor; Table 4-21. */
67abd2
+static const struct desc desc_audio_2_ac_proc_unit_up_down_mix[] = {
67abd2
+	{ .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
67abd2
+	{ .field = "daModes",          .size = 4, .type = DESC_BITMAP,
67abd2
+			.array = { .array = true, .length_field1 = "bNrModes" } },
67abd2
+	{ .field = NULL }
67abd2
+};
67abd2
+
67abd2
+/** UAC2: 4.7.2.11.2 Dolby prologic Processing Unit Descriptor; Table 4-22. */
67abd2
+static const struct desc desc_audio_2_ac_proc_unit_dolby_prologic[] = {
67abd2
+	{ .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
67abd2
+	{ .field = "daModes",          .size = 4, .type = DESC_BITMAP,
67abd2
+			.array = { .array = true, .length_field1 = "bNrModes" } },
67abd2
 	{ .field = NULL }
67abd2
 };
67abd2
 
67abd2
+/** UAC2: Table A-12: Processing Unit Process Types */
67abd2
+static const struct desc_ext desc_audio_2_ac_proc_unit_specific[] = {
67abd2
+	{ .type = 1, .desc = desc_audio_2_ac_proc_unit_up_down_mix },
67abd2
+	{ .type = 2, .desc = desc_audio_2_ac_proc_unit_dolby_prologic },
67abd2
+	{ .desc = NULL }
67abd2
+};
67abd2
+
67abd2
+/** UAC2: Table A-12: Processing Unit Process Types */
67abd2
+static const char * const uac2_proc_unit_types[] = {
67abd2
+	[0] = "Undefined",
67abd2
+	[1] = "Up/Down-mix",
67abd2
+	[2] = "Dolby Prologic",
67abd2
+	[3] = "Stereo Extender",
67abd2
+	[4] = NULL
67abd2
+};
67abd2
+
67abd2
 /** UAC2: 4.7.2.11 Processing Unit Descriptor; Table 4-20. */
67abd2
 static const struct desc desc_audio_2_ac_processing_unit[] = {
67abd2
 	{ .field = "bUnitID",          .size = 1, .type = DESC_NUMBER },
67abd2
-	{ .field = "wProcessType",     .size = 2, .type = DESC_CONSTANT },
67abd2
+	{ .field = "wProcessType",     .size = 2, .type = DESC_NUMBER_STRINGS,
67abd2
+			.number_strings = uac2_proc_unit_types },
67abd2
 	{ .field = "bNrInPins",        .size = 1, .type = DESC_NUMBER },
67abd2
 	{ .field = "baSourceID",       .size = 1, .type = DESC_NUMBER,
67abd2
 			.array = { .array = true, .length_field1 = "bNrInPins" } },
67abd2
@@ -432,34 +502,105 @@ static const struct desc desc_audio_2_ac_processing_unit[] = {
67abd2
 	{ .field = "bmChannelConfig",  .size = 4, .type = DESC_BITMAP_STRINGS,
67abd2
 			.bitmap_strings = { .strings = uac2_channel_names, .count = 26 } },
67abd2
 	{ .field = "iChannelNames",    .size = 1, .type = DESC_STR_DESC_INDEX },
67abd2
-	{ .field = "bControlSize",     .size = 1, .type = DESC_NUMBER },
67abd2
-	{ .field = "bmControls",       .size = 2, .type = DESC_BITMAP,
67abd2
-			.array = { .array = true, .length_field1 = "bControlSize" } },
67abd2
+	{ .field = "bmControls",       .size = 2, .type = DESC_BITMAP },
67abd2
 	{ .field = "iProcessing",      .size = 1, .type = DESC_STR_DESC_INDEX },
67abd2
-	{ .field = "Process-specific", .size = 1, .type = DESC_BITMAP,
67abd2
-			.array = { .array = true } },
67abd2
+	{ .field = "Process-specific", .size = 1, .type = DESC_EXTENSION,
67abd2
+		.extension = { .type_field = "wProcessType", .d = desc_audio_2_ac_proc_unit_specific } },
67abd2
 	{ .field = NULL }
67abd2
 };
67abd2
 
67abd2
-/**
67abd2
- * Undefined descriptor
67abd2
- *
67abd2
- * Ensures remaining data is dumped as garbage at end of descriptor.
67abd2
- */
67abd2
-const struct desc desc_undefined[] = {
67abd2
+/** Processor unit Up/Down-mix bmControls; Human readable bit meanings. */
67abd2
+static const char * const uac3_proc_unit_up_down_mix_bmcontrols[] = {
67abd2
+	[0] = "Mode Select",
67abd2
+	[1] = "Underflow",
67abd2
+	[2] = "Overflow",
67abd2
+	[3] = NULL
67abd2
+};
67abd2
+
67abd2
+/** UAC3: 4.5.2.10.1 Up/Down-mix Processing Unit Descriptor; Table 4-39. */
67abd2
+static const struct desc desc_audio_3_ac_proc_unit_up_down_mix[] = {
67abd2
+	{ .field = "bmControls",       .size = 4, .type = DESC_BMCONTROL_2,
67abd2
+			.bmcontrol = uac3_proc_unit_up_down_mix_bmcontrols },
67abd2
+	{ .field = "bNrModes",         .size = 1, .type = DESC_NUMBER },
67abd2
+	{ .field = "waClusterDescrID", .size = 2, .type = DESC_NUMBER,
67abd2
+			.array = { .array = true, .length_field1 = "bNrModes" } },
67abd2
+	{ .field = NULL }
67abd2
+};
67abd2
+
67abd2
+/** Processor unit stereo extender bmControls; Human readable bit meanings. */
67abd2
+static const char * const uac3_proc_unit_stereo_extender_bmcontrols[] = {
67abd2
+	[0] = "Width",
67abd2
+	[1] = "Underflow",
67abd2
+	[2] = "Overflow",
67abd2
+	[3] = NULL
67abd2
+};
67abd2
+
67abd2
+/** UAC3: 4.5.2.10.2 Stereo Extender Processing Unit Descriptor; Table 4-40. */
67abd2
+static const struct desc desc_audio_3_ac_proc_unit_stereo_extender[] = {
67abd2
+	{ .field = "bmControls", .size = 4, .type = DESC_BMCONTROL_2,
67abd2
+			.bmcontrol = uac3_proc_unit_stereo_extender_bmcontrols },
67abd2
+	{ .field = NULL }
67abd2
+};
67abd2
+
67abd2
+/** UAC3: 4.5.2.10.3 Multi Func Proc Unit Descriptor; Algorithms; Table 4-41. */
67abd2
+static const char *uac3_proc_unit_multi_func_algorithms[] = {
67abd2
+	[0] = "Algorithm Undefined.",
67abd2
+	[1] = "Beam Forming.",
67abd2
+	[2] = "Acoustic Echo Cancellation.",
67abd2
+	[3] = "Active Noise Cancellation.",
67abd2
+	[4] = "Blind Source Separation.",
67abd2
+	[5] = "Noise Suppression/Reduction.",
67abd2
+	[6] = NULL
67abd2
+};
67abd2
+
67abd2
+/** Processor unit Multi Func bmControls; Human readable bit meanings. */
67abd2
+static const char * const uac3_proc_unit_multi_func_bmcontrols[] = {
67abd2
+	[0] = "Underflow",
67abd2
+	[1] = "Overflow",
67abd2
+	[2] = NULL
67abd2
+};
67abd2
+
67abd2
+/** UAC3: 4.5.2.10.3 Multi Function Processing Unit Descriptor; Table 4-41. */
67abd2
+static const struct desc desc_audio_3_ac_proc_unit_multi_function[] = {
67abd2
+	{ .field = "bmControls",       .size = 4, .type = DESC_BMCONTROL_2,
67abd2
+			.bmcontrol = uac3_proc_unit_multi_func_bmcontrols },
67abd2
+	{ .field = "wClusterDescrID",  .size = 2, .type = DESC_NUMBER, },
67abd2
+	{ .field = "bmAlgorithms", .size = 4, .type = DESC_BITMAP_STRINGS,
67abd2
+			.bitmap_strings = {
67abd2
+				.strings = uac3_proc_unit_multi_func_algorithms,
67abd2
+				.count = 6
67abd2
+			} },
67abd2
 	{ .field = NULL }
67abd2
 };
67abd2
 
67abd2
+/** UAC3: Table A-20: Processing Unit Process Types */
67abd2
+static const char * const uac3_proc_unit_types[] = {
67abd2
+	[0] = "Undefined",
67abd2
+	[1] = "Up/Down-mix",
67abd2
+	[2] = "Stereo Extender",
67abd2
+	[3] = "Multi-Function",
67abd2
+	[4] = NULL
67abd2
+};
67abd2
+
67abd2
+/** UAC3: Table A-20: Processing Unit Process Types */
67abd2
+static const struct desc_ext desc_audio_3_ac_proc_unit_specific[] = {
67abd2
+	{ .type = 1, .desc = desc_audio_3_ac_proc_unit_up_down_mix },
67abd2
+	{ .type = 2, .desc = desc_audio_3_ac_proc_unit_stereo_extender },
67abd2
+	{ .type = 3, .desc = desc_audio_3_ac_proc_unit_multi_function },
67abd2
+	{ .desc = NULL }
67abd2
+};
67abd2
+
67abd2
 /** UAC3: 4.5.2.10 Processing Unit Descriptor; Table 4-38. */
67abd2
 static const struct desc desc_audio_3_ac_processing_unit[] = {
67abd2
 	{ .field = "bUnitID",             .size = 1, .type = DESC_NUMBER },
67abd2
-	{ .field = "wProcessType",        .size = 2, .type = DESC_CONSTANT },
67abd2
+	{ .field = "wProcessType",        .size = 2, .type = DESC_NUMBER_STRINGS,
67abd2
+			.number_strings = uac3_proc_unit_types },
67abd2
 	{ .field = "bNrInPins",           .size = 1, .type = DESC_NUMBER },
67abd2
 	{ .field = "baSourceID",          .size = 1, .type = DESC_NUMBER,
67abd2
 			.array = { .array = true, .length_field1 = "bNrInPins" } },
67abd2
 	{ .field = "wProcessingDescrStr", .size = 2, .type = DESC_CS_STR_DESC_ID },
67abd2
-	{ .field = "Process-specific",    .size = 1, .type = DESC_BITMAP,
67abd2
-			.array = { .array = true } },
67abd2
+	{ .field = "Process-specific",    .size = 1, .type = DESC_EXTENSION,
67abd2
+		.extension = { .type_field = "wProcessType", .d = desc_audio_3_ac_proc_unit_specific } },
67abd2
 	{ .field = NULL }
67abd2
 };
67abd2
 
67abd2
-- 
67abd2
2.14.4
67abd2