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