Lines Matching +full:usb +full:- +full:c
1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/usb/generic.c - generic driver for USB devices (not interfaces)
5 * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de>
7 * based on drivers/usb/usb.c which had the following copyrights:
8 * (C) Copyright Linus Torvalds 1999
9 * (C) Copyright Johannes Erdfelt 1999-2001
10 * (C) Copyright Andreas Gal 1999
11 * (C) Copyright Gregory P. Smith 1999
12 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
13 * (C) Copyright Randy Dunlap 2000
14 * (C) Copyright David Brownell 2000-2004
15 * (C) Copyright Yggdrasil Computing, Inc. 2000
17 * (C) Copyright Greg Kroah-Hartman 2002-2003
22 #include <linux/usb.h>
23 #include <linux/usb/hcd.h>
24 #include <uapi/linux/usb/audio.h>
25 #include "usb.h"
34 return desc->bInterfaceClass == USB_CLASS_COMM in is_rndis()
35 && desc->bInterfaceSubClass == 2 in is_rndis()
36 && desc->bInterfaceProtocol == 0xff; in is_rndis()
41 return desc->bInterfaceClass == USB_CLASS_MISC in is_activesync()
42 && desc->bInterfaceSubClass == 1 in is_activesync()
43 && desc->bInterfaceProtocol == 1; in is_activesync()
48 return desc->bInterfaceClass == USB_CLASS_AUDIO; in is_audio()
53 return desc->bInterfaceProtocol == UAC_VERSION_3; in is_uac3_config()
61 struct usb_host_config *c, *best; in usb_choose_configuration() local
67 c = udev->config; in usb_choose_configuration()
68 num_configs = udev->descriptor.bNumConfigurations; in usb_choose_configuration()
69 for (i = 0; i < num_configs; (i++, c++)) { in usb_choose_configuration()
73 if (c->desc.bNumInterfaces > 0) in usb_choose_configuration()
74 desc = &c->intf_cache[0]->altsetting->desc; in usb_choose_configuration()
77 * HP's USB bus-powered keyboard has only one configuration in usb_choose_configuration()
78 * and it claims to be self-powered; other devices may have in usb_choose_configuration()
88 * have any other way to tell whether a device is self-powered, in usb_choose_configuration()
97 /* Rule out self-powered configs for a bus-powered device */ in usb_choose_configuration()
98 if (bus_powered && (c->desc.bmAttributes & in usb_choose_configuration()
106 * to be self-powered when they are really bus-powered. in usb_choose_configuration()
116 if (usb_get_max_power(udev, c) > udev->bus_mA) { in usb_choose_configuration()
130 best = c; in usb_choose_configuration()
136 best = c; in usb_choose_configuration()
147 * pet nonstandard Ethernet-over-USB protocols, ignore it unless in usb_choose_configuration()
156 best = c; in usb_choose_configuration()
161 * first interface is for a non-vendor-specific class. in usb_choose_configuration()
163 * than a vendor-specific driver. */ in usb_choose_configuration()
164 else if (udev->descriptor.bDeviceClass != in usb_choose_configuration()
166 (desc && desc->bInterfaceClass != in usb_choose_configuration()
168 best = c; in usb_choose_configuration()
172 /* If all the remaining configs are vendor-specific, in usb_choose_configuration()
175 best = c; in usb_choose_configuration()
179 dev_info(&udev->dev, "rejected %d configuration%s " in usb_choose_configuration()
184 i = best->desc.bConfigurationValue; in usb_choose_configuration()
185 dev_dbg(&udev->dev, in usb_choose_configuration()
189 i = -1; in usb_choose_configuration()
190 dev_warn(&udev->dev, in usb_choose_configuration()
213 if (udev->use_generic_driver) in usb_generic_driver_match()
228 int err, c; in usb_generic_driver_probe() local
233 if (udev->authorized == 0) in usb_generic_driver_probe()
234 dev_err(&udev->dev, "Device is not authorized for usage\n"); in usb_generic_driver_probe()
236 c = usb_choose_configuration(udev); in usb_generic_driver_probe()
237 if (c >= 0) { in usb_generic_driver_probe()
238 err = usb_set_configuration(udev, c); in usb_generic_driver_probe()
239 if (err && err != -ENODEV) { in usb_generic_driver_probe()
240 dev_err(&udev->dev, "can't set config #%d, error %d\n", in usb_generic_driver_probe()
241 c, err); in usb_generic_driver_probe()
247 /* USB device state == configured ... usable */ in usb_generic_driver_probe()
259 if (udev->actconfig) in usb_generic_driver_disconnect()
260 usb_set_configuration(udev, -1); in usb_generic_driver_disconnect()
269 /* Normal USB devices suspend through their upstream port. in usb_generic_driver_suspend()
271 * so we have to shut down their downstream HC-to-USB in usb_generic_driver_suspend()
274 if (!udev->parent) in usb_generic_driver_suspend()
278 * Non-root USB2 devices don't need to do anything for FREEZE in usb_generic_driver_suspend()
283 && (udev->speed < USB_SPEED_SUPER)) in usb_generic_driver_suspend()
297 /* Normal USB devices resume/reset through their upstream port. in usb_generic_driver_resume()
299 * so we have to start up their downstream HC-to-USB in usb_generic_driver_resume()
302 if (!udev->parent) in usb_generic_driver_resume()
315 .name = "usb",