usbaudio.h 7.8 KB

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