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