xref: /linux-6.15/include/linux/usb/audio-v3.h (revision ce63b2c8)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2017 Ruslan Bilovol <[email protected]>
4  *
5  * This file holds USB constants and structures defined
6  * by the USB DEVICE CLASS DEFINITION FOR AUDIO DEVICES Release 3.0.
7  */
8 
9 #ifndef __LINUX_USB_AUDIO_V3_H
10 #define __LINUX_USB_AUDIO_V3_H
11 
12 #include <linux/types.h>
13 
14 /*
15  * v1.0, v2.0 and v3.0 of this standard have many things in common. For the rest
16  * of the definitions, please refer to audio.h and audio-v2.h
17  */
18 
19 /* All High Capability descriptors have these 2 fields at the beginning */
20 struct uac3_hc_descriptor_header {
21 	__le16 wLength;
22 	__u8 bDescriptorType;
23 	__u8 bDescriptorSubtype;
24 	__le16 wDescriptorID;
25 } __attribute__ ((packed));
26 
27 /* 4.3.1 CLUSTER DESCRIPTOR HEADER */
28 struct uac3_cluster_header_descriptor {
29 	__le16 wLength;
30 	__u8 bDescriptorType;
31 	__u8 bDescriptorSubtype;
32 	__le16 wDescriptorID;
33 	__u8 bNrChannels;
34 } __attribute__ ((packed));
35 
36 /* 4.3.2.1 SEGMENTS */
37 struct uac3_cluster_segment_descriptor {
38 	__le16 wLength;
39 	__u8 bSegmentType;
40 	/* __u8[0]; segment-specific data */
41 } __attribute__ ((packed));
42 
43 /* 4.3.2.1.1 END SEGMENT */
44 struct uac3_cluster_end_segment_descriptor {
45 	__le16 wLength;
46 	__u8 bSegmentType;		/* Constant END_SEGMENT */
47 } __attribute__ ((packed));
48 
49 /* 4.3.2.1.3.1 INFORMATION SEGMENT */
50 struct uac3_cluster_information_segment_descriptor {
51 	__le16 wLength;
52 	__u8 bSegmentType;
53 	__u8 bChPurpose;
54 	__u8 bChRelationship;
55 	__u8 bChGroupID;
56 } __attribute__ ((packed));
57 
58 /* 4.5.2 CLASS-SPECIFIC AC INTERFACE DESCRIPTOR */
59 struct uac3_ac_header_descriptor {
60 	__u8 bLength;			/* 10 */
61 	__u8 bDescriptorType;		/* CS_INTERFACE descriptor type */
62 	__u8 bDescriptorSubtype;	/* HEADER descriptor subtype */
63 	__u8 bCategory;
64 
65 	/* includes Clock Source, Unit, Terminal, and Power Domain desc. */
66 	__le16 wTotalLength;
67 
68 	__le32 bmControls;
69 } __attribute__ ((packed));
70 
71 /* 4.5.2.1 INPUT TERMINAL DESCRIPTOR */
72 struct uac3_input_terminal_descriptor {
73 	__u8 bLength;
74 	__u8 bDescriptorType;
75 	__u8 bDescriptorSubtype;
76 	__u8 bTerminalID;
77 	__le16 wTerminalType;
78 	__u8 bAssocTerminal;
79 	__u8 bCSourceID;
80 	__le32 bmControls;
81 	__le16 wClusterDescrID;
82 	__le16 wExTerminalDescrID;
83 	__le16 wConnectorsDescrID;
84 	__le16 wTerminalDescrStr;
85 } __attribute__((packed));
86 
87 /* 4.5.2.2 OUTPUT TERMINAL DESCRIPTOR */
88 struct uac3_output_terminal_descriptor {
89 	__u8 bLength;
90 	__u8 bDescriptorType;
91 	__u8 bDescriptorSubtype;
92 	__u8 bTerminalID;
93 	__le16 wTerminalType;
94 	__u8 bAssocTerminal;
95 	__u8 bSourceID;
96 	__u8 bCSourceID;
97 	__le32 bmControls;
98 	__le16 wExTerminalDescrID;
99 	__le16 wConnectorsDescrID;
100 	__le16 wTerminalDescrStr;
101 } __attribute__((packed));
102 
103 /* 4.5.2.7 FEATURE UNIT DESCRIPTOR */
104 struct uac3_feature_unit_descriptor {
105 	__u8 bLength;
106 	__u8 bDescriptorType;
107 	__u8 bDescriptorSubtype;
108 	__u8 bUnitID;
109 	__u8 bSourceID;
110 	/* bmaControls is actually u32,
111 	 * but u8 is needed for the hybrid parser */
112 	__u8 bmaControls[0]; /* variable length */
113 	/* wFeatureDescrStr omitted */
114 } __attribute__((packed));
115 
116 #define UAC3_DT_FEATURE_UNIT_SIZE(ch)		(7 + ((ch) + 1) * 4)
117 
118 /* As above, but more useful for defining your own descriptors */
119 #define DECLARE_UAC3_FEATURE_UNIT_DESCRIPTOR(ch)		\
120 struct uac3_feature_unit_descriptor_##ch {			\
121 	__u8 bLength;						\
122 	__u8 bDescriptorType;					\
123 	__u8 bDescriptorSubtype;				\
124 	__u8 bUnitID;						\
125 	__u8 bSourceID;						\
126 	__le32 bmaControls[ch + 1];				\
127 	__le16 wFeatureDescrStr;				\
128 } __attribute__ ((packed))
129 
130 /* 4.5.2.12 CLOCK SOURCE DESCRIPTOR */
131 struct uac3_clock_source_descriptor {
132 	__u8 bLength;
133 	__u8 bDescriptorType;
134 	__u8 bDescriptorSubtype;
135 	__u8 bClockID;
136 	__u8 bmAttributes;
137 	__le32 bmControls;
138 	__u8 bReferenceTerminal;
139 	__le16 wClockSourceStr;
140 } __attribute__((packed));
141 
142 /* bmAttribute fields */
143 #define UAC3_CLOCK_SOURCE_TYPE_EXT	0x0
144 #define UAC3_CLOCK_SOURCE_TYPE_INT	0x1
145 #define UAC3_CLOCK_SOURCE_ASYNC		(0 << 2)
146 #define UAC3_CLOCK_SOURCE_SYNCED_TO_SOF	(1 << 1)
147 
148 /* 4.5.2.13 CLOCK SELECTOR DESCRIPTOR */
149 struct uac3_clock_selector_descriptor {
150 	__u8 bLength;
151 	__u8 bDescriptorType;
152 	__u8 bDescriptorSubtype;
153 	__u8 bClockID;
154 	__u8 bNrInPins;
155 	__u8 baCSourceID[];
156 	/* bmControls and wCSelectorDescrStr omitted */
157 } __attribute__((packed));
158 
159 /* 4.5.2.14 CLOCK MULTIPLIER DESCRIPTOR */
160 struct uac3_clock_multiplier_descriptor {
161 	__u8 bLength;
162 	__u8 bDescriptorType;
163 	__u8 bDescriptorSubtype;
164 	__u8 bClockID;
165 	__u8 bCSourceID;
166 	__le32 bmControls;
167 	__le16 wCMultiplierDescrStr;
168 } __attribute__((packed));
169 
170 /* 4.5.2.15 POWER DOMAIN DESCRIPTOR */
171 struct uac3_power_domain_descriptor {
172 	__u8 bLength;
173 	__u8 bDescriptorType;
174 	__u8 bDescriptorSubtype;
175 	__u8 bPowerDomainID;
176 	__le16 waRecoveryTime1;
177 	__le16 waRecoveryTime2;
178 	__u8 bNrEntities;
179 	__u8 baEntityID[];
180 	/* wPDomainDescrStr omitted */
181 } __attribute__((packed));
182 
183 /* As above, but more useful for defining your own descriptors */
184 #define DECLARE_UAC3_POWER_DOMAIN_DESCRIPTOR(n)			\
185 struct uac3_power_domain_descriptor_##n {			\
186 	__u8 bLength;						\
187 	__u8 bDescriptorType;					\
188 	__u8 bDescriptorSubtype;				\
189 	__u8 bPowerDomainID;					\
190 	__le16 waRecoveryTime1;					\
191 	__le16 waRecoveryTime2;					\
192 	__u8 bNrEntities;					\
193 	__u8 baEntityID[n];					\
194 	__le16 wPDomainDescrStr;					\
195 } __attribute__ ((packed))
196 
197 /* 4.7.2 CLASS-SPECIFIC AS INTERFACE DESCRIPTOR */
198 struct uac3_as_header_descriptor {
199 	__u8 bLength;
200 	__u8 bDescriptorType;
201 	__u8 bDescriptorSubtype;
202 	__u8 bTerminalLink;
203 	__le32 bmControls;
204 	__le16 wClusterDescrID;
205 	__le64 bmFormats;
206 	__u8 bSubslotSize;
207 	__u8 bBitResolution;
208 	__le16 bmAuxProtocols;
209 	__u8 bControlSize;
210 } __attribute__((packed));
211 
212 #define UAC3_FORMAT_TYPE_I_RAW_DATA	(1 << 6)
213 
214 /* 4.8.1.2 CLASS-SPECIFIC AS ISOCHRONOUS AUDIO DATA ENDPOINT DESCRIPTOR */
215 struct uac3_iso_endpoint_descriptor {
216 	__u8 bLength;
217 	__u8 bDescriptorType;
218 	__u8 bDescriptorSubtype;
219 	__le32 bmControls;
220 	__u8 bLockDelayUnits;
221 	__le16 wLockDelay;
222 } __attribute__((packed));
223 
224 /* 6.1 INTERRUPT DATA MESSAGE */
225 struct uac3_interrupt_data_msg {
226 	__u8 bInfo;
227 	__u8 bSourceType;
228 	__le16 wValue;
229 	__le16 wIndex;
230 } __attribute__((packed));
231 
232 /* A.2 AUDIO AUDIO FUNCTION SUBCLASS CODES */
233 #define UAC3_FUNCTION_SUBCLASS_UNDEFINED	0x00
234 #define UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0	0x01
235 /* BADD profiles */
236 #define UAC3_FUNCTION_SUBCLASS_GENERIC_IO	0x20
237 #define UAC3_FUNCTION_SUBCLASS_HEADPHONE	0x21
238 #define UAC3_FUNCTION_SUBCLASS_SPEAKER		0x22
239 #define UAC3_FUNCTION_SUBCLASS_MICROPHONE	0x23
240 #define UAC3_FUNCTION_SUBCLASS_HEADSET		0x24
241 #define UAC3_FUNCTION_SUBCLASS_HEADSET_ADAPTER	0x25
242 #define UAC3_FUNCTION_SUBCLASS_SPEAKERPHONE	0x26
243 
244 /* A.7 AUDIO FUNCTION CATEGORY CODES */
245 #define UAC3_FUNCTION_SUBCLASS_UNDEFINED	0x00
246 #define UAC3_FUNCTION_DESKTOP_SPEAKER		0x01
247 #define UAC3_FUNCTION_HOME_THEATER		0x02
248 #define UAC3_FUNCTION_MICROPHONE		0x03
249 #define UAC3_FUNCTION_HEADSET			0x04
250 #define UAC3_FUNCTION_TELEPHONE			0x05
251 #define UAC3_FUNCTION_CONVERTER			0x06
252 #define UAC3_FUNCTION_SOUND_RECORDER		0x07
253 #define UAC3_FUNCTION_IO_BOX			0x08
254 #define UAC3_FUNCTION_MUSICAL_INSTRUMENT	0x09
255 #define UAC3_FUNCTION_PRO_AUDIO			0x0a
256 #define UAC3_FUNCTION_AUDIO_VIDEO		0x0b
257 #define UAC3_FUNCTION_CONTROL_PANEL		0x0c
258 #define UAC3_FUNCTION_HEADPHONE			0x0d
259 #define UAC3_FUNCTION_GENERIC_SPEAKER		0x0e
260 #define UAC3_FUNCTION_HEADSET_ADAPTER		0x0f
261 #define UAC3_FUNCTION_SPEAKERPHONE		0x10
262 #define UAC3_FUNCTION_OTHER			0xff
263 
264 /* A.8 AUDIO CLASS-SPECIFIC DESCRIPTOR TYPES */
265 #define UAC3_CS_UNDEFINED		0x20
266 #define UAC3_CS_DEVICE			0x21
267 #define UAC3_CS_CONFIGURATION		0x22
268 #define UAC3_CS_STRING			0x23
269 #define UAC3_CS_INTERFACE		0x24
270 #define UAC3_CS_ENDPOINT		0x25
271 #define UAC3_CS_CLUSTER			0x26
272 
273 /* A.10 CLUSTER DESCRIPTOR SEGMENT TYPES */
274 #define UAC3_SEGMENT_UNDEFINED		0x00
275 #define UAC3_CLUSTER_DESCRIPTION	0x01
276 #define UAC3_CLUSTER_VENDOR_DEFINED	0x1F
277 #define UAC3_CHANNEL_INFORMATION	0x20
278 #define UAC3_CHANNEL_AMBISONIC		0x21
279 #define UAC3_CHANNEL_DESCRIPTION	0x22
280 #define UAC3_CHANNEL_VENDOR_DEFINED	0xFE
281 #define UAC3_END_SEGMENT		0xFF
282 
283 /* A.11 CHANNEL PURPOSE DEFINITIONS */
284 #define UAC3_PURPOSE_UNDEFINED		0x00
285 #define UAC3_PURPOSE_GENERIC_AUDIO	0x01
286 #define UAC3_PURPOSE_VOICE		0x02
287 #define UAC3_PURPOSE_SPEECH		0x03
288 #define UAC3_PURPOSE_AMBIENT		0x04
289 #define UAC3_PURPOSE_REFERENCE		0x05
290 #define UAC3_PURPOSE_ULTRASONIC		0x06
291 #define UAC3_PURPOSE_VIBROKINETIC	0x07
292 #define UAC3_PURPOSE_NON_AUDIO		0xFF
293 
294 /* A.12 CHANNEL RELATIONSHIP DEFINITIONS */
295 #define UAC3_CH_RELATIONSHIP_UNDEFINED	0x00
296 #define UAC3_CH_MONO			0x01
297 #define UAC3_CH_LEFT			0x02
298 #define UAC3_CH_RIGHT			0x03
299 #define UAC3_CH_ARRAY			0x04
300 #define UAC3_CH_PATTERN_X		0x20
301 #define UAC3_CH_PATTERN_Y		0x21
302 #define UAC3_CH_PATTERN_A		0x22
303 #define UAC3_CH_PATTERN_B		0x23
304 #define UAC3_CH_PATTERN_M		0x24
305 #define UAC3_CH_PATTERN_S		0x25
306 #define UAC3_CH_FRONT_LEFT		0x80
307 #define UAC3_CH_FRONT_RIGHT		0x81
308 #define UAC3_CH_FRONT_CENTER		0x82
309 #define UAC3_CH_FRONT_LEFT_OF_CENTER	0x83
310 #define UAC3_CH_FRONT_RIGHT_OF_CENTER	0x84
311 #define UAC3_CH_FRONT_WIDE_LEFT		0x85
312 #define UAC3_CH_FRONT_WIDE_RIGHT	0x86
313 #define UAC3_CH_SIDE_LEFT		0x87
314 #define UAC3_CH_SIDE_RIGHT		0x88
315 #define UAC3_CH_SURROUND_ARRAY_LEFT	0x89
316 #define UAC3_CH_SURROUND_ARRAY_RIGHT	0x8A
317 #define UAC3_CH_BACK_LEFT		0x8B
318 #define UAC3_CH_BACK_RIGHT		0x8C
319 #define UAC3_CH_BACK_CENTER		0x8D
320 #define UAC3_CH_BACK_LEFT_OF_CENTER	0x8E
321 #define UAC3_CH_BACK_RIGHT_OF_CENTER	0x8F
322 #define UAC3_CH_BACK_WIDE_LEFT		0x90
323 #define UAC3_CH_BACK_WIDE_RIGHT		0x91
324 #define UAC3_CH_TOP_CENTER		0x92
325 #define UAC3_CH_TOP_FRONT_LEFT		0x93
326 #define UAC3_CH_TOP_FRONT_RIGHT		0x94
327 #define UAC3_CH_TOP_FRONT_CENTER	0x95
328 #define UAC3_CH_TOP_FRONT_LOC		0x96
329 #define UAC3_CH_TOP_FRONT_ROC		0x97
330 #define UAC3_CH_TOP_FRONT_WIDE_LEFT	0x98
331 #define UAC3_CH_TOP_FRONT_WIDE_RIGHT	0x99
332 #define UAC3_CH_TOP_SIDE_LEFT		0x9A
333 #define UAC3_CH_TOP_SIDE_RIGHT		0x9B
334 #define UAC3_CH_TOP_SURR_ARRAY_LEFT	0x9C
335 #define UAC3_CH_TOP_SURR_ARRAY_RIGHT	0x9D
336 #define UAC3_CH_TOP_BACK_LEFT		0x9E
337 #define UAC3_CH_TOP_BACK_RIGHT		0x9F
338 #define UAC3_CH_TOP_BACK_CENTER		0xA0
339 #define UAC3_CH_TOP_BACK_LOC		0xA1
340 #define UAC3_CH_TOP_BACK_ROC		0xA2
341 #define UAC3_CH_TOP_BACK_WIDE_LEFT	0xA3
342 #define UAC3_CH_TOP_BACK_WIDE_RIGHT	0xA4
343 #define UAC3_CH_BOTTOM_CENTER		0xA5
344 #define UAC3_CH_BOTTOM_FRONT_LEFT	0xA6
345 #define UAC3_CH_BOTTOM_FRONT_RIGHT	0xA7
346 #define UAC3_CH_BOTTOM_FRONT_CENTER	0xA8
347 #define UAC3_CH_BOTTOM_FRONT_LOC	0xA9
348 #define UAC3_CH_BOTTOM_FRONT_ROC	0xAA
349 #define UAC3_CH_BOTTOM_FRONT_WIDE_LEFT	0xAB
350 #define UAC3_CH_BOTTOM_FRONT_WIDE_RIGHT	0xAC
351 #define UAC3_CH_BOTTOM_SIDE_LEFT	0xAD
352 #define UAC3_CH_BOTTOM_SIDE_RIGHT	0xAE
353 #define UAC3_CH_BOTTOM_SURR_ARRAY_LEFT	0xAF
354 #define UAC3_CH_BOTTOM_SURR_ARRAY_RIGHT	0xB0
355 #define UAC3_CH_BOTTOM_BACK_LEFT	0xB1
356 #define UAC3_CH_BOTTOM_BACK_RIGHT	0xB2
357 #define UAC3_CH_BOTTOM_BACK_CENTER	0xB3
358 #define UAC3_CH_BOTTOM_BACK_LOC		0xB4
359 #define UAC3_CH_BOTTOM_BACK_ROC		0xB5
360 #define UAC3_CH_BOTTOM_BACK_WIDE_LEFT	0xB6
361 #define UAC3_CH_BOTTOM_BACK_WIDE_RIGHT	0xB7
362 #define UAC3_CH_LOW_FREQUENCY_EFFECTS	0xB8
363 #define UAC3_CH_LFE_LEFT		0xB9
364 #define UAC3_CH_LFE_RIGHT		0xBA
365 #define UAC3_CH_HEADPHONE_LEFT		0xBB
366 #define UAC3_CH_HEADPHONE_RIGHT		0xBC
367 
368 /* A.15 AUDIO CLASS-SPECIFIC AC INTERFACE DESCRIPTOR SUBTYPES */
369 /* see audio.h for the rest, which is identical to v1 */
370 #define UAC3_EXTENDED_TERMINAL		0x04
371 #define UAC3_MIXER_UNIT			0x05
372 #define UAC3_SELECTOR_UNIT		0x06
373 #define UAC3_FEATURE_UNIT		0x07
374 #define UAC3_EFFECT_UNIT		0x08
375 #define UAC3_PROCESSING_UNIT		0x09
376 #define UAC3_EXTENSION_UNIT		0x0a
377 #define UAC3_CLOCK_SOURCE		0x0b
378 #define UAC3_CLOCK_SELECTOR		0x0c
379 #define UAC3_CLOCK_MULTIPLIER		0x0d
380 #define UAC3_SAMPLE_RATE_CONVERTER	0x0e
381 #define UAC3_CONNECTORS			0x0f
382 #define UAC3_POWER_DOMAIN		0x10
383 
384 /* A.22 AUDIO CLASS-SPECIFIC REQUEST CODES */
385 /* see audio-v2.h for the rest, which is identical to v2 */
386 #define UAC3_CS_REQ_INTEN			0x04
387 #define UAC3_CS_REQ_STRING			0x05
388 #define UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR	0x06
389 
390 /* A.23.1 AUDIOCONTROL INTERFACE CONTROL SELECTORS */
391 #define UAC3_AC_CONTROL_UNDEFINED		0x00
392 #define UAC3_AC_ACTIVE_INTERFACE_CONTROL	0x01
393 #define UAC3_AC_POWER_DOMAIN_CONTROL		0x02
394 
395 #endif /* __LINUX_USB_AUDIO_V3_H */
396