1
0

audio.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * <linux/usb/audio.h> -- USB Audio definitions.
  4. *
  5. * Copyright (C) 2006 Thumtronics Pty Ltd.
  6. * Developed for Thumtronics by Grey Innovation
  7. * Ben Williamson <ben.williamson@greyinnovation.com>
  8. *
  9. * This software is distributed under the terms of the GNU General Public
  10. * License ("GPL") version 2, as published by the Free Software Foundation.
  11. *
  12. * This file holds USB constants and structures defined
  13. * by the USB Device Class Definition for Audio Devices.
  14. * Comments below reference relevant sections of that document:
  15. *
  16. * http://www.usb.org/developers/devclass_docs/audio10.pdf
  17. *
  18. * Types and defines in this file are either specific to version 1.0 of
  19. * this standard or common for newer versions.
  20. */
  21. #ifndef _UAPI__LINUX_USB_AUDIO_H
  22. #define _UAPI__LINUX_USB_AUDIO_H
  23. //#include <linux/types.h>
  24. #include <rtthread.h>
  25. typedef int8_t __s8;
  26. typedef uint8_t __u8;
  27. typedef int16_t __s16;
  28. typedef uint16_t __u16;
  29. typedef int32_t __s32;
  30. typedef uint32_t __u32;
  31. typedef int64_t __s64;
  32. typedef uint64_t __u64;
  33. #define UAC_USE_FEATURE_UNIT 0 /* Feature unit does not support */
  34. /*
  35. * Below are truly Linux-specific types that should never collide with
  36. * any application/library that wants linux/types.h.
  37. */
  38. #ifdef __CHECKER__
  39. #define __bitwise__ __attribute__((bitwise))
  40. #else
  41. #define __bitwise__
  42. #endif
  43. #ifdef __CHECK_ENDIAN__
  44. #define __bitwise __bitwise__
  45. #else
  46. #define __bitwise
  47. #endif
  48. typedef __u16 __bitwise __le16;
  49. typedef __u16 __bitwise __be16;
  50. typedef __u32 __bitwise __le32;
  51. typedef __u32 __bitwise __be32;
  52. typedef __u64 __bitwise __le64;
  53. typedef __u64 __bitwise __be64;
  54. typedef __u16 __bitwise __sum16;
  55. typedef __u32 __bitwise __wsum;
  56. /* bInterfaceProtocol values to denote the version of the standard used */
  57. #define UAC_VERSION_1 0x00
  58. #define UAC_VERSION_2 0x20
  59. #define UAC_VERSION_3 0x30
  60. /* A.2 Audio Interface Subclass Codes */
  61. #define USB_SUBCLASS_AUDIOCONTROL 0x01
  62. #define USB_SUBCLASS_AUDIOSTREAMING 0x02
  63. #define USB_SUBCLASS_MIDISTREAMING 0x03
  64. /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
  65. #define UAC_HEADER 0x01
  66. #define UAC_INPUT_TERMINAL 0x02
  67. #define UAC_OUTPUT_TERMINAL 0x03
  68. #define UAC_MIXER_UNIT 0x04
  69. #define UAC_SELECTOR_UNIT 0x05
  70. #define UAC_FEATURE_UNIT 0x06
  71. #define UAC1_PROCESSING_UNIT 0x07
  72. #define UAC1_EXTENSION_UNIT 0x08
  73. /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
  74. #define UAC_AS_GENERAL 0x01
  75. #define UAC_FORMAT_TYPE 0x02
  76. #define UAC_FORMAT_SPECIFIC 0x03
  77. /* A.7 Processing Unit Process Types */
  78. #define UAC_PROCESS_UNDEFINED 0x00
  79. #define UAC_PROCESS_UP_DOWNMIX 0x01
  80. #define UAC_PROCESS_DOLBY_PROLOGIC 0x02
  81. #define UAC_PROCESS_STEREO_EXTENDER 0x03
  82. #define UAC_PROCESS_REVERB 0x04
  83. #define UAC_PROCESS_CHORUS 0x05
  84. #define UAC_PROCESS_DYN_RANGE_COMP 0x06
  85. /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
  86. #define UAC_EP_GENERAL 0x01
  87. /* A.9 Audio Class-Specific Request Codes */
  88. #define UAC_SET_ 0x00
  89. #define UAC_GET_ 0x80
  90. #define UAC__CUR 0x1
  91. #define UAC__MIN 0x2
  92. #define UAC__MAX 0x3
  93. #define UAC__RES 0x4
  94. #define UAC__MEM 0x5
  95. #define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
  96. #define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
  97. #define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
  98. #define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
  99. #define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
  100. #define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
  101. #define UAC_SET_RES (UAC_SET_ | UAC__RES)
  102. #define UAC_GET_RES (UAC_GET_ | UAC__RES)
  103. #define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
  104. #define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
  105. #define UAC_GET_STAT 0xff
  106. /* A.10 Control Selector Codes */
  107. /* A.10.1 Terminal Control Selectors */
  108. #define UAC_TERM_COPY_PROTECT 0x01
  109. /* A.10.2 Feature Unit Control Selectors */
  110. #define UAC_FU_MUTE 0x01
  111. #define UAC_FU_VOLUME 0x02
  112. #define UAC_FU_BASS 0x03
  113. #define UAC_FU_MID 0x04
  114. #define UAC_FU_TREBLE 0x05
  115. #define UAC_FU_GRAPHIC_EQUALIZER 0x06
  116. #define UAC_FU_AUTOMATIC_GAIN 0x07
  117. #define UAC_FU_DELAY 0x08
  118. #define UAC_FU_BASS_BOOST 0x09
  119. #define UAC_FU_LOUDNESS 0x0a
  120. #define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1))
  121. /* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */
  122. #define UAC_UD_ENABLE 0x01
  123. #define UAC_UD_MODE_SELECT 0x02
  124. /* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */
  125. #define UAC_DP_ENABLE 0x01
  126. #define UAC_DP_MODE_SELECT 0x02
  127. /* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */
  128. #define UAC_3D_ENABLE 0x01
  129. #define UAC_3D_SPACE 0x02
  130. /* A.10.3.4 Reverberation Processing Unit Control Selectors */
  131. #define UAC_REVERB_ENABLE 0x01
  132. #define UAC_REVERB_LEVEL 0x02
  133. #define UAC_REVERB_TIME 0x03
  134. #define UAC_REVERB_FEEDBACK 0x04
  135. /* A.10.3.5 Chorus Processing Unit Control Selectors */
  136. #define UAC_CHORUS_ENABLE 0x01
  137. #define UAC_CHORUS_LEVEL 0x02
  138. #define UAC_CHORUS_RATE 0x03
  139. #define UAC_CHORUS_DEPTH 0x04
  140. /* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */
  141. #define UAC_DCR_ENABLE 0x01
  142. #define UAC_DCR_RATE 0x02
  143. #define UAC_DCR_MAXAMPL 0x03
  144. #define UAC_DCR_THRESHOLD 0x04
  145. #define UAC_DCR_ATTACK_TIME 0x05
  146. #define UAC_DCR_RELEASE_TIME 0x06
  147. /* A.10.4 Extension Unit Control Selectors */
  148. #define UAC_XU_ENABLE 0x01
  149. /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
  150. #define UAC_MS_HEADER 0x01
  151. #define UAC_MIDI_IN_JACK 0x02
  152. #define UAC_MIDI_OUT_JACK 0x03
  153. /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
  154. #define UAC_MS_GENERAL 0x01
  155. /* Terminals - 2.1 USB Terminal Types */
  156. #define UAC_TERMINAL_UNDEFINED 0x100
  157. #define UAC_TERMINAL_STREAMING 0x101
  158. #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
  159. /* Terminal Control Selectors */
  160. /* 4.3.2 Class-Specific AC Interface Descriptor */
  161. struct uac1_ac_header_descriptor {
  162. __u8 bLength; /* 8 + n */
  163. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  164. __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
  165. __le16 bcdADC; /* 0x0100 */
  166. __le16 wTotalLength; /* includes Unit and Terminal desc. */
  167. __u8 bInCollection; /* n */
  168. __u8 baInterfaceNr[]; /* [n] */
  169. } __attribute__ ((packed));
  170. #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
  171. /* As above, but more useful for defining your own descriptors: */
  172. #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
  173. struct uac1_ac_header_descriptor_##n { \
  174. __u8 bLength; \
  175. __u8 bDescriptorType; \
  176. __u8 bDescriptorSubtype; \
  177. __le16 bcdADC; \
  178. __le16 wTotalLength; \
  179. __u8 bInCollection; \
  180. __u8 baInterfaceNr[n]; \
  181. } __attribute__ ((packed))
  182. /* 4.3.2.1 Input Terminal Descriptor */
  183. struct uac_input_terminal_descriptor {
  184. __u8 bLength; /* in bytes: 12 */
  185. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  186. __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
  187. __u8 bTerminalID; /* Constant uniquely terminal ID */
  188. __le16 wTerminalType; /* USB Audio Terminal Types */
  189. __u8 bAssocTerminal; /* ID of the Output Terminal associated */
  190. __u8 bNrChannels; /* Number of logical output channels */
  191. __le16 wChannelConfig;
  192. __u8 iChannelNames;
  193. __u8 iTerminal;
  194. } __attribute__ ((packed));
  195. #define UAC_DT_INPUT_TERMINAL_SIZE 12
  196. /* Terminals - 2.2 Input Terminal Types */
  197. #define UAC_INPUT_TERMINAL_UNDEFINED 0x200
  198. #define UAC_INPUT_TERMINAL_MICROPHONE 0x201
  199. #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
  200. #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
  201. #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
  202. #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
  203. #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
  204. /* Terminals - control selectors */
  205. #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
  206. /* 4.3.2.2 Output Terminal Descriptor */
  207. struct uac1_output_terminal_descriptor {
  208. __u8 bLength; /* in bytes: 9 */
  209. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  210. __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
  211. __u8 bTerminalID; /* Constant uniquely terminal ID */
  212. __le16 wTerminalType; /* USB Audio Terminal Types */
  213. __u8 bAssocTerminal; /* ID of the Input Terminal associated */
  214. __u8 bSourceID; /* ID of the connected Unit or Terminal*/
  215. __u8 iTerminal;
  216. } __attribute__ ((packed));
  217. #define UAC_DT_OUTPUT_TERMINAL_SIZE 9
  218. /* Terminals - 2.3 Output Terminal Types */
  219. #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
  220. #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
  221. #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
  222. #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
  223. #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
  224. #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
  225. #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
  226. #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
  227. /* Terminals - 2.4 Bi-directional Terminal Types */
  228. #define UAC_BIDIR_TERMINAL_UNDEFINED 0x400
  229. #define UAC_BIDIR_TERMINAL_HANDSET 0x401
  230. #define UAC_BIDIR_TERMINAL_HEADSET 0x402
  231. #define UAC_BIDIR_TERMINAL_SPEAKER_PHONE 0x403
  232. #define UAC_BIDIR_TERMINAL_ECHO_SUPPRESSING 0x404
  233. #define UAC_BIDIR_TERMINAL_ECHO_CANCELING 0x405
  234. /* Set bControlSize = 2 as default setting */
  235. #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
  236. /* As above, but more useful for defining your own descriptors: */
  237. #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
  238. struct uac_feature_unit_descriptor_##ch { \
  239. __u8 bLength; \
  240. __u8 bDescriptorType; \
  241. __u8 bDescriptorSubtype; \
  242. __u8 bUnitID; \
  243. __u8 bSourceID; \
  244. __u8 bControlSize; \
  245. __le16 bmaControls[ch + 1]; \
  246. __u8 iFeature; \
  247. } __attribute__ ((packed))
  248. /* 4.3.2.3 Mixer Unit Descriptor */
  249. struct uac_mixer_unit_descriptor {
  250. __u8 bLength;
  251. __u8 bDescriptorType;
  252. __u8 bDescriptorSubtype;
  253. __u8 bUnitID;
  254. __u8 bNrInPins;
  255. __u8 baSourceID[];
  256. } __attribute__ ((packed));
  257. static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc)
  258. {
  259. return desc->baSourceID[desc->bNrInPins];
  260. }
  261. static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc,
  262. int protocol)
  263. {
  264. if (protocol == UAC_VERSION_1)
  265. return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
  266. desc->baSourceID[desc->bNrInPins + 1];
  267. else
  268. return (desc->baSourceID[desc->bNrInPins + 4] << 24) |
  269. (desc->baSourceID[desc->bNrInPins + 3] << 16) |
  270. (desc->baSourceID[desc->bNrInPins + 2] << 8) |
  271. (desc->baSourceID[desc->bNrInPins + 1]);
  272. }
  273. static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc,
  274. int protocol)
  275. {
  276. return (protocol == UAC_VERSION_1) ?
  277. desc->baSourceID[desc->bNrInPins + 3] :
  278. desc->baSourceID[desc->bNrInPins + 5];
  279. }
  280. static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc,
  281. int protocol)
  282. {
  283. switch (protocol) {
  284. case UAC_VERSION_1:
  285. return &desc->baSourceID[desc->bNrInPins + 4];
  286. case UAC_VERSION_2:
  287. return &desc->baSourceID[desc->bNrInPins + 6];
  288. case UAC_VERSION_3:
  289. return &desc->baSourceID[desc->bNrInPins + 2];
  290. default:
  291. return NULL;
  292. }
  293. }
  294. static inline __u16 uac3_mixer_unit_wClusterDescrID(struct uac_mixer_unit_descriptor *desc)
  295. {
  296. return (desc->baSourceID[desc->bNrInPins + 1] << 8) |
  297. desc->baSourceID[desc->bNrInPins];
  298. }
  299. static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc)
  300. {
  301. __u8 *raw = (__u8 *) desc;
  302. return raw[desc->bLength - 1];
  303. }
  304. /* 4.3.2.4 Selector Unit Descriptor */
  305. struct uac_selector_unit_descriptor {
  306. __u8 bLength;
  307. __u8 bDescriptorType;
  308. __u8 bDescriptorSubtype;
  309. __u8 bUintID;
  310. __u8 bNrInPins;
  311. __u8 baSourceID[];
  312. } __attribute__ ((packed));
  313. static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc)
  314. {
  315. __u8 *raw = (__u8 *) desc;
  316. return raw[desc->bLength - 1];
  317. }
  318. #if UAC_USE_FEATURE_UNIT
  319. /* 4.3.2.5 Feature Unit Descriptor */
  320. struct uac_feature_unit_descriptor {
  321. __u8 bLength;
  322. __u8 bDescriptorType;
  323. __u8 bDescriptorSubtype;
  324. __u8 bUnitID;
  325. __u8 bSourceID;
  326. __u8 bControlSize;
  327. __u8 bmaControls[0]; /* variable length */
  328. } __attribute__((packed));
  329. static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc)
  330. {
  331. __u8 *raw = (__u8 *) desc;
  332. return raw[desc->bLength - 1];
  333. }
  334. #endif
  335. /* 4.3.2.6 Processing Unit Descriptors */
  336. struct uac_processing_unit_descriptor {
  337. __u8 bLength;
  338. __u8 bDescriptorType;
  339. __u8 bDescriptorSubtype;
  340. __u8 bUnitID;
  341. __le16 wProcessType;
  342. __u8 bNrInPins;
  343. __u8 baSourceID[];
  344. } __attribute__ ((packed));
  345. static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc)
  346. {
  347. return desc->baSourceID[desc->bNrInPins];
  348. }
  349. static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc,
  350. int protocol)
  351. {
  352. if (protocol == UAC_VERSION_1)
  353. return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
  354. desc->baSourceID[desc->bNrInPins + 1];
  355. else
  356. return (desc->baSourceID[desc->bNrInPins + 4] << 24) |
  357. (desc->baSourceID[desc->bNrInPins + 3] << 16) |
  358. (desc->baSourceID[desc->bNrInPins + 2] << 8) |
  359. (desc->baSourceID[desc->bNrInPins + 1]);
  360. }
  361. static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc,
  362. int protocol)
  363. {
  364. return (protocol == UAC_VERSION_1) ?
  365. desc->baSourceID[desc->bNrInPins + 3] :
  366. desc->baSourceID[desc->bNrInPins + 5];
  367. }
  368. static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc,
  369. int protocol)
  370. {
  371. switch (protocol) {
  372. case UAC_VERSION_1:
  373. return desc->baSourceID[desc->bNrInPins + 4];
  374. case UAC_VERSION_2:
  375. return 2; /* in UAC2, this value is constant */
  376. case UAC_VERSION_3:
  377. return 4; /* in UAC3, this value is constant */
  378. default:
  379. return 1;
  380. }
  381. }
  382. static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc,
  383. int protocol)
  384. {
  385. switch (protocol) {
  386. case UAC_VERSION_1:
  387. return &desc->baSourceID[desc->bNrInPins + 5];
  388. case UAC_VERSION_2:
  389. return &desc->baSourceID[desc->bNrInPins + 6];
  390. case UAC_VERSION_3:
  391. return &desc->baSourceID[desc->bNrInPins + 2];
  392. default:
  393. return NULL;
  394. }
  395. }
  396. static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc,
  397. int protocol)
  398. {
  399. __u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
  400. switch (protocol) {
  401. case UAC_VERSION_1:
  402. case UAC_VERSION_2:
  403. default:
  404. return *(uac_processing_unit_bmControls(desc, protocol)
  405. + control_size);
  406. case UAC_VERSION_3:
  407. return 0; /* UAC3 does not have this field */
  408. }
  409. }
  410. static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc,
  411. int protocol)
  412. {
  413. __u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
  414. switch (protocol) {
  415. case UAC_VERSION_1:
  416. case UAC_VERSION_2:
  417. default:
  418. return uac_processing_unit_bmControls(desc, protocol)
  419. + control_size + 1;
  420. case UAC_VERSION_3:
  421. return uac_processing_unit_bmControls(desc, protocol)
  422. + control_size;
  423. }
  424. }
  425. /*
  426. * Extension Unit (XU) has almost compatible layout with Processing Unit, but
  427. * on UAC2, it has a different bmControls size (bControlSize); it's 1 byte for
  428. * XU while 2 bytes for PU. The last iExtension field is a one-byte index as
  429. * well as iProcessing field of PU.
  430. */
  431. static inline __u8 uac_extension_unit_bControlSize(struct uac_processing_unit_descriptor *desc,
  432. int protocol)
  433. {
  434. switch (protocol) {
  435. case UAC_VERSION_1:
  436. return desc->baSourceID[desc->bNrInPins + 4];
  437. case UAC_VERSION_2:
  438. return 1; /* in UAC2, this value is constant */
  439. case UAC_VERSION_3:
  440. return 4; /* in UAC3, this value is constant */
  441. default:
  442. return 1;
  443. }
  444. }
  445. static inline __u8 uac_extension_unit_iExtension(struct uac_processing_unit_descriptor *desc,
  446. int protocol)
  447. {
  448. __u8 control_size = uac_extension_unit_bControlSize(desc, protocol);
  449. switch (protocol) {
  450. case UAC_VERSION_1:
  451. case UAC_VERSION_2:
  452. default:
  453. return *(uac_processing_unit_bmControls(desc, protocol)
  454. + control_size);
  455. case UAC_VERSION_3:
  456. return 0; /* UAC3 does not have this field */
  457. }
  458. }
  459. /* 4.5.2 Class-Specific AS Interface Descriptor */
  460. struct uac1_as_header_descriptor {
  461. __u8 bLength; /* in bytes: 7 */
  462. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  463. __u8 bDescriptorSubtype; /* AS_GENERAL */
  464. __u8 bTerminalLink; /* Terminal ID of connected Terminal */
  465. __u8 bDelay; /* Delay introduced by the data path */
  466. __le16 wFormatTag; /* The Audio Data Format */
  467. } __attribute__ ((packed));
  468. #define UAC_DT_AS_HEADER_SIZE 7
  469. /* Formats - A.1.1 Audio Data Format Type I Codes */
  470. #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
  471. #define UAC_FORMAT_TYPE_I_PCM 0x1
  472. #define UAC_FORMAT_TYPE_I_PCM8 0x2
  473. #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
  474. #define UAC_FORMAT_TYPE_I_ALAW 0x4
  475. #define UAC_FORMAT_TYPE_I_MULAW 0x5
  476. struct uac_format_type_i_continuous_descriptor {
  477. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  478. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  479. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  480. __u8 bFormatType; /* FORMAT_TYPE_1 */
  481. __u8 bNrChannels; /* physical channels in the stream */
  482. __u8 bSubframeSize; /* */
  483. __u8 bBitResolution;
  484. __u8 bSamFreqType;
  485. __u8 tLowerSamFreq[3];
  486. __u8 tUpperSamFreq[3];
  487. } __attribute__ ((packed));
  488. #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
  489. struct uac_format_type_i_discrete_descriptor {
  490. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  491. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  492. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  493. __u8 bFormatType; /* FORMAT_TYPE_1 */
  494. __u8 bNrChannels; /* physical channels in the stream */
  495. __u8 bSubframeSize; /* */
  496. __u8 bBitResolution;
  497. __u8 bSamFreqType;
  498. __u8 tSamFreq[][3];
  499. } __attribute__ ((packed));
  500. #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
  501. struct uac_format_type_i_discrete_descriptor_##n { \
  502. __u8 bLength; \
  503. __u8 bDescriptorType; \
  504. __u8 bDescriptorSubtype; \
  505. __u8 bFormatType; \
  506. __u8 bNrChannels; \
  507. __u8 bSubframeSize; \
  508. __u8 bBitResolution; \
  509. __u8 bSamFreqType; \
  510. __u8 tSamFreq[n][3]; \
  511. } __attribute__ ((packed))
  512. #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
  513. struct uac_format_type_i_ext_descriptor {
  514. __u8 bLength;
  515. __u8 bDescriptorType;
  516. __u8 bDescriptorSubtype;
  517. __u8 bFormatType;
  518. __u8 bSubslotSize;
  519. __u8 bBitResolution;
  520. __u8 bHeaderLength;
  521. __u8 bControlSize;
  522. __u8 bSideBandProtocol;
  523. } __attribute__((packed));
  524. /* Formats - Audio Data Format Type I Codes */
  525. #define UAC_FORMAT_TYPE_II_MPEG 0x1001
  526. #define UAC_FORMAT_TYPE_II_AC3 0x1002
  527. struct uac_format_type_ii_discrete_descriptor {
  528. __u8 bLength;
  529. __u8 bDescriptorType;
  530. __u8 bDescriptorSubtype;
  531. __u8 bFormatType;
  532. __le16 wMaxBitRate;
  533. __le16 wSamplesPerFrame;
  534. __u8 bSamFreqType;
  535. __u8 tSamFreq[][3];
  536. } __attribute__((packed));
  537. struct uac_format_type_ii_ext_descriptor {
  538. __u8 bLength;
  539. __u8 bDescriptorType;
  540. __u8 bDescriptorSubtype;
  541. __u8 bFormatType;
  542. __le16 wMaxBitRate;
  543. __le16 wSamplesPerFrame;
  544. __u8 bHeaderLength;
  545. __u8 bSideBandProtocol;
  546. } __attribute__((packed));
  547. /* type III */
  548. #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001
  549. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002
  550. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003
  551. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004
  552. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005
  553. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006
  554. /* Formats - A.2 Format Type Codes */
  555. #define UAC_FORMAT_TYPE_UNDEFINED 0x0
  556. #define UAC_FORMAT_TYPE_I 0x1
  557. #define UAC_FORMAT_TYPE_II 0x2
  558. #define UAC_FORMAT_TYPE_III 0x3
  559. #define UAC_EXT_FORMAT_TYPE_I 0x81
  560. #define UAC_EXT_FORMAT_TYPE_II 0x82
  561. #define UAC_EXT_FORMAT_TYPE_III 0x83
  562. struct uac_iso_endpoint_descriptor {
  563. __u8 bLength; /* in bytes: 7 */
  564. __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
  565. __u8 bDescriptorSubtype; /* EP_GENERAL */
  566. __u8 bmAttributes;
  567. __u8 bLockDelayUnits;
  568. __le16 wLockDelay;
  569. } __attribute__((packed));
  570. #define UAC_ISO_ENDPOINT_DESC_SIZE 7
  571. #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
  572. #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
  573. #define UAC_EP_CS_ATTR_FILL_MAX 0x80
  574. /* status word format (3.7.1.1) */
  575. #define UAC1_STATUS_TYPE_ORIG_MASK 0x0f
  576. #define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0
  577. #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1
  578. #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2
  579. #define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7)
  580. #define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6)
  581. struct uac1_status_word {
  582. __u8 bStatusType;
  583. __u8 bOriginator;
  584. } __attribute__((packed));
  585. #endif /* _UAPI__LINUX_USB_AUDIO_H */