audio.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 USB_SUBCLASS_VENDOR_SPEC 0xff
  25. /* A.5 Audio Class-Specific AC interface Descriptor Subtypes*/
  26. #define HEADER 0x01
  27. #define INPUT_TERMINAL 0x02
  28. #define OUTPUT_TERMINAL 0x03
  29. #define MIXER_UNIT 0x04
  30. #define SELECTOR_UNIT 0x05
  31. #define FEATURE_UNIT 0x06
  32. #define PROCESSING_UNIT 0x07
  33. #define EXTENSION_UNIT 0x08
  34. #define AS_GENERAL 0x01
  35. #define FORMAT_TYPE 0x02
  36. #define FORMAT_SPECIFIC 0x03
  37. #define EP_GENERAL 0x01
  38. #define MS_GENERAL 0x01
  39. #define MIDI_IN_JACK 0x02
  40. #define MIDI_OUT_JACK 0x03
  41. /* endpoint attributes */
  42. #define EP_ATTR_MASK 0x0c
  43. #define EP_ATTR_ASYNC 0x04
  44. #define EP_ATTR_ADAPTIVE 0x08
  45. #define EP_ATTR_SYNC 0x0c
  46. /* cs endpoint attributes */
  47. #define EP_CS_ATTR_SAMPLE_RATE 0x01
  48. #define EP_CS_ATTR_PITCH_CONTROL 0x02
  49. #define EP_CS_ATTR_FILL_MAX 0x80
  50. /* Audio Class specific Request Codes */
  51. #define USB_AUDIO_SET_INTF 0x21
  52. #define USB_AUDIO_SET_ENDPOINT 0x22
  53. #define USB_AUDIO_GET_INTF 0xa1
  54. #define USB_AUDIO_GET_ENDPOINT 0xa2
  55. #define SET_ 0x00
  56. #define GET_ 0x80
  57. #define _CUR 0x1
  58. #define _MIN 0x2
  59. #define _MAX 0x3
  60. #define _RES 0x4
  61. #define _MEM 0x5
  62. #define SET_CUR (SET_ | _CUR)
  63. #define GET_CUR (GET_ | _CUR)
  64. #define SET_MIN (SET_ | _MIN)
  65. #define GET_MIN (GET_ | _MIN)
  66. #define SET_MAX (SET_ | _MAX)
  67. #define GET_MAX (GET_ | _MAX)
  68. #define SET_RES (SET_ | _RES)
  69. #define GET_RES (GET_ | _RES)
  70. #define SET_MEM (SET_ | _MEM)
  71. #define GET_MEM (GET_ | _MEM)
  72. #define GET_STAT 0xff
  73. #define USB_AC_TERMINAL_UNDEFINED 0x100
  74. #define USB_AC_TERMINAL_STREAMING 0x101
  75. #define USB_AC_TERMINAL_VENDOR_SPEC 0x1FF
  76. /* Terminal Control Selectors */
  77. /* 4.3.2 Class-Specific AC Interface Descriptor */
  78. struct usb_ac_header_descriptor {
  79. __u8 bLength; /* 8 + n */
  80. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  81. __u8 bDescriptorSubtype; /* USB_MS_HEADER */
  82. __le16 bcdADC; /* 0x0100 */
  83. __le16 wTotalLength; /* includes Unit and Terminal desc. */
  84. __u8 bInCollection; /* n */
  85. __u8 baInterfaceNr[]; /* [n] */
  86. } __attribute__ ((packed));
  87. #define USB_DT_AC_HEADER_SIZE(n) (8 + (n))
  88. /* As above, but more useful for defining your own descriptors: */
  89. #define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \
  90. struct usb_ac_header_descriptor_##n { \
  91. __u8 bLength; \
  92. __u8 bDescriptorType; \
  93. __u8 bDescriptorSubtype; \
  94. __le16 bcdADC; \
  95. __le16 wTotalLength; \
  96. __u8 bInCollection; \
  97. __u8 baInterfaceNr[n]; \
  98. } __attribute__ ((packed))
  99. /* 4.3.2.1 Input Terminal Descriptor */
  100. struct usb_input_terminal_descriptor {
  101. __u8 bLength; /* in bytes: 12 */
  102. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  103. __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
  104. __u8 bTerminalID; /* Constant uniquely terminal ID */
  105. __le16 wTerminalType; /* USB Audio Terminal Types */
  106. __u8 bAssocTerminal; /* ID of the Output Terminal associated */
  107. __u8 bNrChannels; /* Number of logical output channels */
  108. __le16 wChannelConfig;
  109. __u8 iChannelNames;
  110. __u8 iTerminal;
  111. } __attribute__ ((packed));
  112. #define USB_DT_AC_INPUT_TERMINAL_SIZE 12
  113. #define USB_AC_INPUT_TERMINAL_UNDEFINED 0x200
  114. #define USB_AC_INPUT_TERMINAL_MICROPHONE 0x201
  115. #define USB_AC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
  116. #define USB_AC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
  117. #define USB_AC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
  118. #define USB_AC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
  119. #define USB_AC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
  120. /* 4.3.2.2 Output Terminal Descriptor */
  121. struct usb_output_terminal_descriptor {
  122. __u8 bLength; /* in bytes: 9 */
  123. __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
  124. __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
  125. __u8 bTerminalID; /* Constant uniquely terminal ID */
  126. __le16 wTerminalType; /* USB Audio Terminal Types */
  127. __u8 bAssocTerminal; /* ID of the Input Terminal associated */
  128. __u8 bSourceID; /* ID of the connected Unit or Terminal*/
  129. __u8 iTerminal;
  130. } __attribute__ ((packed));
  131. #define USB_DT_AC_OUTPUT_TERMINAL_SIZE 9
  132. #define USB_AC_OUTPUT_TERMINAL_UNDEFINED 0x300
  133. #define USB_AC_OUTPUT_TERMINAL_SPEAKER 0x301
  134. #define USB_AC_OUTPUT_TERMINAL_HEADPHONES 0x302
  135. #define USB_AC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
  136. #define USB_AC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
  137. #define USB_AC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
  138. #define USB_AC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
  139. #define USB_AC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
  140. /* Set bControlSize = 2 as default setting */
  141. #define USB_DT_AC_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
  142. /* As above, but more useful for defining your own descriptors: */
  143. #define DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(ch) \
  144. struct usb_ac_feature_unit_descriptor_##ch { \
  145. __u8 bLength; \
  146. __u8 bDescriptorType; \
  147. __u8 bDescriptorSubtype; \
  148. __u8 bUnitID; \
  149. __u8 bSourceID; \
  150. __u8 bControlSize; \
  151. __le16 bmaControls[ch + 1]; \
  152. __u8 iFeature; \
  153. } __attribute__ ((packed))
  154. /* 4.5.2 Class-Specific AS Interface Descriptor */
  155. struct usb_as_header_descriptor {
  156. __u8 bLength; /* in bytes: 7 */
  157. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  158. __u8 bDescriptorSubtype; /* AS_GENERAL */
  159. __u8 bTerminalLink; /* Terminal ID of connected Terminal */
  160. __u8 bDelay; /* Delay introduced by the data path */
  161. __le16 wFormatTag; /* The Audio Data Format */
  162. } __attribute__ ((packed));
  163. #define USB_DT_AS_HEADER_SIZE 7
  164. #define USB_AS_AUDIO_FORMAT_TYPE_I_UNDEFINED 0x0
  165. #define USB_AS_AUDIO_FORMAT_TYPE_I_PCM 0x1
  166. #define USB_AS_AUDIO_FORMAT_TYPE_I_PCM8 0x2
  167. #define USB_AS_AUDIO_FORMAT_TYPE_I_IEEE_FLOAT 0x3
  168. #define USB_AS_AUDIO_FORMAT_TYPE_I_ALAW 0x4
  169. #define USB_AS_AUDIO_FORMAT_TYPE_I_MULAW 0x5
  170. struct usb_as_format_type_i_continuous_descriptor {
  171. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  172. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  173. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  174. __u8 bFormatType; /* FORMAT_TYPE_1 */
  175. __u8 bNrChannels; /* physical channels in the stream */
  176. __u8 bSubframeSize; /* */
  177. __u8 bBitResolution;
  178. __u8 bSamFreqType;
  179. __u8 tLowerSamFreq[3];
  180. __u8 tUpperSamFreq[3];
  181. } __attribute__ ((packed));
  182. #define USB_AS_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
  183. struct usb_as_formate_type_i_discrete_descriptor {
  184. __u8 bLength; /* in bytes: 8 + (ns * 3) */
  185. __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
  186. __u8 bDescriptorSubtype; /* FORMAT_TYPE */
  187. __u8 bFormatType; /* FORMAT_TYPE_1 */
  188. __u8 bNrChannels; /* physical channels in the stream */
  189. __u8 bSubframeSize; /* */
  190. __u8 bBitResolution;
  191. __u8 bSamFreqType;
  192. __u8 tSamFreq[][3];
  193. } __attribute__ ((packed));
  194. #define DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(n) \
  195. struct usb_as_formate_type_i_discrete_descriptor_##n { \
  196. __u8 bLength; \
  197. __u8 bDescriptorType; \
  198. __u8 bDescriptorSubtype; \
  199. __u8 bFormatType; \
  200. __u8 bNrChannels; \
  201. __u8 bSubframeSize; \
  202. __u8 bBitResolution; \
  203. __u8 bSamFreqType; \
  204. __u8 tSamFreq[n][3]; \
  205. } __attribute__ ((packed))
  206. #define USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
  207. #define USB_AS_FORMAT_TYPE_UNDEFINED 0x0
  208. #define USB_AS_FORMAT_TYPE_I 0x1
  209. #define USB_AS_FORMAT_TYPE_II 0x2
  210. #define USB_AS_FORMAT_TYPE_III 0x3
  211. #define USB_AS_ENDPOINT_ASYNC (1 << 2)
  212. #define USB_AS_ENDPOINT_ADAPTIVE (2 << 2)
  213. #define USB_AS_ENDPOINT_SYNC (3 << 2)
  214. struct usb_as_iso_endpoint_descriptor {
  215. __u8 bLength; /* in bytes: 7 */
  216. __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
  217. __u8 bDescriptorSubtype; /* EP_GENERAL */
  218. __u8 bmAttributes;
  219. __u8 bLockDelayUnits;
  220. __le16 wLockDelay;
  221. };
  222. #define USB_AS_ISO_ENDPOINT_DESC_SIZE 7
  223. #define FU_CONTROL_UNDEFINED 0x00
  224. #define MUTE_CONTROL 0x01
  225. #define VOLUME_CONTROL 0x02
  226. #define BASS_CONTROL 0x03
  227. #define MID_CONTROL 0x04
  228. #define TREBLE_CONTROL 0x05
  229. #define GRAPHIC_EQUALIZER_CONTROL 0x06
  230. #define AUTOMATIC_GAIN_CONTROL 0x07
  231. #define DELAY_CONTROL 0x08
  232. #define BASS_BOOST_CONTROL 0x09
  233. #define LOUDNESS_CONTROL 0x0a
  234. #define FU_MUTE (1 << (MUTE_CONTROL - 1))
  235. #define FU_VOLUME (1 << (VOLUME_CONTROL - 1))
  236. #define FU_BASS (1 << (BASS_CONTROL - 1))
  237. #define FU_MID (1 << (MID_CONTROL - 1))
  238. #define FU_TREBLE (1 << (TREBLE_CONTROL - 1))
  239. #define FU_GRAPHIC_EQ (1 << (GRAPHIC_EQUALIZER_CONTROL - 1))
  240. #define FU_AUTO_GAIN (1 << (AUTOMATIC_GAIN_CONTROL - 1))
  241. #define FU_DELAY (1 << (DELAY_CONTROL - 1))
  242. #define FU_BASS_BOOST (1 << (BASS_BOOST_CONTROL - 1))
  243. #define FU_LOUDNESS (1 << (LOUDNESS_CONTROL - 1))
  244. struct usb_audio_control {
  245. struct list_head list;
  246. const char *name;
  247. u8 type;
  248. int data[5];
  249. int (*set)(struct usb_audio_control *con, u8 cmd, int value);
  250. int (*get)(struct usb_audio_control *con, u8 cmd);
  251. };
  252. static inline int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
  253. {
  254. con->data[cmd] = value;
  255. return 0;
  256. }
  257. static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
  258. {
  259. return con->data[cmd];
  260. }
  261. struct usb_audio_control_selector {
  262. struct list_head list;
  263. struct list_head control;
  264. u8 id;
  265. const char *name;
  266. u8 type;
  267. struct usb_descriptor_header *desc;
  268. };
  269. #endif /* __LINUX_USB_AUDIO_H */