audio.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * <linux/usb/audio.h> -- USB Audio definitions.
  3. *
  4. * Copyright (C) 2006 Thumtronics Pty Ltd.
  5. * Developed for Thumtronics by Grey Innovation
  6. * Ben Williamson <ben.williamson@greyinnovation.com>
  7. *
  8. * This software is distributed under the terms of the GNU General Public
  9. * License ("GPL") version 2, as published by the Free Software Foundation.
  10. *
  11. * This file holds USB constants and structures defined
  12. * by the USB Device Class Definition for Audio Devices.
  13. * Comments below reference relevant sections of that document:
  14. *
  15. * http://www.usb.org/developers/devclass_docs/audio10.pdf
  16. *
  17. * Types and defines in this file are either specific to version 1.0 of
  18. * this standard or common for newer versions.
  19. */
  20. #ifndef __LINUX_USB_AUDIO_H
  21. #define __LINUX_USB_AUDIO_H
  22. #include <linux/types.h>
  23. /* bInterfaceProtocol values to denote the version of the standard used */
  24. #define UAC_VERSION_1 0x00
  25. #define UAC_VERSION_2 0x20
  26. /* A.2 Audio Interface Subclass Codes */
  27. #define USB_SUBCLASS_AUDIOCONTROL 0x01
  28. #define USB_SUBCLASS_AUDIOSTREAMING 0x02
  29. #define USB_SUBCLASS_MIDISTREAMING 0x03
  30. /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
  31. #define UAC_HEADER 0x01
  32. #define UAC_INPUT_TERMINAL 0x02
  33. #define UAC_OUTPUT_TERMINAL 0x03
  34. #define UAC_MIXER_UNIT 0x04
  35. #define UAC_SELECTOR_UNIT 0x05
  36. #define UAC_FEATURE_UNIT 0x06
  37. #define UAC_PROCESSING_UNIT_V1 0x07
  38. #define UAC_EXTENSION_UNIT_V1 0x08
  39. /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
  40. #define UAC_AS_GENERAL 0x01
  41. #define UAC_FORMAT_TYPE 0x02
  42. #define UAC_FORMAT_SPECIFIC 0x03
  43. /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
  44. #define UAC_EP_GENERAL 0x01
  45. /* A.9 Audio Class-Specific Request Codes */
  46. #define UAC_SET_ 0x00
  47. #define UAC_GET_ 0x80
  48. #define UAC__CUR 0x1
  49. #define UAC__MIN 0x2
  50. #define UAC__MAX 0x3
  51. #define UAC__RES 0x4
  52. #define UAC__MEM 0x5
  53. #define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
  54. #define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
  55. #define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
  56. #define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
  57. #define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
  58. #define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
  59. #define UAC_SET_RES (UAC_SET_ | UAC__RES)
  60. #define UAC_GET_RES (UAC_GET_ | UAC__RES)
  61. #define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
  62. #define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
  63. #define UAC_GET_STAT 0xff
  64. /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
  65. #define UAC_MS_HEADER 0x01
  66. #define UAC_MIDI_IN_JACK 0x02
  67. #define UAC_MIDI_OUT_JACK 0x03
  68. /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
  69. #define UAC_MS_GENERAL 0x01
  70. /* Terminals - 2.1 USB Terminal Types */
  71. #define UAC_TERMINAL_UNDEFINED 0x100
  72. #define UAC_TERMINAL_STREAMING 0x101
  73. #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
  74. /* Terminal Control Selectors */
  75. /* 4.3.2 Class-Specific AC Interface Descriptor */
  76. struct uac_ac_header_descriptor_v1 {
  77. __u8 bLength; /* 8 + n */
  78. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  79. __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
  80. __le16 bcdADC; /* 0x0100 */
  81. __le16 wTotalLength; /* includes Unit and Terminal desc. */
  82. __u8 bInCollection; /* n */
  83. __u8 baInterfaceNr[]; /* [n] */
  84. } __attribute__ ((packed));
  85. #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
  86. /* As above, but more useful for defining your own descriptors: */
  87. #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
  88. struct uac_ac_header_descriptor_v1_##n { \
  89. __u8 bLength; \
  90. __u8 bDescriptorType; \
  91. __u8 bDescriptorSubtype; \
  92. __le16 bcdADC; \
  93. __le16 wTotalLength; \
  94. __u8 bInCollection; \
  95. __u8 baInterfaceNr[n]; \
  96. } __attribute__ ((packed))
  97. /* 4.3.2.1 Input Terminal Descriptor */
  98. struct uac_input_terminal_descriptor {
  99. __u8 bLength; /* in bytes: 12 */
  100. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  101. __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
  102. __u8 bTerminalID; /* Constant uniquely terminal ID */
  103. __le16 wTerminalType; /* USB Audio Terminal Types */
  104. __u8 bAssocTerminal; /* ID of the Output Terminal associated */
  105. __u8 bNrChannels; /* Number of logical output channels */
  106. __le16 wChannelConfig;
  107. __u8 iChannelNames;
  108. __u8 iTerminal;
  109. } __attribute__ ((packed));
  110. #define UAC_DT_INPUT_TERMINAL_SIZE 12
  111. /* Terminals - 2.2 Input Terminal Types */
  112. #define UAC_INPUT_TERMINAL_UNDEFINED 0x200
  113. #define UAC_INPUT_TERMINAL_MICROPHONE 0x201
  114. #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
  115. #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
  116. #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
  117. #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
  118. #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
  119. /* Terminals - control selectors */
  120. #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
  121. /* 4.3.2.2 Output Terminal Descriptor */
  122. struct uac_output_terminal_descriptor_v1 {
  123. __u8 bLength; /* in bytes: 9 */
  124. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  125. __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
  126. __u8 bTerminalID; /* Constant uniquely terminal ID */
  127. __le16 wTerminalType; /* USB Audio Terminal Types */
  128. __u8 bAssocTerminal; /* ID of the Input Terminal associated */
  129. __u8 bSourceID; /* ID of the connected Unit or Terminal*/
  130. __u8 iTerminal;
  131. } __attribute__ ((packed));
  132. #define UAC_DT_OUTPUT_TERMINAL_SIZE 9
  133. /* Terminals - 2.3 Output Terminal Types */
  134. #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
  135. #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
  136. #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
  137. #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
  138. #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
  139. #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
  140. #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
  141. #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
  142. /* Set bControlSize = 2 as default setting */
  143. #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
  144. /* As above, but more useful for defining your own descriptors: */
  145. #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
  146. struct uac_feature_unit_descriptor_##ch { \
  147. __u8 bLength; \
  148. __u8 bDescriptorType; \
  149. __u8 bDescriptorSubtype; \
  150. __u8 bUnitID; \
  151. __u8 bSourceID; \
  152. __u8 bControlSize; \
  153. __le16 bmaControls[ch + 1]; \
  154. __u8 iFeature; \
  155. } __attribute__ ((packed))
  156. /* 4.3.2.3 Mixer Unit Descriptor */
  157. struct uac_mixer_unit_descriptor {
  158. __u8 bLength;
  159. __u8 bDescriptorType;
  160. __u8 bDescriptorSubtype;
  161. __u8 bUnitID;
  162. __u8 bNrInPins;
  163. __u8 baSourceID[];
  164. } __attribute__ ((packed));
  165. static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc)
  166. {
  167. return desc->baSourceID[desc->bNrInPins];
  168. }
  169. static inline __u16 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc)
  170. {
  171. return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
  172. desc->baSourceID[desc->bNrInPins + 1];
  173. }
  174. static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc)
  175. {
  176. return desc->baSourceID[desc->bNrInPins + 3];
  177. }
  178. static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc)
  179. {
  180. return &desc->baSourceID[desc->bNrInPins + 4];
  181. }
  182. static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc)
  183. {
  184. __u8 *raw = (__u8 *) desc;
  185. return raw[desc->bLength - 1];
  186. }
  187. /* 4.3.2.4 Selector Unit Descriptor */
  188. struct uac_selector_unit_descriptor {
  189. __u8 bLength;
  190. __u8 bDescriptorType;
  191. __u8 bDescriptorSubtype;
  192. __u8 bUintID;
  193. __u8 bNrInPins;
  194. __u8 baSourceID[];
  195. } __attribute__ ((packed));
  196. static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc)
  197. {
  198. __u8 *raw = (__u8 *) desc;
  199. return raw[desc->bLength - 1];
  200. }
  201. /* 4.3.2.5 Feature Unit Descriptor */
  202. struct uac_feature_unit_descriptor {
  203. __u8 bLength;
  204. __u8 bDescriptorType;
  205. __u8 bDescriptorSubtype;
  206. __u8 bUnitID;
  207. __u8 bSourceID;
  208. __u8 bControlSize;
  209. __u8 bmaControls[0]; /* variable length */
  210. } __attribute__((packed));
  211. static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc)
  212. {
  213. __u8 *raw = (__u8 *) desc;
  214. return raw[desc->bLength - 1];
  215. }
  216. /* 4.3.2.6 Processing Unit Descriptors */
  217. struct uac_processing_unit_descriptor {
  218. __u8 bLength;
  219. __u8 bDescriptorType;
  220. __u8 bDescriptorSubtype;
  221. __u8 bUnitID;
  222. __u16 wProcessType;
  223. __u8 bNrInPins;
  224. __u8 baSourceID[];
  225. } __attribute__ ((packed));
  226. static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc)
  227. {
  228. return desc->baSourceID[desc->bNrInPins];
  229. }
  230. static inline __u16 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc)
  231. {
  232. return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
  233. desc->baSourceID[desc->bNrInPins + 1];
  234. }
  235. static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc)
  236. {
  237. return desc->baSourceID[desc->bNrInPins + 3];
  238. }
  239. static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc)
  240. {
  241. return desc->baSourceID[desc->bNrInPins + 4];
  242. }
  243. static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc)
  244. {
  245. return &desc->baSourceID[desc->bNrInPins + 5];
  246. }
  247. static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc)
  248. {
  249. __u8 control_size = uac_processing_unit_bControlSize(desc);
  250. return desc->baSourceID[desc->bNrInPins + control_size];
  251. }
  252. static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc)
  253. {
  254. __u8 control_size = uac_processing_unit_bControlSize(desc);
  255. return &desc->baSourceID[desc->bNrInPins + control_size + 1];
  256. }
  257. /* 4.5.2 Class-Specific AS Interface Descriptor */
  258. struct uac_as_header_descriptor_v1 {
  259. __u8 bLength; /* in bytes: 7 */
  260. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  261. __u8 bDescriptorSubtype; /* AS_GENERAL */
  262. __u8 bTerminalLink; /* Terminal ID of connected Terminal */
  263. __u8 bDelay; /* Delay introduced by the data path */
  264. __le16 wFormatTag; /* The Audio Data Format */
  265. } __attribute__ ((packed));
  266. #define UAC_DT_AS_HEADER_SIZE 7
  267. /* Formats - A.1.1 Audio Data Format Type I Codes */
  268. #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
  269. #define UAC_FORMAT_TYPE_I_PCM 0x1
  270. #define UAC_FORMAT_TYPE_I_PCM8 0x2
  271. #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
  272. #define UAC_FORMAT_TYPE_I_ALAW 0x4
  273. #define UAC_FORMAT_TYPE_I_MULAW 0x5
  274. struct uac_format_type_i_continuous_descriptor {
  275. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  276. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  277. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  278. __u8 bFormatType; /* FORMAT_TYPE_1 */
  279. __u8 bNrChannels; /* physical channels in the stream */
  280. __u8 bSubframeSize; /* */
  281. __u8 bBitResolution;
  282. __u8 bSamFreqType;
  283. __u8 tLowerSamFreq[3];
  284. __u8 tUpperSamFreq[3];
  285. } __attribute__ ((packed));
  286. #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
  287. struct uac_format_type_i_discrete_descriptor {
  288. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  289. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  290. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  291. __u8 bFormatType; /* FORMAT_TYPE_1 */
  292. __u8 bNrChannels; /* physical channels in the stream */
  293. __u8 bSubframeSize; /* */
  294. __u8 bBitResolution;
  295. __u8 bSamFreqType;
  296. __u8 tSamFreq[][3];
  297. } __attribute__ ((packed));
  298. #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
  299. struct uac_format_type_i_discrete_descriptor_##n { \
  300. __u8 bLength; \
  301. __u8 bDescriptorType; \
  302. __u8 bDescriptorSubtype; \
  303. __u8 bFormatType; \
  304. __u8 bNrChannels; \
  305. __u8 bSubframeSize; \
  306. __u8 bBitResolution; \
  307. __u8 bSamFreqType; \
  308. __u8 tSamFreq[n][3]; \
  309. } __attribute__ ((packed))
  310. #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
  311. struct uac_format_type_i_ext_descriptor {
  312. __u8 bLength;
  313. __u8 bDescriptorType;
  314. __u8 bDescriptorSubtype;
  315. __u8 bFormatType;
  316. __u8 bSubslotSize;
  317. __u8 bBitResolution;
  318. __u8 bHeaderLength;
  319. __u8 bControlSize;
  320. __u8 bSideBandProtocol;
  321. } __attribute__((packed));
  322. /* Formats - Audio Data Format Type I Codes */
  323. #define UAC_FORMAT_TYPE_II_MPEG 0x1001
  324. #define UAC_FORMAT_TYPE_II_AC3 0x1002
  325. struct uac_format_type_ii_discrete_descriptor {
  326. __u8 bLength;
  327. __u8 bDescriptorType;
  328. __u8 bDescriptorSubtype;
  329. __u8 bFormatType;
  330. __le16 wMaxBitRate;
  331. __le16 wSamplesPerFrame;
  332. __u8 bSamFreqType;
  333. __u8 tSamFreq[][3];
  334. } __attribute__((packed));
  335. struct uac_format_type_ii_ext_descriptor {
  336. __u8 bLength;
  337. __u8 bDescriptorType;
  338. __u8 bDescriptorSubtype;
  339. __u8 bFormatType;
  340. __u16 wMaxBitRate;
  341. __u16 wSamplesPerFrame;
  342. __u8 bHeaderLength;
  343. __u8 bSideBandProtocol;
  344. } __attribute__((packed));
  345. /* type III */
  346. #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001
  347. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002
  348. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003
  349. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004
  350. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005
  351. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006
  352. /* Formats - A.2 Format Type Codes */
  353. #define UAC_FORMAT_TYPE_UNDEFINED 0x0
  354. #define UAC_FORMAT_TYPE_I 0x1
  355. #define UAC_FORMAT_TYPE_II 0x2
  356. #define UAC_FORMAT_TYPE_III 0x3
  357. #define UAC_EXT_FORMAT_TYPE_I 0x81
  358. #define UAC_EXT_FORMAT_TYPE_II 0x82
  359. #define UAC_EXT_FORMAT_TYPE_III 0x83
  360. struct uac_iso_endpoint_descriptor {
  361. __u8 bLength; /* in bytes: 7 */
  362. __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
  363. __u8 bDescriptorSubtype; /* EP_GENERAL */
  364. __u8 bmAttributes;
  365. __u8 bLockDelayUnits;
  366. __le16 wLockDelay;
  367. };
  368. #define UAC_ISO_ENDPOINT_DESC_SIZE 7
  369. #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
  370. #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
  371. #define UAC_EP_CS_ATTR_FILL_MAX 0x80
  372. /* A.10.2 Feature Unit Control Selectors */
  373. #define UAC_FU_CONTROL_UNDEFINED 0x00
  374. #define UAC_MUTE_CONTROL 0x01
  375. #define UAC_VOLUME_CONTROL 0x02
  376. #define UAC_BASS_CONTROL 0x03
  377. #define UAC_MID_CONTROL 0x04
  378. #define UAC_TREBLE_CONTROL 0x05
  379. #define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06
  380. #define UAC_AUTOMATIC_GAIN_CONTROL 0x07
  381. #define UAC_DELAY_CONTROL 0x08
  382. #define UAC_BASS_BOOST_CONTROL 0x09
  383. #define UAC_LOUDNESS_CONTROL 0x0a
  384. #define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1))
  385. #define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1))
  386. #define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1))
  387. #define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1))
  388. #define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1))
  389. #define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
  390. #define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
  391. #define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1))
  392. #define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1))
  393. #define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1))
  394. #ifdef __KERNEL__
  395. struct usb_audio_control {
  396. struct list_head list;
  397. const char *name;
  398. u8 type;
  399. int data[5];
  400. int (*set)(struct usb_audio_control *con, u8 cmd, int value);
  401. int (*get)(struct usb_audio_control *con, u8 cmd);
  402. };
  403. struct usb_audio_control_selector {
  404. struct list_head list;
  405. struct list_head control;
  406. u8 id;
  407. const char *name;
  408. u8 type;
  409. struct usb_descriptor_header *desc;
  410. };
  411. #endif /* __KERNEL__ */
  412. #endif /* __LINUX_USB_AUDIO_H */