audio.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. #ifndef __LINUX_USB_AUDIO_H
  18. #define __LINUX_USB_AUDIO_H
  19. #include <linux/types.h>
  20. /* A.2 Audio Interface Subclass Codes */
  21. #define USB_SUBCLASS_AUDIOCONTROL 0x01
  22. #define USB_SUBCLASS_AUDIOSTREAMING 0x02
  23. #define USB_SUBCLASS_MIDISTREAMING 0x03
  24. #define UAC_VERSION_1 0x00
  25. #define UAC_VERSION_2 0x20
  26. /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
  27. #define UAC_HEADER 0x01
  28. #define UAC_INPUT_TERMINAL 0x02
  29. #define UAC_OUTPUT_TERMINAL 0x03
  30. #define UAC_MIXER_UNIT 0x04
  31. #define UAC_SELECTOR_UNIT 0x05
  32. #define UAC_FEATURE_UNIT 0x06
  33. #define UAC_PROCESSING_UNIT_V1 0x07
  34. #define UAC_EXTENSION_UNIT_V1 0x08
  35. /* UAC v2.0 types */
  36. #define UAC_EFFECT_UNIT 0x07
  37. #define UAC_PROCESSING_UNIT_V2 0x08
  38. #define UAC_EXTENSION_UNIT_V2 0x09
  39. #define UAC_CLOCK_SOURCE 0x0a
  40. #define UAC_CLOCK_SELECTOR 0x0b
  41. #define UAC_CLOCK_MULTIPLIER 0x0c
  42. #define UAC_SAMPLE_RATE_CONVERTER 0x0d
  43. /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
  44. #define UAC_AS_GENERAL 0x01
  45. #define UAC_FORMAT_TYPE 0x02
  46. #define UAC_FORMAT_SPECIFIC 0x03
  47. /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
  48. #define UAC_EP_GENERAL 0x01
  49. /* A.9 Audio Class-Specific Request Codes */
  50. #define UAC_SET_ 0x00
  51. #define UAC_GET_ 0x80
  52. #define UAC__CUR 0x1
  53. #define UAC__MIN 0x2
  54. #define UAC__MAX 0x3
  55. #define UAC__RES 0x4
  56. #define UAC__MEM 0x5
  57. #define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
  58. #define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
  59. #define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
  60. #define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
  61. #define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
  62. #define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
  63. #define UAC_SET_RES (UAC_SET_ | UAC__RES)
  64. #define UAC_GET_RES (UAC_GET_ | UAC__RES)
  65. #define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
  66. #define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
  67. #define UAC_GET_STAT 0xff
  68. /* Audio class v2.0 handles all the parameter calls differently */
  69. #define UAC2_CS_CUR 0x01
  70. #define UAC2_CS_RANGE 0x02
  71. /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
  72. #define UAC_MS_HEADER 0x01
  73. #define UAC_MIDI_IN_JACK 0x02
  74. #define UAC_MIDI_OUT_JACK 0x03
  75. /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
  76. #define UAC_MS_GENERAL 0x01
  77. /* Terminals - 2.1 USB Terminal Types */
  78. #define UAC_TERMINAL_UNDEFINED 0x100
  79. #define UAC_TERMINAL_STREAMING 0x101
  80. #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
  81. /* Terminal Control Selectors */
  82. /* 4.3.2 Class-Specific AC Interface Descriptor */
  83. struct uac_ac_header_descriptor_v1 {
  84. __u8 bLength; /* 8 + n */
  85. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  86. __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
  87. __le16 bcdADC; /* 0x0100 */
  88. __le16 wTotalLength; /* includes Unit and Terminal desc. */
  89. __u8 bInCollection; /* n */
  90. __u8 baInterfaceNr[]; /* [n] */
  91. } __attribute__ ((packed));
  92. #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
  93. /* As above, but more useful for defining your own descriptors: */
  94. #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
  95. struct uac_ac_header_descriptor_v1_##n { \
  96. __u8 bLength; \
  97. __u8 bDescriptorType; \
  98. __u8 bDescriptorSubtype; \
  99. __le16 bcdADC; \
  100. __le16 wTotalLength; \
  101. __u8 bInCollection; \
  102. __u8 baInterfaceNr[n]; \
  103. } __attribute__ ((packed))
  104. /* 4.3.2.1 Input Terminal Descriptor */
  105. struct uac_input_terminal_descriptor {
  106. __u8 bLength; /* in bytes: 12 */
  107. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  108. __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
  109. __u8 bTerminalID; /* Constant uniquely terminal ID */
  110. __le16 wTerminalType; /* USB Audio Terminal Types */
  111. __u8 bAssocTerminal; /* ID of the Output Terminal associated */
  112. __u8 bNrChannels; /* Number of logical output channels */
  113. __le16 wChannelConfig;
  114. __u8 iChannelNames;
  115. __u8 iTerminal;
  116. } __attribute__ ((packed));
  117. #define UAC_DT_INPUT_TERMINAL_SIZE 12
  118. /* Terminals - 2.2 Input Terminal Types */
  119. #define UAC_INPUT_TERMINAL_UNDEFINED 0x200
  120. #define UAC_INPUT_TERMINAL_MICROPHONE 0x201
  121. #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
  122. #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
  123. #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
  124. #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
  125. #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
  126. /* Terminals - control selectors */
  127. #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
  128. /* 4.3.2.2 Output Terminal Descriptor */
  129. struct uac_output_terminal_descriptor_v1 {
  130. __u8 bLength; /* in bytes: 9 */
  131. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  132. __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
  133. __u8 bTerminalID; /* Constant uniquely terminal ID */
  134. __le16 wTerminalType; /* USB Audio Terminal Types */
  135. __u8 bAssocTerminal; /* ID of the Input Terminal associated */
  136. __u8 bSourceID; /* ID of the connected Unit or Terminal*/
  137. __u8 iTerminal;
  138. } __attribute__ ((packed));
  139. #define UAC_DT_OUTPUT_TERMINAL_SIZE 9
  140. /* Terminals - 2.3 Output Terminal Types */
  141. #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
  142. #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
  143. #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
  144. #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
  145. #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
  146. #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
  147. #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
  148. #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
  149. /* Set bControlSize = 2 as default setting */
  150. #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
  151. /* As above, but more useful for defining your own descriptors: */
  152. #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
  153. struct uac_feature_unit_descriptor_##ch { \
  154. __u8 bLength; \
  155. __u8 bDescriptorType; \
  156. __u8 bDescriptorSubtype; \
  157. __u8 bUnitID; \
  158. __u8 bSourceID; \
  159. __u8 bControlSize; \
  160. __le16 bmaControls[ch + 1]; \
  161. __u8 iFeature; \
  162. } __attribute__ ((packed))
  163. /* 4.5.2 Class-Specific AS Interface Descriptor */
  164. struct uac_as_header_descriptor_v1 {
  165. __u8 bLength; /* in bytes: 7 */
  166. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  167. __u8 bDescriptorSubtype; /* AS_GENERAL */
  168. __u8 bTerminalLink; /* Terminal ID of connected Terminal */
  169. __u8 bDelay; /* Delay introduced by the data path */
  170. __le16 wFormatTag; /* The Audio Data Format */
  171. } __attribute__ ((packed));
  172. struct uac_as_header_descriptor_v2 {
  173. __u8 bLength;
  174. __u8 bDescriptorType;
  175. __u8 bDescriptorSubtype;
  176. __u8 bTerminalLink;
  177. __u8 bmControls;
  178. __u8 bFormatType;
  179. __u32 bmFormats;
  180. __u8 bNrChannels;
  181. __u32 bmChannelConfig;
  182. __u8 iChannelNames;
  183. } __attribute__((packed));
  184. #define UAC_DT_AS_HEADER_SIZE 7
  185. /* Formats - A.1.1 Audio Data Format Type I Codes */
  186. #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
  187. #define UAC_FORMAT_TYPE_I_PCM 0x1
  188. #define UAC_FORMAT_TYPE_I_PCM8 0x2
  189. #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
  190. #define UAC_FORMAT_TYPE_I_ALAW 0x4
  191. #define UAC_FORMAT_TYPE_I_MULAW 0x5
  192. struct uac_format_type_i_continuous_descriptor {
  193. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  194. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  195. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  196. __u8 bFormatType; /* FORMAT_TYPE_1 */
  197. __u8 bNrChannels; /* physical channels in the stream */
  198. __u8 bSubframeSize; /* */
  199. __u8 bBitResolution;
  200. __u8 bSamFreqType;
  201. __u8 tLowerSamFreq[3];
  202. __u8 tUpperSamFreq[3];
  203. } __attribute__ ((packed));
  204. #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
  205. struct uac_format_type_i_discrete_descriptor {
  206. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  207. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  208. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  209. __u8 bFormatType; /* FORMAT_TYPE_1 */
  210. __u8 bNrChannels; /* physical channels in the stream */
  211. __u8 bSubframeSize; /* */
  212. __u8 bBitResolution;
  213. __u8 bSamFreqType;
  214. __u8 tSamFreq[][3];
  215. } __attribute__ ((packed));
  216. #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
  217. struct uac_format_type_i_discrete_descriptor_##n { \
  218. __u8 bLength; \
  219. __u8 bDescriptorType; \
  220. __u8 bDescriptorSubtype; \
  221. __u8 bFormatType; \
  222. __u8 bNrChannels; \
  223. __u8 bSubframeSize; \
  224. __u8 bBitResolution; \
  225. __u8 bSamFreqType; \
  226. __u8 tSamFreq[n][3]; \
  227. } __attribute__ ((packed))
  228. #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
  229. struct uac_format_type_i_ext_descriptor {
  230. __u8 bLength;
  231. __u8 bDescriptorType;
  232. __u8 bDescriptorSubtype;
  233. __u8 bFormatType;
  234. __u8 bSubslotSize;
  235. __u8 bBitResolution;
  236. __u8 bHeaderLength;
  237. __u8 bControlSize;
  238. __u8 bSideBandProtocol;
  239. } __attribute__((packed));
  240. /* Formats - Audio Data Format Type I Codes */
  241. #define UAC_FORMAT_TYPE_II_MPEG 0x1001
  242. #define UAC_FORMAT_TYPE_II_AC3 0x1002
  243. struct uac_format_type_ii_discrete_descriptor {
  244. __u8 bLength;
  245. __u8 bDescriptorType;
  246. __u8 bDescriptorSubtype;
  247. __u8 bFormatType;
  248. __le16 wMaxBitRate;
  249. __le16 wSamplesPerFrame;
  250. __u8 bSamFreqType;
  251. __u8 tSamFreq[][3];
  252. } __attribute__((packed));
  253. struct uac_format_type_ii_ext_descriptor {
  254. __u8 bLength;
  255. __u8 bDescriptorType;
  256. __u8 bDescriptorSubtype;
  257. __u8 bFormatType;
  258. __u16 wMaxBitRate;
  259. __u16 wSamplesPerFrame;
  260. __u8 bHeaderLength;
  261. __u8 bSideBandProtocol;
  262. } __attribute__((packed));
  263. /* type III */
  264. #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001
  265. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002
  266. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003
  267. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004
  268. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005
  269. #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006
  270. /* Formats - A.2 Format Type Codes */
  271. #define UAC_FORMAT_TYPE_UNDEFINED 0x0
  272. #define UAC_FORMAT_TYPE_I 0x1
  273. #define UAC_FORMAT_TYPE_II 0x2
  274. #define UAC_FORMAT_TYPE_III 0x3
  275. #define UAC_EXT_FORMAT_TYPE_I 0x81
  276. #define UAC_EXT_FORMAT_TYPE_II 0x82
  277. #define UAC_EXT_FORMAT_TYPE_III 0x83
  278. struct uac_iso_endpoint_descriptor {
  279. __u8 bLength; /* in bytes: 7 */
  280. __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
  281. __u8 bDescriptorSubtype; /* EP_GENERAL */
  282. __u8 bmAttributes;
  283. __u8 bLockDelayUnits;
  284. __le16 wLockDelay;
  285. };
  286. #define UAC_ISO_ENDPOINT_DESC_SIZE 7
  287. #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
  288. #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
  289. #define UAC_EP_CS_ATTR_FILL_MAX 0x80
  290. /* Audio class v2.0: CLOCK_SOURCE descriptor */
  291. struct uac_clock_source_descriptor {
  292. __u8 bLength;
  293. __u8 bDescriptorType;
  294. __u8 bDescriptorSubtype;
  295. __u8 bClockID;
  296. __u8 bmAttributes;
  297. __u8 bmControls;
  298. __u8 bAssocTerminal;
  299. __u8 iClockSource;
  300. } __attribute__((packed));
  301. /* A.10.2 Feature Unit Control Selectors */
  302. struct uac_feature_unit_descriptor {
  303. __u8 bLength;
  304. __u8 bDescriptorType;
  305. __u8 bDescriptorSubtype;
  306. __u8 bUnitID;
  307. __u8 bSourceID;
  308. __u8 bControlSize;
  309. __u8 controls[0]; /* variable length */
  310. } __attribute__((packed));
  311. #define UAC_FU_CONTROL_UNDEFINED 0x00
  312. #define UAC_MUTE_CONTROL 0x01
  313. #define UAC_VOLUME_CONTROL 0x02
  314. #define UAC_BASS_CONTROL 0x03
  315. #define UAC_MID_CONTROL 0x04
  316. #define UAC_TREBLE_CONTROL 0x05
  317. #define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06
  318. #define UAC_AUTOMATIC_GAIN_CONTROL 0x07
  319. #define UAC_DELAY_CONTROL 0x08
  320. #define UAC_BASS_BOOST_CONTROL 0x09
  321. #define UAC_LOUDNESS_CONTROL 0x0a
  322. #define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1))
  323. #define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1))
  324. #define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1))
  325. #define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1))
  326. #define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1))
  327. #define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
  328. #define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
  329. #define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1))
  330. #define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1))
  331. #define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1))
  332. #ifdef __KERNEL__
  333. struct usb_audio_control {
  334. struct list_head list;
  335. const char *name;
  336. u8 type;
  337. int data[5];
  338. int (*set)(struct usb_audio_control *con, u8 cmd, int value);
  339. int (*get)(struct usb_audio_control *con, u8 cmd);
  340. };
  341. struct usb_audio_control_selector {
  342. struct list_head list;
  343. struct list_head control;
  344. u8 id;
  345. const char *name;
  346. u8 type;
  347. struct usb_descriptor_header *desc;
  348. };
  349. #endif /* __KERNEL__ */
  350. #endif /* __LINUX_USB_AUDIO_H */