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 10 /* handling of USB vendor/product ID pairs as 32-bit numbers */ 11 #define USB_ID(vendor, product) (((unsigned int)(vendor) << 16) | (product)) 12 #define USB_ID_VENDOR(id) ((id) >> 16) 13 #define USB_ID_PRODUCT(id) ((u16)(id)) 14 15 #include <linux/android_kabi.h> 16 17 /* 18 * 19 */ 20 21 struct media_device; 22 struct media_intf_devnode; 23 24 #define MAX_CARD_INTERFACES 16 25 26 struct snd_usb_audio { 27 int index; 28 struct usb_device *dev; 29 struct snd_card *card; 30 struct usb_interface *intf[MAX_CARD_INTERFACES]; 31 u32 usb_id; 32 uint16_t quirk_type; 33 struct mutex mutex; 34 unsigned int system_suspend; 35 atomic_t active; 36 atomic_t shutdown; 37 atomic_t usage_count; 38 wait_queue_head_t shutdown_wait; 39 unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */ 40 unsigned int tx_length_quirk:1; /* Put length specifier in transfers */ 41 unsigned int setup_fmt_after_resume_quirk:1; /* setup the format to interface after resume */ 42 unsigned int need_delayed_register:1; /* warn for delayed registration */ 43 int num_interfaces; 44 int num_suspended_intf; 45 int sample_rate_read_error; 46 47 int badd_profile; /* UAC3 BADD profile */ 48 49 struct list_head pcm_list; /* list of pcm streams */ 50 struct list_head ep_list; /* list of audio-related endpoints */ 51 int pcm_devs; 52 53 struct list_head midi_list; /* list of midi interfaces */ 54 55 struct list_head mixer_list; /* list of mixer interfaces */ 56 57 int setup; /* from the 'device_setup' module param */ 58 bool autoclock; /* from the 'autoclock' module param */ 59 bool keep_iface; /* keep interface/altset after closing 60 * or parameter change 61 */ 62 63 struct usb_host_interface *ctrl_intf; /* the audio control interface */ 64 struct media_device *media_dev; 65 struct media_intf_devnode *ctl_intf_media_devnode; 66 struct mutex dev_lock; /* to protect any race with disconnect */ 67 int card_num; /* cache pcm card number to use upon disconnect */ 68 void (*disconnect_cb)(struct snd_usb_audio *chip); 69 70 ANDROID_KABI_RESERVE(1); 71 ANDROID_KABI_RESERVE(2); 72 ANDROID_KABI_RESERVE(3); 73 ANDROID_KABI_RESERVE(4); 74 }; 75 76 #define USB_AUDIO_IFACE_UNUSED ((void *)-1L) 77 78 #define usb_audio_err(chip, fmt, args...) \ 79 dev_err(&(chip)->dev->dev, fmt, ##args) 80 #define usb_audio_warn(chip, fmt, args...) \ 81 dev_warn(&(chip)->dev->dev, fmt, ##args) 82 #define usb_audio_info(chip, fmt, args...) \ 83 dev_info(&(chip)->dev->dev, fmt, ##args) 84 #define usb_audio_dbg(chip, fmt, args...) \ 85 dev_dbg(&(chip)->dev->dev, fmt, ##args) 86 87 /* 88 * Information about devices with broken descriptors 89 */ 90 91 /* special values for .ifnum */ 92 #define QUIRK_NO_INTERFACE -2 93 #define QUIRK_ANY_INTERFACE -1 94 95 enum quirk_type { 96 QUIRK_IGNORE_INTERFACE, 97 QUIRK_COMPOSITE, 98 QUIRK_AUTODETECT, 99 QUIRK_MIDI_STANDARD_INTERFACE, 100 QUIRK_MIDI_FIXED_ENDPOINT, 101 QUIRK_MIDI_YAMAHA, 102 QUIRK_MIDI_ROLAND, 103 QUIRK_MIDI_MIDIMAN, 104 QUIRK_MIDI_NOVATION, 105 QUIRK_MIDI_RAW_BYTES, 106 QUIRK_MIDI_EMAGIC, 107 QUIRK_MIDI_CME, 108 QUIRK_MIDI_AKAI, 109 QUIRK_MIDI_US122L, 110 QUIRK_MIDI_FTDI, 111 QUIRK_MIDI_CH345, 112 QUIRK_AUDIO_STANDARD_INTERFACE, 113 QUIRK_AUDIO_FIXED_ENDPOINT, 114 QUIRK_AUDIO_EDIROL_UAXX, 115 QUIRK_AUDIO_ALIGN_TRANSFER, 116 QUIRK_AUDIO_STANDARD_MIXER, 117 QUIRK_SETUP_FMT_AFTER_RESUME, 118 QUIRK_SETUP_DISABLE_AUTOSUSPEND, 119 120 QUIRK_TYPE_COUNT 121 }; 122 123 struct snd_usb_audio_quirk { 124 const char *vendor_name; 125 const char *product_name; 126 int16_t ifnum; 127 uint16_t type; 128 bool shares_media_device; 129 const void *data; 130 }; 131 132 #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8)) 133 #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) 134 #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) 135 136 int snd_usb_lock_shutdown(struct snd_usb_audio *chip); 137 void snd_usb_unlock_shutdown(struct snd_usb_audio *chip); 138 139 extern bool snd_usb_use_vmalloc; 140 extern bool snd_usb_skip_validation; 141 142 struct audioformat; 143 144 enum snd_vendor_pcm_open_close { 145 SOUND_PCM_CLOSE = 0, 146 SOUND_PCM_OPEN, 147 }; 148 149 /** 150 * struct snd_usb_audio_vendor_ops - function callbacks for USB audio accelerators 151 * @connect: called when a new interface is found 152 * @disconnect: called when an interface is removed 153 * @set_interface: called when an interface is initialized 154 * @set_rate: called when the rate is set 155 * @set_pcm_buf: called when the pcm buffer is set 156 * @set_pcm_intf: called when the pcm interface is set 157 * @set_pcm_connection: called when pcm is opened/closed 158 * @set_pcm_binterval: called when the pcm binterval is set 159 * @usb_add_ctls: called when USB controls are added 160 * 161 * Set of callbacks for some accelerated USB audio streaming hardware. 162 * 163 * TODO: make this USB host-controller specific, right now this only works for 164 * one USB controller in the system at a time, which is only realistic for 165 * self-contained systems like phones. 166 */ 167 struct snd_usb_audio_vendor_ops { 168 int (*connect)(struct usb_interface *intf); 169 void (*disconnect)(struct usb_interface *intf); 170 171 int (*set_interface)(struct usb_device *udev, 172 struct usb_host_interface *alts, 173 int iface, int alt); 174 int (*set_rate)(struct usb_interface *intf, int iface, int rate, 175 int alt); 176 int (*set_pcm_buf)(struct usb_device *udev, int iface); 177 int (*set_pcm_intf)(struct usb_interface *intf, int iface, int alt, 178 int direction); 179 int (*set_pcm_connection)(struct usb_device *udev, 180 enum snd_vendor_pcm_open_close onoff, 181 int direction); 182 int (*set_pcm_binterval)(struct audioformat *fp, 183 struct audioformat *found, 184 int *cur_attr, int *attr); 185 int (*usb_add_ctls)(struct snd_usb_audio *chip); 186 187 ANDROID_KABI_RESERVE(1); 188 ANDROID_KABI_RESERVE(2); 189 }; 190 191 #endif /* __USBAUDIO_H */ 192