audio.h 9.4 KB

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