usbaudio.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __USBAUDIO_H
  3. #define __USBAUDIO_H
  4. /*
  5. * (Tentative) USB Audio Driver for ALSA
  6. *
  7. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  8. */
  9. /* handling of USB vendor/product ID pairs as 32-bit numbers */
  10. #define USB_ID(vendor, product) (((unsigned int)(vendor) << 16) | (product))
  11. #define USB_ID_VENDOR(id) ((id) >> 16)
  12. #define USB_ID_PRODUCT(id) ((u16)(id))
  13. /*
  14. *
  15. */
  16. struct media_device;
  17. struct media_intf_devnode;
  18. #define MAX_CARD_INTERFACES 16
  19. /*
  20. * Structure holding assosiation between Audio Control Interface
  21. * and given Streaming or Midi Interface.
  22. */
  23. struct snd_intf_to_ctrl {
  24. u8 interface;
  25. struct usb_host_interface *ctrl_intf;
  26. };
  27. struct snd_usb_audio {
  28. int index;
  29. struct usb_device *dev;
  30. struct snd_card *card;
  31. struct usb_interface *intf[MAX_CARD_INTERFACES];
  32. u32 usb_id;
  33. uint16_t quirk_type;
  34. struct mutex mutex;
  35. unsigned int system_suspend;
  36. atomic_t active;
  37. atomic_t shutdown;
  38. atomic_t usage_count;
  39. wait_queue_head_t shutdown_wait;
  40. unsigned int quirk_flags;
  41. unsigned int need_delayed_register:1; /* warn for delayed registration */
  42. int num_interfaces;
  43. int last_iface;
  44. int num_suspended_intf;
  45. int sample_rate_read_error;
  46. int badd_profile; /* UAC3 BADD profile */
  47. struct list_head pcm_list; /* list of pcm streams */
  48. struct list_head ep_list; /* list of audio-related endpoints */
  49. struct list_head iface_ref_list; /* list of interface refcounts */
  50. struct list_head clock_ref_list; /* list of clock refcounts */
  51. int pcm_devs;
  52. unsigned int num_rawmidis; /* number of created rawmidi devices */
  53. struct list_head midi_list; /* list of midi interfaces */
  54. struct list_head midi_v2_list; /* list of MIDI 2 interfaces */
  55. struct list_head mixer_list; /* list of mixer interfaces */
  56. int setup; /* from the 'device_setup' module param */
  57. bool generic_implicit_fb; /* from the 'implicit_fb' module param */
  58. bool autoclock; /* from the 'autoclock' module param */
  59. bool lowlatency; /* from the 'lowlatency' module param */
  60. struct usb_host_interface *ctrl_intf; /* the audio control interface */
  61. struct media_device *media_dev;
  62. struct media_intf_devnode *ctl_intf_media_devnode;
  63. unsigned int num_intf_to_ctrl;
  64. struct snd_intf_to_ctrl intf_to_ctrl[MAX_CARD_INTERFACES];
  65. };
  66. #define USB_AUDIO_IFACE_UNUSED ((void *)-1L)
  67. #define usb_audio_err(chip, fmt, args...) \
  68. dev_err(&(chip)->dev->dev, fmt, ##args)
  69. #define usb_audio_err_ratelimited(chip, fmt, args...) \
  70. dev_err_ratelimited(&(chip)->dev->dev, fmt, ##args)
  71. #define usb_audio_warn(chip, fmt, args...) \
  72. dev_warn(&(chip)->dev->dev, fmt, ##args)
  73. #define usb_audio_info(chip, fmt, args...) \
  74. dev_info(&(chip)->dev->dev, fmt, ##args)
  75. #define usb_audio_dbg(chip, fmt, args...) \
  76. dev_dbg(&(chip)->dev->dev, fmt, ##args)
  77. /*
  78. * Information about devices with broken descriptors
  79. */
  80. /* special values for .ifnum */
  81. #define QUIRK_NODEV_INTERFACE -3 /* return -ENODEV */
  82. #define QUIRK_NO_INTERFACE -2
  83. #define QUIRK_ANY_INTERFACE -1
  84. enum quirk_type {
  85. QUIRK_IGNORE_INTERFACE,
  86. QUIRK_COMPOSITE,
  87. QUIRK_AUTODETECT,
  88. QUIRK_MIDI_STANDARD_INTERFACE,
  89. QUIRK_MIDI_FIXED_ENDPOINT,
  90. QUIRK_MIDI_YAMAHA,
  91. QUIRK_MIDI_ROLAND,
  92. QUIRK_MIDI_MIDIMAN,
  93. QUIRK_MIDI_NOVATION,
  94. QUIRK_MIDI_RAW_BYTES,
  95. QUIRK_MIDI_EMAGIC,
  96. QUIRK_MIDI_CME,
  97. QUIRK_MIDI_AKAI,
  98. QUIRK_MIDI_US122L,
  99. QUIRK_MIDI_FTDI,
  100. QUIRK_MIDI_CH345,
  101. QUIRK_AUDIO_STANDARD_INTERFACE,
  102. QUIRK_AUDIO_FIXED_ENDPOINT,
  103. QUIRK_AUDIO_EDIROL_UAXX,
  104. QUIRK_AUDIO_STANDARD_MIXER,
  105. QUIRK_TYPE_COUNT
  106. };
  107. struct snd_usb_audio_quirk {
  108. const char *vendor_name;
  109. const char *product_name;
  110. int16_t ifnum;
  111. uint16_t type;
  112. const void *data;
  113. };
  114. #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8))
  115. #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16))
  116. #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24))
  117. int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
  118. void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
  119. extern bool snd_usb_use_vmalloc;
  120. extern bool snd_usb_skip_validation;
  121. /*
  122. * Driver behavior quirk flags, stored in chip->quirk_flags
  123. *
  124. * QUIRK_FLAG_GET_SAMPLE_RATE:
  125. * Skip reading sample rate for devices, as some devices behave inconsistently
  126. * or return error
  127. * QUIRK_FLAG_SHARE_MEDIA_DEVICE:
  128. * Create Media Controller API entries
  129. * QUIRK_FLAG_ALIGN_TRANSFER:
  130. * Allow alignment on audio sub-slot (channel samples) rather than on audio
  131. * slots (audio frames)
  132. * QUIRK_TX_LENGTH:
  133. * Add length specifier to transfers
  134. * QUIRK_FLAG_PLAYBACK_FIRST:
  135. * Start playback stream at first even in implement feedback mode
  136. * QUIRK_FLAG_SKIP_CLOCK_SELECTOR:
  137. * Skip clock selector setup; the device may reset to invalid state
  138. * QUIRK_FLAG_IGNORE_CLOCK_SOURCE:
  139. * Ignore errors from clock source search; i.e. hardcoded clock
  140. * QUIRK_FLAG_ITF_USB_DSD_DAC:
  141. * Indicates the device is for ITF-USB DSD based DACs that need a vendor cmd
  142. * to switch between PCM and native DSD mode
  143. * QUIRK_FLAG_CTL_MSG_DELAY:
  144. * Add a delay of 20ms at each control message handling
  145. * QUIRK_FLAG_CTL_MSG_DELAY_1M:
  146. * Add a delay of 1-2ms at each control message handling
  147. * QUIRK_FLAG_CTL_MSG_DELAY_5M:
  148. * Add a delay of 5-6ms at each control message handling
  149. * QUIRK_FLAG_IFACE_DELAY:
  150. * Add a delay of 50ms at each interface setup
  151. * QUIRK_FLAG_VALIDATE_RATES:
  152. * Perform sample rate validations at probe
  153. * QUIRK_FLAG_DISABLE_AUTOSUSPEND:
  154. * Disable runtime PM autosuspend
  155. * QUIRK_FLAG_IGNORE_CTL_ERROR:
  156. * Ignore errors for mixer access
  157. * QUIRK_FLAG_DSD_RAW:
  158. * Support generic DSD raw U32_BE format
  159. * QUIRK_FLAG_SET_IFACE_FIRST:
  160. * Set up the interface at first like UAC1
  161. * QUIRK_FLAG_GENERIC_IMPLICIT_FB
  162. * Apply the generic implicit feedback sync mode (same as implicit_fb=1 option)
  163. * QUIRK_FLAG_SKIP_IMPLICIT_FB
  164. * Don't apply implicit feedback sync mode
  165. * QUIRK_FLAG_IFACE_SKIP_CLOSE
  166. * Don't closed interface during setting sample rate
  167. * QUIRK_FLAG_FORCE_IFACE_RESET
  168. * Force an interface reset whenever stopping & restarting a stream
  169. * (e.g. after xrun)
  170. * QUIRK_FLAG_FIXED_RATE
  171. * Do not set PCM rate (frequency) when only one rate is available
  172. * for the given endpoint.
  173. * QUIRK_FLAG_MIC_RES_16 and QUIRK_FLAG_MIC_RES_384
  174. * Set the fixed resolution for Mic Capture Volume (mostly for webcams)
  175. */
  176. #define QUIRK_FLAG_GET_SAMPLE_RATE (1U << 0)
  177. #define QUIRK_FLAG_SHARE_MEDIA_DEVICE (1U << 1)
  178. #define QUIRK_FLAG_ALIGN_TRANSFER (1U << 2)
  179. #define QUIRK_FLAG_TX_LENGTH (1U << 3)
  180. #define QUIRK_FLAG_PLAYBACK_FIRST (1U << 4)
  181. #define QUIRK_FLAG_SKIP_CLOCK_SELECTOR (1U << 5)
  182. #define QUIRK_FLAG_IGNORE_CLOCK_SOURCE (1U << 6)
  183. #define QUIRK_FLAG_ITF_USB_DSD_DAC (1U << 7)
  184. #define QUIRK_FLAG_CTL_MSG_DELAY (1U << 8)
  185. #define QUIRK_FLAG_CTL_MSG_DELAY_1M (1U << 9)
  186. #define QUIRK_FLAG_CTL_MSG_DELAY_5M (1U << 10)
  187. #define QUIRK_FLAG_IFACE_DELAY (1U << 11)
  188. #define QUIRK_FLAG_VALIDATE_RATES (1U << 12)
  189. #define QUIRK_FLAG_DISABLE_AUTOSUSPEND (1U << 13)
  190. #define QUIRK_FLAG_IGNORE_CTL_ERROR (1U << 14)
  191. #define QUIRK_FLAG_DSD_RAW (1U << 15)
  192. #define QUIRK_FLAG_SET_IFACE_FIRST (1U << 16)
  193. #define QUIRK_FLAG_GENERIC_IMPLICIT_FB (1U << 17)
  194. #define QUIRK_FLAG_SKIP_IMPLICIT_FB (1U << 18)
  195. #define QUIRK_FLAG_IFACE_SKIP_CLOSE (1U << 19)
  196. #define QUIRK_FLAG_FORCE_IFACE_RESET (1U << 20)
  197. #define QUIRK_FLAG_FIXED_RATE (1U << 21)
  198. #define QUIRK_FLAG_MIC_RES_16 (1U << 22)
  199. #define QUIRK_FLAG_MIC_RES_384 (1U << 23)
  200. #endif /* __USBAUDIO_H */