audio-v2.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*
  2. * Copyright (c) 2010 Daniel Mack <daniel@caiaq.de>
  3. *
  4. * This software is distributed under the terms of the GNU General Public
  5. * License ("GPL") version 2, as published by the Free Software Foundation.
  6. *
  7. * This file holds USB constants and structures defined
  8. * by the USB Device Class Definition for Audio Devices in version 2.0.
  9. * Comments below reference relevant sections of the documents contained
  10. * in http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
  11. */
  12. #ifndef __LINUX_USB_AUDIO_V2_H
  13. #define __LINUX_USB_AUDIO_V2_H
  14. #include <linux/types.h>
  15. /* v1.0 and v2.0 of this standard have many things in common. For the rest
  16. * of the definitions, please refer to audio.h */
  17. /*
  18. * bmControl field decoders
  19. *
  20. * From the USB Audio spec v2.0:
  21. *
  22. * bmaControls() is a (ch+1)-element array of 4-byte bitmaps,
  23. * each containing a set of bit pairs. If a Control is present,
  24. * it must be Host readable. If a certain Control is not
  25. * present then the bit pair must be set to 0b00.
  26. * If a Control is present but read-only, the bit pair must be
  27. * set to 0b01. If a Control is also Host programmable, the bit
  28. * pair must be set to 0b11. The value 0b10 is not allowed.
  29. *
  30. */
  31. static inline bool uac2_control_is_readable(u32 bmControls, u8 control)
  32. {
  33. return (bmControls >> (control * 2)) & 0x1;
  34. }
  35. static inline bool uac2_control_is_writeable(u32 bmControls, u8 control)
  36. {
  37. return (bmControls >> (control * 2)) & 0x2;
  38. }
  39. /* 4.7.2 Class-Specific AC Interface Descriptor */
  40. struct uac2_ac_header_descriptor {
  41. __u8 bLength; /* 9 */
  42. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  43. __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
  44. __le16 bcdADC; /* 0x0200 */
  45. __u8 bCategory;
  46. __le16 wTotalLength; /* includes Unit and Terminal desc. */
  47. __u8 bmControls;
  48. } __packed;
  49. /* 2.3.1.6 Type I Format Type Descriptor (Frmts20 final.pdf)*/
  50. struct uac2_format_type_i_descriptor {
  51. __u8 bLength; /* in bytes: 6 */
  52. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  53. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  54. __u8 bFormatType; /* FORMAT_TYPE_1 */
  55. __u8 bSubslotSize; /* {1,2,3,4} */
  56. __u8 bBitResolution;
  57. } __packed;
  58. /* 4.7.2.1 Clock Source Descriptor */
  59. struct uac_clock_source_descriptor {
  60. __u8 bLength;
  61. __u8 bDescriptorType;
  62. __u8 bDescriptorSubtype;
  63. __u8 bClockID;
  64. __u8 bmAttributes;
  65. __u8 bmControls;
  66. __u8 bAssocTerminal;
  67. __u8 iClockSource;
  68. } __attribute__((packed));
  69. /* bmAttribute fields */
  70. #define UAC_CLOCK_SOURCE_TYPE_EXT 0x0
  71. #define UAC_CLOCK_SOURCE_TYPE_INT_FIXED 0x1
  72. #define UAC_CLOCK_SOURCE_TYPE_INT_VAR 0x2
  73. #define UAC_CLOCK_SOURCE_TYPE_INT_PROG 0x3
  74. #define UAC_CLOCK_SOURCE_SYNCED_TO_SOF (1 << 2)
  75. /* 4.7.2.2 Clock Source Descriptor */
  76. struct uac_clock_selector_descriptor {
  77. __u8 bLength;
  78. __u8 bDescriptorType;
  79. __u8 bDescriptorSubtype;
  80. __u8 bClockID;
  81. __u8 bNrInPins;
  82. __u8 baCSourceID[];
  83. /* bmControls, bAssocTerminal and iClockSource omitted */
  84. } __attribute__((packed));
  85. /* 4.7.2.3 Clock Multiplier Descriptor */
  86. struct uac_clock_multiplier_descriptor {
  87. __u8 bLength;
  88. __u8 bDescriptorType;
  89. __u8 bDescriptorSubtype;
  90. __u8 bClockID;
  91. __u8 bCSourceID;
  92. __u8 bmControls;
  93. __u8 iClockMultiplier;
  94. } __attribute__((packed));
  95. /* 4.7.2.4 Input terminal descriptor */
  96. struct uac2_input_terminal_descriptor {
  97. __u8 bLength;
  98. __u8 bDescriptorType;
  99. __u8 bDescriptorSubtype;
  100. __u8 bTerminalID;
  101. __u16 wTerminalType;
  102. __u8 bAssocTerminal;
  103. __u8 bCSourceID;
  104. __u8 bNrChannels;
  105. __u32 bmChannelConfig;
  106. __u8 iChannelNames;
  107. __u16 bmControls;
  108. __u8 iTerminal;
  109. } __attribute__((packed));
  110. /* 4.7.2.5 Output terminal descriptor */
  111. struct uac2_output_terminal_descriptor {
  112. __u8 bLength;
  113. __u8 bDescriptorType;
  114. __u8 bDescriptorSubtype;
  115. __u8 bTerminalID;
  116. __u16 wTerminalType;
  117. __u8 bAssocTerminal;
  118. __u8 bSourceID;
  119. __u8 bCSourceID;
  120. __u16 bmControls;
  121. __u8 iTerminal;
  122. } __attribute__((packed));
  123. /* 4.7.2.8 Feature Unit Descriptor */
  124. struct uac2_feature_unit_descriptor {
  125. __u8 bLength;
  126. __u8 bDescriptorType;
  127. __u8 bDescriptorSubtype;
  128. __u8 bUnitID;
  129. __u8 bSourceID;
  130. /* bmaControls is actually u32,
  131. * but u8 is needed for the hybrid parser */
  132. __u8 bmaControls[0]; /* variable length */
  133. } __attribute__((packed));
  134. /* 4.9.2 Class-Specific AS Interface Descriptor */
  135. struct uac2_as_header_descriptor {
  136. __u8 bLength;
  137. __u8 bDescriptorType;
  138. __u8 bDescriptorSubtype;
  139. __u8 bTerminalLink;
  140. __u8 bmControls;
  141. __u8 bFormatType;
  142. __u32 bmFormats;
  143. __u8 bNrChannels;
  144. __u32 bmChannelConfig;
  145. __u8 iChannelNames;
  146. } __attribute__((packed));
  147. #define UAC2_FORMAT_TYPE_I_RAW_DATA (1 << 31)
  148. /* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
  149. struct uac2_iso_endpoint_descriptor {
  150. __u8 bLength; /* in bytes: 8 */
  151. __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
  152. __u8 bDescriptorSubtype; /* EP_GENERAL */
  153. __u8 bmAttributes;
  154. __u8 bmControls;
  155. __u8 bLockDelayUnits;
  156. __le16 wLockDelay;
  157. } __attribute__((packed));
  158. #define UAC2_CONTROL_PITCH (3 << 0)
  159. #define UAC2_CONTROL_DATA_OVERRUN (3 << 2)
  160. #define UAC2_CONTROL_DATA_UNDERRUN (3 << 4)
  161. /* 6.1 Interrupt Data Message */
  162. #define UAC2_INTERRUPT_DATA_MSG_VENDOR (1 << 0)
  163. #define UAC2_INTERRUPT_DATA_MSG_EP (1 << 1)
  164. struct uac2_interrupt_data_msg {
  165. __u8 bInfo;
  166. __u8 bAttribute;
  167. __le16 wValue;
  168. __le16 wIndex;
  169. } __attribute__((packed));
  170. /* A.7 Audio Function Category Codes */
  171. #define UAC2_FUNCTION_SUBCLASS_UNDEFINED 0x00
  172. #define UAC2_FUNCTION_DESKTOP_SPEAKER 0x01
  173. #define UAC2_FUNCTION_HOME_THEATER 0x02
  174. #define UAC2_FUNCTION_MICROPHONE 0x03
  175. #define UAC2_FUNCTION_HEADSET 0x04
  176. #define UAC2_FUNCTION_TELEPHONE 0x05
  177. #define UAC2_FUNCTION_CONVERTER 0x06
  178. #define UAC2_FUNCTION_SOUND_RECORDER 0x07
  179. #define UAC2_FUNCTION_IO_BOX 0x08
  180. #define UAC2_FUNCTION_MUSICAL_INSTRUMENT 0x09
  181. #define UAC2_FUNCTION_PRO_AUDIO 0x0a
  182. #define UAC2_FUNCTION_AUDIO_VIDEO 0x0b
  183. #define UAC2_FUNCTION_CONTROL_PANEL 0x0c
  184. #define UAC2_FUNCTION_OTHER 0xff
  185. /* A.9 Audio Class-Specific AC Interface Descriptor Subtypes */
  186. /* see audio.h for the rest, which is identical to v1 */
  187. #define UAC2_EFFECT_UNIT 0x07
  188. #define UAC2_PROCESSING_UNIT_V2 0x08
  189. #define UAC2_EXTENSION_UNIT_V2 0x09
  190. #define UAC2_CLOCK_SOURCE 0x0a
  191. #define UAC2_CLOCK_SELECTOR 0x0b
  192. #define UAC2_CLOCK_MULTIPLIER 0x0c
  193. #define UAC2_SAMPLE_RATE_CONVERTER 0x0d
  194. /* A.10 Audio Class-Specific AS Interface Descriptor Subtypes */
  195. /* see audio.h for the rest, which is identical to v1 */
  196. #define UAC2_ENCODER 0x03
  197. #define UAC2_DECODER 0x04
  198. /* A.11 Effect Unit Effect Types */
  199. #define UAC2_EFFECT_UNDEFINED 0x00
  200. #define UAC2_EFFECT_PARAM_EQ 0x01
  201. #define UAC2_EFFECT_REVERB 0x02
  202. #define UAC2_EFFECT_MOD_DELAY 0x03
  203. #define UAC2_EFFECT_DYN_RANGE_COMP 0x04
  204. /* A.12 Processing Unit Process Types */
  205. #define UAC2_PROCESS_UNDEFINED 0x00
  206. #define UAC2_PROCESS_UP_DOWNMIX 0x01
  207. #define UAC2_PROCESS_DOLBY_PROLOCIC 0x02
  208. #define UAC2_PROCESS_STEREO_EXTENDER 0x03
  209. /* A.14 Audio Class-Specific Request Codes */
  210. #define UAC2_CS_CUR 0x01
  211. #define UAC2_CS_RANGE 0x02
  212. #define UAC2_CS_MEM 0x03
  213. /* A.15 Encoder Type Codes */
  214. #define UAC2_ENCODER_UNDEFINED 0x00
  215. #define UAC2_ENCODER_OTHER 0x01
  216. #define UAC2_ENCODER_MPEG 0x02
  217. #define UAC2_ENCODER_AC3 0x03
  218. #define UAC2_ENCODER_WMA 0x04
  219. #define UAC2_ENCODER_DTS 0x05
  220. /* A.16 Decoder Type Codes */
  221. #define UAC2_DECODER_UNDEFINED 0x00
  222. #define UAC2_DECODER_OTHER 0x01
  223. #define UAC2_DECODER_MPEG 0x02
  224. #define UAC2_DECODER_AC3 0x03
  225. #define UAC2_DECODER_WMA 0x04
  226. #define UAC2_DECODER_DTS 0x05
  227. /* A.17.1 Clock Source Control Selectors */
  228. #define UAC2_CS_UNDEFINED 0x00
  229. #define UAC2_CS_CONTROL_SAM_FREQ 0x01
  230. #define UAC2_CS_CONTROL_CLOCK_VALID 0x02
  231. /* A.17.2 Clock Selector Control Selectors */
  232. #define UAC2_CX_UNDEFINED 0x00
  233. #define UAC2_CX_CLOCK_SELECTOR 0x01
  234. /* A.17.3 Clock Multiplier Control Selectors */
  235. #define UAC2_CM_UNDEFINED 0x00
  236. #define UAC2_CM_NUMERATOR 0x01
  237. #define UAC2_CM_DENOMINTATOR 0x02
  238. /* A.17.4 Terminal Control Selectors */
  239. #define UAC2_TE_UNDEFINED 0x00
  240. #define UAC2_TE_COPY_PROTECT 0x01
  241. #define UAC2_TE_CONNECTOR 0x02
  242. #define UAC2_TE_OVERLOAD 0x03
  243. #define UAC2_TE_CLUSTER 0x04
  244. #define UAC2_TE_UNDERFLOW 0x05
  245. #define UAC2_TE_OVERFLOW 0x06
  246. #define UAC2_TE_LATENCY 0x07
  247. /* A.17.5 Mixer Control Selectors */
  248. #define UAC2_MU_UNDEFINED 0x00
  249. #define UAC2_MU_MIXER 0x01
  250. #define UAC2_MU_CLUSTER 0x02
  251. #define UAC2_MU_UNDERFLOW 0x03
  252. #define UAC2_MU_OVERFLOW 0x04
  253. #define UAC2_MU_LATENCY 0x05
  254. /* A.17.6 Selector Control Selectors */
  255. #define UAC2_SU_UNDEFINED 0x00
  256. #define UAC2_SU_SELECTOR 0x01
  257. #define UAC2_SU_LATENCY 0x02
  258. /* A.17.7 Feature Unit Control Selectors */
  259. /* see audio.h for the rest, which is identical to v1 */
  260. #define UAC2_FU_INPUT_GAIN 0x0b
  261. #define UAC2_FU_INPUT_GAIN_PAD 0x0c
  262. #define UAC2_FU_PHASE_INVERTER 0x0d
  263. #define UAC2_FU_UNDERFLOW 0x0e
  264. #define UAC2_FU_OVERFLOW 0x0f
  265. #define UAC2_FU_LATENCY 0x10
  266. /* A.17.8.1 Parametric Equalizer Section Effect Unit Control Selectors */
  267. #define UAC2_PE_UNDEFINED 0x00
  268. #define UAC2_PE_ENABLE 0x01
  269. #define UAC2_PE_CENTERFREQ 0x02
  270. #define UAC2_PE_QFACTOR 0x03
  271. #define UAC2_PE_GAIN 0x04
  272. #define UAC2_PE_UNDERFLOW 0x05
  273. #define UAC2_PE_OVERFLOW 0x06
  274. #define UAC2_PE_LATENCY 0x07
  275. /* A.17.8.2 Reverberation Effect Unit Control Selectors */
  276. #define UAC2_RV_UNDEFINED 0x00
  277. #define UAC2_RV_ENABLE 0x01
  278. #define UAC2_RV_TYPE 0x02
  279. #define UAC2_RV_LEVEL 0x03
  280. #define UAC2_RV_TIME 0x04
  281. #define UAC2_RV_FEEDBACK 0x05
  282. #define UAC2_RV_PREDELAY 0x06
  283. #define UAC2_RV_DENSITY 0x07
  284. #define UAC2_RV_HIFREQ_ROLLOFF 0x08
  285. #define UAC2_RV_UNDERFLOW 0x09
  286. #define UAC2_RV_OVERFLOW 0x0a
  287. #define UAC2_RV_LATENCY 0x0b
  288. /* A.17.8.3 Modulation Delay Effect Control Selectors */
  289. #define UAC2_MD_UNDEFINED 0x00
  290. #define UAC2_MD_ENABLE 0x01
  291. #define UAC2_MD_BALANCE 0x02
  292. #define UAC2_MD_RATE 0x03
  293. #define UAC2_MD_DEPTH 0x04
  294. #define UAC2_MD_TIME 0x05
  295. #define UAC2_MD_FEEDBACK 0x06
  296. #define UAC2_MD_UNDERFLOW 0x07
  297. #define UAC2_MD_OVERFLOW 0x08
  298. #define UAC2_MD_LATENCY 0x09
  299. /* A.17.8.4 Dynamic Range Compressor Effect Unit Control Selectors */
  300. #define UAC2_DR_UNDEFINED 0x00
  301. #define UAC2_DR_ENABLE 0x01
  302. #define UAC2_DR_COMPRESSION_RATE 0x02
  303. #define UAC2_DR_MAXAMPL 0x03
  304. #define UAC2_DR_THRESHOLD 0x04
  305. #define UAC2_DR_ATTACK_TIME 0x05
  306. #define UAC2_DR_RELEASE_TIME 0x06
  307. #define UAC2_DR_UNDEFLOW 0x07
  308. #define UAC2_DR_OVERFLOW 0x08
  309. #define UAC2_DR_LATENCY 0x09
  310. /* A.17.9.1 Up/Down-mix Processing Unit Control Selectors */
  311. #define UAC2_UD_UNDEFINED 0x00
  312. #define UAC2_UD_ENABLE 0x01
  313. #define UAC2_UD_MODE_SELECT 0x02
  314. #define UAC2_UD_CLUSTER 0x03
  315. #define UAC2_UD_UNDERFLOW 0x04
  316. #define UAC2_UD_OVERFLOW 0x05
  317. #define UAC2_UD_LATENCY 0x06
  318. /* A.17.9.2 Dolby Prologic[tm] Processing Unit Control Selectors */
  319. #define UAC2_DP_UNDEFINED 0x00
  320. #define UAC2_DP_ENABLE 0x01
  321. #define UAC2_DP_MODE_SELECT 0x02
  322. #define UAC2_DP_CLUSTER 0x03
  323. #define UAC2_DP_UNDERFFLOW 0x04
  324. #define UAC2_DP_OVERFLOW 0x05
  325. #define UAC2_DP_LATENCY 0x06
  326. /* A.17.9.3 Stereo Expander Processing Unit Control Selectors */
  327. #define UAC2_ST_EXT_UNDEFINED 0x00
  328. #define UAC2_ST_EXT_ENABLE 0x01
  329. #define UAC2_ST_EXT_WIDTH 0x02
  330. #define UAC2_ST_EXT_UNDEFLOW 0x03
  331. #define UAC2_ST_EXT_OVERFLOW 0x04
  332. #define UAC2_ST_EXT_LATENCY 0x05
  333. /* A.17.10 Extension Unit Control Selectors */
  334. #define UAC2_XU_UNDEFINED 0x00
  335. #define UAC2_XU_ENABLE 0x01
  336. #define UAC2_XU_CLUSTER 0x02
  337. #define UAC2_XU_UNDERFLOW 0x03
  338. #define UAC2_XU_OVERFLOW 0x04
  339. #define UAC2_XU_LATENCY 0x05
  340. /* A.17.11 AudioStreaming Interface Control Selectors */
  341. #define UAC2_AS_UNDEFINED 0x00
  342. #define UAC2_AS_ACT_ALT_SETTING 0x01
  343. #define UAC2_AS_VAL_ALT_SETTINGS 0x02
  344. #define UAC2_AS_AUDIO_DATA_FORMAT 0x03
  345. /* A.17.12 Encoder Control Selectors */
  346. #define UAC2_EN_UNDEFINED 0x00
  347. #define UAC2_EN_BIT_RATE 0x01
  348. #define UAC2_EN_QUALITY 0x02
  349. #define UAC2_EN_VBR 0x03
  350. #define UAC2_EN_TYPE 0x04
  351. #define UAC2_EN_UNDERFLOW 0x05
  352. #define UAC2_EN_OVERFLOW 0x06
  353. #define UAC2_EN_ENCODER_ERROR 0x07
  354. #define UAC2_EN_PARAM1 0x08
  355. #define UAC2_EN_PARAM2 0x09
  356. #define UAC2_EN_PARAM3 0x0a
  357. #define UAC2_EN_PARAM4 0x0b
  358. #define UAC2_EN_PARAM5 0x0c
  359. #define UAC2_EN_PARAM6 0x0d
  360. #define UAC2_EN_PARAM7 0x0e
  361. #define UAC2_EN_PARAM8 0x0f
  362. /* A.17.13.1 MPEG Decoder Control Selectors */
  363. #define UAC2_MPEG_UNDEFINED 0x00
  364. #define UAC2_MPEG_DUAL_CHANNEL 0x01
  365. #define UAC2_MPEG_SECOND_STEREO 0x02
  366. #define UAC2_MPEG_MULTILINGUAL 0x03
  367. #define UAC2_MPEG_DYN_RANGE 0x04
  368. #define UAC2_MPEG_SCALING 0x05
  369. #define UAC2_MPEG_HILO_SCALING 0x06
  370. #define UAC2_MPEG_UNDERFLOW 0x07
  371. #define UAC2_MPEG_OVERFLOW 0x08
  372. #define UAC2_MPEG_DECODER_ERROR 0x09
  373. /* A17.13.2 AC3 Decoder Control Selectors */
  374. #define UAC2_AC3_UNDEFINED 0x00
  375. #define UAC2_AC3_MODE 0x01
  376. #define UAC2_AC3_DYN_RANGE 0x02
  377. #define UAC2_AC3_SCALING 0x03
  378. #define UAC2_AC3_HILO_SCALING 0x04
  379. #define UAC2_AC3_UNDERFLOW 0x05
  380. #define UAC2_AC3_OVERFLOW 0x06
  381. #define UAC2_AC3_DECODER_ERROR 0x07
  382. /* A17.13.3 WMA Decoder Control Selectors */
  383. #define UAC2_WMA_UNDEFINED 0x00
  384. #define UAC2_WMA_UNDERFLOW 0x01
  385. #define UAC2_WMA_OVERFLOW 0x02
  386. #define UAC2_WMA_DECODER_ERROR 0x03
  387. /* A17.13.4 DTS Decoder Control Selectors */
  388. #define UAC2_DTS_UNDEFINED 0x00
  389. #define UAC2_DTS_UNDERFLOW 0x01
  390. #define UAC2_DTS_OVERFLOW 0x02
  391. #define UAC2_DTS_DECODER_ERROR 0x03
  392. /* A17.14 Endpoint Control Selectors */
  393. #define UAC2_EP_CS_UNDEFINED 0x00
  394. #define UAC2_EP_CS_PITCH 0x01
  395. #define UAC2_EP_CS_DATA_OVERRUN 0x02
  396. #define UAC2_EP_CS_DATA_UNDERRUN 0x03
  397. #endif /* __LINUX_USB_AUDIO_V2_H */