usbaudio.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #ifndef __USBAUDIO_H
  2. #define __USBAUDIO_H
  3. /*
  4. * (Tentative) USB Audio Driver for ALSA
  5. *
  6. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /*
  24. */
  25. #define USB_SUBCLASS_AUDIO_CONTROL 0x01
  26. #define USB_SUBCLASS_AUDIO_STREAMING 0x02
  27. #define USB_SUBCLASS_MIDI_STREAMING 0x03
  28. #define USB_SUBCLASS_VENDOR_SPEC 0xff
  29. #define CS_AUDIO_UNDEFINED 0x20
  30. #define CS_AUDIO_DEVICE 0x21
  31. #define CS_AUDIO_CONFIGURATION 0x22
  32. #define CS_AUDIO_STRING 0x23
  33. #define CS_AUDIO_INTERFACE 0x24
  34. #define CS_AUDIO_ENDPOINT 0x25
  35. #define HEADER 0x01
  36. #define INPUT_TERMINAL 0x02
  37. #define OUTPUT_TERMINAL 0x03
  38. #define MIXER_UNIT 0x04
  39. #define SELECTOR_UNIT 0x05
  40. #define FEATURE_UNIT 0x06
  41. #define PROCESSING_UNIT 0x07
  42. #define EXTENSION_UNIT 0x08
  43. #define AS_GENERAL 0x01
  44. #define FORMAT_TYPE 0x02
  45. #define FORMAT_SPECIFIC 0x03
  46. #define EP_GENERAL 0x01
  47. #define MS_GENERAL 0x01
  48. #define MIDI_IN_JACK 0x02
  49. #define MIDI_OUT_JACK 0x03
  50. /* endpoint attributes */
  51. #define EP_ATTR_MASK 0x0c
  52. #define EP_ATTR_ASYNC 0x04
  53. #define EP_ATTR_ADAPTIVE 0x08
  54. #define EP_ATTR_SYNC 0x0c
  55. /* cs endpoint attributes */
  56. #define EP_CS_ATTR_SAMPLE_RATE 0x01
  57. #define EP_CS_ATTR_PITCH_CONTROL 0x02
  58. #define EP_CS_ATTR_FILL_MAX 0x80
  59. /* Audio Class specific Request Codes */
  60. #define SET_CUR 0x01
  61. #define GET_CUR 0x81
  62. #define SET_MIN 0x02
  63. #define GET_MIN 0x82
  64. #define SET_MAX 0x03
  65. #define GET_MAX 0x83
  66. #define SET_RES 0x04
  67. #define GET_RES 0x84
  68. #define SET_MEM 0x05
  69. #define GET_MEM 0x85
  70. #define GET_STAT 0xff
  71. /* Terminal Control Selectors */
  72. #define COPY_PROTECT_CONTROL 0x01
  73. /* Endpoint Control Selectors */
  74. #define SAMPLING_FREQ_CONTROL 0x01
  75. #define PITCH_CONTROL 0x02
  76. /* Format Types */
  77. #define USB_FORMAT_TYPE_I 0x01
  78. #define USB_FORMAT_TYPE_II 0x02
  79. #define USB_FORMAT_TYPE_III 0x03
  80. /* type I */
  81. #define USB_AUDIO_FORMAT_PCM 0x01
  82. #define USB_AUDIO_FORMAT_PCM8 0x02
  83. #define USB_AUDIO_FORMAT_IEEE_FLOAT 0x03
  84. #define USB_AUDIO_FORMAT_ALAW 0x04
  85. #define USB_AUDIO_FORMAT_MU_LAW 0x05
  86. /* type II */
  87. #define USB_AUDIO_FORMAT_MPEG 0x1001
  88. #define USB_AUDIO_FORMAT_AC3 0x1002
  89. /* type III */
  90. #define USB_AUDIO_FORMAT_IEC1937_AC3 0x2001
  91. #define USB_AUDIO_FORMAT_IEC1937_MPEG1_LAYER1 0x2002
  92. #define USB_AUDIO_FORMAT_IEC1937_MPEG2_NOEXT 0x2003
  93. #define USB_AUDIO_FORMAT_IEC1937_MPEG2_EXT 0x2004
  94. #define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER1_LS 0x2005
  95. #define USB_AUDIO_FORMAT_IEC1937_MPEG2_LAYER23_LS 0x2006
  96. /* maximum number of endpoints per interface */
  97. #define MIDI_MAX_ENDPOINTS 2
  98. /*
  99. */
  100. typedef struct snd_usb_audio snd_usb_audio_t;
  101. struct snd_usb_audio {
  102. int index;
  103. struct usb_device *dev;
  104. snd_card_t *card;
  105. int shutdown;
  106. int num_interfaces;
  107. struct list_head pcm_list; /* list of pcm streams */
  108. int pcm_devs;
  109. struct list_head midi_list; /* list of midi interfaces */
  110. int next_midi_device;
  111. unsigned int ignore_ctl_error; /* for mixer */
  112. };
  113. /*
  114. * Information about devices with broken descriptors
  115. */
  116. /* special values for .ifnum */
  117. #define QUIRK_NO_INTERFACE -2
  118. #define QUIRK_ANY_INTERFACE -1
  119. /* quirk type */
  120. #define QUIRK_MIDI_FIXED_ENDPOINT 0
  121. #define QUIRK_MIDI_YAMAHA 1
  122. #define QUIRK_MIDI_MIDIMAN 2
  123. #define QUIRK_COMPOSITE 3
  124. #define QUIRK_AUDIO_FIXED_ENDPOINT 4
  125. #define QUIRK_AUDIO_STANDARD_INTERFACE 5
  126. #define QUIRK_MIDI_STANDARD_INTERFACE 6
  127. #define QUIRK_AUDIO_EDIROL_UA700_UA25 7
  128. #define QUIRK_AUDIO_EDIROL_UA1000 8
  129. #define QUIRK_IGNORE_INTERFACE 9
  130. #define QUIRK_MIDI_NOVATION 10
  131. #define QUIRK_MIDI_MOTU 11
  132. #define QUIRK_MIDI_EMAGIC 12
  133. typedef struct snd_usb_audio_quirk snd_usb_audio_quirk_t;
  134. typedef struct snd_usb_midi_endpoint_info snd_usb_midi_endpoint_info_t;
  135. struct snd_usb_audio_quirk {
  136. const char *vendor_name;
  137. const char *product_name;
  138. int16_t ifnum;
  139. int16_t type;
  140. const void *data;
  141. };
  142. /* data for QUIRK_MIDI_FIXED_ENDPOINT */
  143. struct snd_usb_midi_endpoint_info {
  144. int8_t out_ep; /* ep number, 0 autodetect */
  145. uint8_t out_interval; /* interval for interrupt endpoints */
  146. int8_t in_ep;
  147. uint8_t in_interval;
  148. uint16_t out_cables; /* bitmask */
  149. uint16_t in_cables; /* bitmask */
  150. };
  151. /* for QUIRK_MIDI_YAMAHA, data is NULL */
  152. /* for QUIRK_MIDI_MIDIMAN, data points to a snd_usb_midi_endpoint_info
  153. * structure (out_cables and in_cables only) */
  154. /* for QUIRK_COMPOSITE, data points to an array of snd_usb_audio_quirk
  155. * structures, terminated with .ifnum = -1 */
  156. /* for QUIRK_AUDIO_FIXED_ENDPOINT, data points to an audioformat structure */
  157. /* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */
  158. /* for QUIRK_AUDIO_EDIROL_UA700_UA25/UA1000, data is NULL */
  159. /* for QUIRK_IGNORE_INTERFACE, data is NULL */
  160. /* for QUIRK_MIDI_NOVATION and _MOTU, data is NULL */
  161. /* for QUIRK_MIDI_EMAGIC, data points to a snd_usb_midi_endpoint_info
  162. * structure (out_cables and in_cables only) */
  163. /*
  164. */
  165. #define combine_word(s) ((*s) | ((unsigned int)(s)[1] << 8))
  166. #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16))
  167. #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24))
  168. unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size);
  169. void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype);
  170. void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype);
  171. int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size, int timeout);
  172. int snd_usb_create_mixer(snd_usb_audio_t *chip, int ctrlif);
  173. int snd_usb_create_midi_interface(snd_usb_audio_t *chip, struct usb_interface *iface, const snd_usb_audio_quirk_t *quirk);
  174. void snd_usbmidi_input_stop(struct list_head* p);
  175. void snd_usbmidi_input_start(struct list_head* p);
  176. void snd_usbmidi_disconnect(struct list_head *p, struct usb_driver *driver);
  177. /*
  178. * retrieve usb_interface descriptor from the host interface
  179. * (conditional for compatibility with the older API)
  180. */
  181. #ifndef get_iface_desc
  182. #define get_iface_desc(iface) (&(iface)->desc)
  183. #define get_endpoint(alt,ep) (&(alt)->endpoint[ep].desc)
  184. #define get_ep_desc(ep) (&(ep)->desc)
  185. #define get_cfg_desc(cfg) (&(cfg)->desc)
  186. #endif
  187. #ifndef usb_pipe_needs_resubmit
  188. #define usb_pipe_needs_resubmit(pipe) 1
  189. #endif
  190. #ifndef snd_usb_complete_callback
  191. #define snd_usb_complete_callback(x) (x)
  192. #endif
  193. #ifndef snd_usb_get_speed
  194. #define snd_usb_get_speed(dev) ((dev)->speed)
  195. #endif
  196. #endif /* __USBAUDIO_H */