• 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 /*
16  *
17  */
18 
19 struct media_device;
20 struct media_intf_devnode;
21 
22 struct snd_usb_audio {
23 	int index;
24 	struct usb_device *dev;
25 	struct snd_card *card;
26 	struct usb_interface *pm_intf;
27 	u32 usb_id;
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 txfr_quirk:1; /* Subframe boundaries on transfers */
35 	unsigned int tx_length_quirk:1; /* Put length specifier in transfers */
36 	unsigned int setup_fmt_after_resume_quirk:1; /* setup the format to interface after resume */
37 	int num_interfaces;
38 	int num_suspended_intf;
39 	int sample_rate_read_error;
40 
41 	int badd_profile;		/* UAC3 BADD profile */
42 
43 	struct list_head pcm_list;	/* list of pcm streams */
44 	struct list_head ep_list;	/* list of audio-related endpoints */
45 	int pcm_devs;
46 
47 	struct list_head midi_list;	/* list of midi interfaces */
48 
49 	struct list_head mixer_list;	/* list of mixer interfaces */
50 
51 	int setup;			/* from the 'device_setup' module param */
52 	bool autoclock;			/* from the 'autoclock' module param */
53 	bool keep_iface;		/* keep interface/altset after closing
54 					 * or parameter change
55 					 */
56 
57 	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
58 	struct media_device *media_dev;
59 	struct media_intf_devnode *ctl_intf_media_devnode;
60 	struct mutex dev_lock;  /* to protect any race with disconnect */
61 	int card_num;	/* cache pcm card number to use upon disconnect */
62 	void (*disconnect_cb)(struct snd_usb_audio *chip);
63 };
64 
65 #define USB_AUDIO_IFACE_UNUSED	((void *)-1L)
66 
67 #define usb_audio_err(chip, fmt, args...) \
68 	dev_err(&(chip)->dev->dev, fmt, ##args)
69 #define usb_audio_warn(chip, fmt, args...) \
70 	dev_warn(&(chip)->dev->dev, fmt, ##args)
71 #define usb_audio_info(chip, fmt, args...) \
72 	dev_info(&(chip)->dev->dev, fmt, ##args)
73 #define usb_audio_dbg(chip, fmt, args...) \
74 	dev_dbg(&(chip)->dev->dev, fmt, ##args)
75 
76 /*
77  * Information about devices with broken descriptors
78  */
79 
80 /* special values for .ifnum */
81 #define QUIRK_NO_INTERFACE		-2
82 #define QUIRK_ANY_INTERFACE		-1
83 
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_ALIGN_TRANSFER,
105 	QUIRK_AUDIO_STANDARD_MIXER,
106 	QUIRK_SETUP_FMT_AFTER_RESUME,
107 
108 	QUIRK_TYPE_COUNT
109 };
110 
111 struct snd_usb_audio_quirk {
112 	const char *vendor_name;
113 	const char *product_name;
114 	const char *profile_name;	/* override the card->longname */
115 	int16_t ifnum;
116 	uint16_t type;
117 	bool shares_media_device;
118 	const void *data;
119 };
120 
121 #define combine_word(s)    ((*(s)) | ((unsigned int)(s)[1] << 8))
122 #define combine_triple(s)  (combine_word(s) | ((unsigned int)(s)[2] << 16))
123 #define combine_quad(s)    (combine_triple(s) | ((unsigned int)(s)[3] << 24))
124 
125 int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
126 void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
127 
128 extern bool snd_usb_use_vmalloc;
129 
130 struct audioformat;
131 
132 enum snd_vendor_pcm_open_close {
133 	SOUND_PCM_CLOSE = 0,
134 	SOUND_PCM_OPEN,
135 };
136 
137 /**
138  * struct snd_usb_audio_vendor_ops - function callbacks for USB audio accelerators
139  * @connect: called when a new interface is found
140  * @disconnect: called when an interface is removed
141  * @set_interface: called when an interface is initialized
142  * @set_rate: called when the rate is set
143  * @set_pcm_buf: called when the pcm buffer is set
144  * @set_pcm_intf: called when the pcm interface is set
145  * @set_pcm_connection: called when pcm is opened/closed
146  * @set_pcm_binterval: called when the pcm binterval is set
147  * @usb_add_ctls: called when USB controls are added
148  *
149  * Set of callbacks for some accelerated USB audio streaming hardware.
150  *
151  * TODO: make this USB host-controller specific, right now this only works for
152  * one USB controller in the system at a time, which is only realistic for
153  * self-contained systems like phones.
154  */
155 struct snd_usb_audio_vendor_ops {
156 	int (*connect)(struct usb_interface *intf);
157 	void (*disconnect)(struct usb_interface *intf);
158 
159 	int (*set_interface)(struct usb_device *udev,
160 			     struct usb_host_interface *alts,
161 			     int iface, int alt);
162 	int (*set_rate)(struct usb_interface *intf, int iface, int rate,
163 			int alt);
164 	int (*set_pcm_buf)(struct usb_device *udev, int iface);
165 	int (*set_pcm_intf)(struct usb_interface *intf, int iface, int alt,
166 			    int direction);
167 	int (*set_pcm_connection)(struct usb_device *udev,
168 				  enum snd_vendor_pcm_open_close onoff,
169 				  int direction);
170 	int (*set_pcm_binterval)(struct audioformat *fp,
171 				 struct audioformat *found,
172 				 int *cur_attr, int *attr);
173 	int (*usb_add_ctls)(struct snd_usb_audio *chip);
174 };
175 
176 #endif /* __USBAUDIO_H */
177