hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/usb/core/generic.c
....@@ -21,6 +21,7 @@
2121
2222 #include <linux/usb.h>
2323 #include <linux/usb/hcd.h>
24
+#include <uapi/linux/usb/audio.h>
2425 #include "usb.h"
2526
2627 static inline const char *plural(int n)
....@@ -42,34 +43,14 @@
4243 && desc->bInterfaceProtocol == 1;
4344 }
4445
45
-static int get_usb_audio_config(struct usb_host_bos *bos)
46
+static bool is_audio(struct usb_interface_descriptor *desc)
4647 {
47
- unsigned int desc_cnt, num_cfg_desc, len = 0;
48
- unsigned char *buffer;
49
- struct usb_config_summary_descriptor *conf_summary;
48
+ return desc->bInterfaceClass == USB_CLASS_AUDIO;
49
+}
5050
51
- if (!bos || !bos->config_summary)
52
- goto done;
53
-
54
- num_cfg_desc = bos->num_config_summary_desc;
55
- conf_summary = bos->config_summary;
56
- buffer = (unsigned char *)conf_summary;
57
- for (desc_cnt = 0; desc_cnt < num_cfg_desc; desc_cnt++) {
58
- conf_summary =
59
- (struct usb_config_summary_descriptor *)(buffer + len);
60
-
61
- len += conf_summary->bLength;
62
-
63
- if (conf_summary->bcdVersion != USB_CONFIG_SUMMARY_DESC_REV ||
64
- conf_summary->bClass != USB_CLASS_AUDIO)
65
- continue;
66
-
67
- /* return 1st config as per device preference */
68
- return conf_summary->bConfigurationIndex[0];
69
- }
70
-
71
-done:
72
- return -EINVAL;
51
+static bool is_uac3_config(struct usb_interface_descriptor *desc)
52
+{
53
+ return desc->bInterfaceProtocol == UAC_VERSION_3;
7354 }
7455
7556 int usb_choose_configuration(struct usb_device *udev)
....@@ -137,6 +118,31 @@
137118 continue;
138119 }
139120
121
+ /*
122
+ * Select first configuration as default for audio so that
123
+ * devices that don't comply with UAC3 protocol are supported.
124
+ * But, still iterate through other configurations and
125
+ * select UAC3 compliant config if present.
126
+ */
127
+ if (desc && is_audio(desc)) {
128
+ /* Always prefer the first found UAC3 config */
129
+ if (is_uac3_config(desc)) {
130
+ best = c;
131
+ break;
132
+ }
133
+
134
+ /* If there is no UAC3 config, prefer the first config */
135
+ else if (i == 0)
136
+ best = c;
137
+
138
+ /* Unconditional continue, because the rest of the code
139
+ * in the loop is irrelevant for audio devices, and
140
+ * because it can reassign best, which for audio devices
141
+ * we don't want.
142
+ */
143
+ continue;
144
+ }
145
+
140146 /* When the first config's first interface is one of Microsoft's
141147 * pet nonstandard Ethernet-over-USB protocols, ignore it unless
142148 * this kernel has enabled the necessary host side driver.
....@@ -175,10 +181,7 @@
175181 insufficient_power, plural(insufficient_power));
176182
177183 if (best) {
178
- /* choose device preferred config */
179
- i = get_usb_audio_config(udev->bos);
180
- if (i < 0)
181
- i = best->desc.bConfigurationValue;
184
+ i = best->desc.bConfigurationValue;
182185 dev_dbg(&udev->dev,
183186 "configuration #%d chosen from %d choice%s\n",
184187 i, num_configs, plural(num_configs));
....@@ -192,7 +195,35 @@
192195 }
193196 EXPORT_SYMBOL_GPL(usb_choose_configuration);
194197
195
-static int generic_probe(struct usb_device *udev)
198
+static int __check_for_non_generic_match(struct device_driver *drv, void *data)
199
+{
200
+ struct usb_device *udev = data;
201
+ struct usb_device_driver *udrv;
202
+
203
+ if (!is_usb_device_driver(drv))
204
+ return 0;
205
+ udrv = to_usb_device_driver(drv);
206
+ if (udrv == &usb_generic_driver)
207
+ return 0;
208
+ return usb_driver_applicable(udev, udrv);
209
+}
210
+
211
+static bool usb_generic_driver_match(struct usb_device *udev)
212
+{
213
+ if (udev->use_generic_driver)
214
+ return true;
215
+
216
+ /*
217
+ * If any other driver wants the device, leave the device to this other
218
+ * driver.
219
+ */
220
+ if (bus_for_each_drv(&usb_bus_type, NULL, udev, __check_for_non_generic_match))
221
+ return false;
222
+
223
+ return true;
224
+}
225
+
226
+int usb_generic_driver_probe(struct usb_device *udev)
196227 {
197228 int err, c;
198229
....@@ -219,7 +250,7 @@
219250 return 0;
220251 }
221252
222
-static void generic_disconnect(struct usb_device *udev)
253
+void usb_generic_driver_disconnect(struct usb_device *udev)
223254 {
224255 usb_notify_remove_device(udev);
225256
....@@ -231,7 +262,7 @@
231262
232263 #ifdef CONFIG_PM
233264
234
-static int generic_suspend(struct usb_device *udev, pm_message_t msg)
265
+int usb_generic_driver_suspend(struct usb_device *udev, pm_message_t msg)
235266 {
236267 int rc;
237268
....@@ -254,10 +285,12 @@
254285 else
255286 rc = usb_port_suspend(udev, msg);
256287
288
+ if (rc == 0)
289
+ usbfs_notify_suspend(udev);
257290 return rc;
258291 }
259292
260
-static int generic_resume(struct usb_device *udev, pm_message_t msg)
293
+int usb_generic_driver_resume(struct usb_device *udev, pm_message_t msg)
261294 {
262295 int rc;
263296
....@@ -270,6 +303,9 @@
270303 rc = hcd_bus_resume(udev, msg);
271304 else
272305 rc = usb_port_resume(udev, msg);
306
+
307
+ if (rc == 0)
308
+ usbfs_notify_resume(udev);
273309 return rc;
274310 }
275311
....@@ -277,11 +313,12 @@
277313
278314 struct usb_device_driver usb_generic_driver = {
279315 .name = "usb",
280
- .probe = generic_probe,
281
- .disconnect = generic_disconnect,
316
+ .match = usb_generic_driver_match,
317
+ .probe = usb_generic_driver_probe,
318
+ .disconnect = usb_generic_driver_disconnect,
282319 #ifdef CONFIG_PM
283
- .suspend = generic_suspend,
284
- .resume = generic_resume,
320
+ .suspend = usb_generic_driver_suspend,
321
+ .resume = usb_generic_driver_resume,
285322 #endif
286323 .supports_autosuspend = 1,
287324 };