Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/driver.c - most of the driver model stuff for usb |
| 3 | * |
| 4 | * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de> |
| 5 | * |
| 6 | * based on drivers/usb/usb.c which had the following copyrights: |
| 7 | * (C) Copyright Linus Torvalds 1999 |
| 8 | * (C) Copyright Johannes Erdfelt 1999-2001 |
| 9 | * (C) Copyright Andreas Gal 1999 |
| 10 | * (C) Copyright Gregory P. Smith 1999 |
| 11 | * (C) Copyright Deti Fliegl 1999 (new USB architecture) |
| 12 | * (C) Copyright Randy Dunlap 2000 |
| 13 | * (C) Copyright David Brownell 2000-2004 |
| 14 | * (C) Copyright Yggdrasil Computing, Inc. 2000 |
| 15 | * (usb_device_id matching changes by Adam J. Richter) |
| 16 | * (C) Copyright Greg Kroah-Hartman 2002-2003 |
| 17 | * |
| 18 | * NOTE! This is not actually a driver at all, rather this is |
| 19 | * just a collection of helper routines that implement the |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 20 | * matching, probing, releasing, suspending and resuming for |
| 21 | * real drivers. |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 25 | #include <linux/device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Paul Gortmaker | f940fcd | 2011-05-27 09:56:31 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 28 | #include <linux/usb.h> |
Alan Stern | 6bc6cff | 2007-05-04 11:53:03 -0400 | [diff] [blame] | 29 | #include <linux/usb/quirks.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 30 | #include <linux/usb/hcd.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 31 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 32 | #include "usb.h" |
| 33 | |
Alan Stern | 20dfdad | 2007-05-22 11:50:17 -0400 | [diff] [blame] | 34 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 35 | #ifdef CONFIG_HOTPLUG |
| 36 | |
| 37 | /* |
| 38 | * Adds a new dynamic USBdevice ID to this driver, |
| 39 | * and cause the driver to probe for all devices again. |
| 40 | */ |
Greg Kroah-Hartman | 93bacef | 2006-12-17 21:50:23 +0100 | [diff] [blame] | 41 | ssize_t usb_store_new_id(struct usb_dynids *dynids, |
| 42 | struct device_driver *driver, |
| 43 | const char *buf, size_t count) |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 44 | { |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 45 | struct usb_dynid *dynid; |
| 46 | u32 idVendor = 0; |
| 47 | u32 idProduct = 0; |
Josua Dietze | ff231db | 2011-10-23 14:22:29 +0200 | [diff] [blame] | 48 | unsigned int bInterfaceClass = 0; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 49 | int fields = 0; |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 50 | int retval = 0; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 51 | |
Josua Dietze | ff231db | 2011-10-23 14:22:29 +0200 | [diff] [blame] | 52 | fields = sscanf(buf, "%x %x %x", &idVendor, &idProduct, |
| 53 | &bInterfaceClass); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 54 | if (fields < 2) |
| 55 | return -EINVAL; |
| 56 | |
| 57 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 58 | if (!dynid) |
| 59 | return -ENOMEM; |
| 60 | |
| 61 | INIT_LIST_HEAD(&dynid->node); |
| 62 | dynid->id.idVendor = idVendor; |
| 63 | dynid->id.idProduct = idProduct; |
| 64 | dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
Josua Dietze | ff231db | 2011-10-23 14:22:29 +0200 | [diff] [blame] | 65 | if (fields == 3) { |
| 66 | dynid->id.bInterfaceClass = (u8)bInterfaceClass; |
| 67 | dynid->id.match_flags |= USB_DEVICE_ID_MATCH_INT_CLASS; |
| 68 | } |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 69 | |
Greg Kroah-Hartman | 93bacef | 2006-12-17 21:50:23 +0100 | [diff] [blame] | 70 | spin_lock(&dynids->lock); |
Nathael Pajani | e5dd011 | 2007-09-04 11:46:23 +0200 | [diff] [blame] | 71 | list_add_tail(&dynid->node, &dynids->list); |
Greg Kroah-Hartman | 93bacef | 2006-12-17 21:50:23 +0100 | [diff] [blame] | 72 | spin_unlock(&dynids->lock); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 73 | |
Alan Stern | cef9bc5 | 2012-01-24 13:34:41 -0500 | [diff] [blame] | 74 | retval = driver_attach(driver); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 75 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 76 | if (retval) |
| 77 | return retval; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 78 | return count; |
| 79 | } |
Greg Kroah-Hartman | 93bacef | 2006-12-17 21:50:23 +0100 | [diff] [blame] | 80 | EXPORT_SYMBOL_GPL(usb_store_new_id); |
| 81 | |
| 82 | static ssize_t store_new_id(struct device_driver *driver, |
| 83 | const char *buf, size_t count) |
| 84 | { |
| 85 | struct usb_driver *usb_drv = to_usb_driver(driver); |
| 86 | |
| 87 | return usb_store_new_id(&usb_drv->dynids, driver, buf, count); |
| 88 | } |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 89 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); |
| 90 | |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 91 | /** |
| 92 | * store_remove_id - remove a USB device ID from this driver |
| 93 | * @driver: target device driver |
| 94 | * @buf: buffer for scanning device ID data |
| 95 | * @count: input size |
| 96 | * |
| 97 | * Removes a dynamic usb device ID from this driver. |
| 98 | */ |
| 99 | static ssize_t |
| 100 | store_remove_id(struct device_driver *driver, const char *buf, size_t count) |
| 101 | { |
| 102 | struct usb_dynid *dynid, *n; |
| 103 | struct usb_driver *usb_driver = to_usb_driver(driver); |
| 104 | u32 idVendor = 0; |
| 105 | u32 idProduct = 0; |
| 106 | int fields = 0; |
| 107 | int retval = 0; |
| 108 | |
| 109 | fields = sscanf(buf, "%x %x", &idVendor, &idProduct); |
| 110 | if (fields < 2) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | spin_lock(&usb_driver->dynids.lock); |
| 114 | list_for_each_entry_safe(dynid, n, &usb_driver->dynids.list, node) { |
| 115 | struct usb_device_id *id = &dynid->id; |
| 116 | if ((id->idVendor == idVendor) && |
| 117 | (id->idProduct == idProduct)) { |
| 118 | list_del(&dynid->node); |
| 119 | kfree(dynid); |
| 120 | retval = 0; |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | spin_unlock(&usb_driver->dynids.lock); |
| 125 | |
| 126 | if (retval) |
| 127 | return retval; |
| 128 | return count; |
| 129 | } |
| 130 | static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id); |
| 131 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 132 | static int usb_create_newid_files(struct usb_driver *usb_drv) |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 133 | { |
| 134 | int error = 0; |
| 135 | |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 136 | if (usb_drv->no_dynamic_id) |
| 137 | goto exit; |
| 138 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 139 | if (usb_drv->probe != NULL) { |
Greg Kroah-Hartman | 15147ff | 2007-11-28 12:23:18 -0800 | [diff] [blame] | 140 | error = driver_create_file(&usb_drv->drvwrap.driver, |
| 141 | &driver_attr_new_id); |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 142 | if (error == 0) { |
| 143 | error = driver_create_file(&usb_drv->drvwrap.driver, |
| 144 | &driver_attr_remove_id); |
| 145 | if (error) |
| 146 | driver_remove_file(&usb_drv->drvwrap.driver, |
| 147 | &driver_attr_new_id); |
| 148 | } |
| 149 | } |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 150 | exit: |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 151 | return error; |
| 152 | } |
| 153 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 154 | static void usb_remove_newid_files(struct usb_driver *usb_drv) |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 155 | { |
| 156 | if (usb_drv->no_dynamic_id) |
| 157 | return; |
| 158 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 159 | if (usb_drv->probe != NULL) { |
| 160 | driver_remove_file(&usb_drv->drvwrap.driver, |
| 161 | &driver_attr_remove_id); |
Greg Kroah-Hartman | 15147ff | 2007-11-28 12:23:18 -0800 | [diff] [blame] | 162 | driver_remove_file(&usb_drv->drvwrap.driver, |
| 163 | &driver_attr_new_id); |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 164 | } |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 165 | } |
| 166 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 167 | static void usb_free_dynids(struct usb_driver *usb_drv) |
| 168 | { |
| 169 | struct usb_dynid *dynid, *n; |
| 170 | |
| 171 | spin_lock(&usb_drv->dynids.lock); |
| 172 | list_for_each_entry_safe(dynid, n, &usb_drv->dynids.list, node) { |
| 173 | list_del(&dynid->node); |
| 174 | kfree(dynid); |
| 175 | } |
| 176 | spin_unlock(&usb_drv->dynids.lock); |
| 177 | } |
| 178 | #else |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 179 | static inline int usb_create_newid_files(struct usb_driver *usb_drv) |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 180 | { |
| 181 | return 0; |
| 182 | } |
| 183 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 184 | static void usb_remove_newid_files(struct usb_driver *usb_drv) |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 185 | { |
| 186 | } |
| 187 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 188 | static inline void usb_free_dynids(struct usb_driver *usb_drv) |
| 189 | { |
| 190 | } |
| 191 | #endif |
| 192 | |
| 193 | static const struct usb_device_id *usb_match_dynamic_id(struct usb_interface *intf, |
| 194 | struct usb_driver *drv) |
| 195 | { |
| 196 | struct usb_dynid *dynid; |
| 197 | |
| 198 | spin_lock(&drv->dynids.lock); |
| 199 | list_for_each_entry(dynid, &drv->dynids.list, node) { |
| 200 | if (usb_match_one_id(intf, &dynid->id)) { |
| 201 | spin_unlock(&drv->dynids.lock); |
| 202 | return &dynid->id; |
| 203 | } |
| 204 | } |
| 205 | spin_unlock(&drv->dynids.lock); |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 210 | /* called from driver core with dev locked */ |
| 211 | static int usb_probe_device(struct device *dev) |
| 212 | { |
| 213 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 214 | struct usb_device *udev = to_usb_device(dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 215 | int error = 0; |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 216 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 217 | dev_dbg(dev, "%s\n", __func__); |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 218 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 219 | /* TODO: Add real matching code */ |
| 220 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 221 | /* The device should always appear to be in use |
| 222 | * unless the driver suports autosuspend. |
| 223 | */ |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 224 | if (!udriver->supports_autosuspend) |
| 225 | error = usb_autoresume_device(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 226 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 227 | if (!error) |
| 228 | error = udriver->probe(udev); |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 229 | return error; |
| 230 | } |
| 231 | |
| 232 | /* called from driver core with dev locked */ |
| 233 | static int usb_unbind_device(struct device *dev) |
| 234 | { |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 235 | struct usb_device *udev = to_usb_device(dev); |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 236 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
| 237 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 238 | udriver->disconnect(udev); |
| 239 | if (!udriver->supports_autosuspend) |
| 240 | usb_autosuspend_device(udev); |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | |
Inaky Perez-Gonzalez | dc023dc | 2008-11-13 10:31:35 -0800 | [diff] [blame] | 244 | /* |
| 245 | * Cancel any pending scheduled resets |
| 246 | * |
| 247 | * [see usb_queue_reset_device()] |
| 248 | * |
| 249 | * Called after unconfiguring / when releasing interfaces. See |
| 250 | * comments in __usb_queue_reset_device() regarding |
| 251 | * udev->reset_running. |
| 252 | */ |
| 253 | static void usb_cancel_queued_reset(struct usb_interface *iface) |
| 254 | { |
| 255 | if (iface->reset_running == 0) |
| 256 | cancel_work_sync(&iface->reset_ws); |
| 257 | } |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 258 | |
| 259 | /* called from driver core with dev locked */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 260 | static int usb_probe_interface(struct device *dev) |
| 261 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 262 | struct usb_driver *driver = to_usb_driver(dev->driver); |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 263 | struct usb_interface *intf = to_usb_interface(dev); |
| 264 | struct usb_device *udev = interface_to_usbdev(intf); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 265 | const struct usb_device_id *id; |
| 266 | int error = -ENODEV; |
| 267 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 268 | dev_dbg(dev, "%s\n", __func__); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 269 | |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 270 | intf->needs_binding = 0; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 271 | |
Alan Stern | 7cbe5dc | 2009-06-29 10:56:54 -0400 | [diff] [blame] | 272 | if (usb_device_is_owned(udev)) |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 273 | return error; |
Alan Stern | 7cbe5dc | 2009-06-29 10:56:54 -0400 | [diff] [blame] | 274 | |
Greg Kroah-Hartman | 2c044a4 | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 275 | if (udev->authorized == 0) { |
| 276 | dev_err(&intf->dev, "Device is not authorized for usage\n"); |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 277 | return error; |
Greg Kroah-Hartman | 2c044a4 | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 278 | } |
Inaky Perez-Gonzalez | 72230ab | 2007-07-31 20:34:03 -0700 | [diff] [blame] | 279 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 280 | id = usb_match_id(intf, driver->id_table); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 281 | if (!id) |
| 282 | id = usb_match_dynamic_id(intf, driver); |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 283 | if (!id) |
| 284 | return error; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 285 | |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 286 | dev_dbg(dev, "%s - got id\n", __func__); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 287 | |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 288 | error = usb_autoresume_device(udev); |
| 289 | if (error) |
| 290 | return error; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 291 | |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 292 | intf->condition = USB_INTERFACE_BINDING; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 293 | |
Alan Stern | 571dc79 | 2010-04-09 16:03:43 -0400 | [diff] [blame] | 294 | /* Probed interfaces are initially active. They are |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 295 | * runtime-PM-enabled only if the driver has autosuspend support. |
| 296 | * They are sensitive to their children's power states. |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 297 | */ |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 298 | pm_runtime_set_active(dev); |
| 299 | pm_suspend_ignore_children(dev, false); |
| 300 | if (driver->supports_autosuspend) |
| 301 | pm_runtime_enable(dev); |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 302 | |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 303 | /* Carry out a deferred switch to altsetting 0 */ |
| 304 | if (intf->needs_altsetting0) { |
| 305 | error = usb_set_interface(udev, intf->altsetting[0]. |
| 306 | desc.bInterfaceNumber, 0); |
| 307 | if (error < 0) |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 308 | goto err; |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 309 | intf->needs_altsetting0 = 0; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 312 | error = driver->probe(intf, id); |
| 313 | if (error) |
| 314 | goto err; |
| 315 | |
| 316 | intf->condition = USB_INTERFACE_BOUND; |
| 317 | usb_autosuspend_device(udev); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 318 | return error; |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 319 | |
Alan Stern | 0f3dda9 | 2010-01-08 12:56:04 -0500 | [diff] [blame] | 320 | err: |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 321 | intf->needs_remote_wakeup = 0; |
| 322 | intf->condition = USB_INTERFACE_UNBOUND; |
| 323 | usb_cancel_queued_reset(intf); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 324 | |
| 325 | /* Unbound interfaces are always runtime-PM-disabled and -suspended */ |
Alan Stern | 89842ae | 2010-05-11 11:44:06 -0400 | [diff] [blame] | 326 | if (driver->supports_autosuspend) |
| 327 | pm_runtime_disable(dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 328 | pm_runtime_set_suspended(dev); |
| 329 | |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 330 | usb_autosuspend_device(udev); |
| 331 | return error; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 334 | /* called from driver core with dev locked */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 335 | static int usb_unbind_interface(struct device *dev) |
| 336 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 337 | struct usb_driver *driver = to_usb_driver(dev->driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 338 | struct usb_interface *intf = to_usb_interface(dev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 339 | struct usb_device *udev; |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 340 | int error, r; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 341 | |
| 342 | intf->condition = USB_INTERFACE_UNBINDING; |
| 343 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 344 | /* Autoresume for set_interface call below */ |
| 345 | udev = interface_to_usbdev(intf); |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 346 | error = usb_autoresume_device(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 347 | |
Alan Stern | 9da82bd | 2008-05-08 11:54:37 -0400 | [diff] [blame] | 348 | /* Terminate all URBs for this interface unless the driver |
| 349 | * supports "soft" unbinding. |
| 350 | */ |
| 351 | if (!driver->soft_unbind) |
Alan Stern | ddeac4e | 2009-01-15 17:03:33 -0500 | [diff] [blame] | 352 | usb_disable_interface(udev, intf, false); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 353 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 354 | driver->disconnect(intf); |
Inaky Perez-Gonzalez | dc023dc | 2008-11-13 10:31:35 -0800 | [diff] [blame] | 355 | usb_cancel_queued_reset(intf); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 356 | |
Alan Stern | 55151d7 | 2008-08-12 14:33:59 -0400 | [diff] [blame] | 357 | /* Reset other interface state. |
| 358 | * We cannot do a Set-Interface if the device is suspended or |
| 359 | * if it is prepared for a system sleep (since installing a new |
| 360 | * altsetting means creating new endpoint device entries). |
| 361 | * When either of these happens, defer the Set-Interface. |
| 362 | */ |
Alan Stern | 2caf7fc | 2008-12-31 11:31:33 -0500 | [diff] [blame] | 363 | if (intf->cur_altsetting->desc.bAlternateSetting == 0) { |
| 364 | /* Already in altsetting 0 so skip Set-Interface. |
| 365 | * Just re-enable it without affecting the endpoint toggles. |
| 366 | */ |
| 367 | usb_enable_interface(udev, intf, false); |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 368 | } else if (!error && !intf->dev.power.is_prepared) { |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 369 | r = usb_set_interface(udev, intf->altsetting[0]. |
Alan Stern | 55151d7 | 2008-08-12 14:33:59 -0400 | [diff] [blame] | 370 | desc.bInterfaceNumber, 0); |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 371 | if (r < 0) |
| 372 | intf->needs_altsetting0 = 1; |
| 373 | } else { |
Alan Stern | 55151d7 | 2008-08-12 14:33:59 -0400 | [diff] [blame] | 374 | intf->needs_altsetting0 = 1; |
Oliver Neukum | 1e5ea5e | 2009-08-27 16:46:56 +0200 | [diff] [blame] | 375 | } |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 376 | usb_set_intfdata(intf, NULL); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 377 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 378 | intf->condition = USB_INTERFACE_UNBOUND; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 379 | intf->needs_remote_wakeup = 0; |
| 380 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 381 | /* Unbound interfaces are always runtime-PM-disabled and -suspended */ |
Alan Stern | 89842ae | 2010-05-11 11:44:06 -0400 | [diff] [blame] | 382 | if (driver->supports_autosuspend) |
| 383 | pm_runtime_disable(dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 384 | pm_runtime_set_suspended(dev); |
| 385 | |
| 386 | /* Undo any residual pm_autopm_get_interface_* calls */ |
| 387 | for (r = atomic_read(&intf->pm_usage_cnt); r > 0; --r) |
| 388 | usb_autopm_put_interface_no_suspend(intf); |
| 389 | atomic_set(&intf->pm_usage_cnt, 0); |
| 390 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 391 | if (!error) |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 392 | usb_autosuspend_device(udev); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 397 | /** |
| 398 | * usb_driver_claim_interface - bind a driver to an interface |
| 399 | * @driver: the driver to be bound |
| 400 | * @iface: the interface to which it will be bound; must be in the |
| 401 | * usb device's active configuration |
| 402 | * @priv: driver data associated with that interface |
| 403 | * |
| 404 | * This is used by usb device drivers that need to claim more than one |
| 405 | * interface on a device when probing (audio and acm are current examples). |
| 406 | * No device driver should directly modify internal usb_interface or |
| 407 | * usb_device structure members. |
| 408 | * |
| 409 | * Few drivers should need to use this routine, since the most natural |
| 410 | * way to bind to an interface is to return the private data from |
| 411 | * the driver's probe() method. |
| 412 | * |
Greg Kroah-Hartman | 341487a | 2007-04-09 11:52:31 -0400 | [diff] [blame] | 413 | * Callers must own the device lock, so driver probe() entries don't need |
| 414 | * extra locking, but other call contexts may need to explicitly claim that |
| 415 | * lock. |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 416 | */ |
| 417 | int usb_driver_claim_interface(struct usb_driver *driver, |
Greg Kroah-Hartman | 2c044a4 | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 418 | struct usb_interface *iface, void *priv) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 419 | { |
| 420 | struct device *dev = &iface->dev; |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 421 | int retval = 0; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 422 | |
| 423 | if (dev->driver) |
| 424 | return -EBUSY; |
| 425 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 426 | dev->driver = &driver->drvwrap.driver; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 427 | usb_set_intfdata(iface, priv); |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 428 | iface->needs_binding = 0; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 429 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 430 | iface->condition = USB_INTERFACE_BOUND; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 431 | |
Alan Stern | 89842ae | 2010-05-11 11:44:06 -0400 | [diff] [blame] | 432 | /* Claimed interfaces are initially inactive (suspended) and |
| 433 | * runtime-PM-enabled, but only if the driver has autosuspend |
| 434 | * support. Otherwise they are marked active, to prevent the |
| 435 | * device from being autosuspended, but left disabled. In either |
| 436 | * case they are sensitive to their children's power states. |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 437 | */ |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 438 | pm_suspend_ignore_children(dev, false); |
| 439 | if (driver->supports_autosuspend) |
| 440 | pm_runtime_enable(dev); |
Alan Stern | 89842ae | 2010-05-11 11:44:06 -0400 | [diff] [blame] | 441 | else |
| 442 | pm_runtime_set_active(dev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 443 | |
| 444 | /* if interface was already added, bind now; else let |
| 445 | * the future device_add() bind it, bypassing probe() |
| 446 | */ |
| 447 | if (device_is_registered(dev)) |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 448 | retval = device_bind_driver(dev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 449 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 450 | return retval; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 451 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 452 | EXPORT_SYMBOL_GPL(usb_driver_claim_interface); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 453 | |
| 454 | /** |
| 455 | * usb_driver_release_interface - unbind a driver from an interface |
| 456 | * @driver: the driver to be unbound |
| 457 | * @iface: the interface from which it will be unbound |
| 458 | * |
| 459 | * This can be used by drivers to release an interface without waiting |
| 460 | * for their disconnect() methods to be called. In typical cases this |
| 461 | * also causes the driver disconnect() method to be called. |
| 462 | * |
| 463 | * This call is synchronous, and may not be used in an interrupt context. |
Greg Kroah-Hartman | 341487a | 2007-04-09 11:52:31 -0400 | [diff] [blame] | 464 | * Callers must own the device lock, so driver disconnect() entries don't |
| 465 | * need extra locking, but other call contexts may need to explicitly claim |
| 466 | * that lock. |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 467 | */ |
| 468 | void usb_driver_release_interface(struct usb_driver *driver, |
| 469 | struct usb_interface *iface) |
| 470 | { |
| 471 | struct device *dev = &iface->dev; |
| 472 | |
| 473 | /* this should never happen, don't release something that's not ours */ |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 474 | if (!dev->driver || dev->driver != &driver->drvwrap.driver) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 475 | return; |
| 476 | |
| 477 | /* don't release from within disconnect() */ |
| 478 | if (iface->condition != USB_INTERFACE_BOUND) |
| 479 | return; |
Alan Stern | 91f8d06 | 2009-04-16 15:35:09 -0400 | [diff] [blame] | 480 | iface->condition = USB_INTERFACE_UNBINDING; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 481 | |
Alan Stern | 91f8d06 | 2009-04-16 15:35:09 -0400 | [diff] [blame] | 482 | /* Release via the driver core only if the interface |
| 483 | * has already been registered |
| 484 | */ |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 485 | if (device_is_registered(dev)) { |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 486 | device_release_driver(dev); |
Inaky Perez-Gonzalez | dc023dc | 2008-11-13 10:31:35 -0800 | [diff] [blame] | 487 | } else { |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 488 | device_lock(dev); |
Alan Stern | 91f8d06 | 2009-04-16 15:35:09 -0400 | [diff] [blame] | 489 | usb_unbind_interface(dev); |
| 490 | dev->driver = NULL; |
Greg Kroah-Hartman | 8e9394c | 2010-02-17 10:57:05 -0800 | [diff] [blame] | 491 | device_unlock(dev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 492 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 493 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 494 | EXPORT_SYMBOL_GPL(usb_driver_release_interface); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 495 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 496 | /* returns 0 if no match, 1 if match */ |
Greg Kroah-Hartman | bb41702 | 2007-01-26 14:26:21 +0100 | [diff] [blame] | 497 | int usb_match_device(struct usb_device *dev, const struct usb_device_id *id) |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 498 | { |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 499 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && |
| 500 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) |
| 501 | return 0; |
| 502 | |
| 503 | if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && |
| 504 | id->idProduct != le16_to_cpu(dev->descriptor.idProduct)) |
| 505 | return 0; |
| 506 | |
| 507 | /* No need to test id->bcdDevice_lo != 0, since 0 is never |
| 508 | greater than any unsigned number. */ |
| 509 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && |
| 510 | (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice))) |
| 511 | return 0; |
| 512 | |
| 513 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && |
| 514 | (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice))) |
| 515 | return 0; |
| 516 | |
| 517 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && |
| 518 | (id->bDeviceClass != dev->descriptor.bDeviceClass)) |
| 519 | return 0; |
| 520 | |
| 521 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && |
Greg Kroah-Hartman | 2c044a4 | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 522 | (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass)) |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 523 | return 0; |
| 524 | |
| 525 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && |
| 526 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) |
| 527 | return 0; |
| 528 | |
Greg Kroah-Hartman | bb41702 | 2007-01-26 14:26:21 +0100 | [diff] [blame] | 529 | return 1; |
| 530 | } |
| 531 | |
| 532 | /* returns 0 if no match, 1 if match */ |
| 533 | int usb_match_one_id(struct usb_interface *interface, |
| 534 | const struct usb_device_id *id) |
| 535 | { |
| 536 | struct usb_host_interface *intf; |
| 537 | struct usb_device *dev; |
| 538 | |
| 539 | /* proc_connectinfo in devio.c may call us with id == NULL. */ |
| 540 | if (id == NULL) |
| 541 | return 0; |
| 542 | |
| 543 | intf = interface->cur_altsetting; |
| 544 | dev = interface_to_usbdev(interface); |
| 545 | |
| 546 | if (!usb_match_device(dev, id)) |
| 547 | return 0; |
| 548 | |
Bjørn Mork | 2f2f189 | 2012-05-18 21:27:43 +0200 | [diff] [blame] | 549 | /* The interface class, subclass, protocol and number should never be |
Alan Stern | 93c8bf4 | 2006-10-18 16:41:51 -0400 | [diff] [blame] | 550 | * checked for a match if the device class is Vendor Specific, |
| 551 | * unless the match record specifies the Vendor ID. */ |
| 552 | if (dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC && |
| 553 | !(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && |
| 554 | (id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS | |
| 555 | USB_DEVICE_ID_MATCH_INT_SUBCLASS | |
Bjørn Mork | 2f2f189 | 2012-05-18 21:27:43 +0200 | [diff] [blame] | 556 | USB_DEVICE_ID_MATCH_INT_PROTOCOL | |
| 557 | USB_DEVICE_ID_MATCH_INT_NUMBER))) |
Alan Stern | 93c8bf4 | 2006-10-18 16:41:51 -0400 | [diff] [blame] | 558 | return 0; |
| 559 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 560 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && |
| 561 | (id->bInterfaceClass != intf->desc.bInterfaceClass)) |
| 562 | return 0; |
| 563 | |
| 564 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && |
| 565 | (id->bInterfaceSubClass != intf->desc.bInterfaceSubClass)) |
| 566 | return 0; |
| 567 | |
| 568 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && |
| 569 | (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) |
| 570 | return 0; |
| 571 | |
Bjørn Mork | 2f2f189 | 2012-05-18 21:27:43 +0200 | [diff] [blame] | 572 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_NUMBER) && |
| 573 | (id->bInterfaceNumber != intf->desc.bInterfaceNumber)) |
| 574 | return 0; |
| 575 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 576 | return 1; |
| 577 | } |
Greg Kroah-Hartman | 93bacef | 2006-12-17 21:50:23 +0100 | [diff] [blame] | 578 | EXPORT_SYMBOL_GPL(usb_match_one_id); |
| 579 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 580 | /** |
| 581 | * usb_match_id - find first usb_device_id matching device or interface |
| 582 | * @interface: the interface of interest |
| 583 | * @id: array of usb_device_id structures, terminated by zero entry |
| 584 | * |
| 585 | * usb_match_id searches an array of usb_device_id's and returns |
| 586 | * the first one matching the device or interface, or null. |
| 587 | * This is used when binding (or rebinding) a driver to an interface. |
| 588 | * Most USB device drivers will use this indirectly, through the usb core, |
| 589 | * but some layered driver frameworks use it directly. |
| 590 | * These device tables are exported with MODULE_DEVICE_TABLE, through |
| 591 | * modutils, to support the driver loading functionality of USB hotplugging. |
| 592 | * |
| 593 | * What Matches: |
| 594 | * |
| 595 | * The "match_flags" element in a usb_device_id controls which |
| 596 | * members are used. If the corresponding bit is set, the |
| 597 | * value in the device_id must match its corresponding member |
| 598 | * in the device or interface descriptor, or else the device_id |
| 599 | * does not match. |
| 600 | * |
| 601 | * "driver_info" is normally used only by device drivers, |
| 602 | * but you can create a wildcard "matches anything" usb_device_id |
| 603 | * as a driver's "modules.usbmap" entry if you provide an id with |
| 604 | * only a nonzero "driver_info" field. If you do this, the USB device |
| 605 | * driver's probe() routine should use additional intelligence to |
| 606 | * decide whether to bind to the specified interface. |
| 607 | * |
| 608 | * What Makes Good usb_device_id Tables: |
| 609 | * |
| 610 | * The match algorithm is very simple, so that intelligence in |
| 611 | * driver selection must come from smart driver id records. |
| 612 | * Unless you have good reasons to use another selection policy, |
| 613 | * provide match elements only in related groups, and order match |
| 614 | * specifiers from specific to general. Use the macros provided |
| 615 | * for that purpose if you can. |
| 616 | * |
| 617 | * The most specific match specifiers use device descriptor |
| 618 | * data. These are commonly used with product-specific matches; |
| 619 | * the USB_DEVICE macro lets you provide vendor and product IDs, |
| 620 | * and you can also match against ranges of product revisions. |
| 621 | * These are widely used for devices with application or vendor |
| 622 | * specific bDeviceClass values. |
| 623 | * |
| 624 | * Matches based on device class/subclass/protocol specifications |
| 625 | * are slightly more general; use the USB_DEVICE_INFO macro, or |
| 626 | * its siblings. These are used with single-function devices |
| 627 | * where bDeviceClass doesn't specify that each interface has |
| 628 | * its own class. |
| 629 | * |
| 630 | * Matches based on interface class/subclass/protocol are the |
| 631 | * most general; they let drivers bind to any interface on a |
| 632 | * multiple-function device. Use the USB_INTERFACE_INFO |
| 633 | * macro, or its siblings, to match class-per-interface style |
Alan Stern | 93c8bf4 | 2006-10-18 16:41:51 -0400 | [diff] [blame] | 634 | * devices (as recorded in bInterfaceClass). |
| 635 | * |
| 636 | * Note that an entry created by USB_INTERFACE_INFO won't match |
| 637 | * any interface if the device class is set to Vendor-Specific. |
| 638 | * This is deliberate; according to the USB spec the meanings of |
| 639 | * the interface class/subclass/protocol for these devices are also |
| 640 | * vendor-specific, and hence matching against a standard product |
| 641 | * class wouldn't work anyway. If you really want to use an |
| 642 | * interface-based match for such a device, create a match record |
| 643 | * that also specifies the vendor ID. (Unforunately there isn't a |
| 644 | * standard macro for creating records like this.) |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 645 | * |
| 646 | * Within those groups, remember that not all combinations are |
| 647 | * meaningful. For example, don't give a product version range |
| 648 | * without vendor and product IDs; or specify a protocol without |
| 649 | * its associated class and subclass. |
| 650 | */ |
| 651 | const struct usb_device_id *usb_match_id(struct usb_interface *interface, |
| 652 | const struct usb_device_id *id) |
| 653 | { |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 654 | /* proc_connectinfo in devio.c may call us with id == NULL. */ |
| 655 | if (id == NULL) |
| 656 | return NULL; |
| 657 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 658 | /* It is important to check that id->driver_info is nonzero, |
| 659 | since an entry that is all zeroes except for a nonzero |
| 660 | id->driver_info is the way to create an entry that |
| 661 | indicates that the driver want to examine every |
| 662 | device and interface. */ |
Greg Kroah-Hartman | de6f92b | 2008-01-28 09:50:12 -0800 | [diff] [blame] | 663 | for (; id->idVendor || id->idProduct || id->bDeviceClass || |
| 664 | id->bInterfaceClass || id->driver_info; id++) { |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 665 | if (usb_match_one_id(interface, id)) |
| 666 | return id; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | return NULL; |
| 670 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 671 | EXPORT_SYMBOL_GPL(usb_match_id); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 672 | |
Adrian Bunk | 8bb22d2 | 2006-11-21 22:02:54 +0100 | [diff] [blame] | 673 | static int usb_device_match(struct device *dev, struct device_driver *drv) |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 674 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 675 | /* devices and interfaces are handled separately */ |
| 676 | if (is_usb_device(dev)) { |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 677 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 678 | /* interface drivers never match devices */ |
| 679 | if (!is_usb_device_driver(drv)) |
| 680 | return 0; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 681 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 682 | /* TODO: Add real matching code */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 683 | return 1; |
| 684 | |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 685 | } else if (is_usb_interface(dev)) { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 686 | struct usb_interface *intf; |
| 687 | struct usb_driver *usb_drv; |
| 688 | const struct usb_device_id *id; |
| 689 | |
| 690 | /* device drivers never match interfaces */ |
| 691 | if (is_usb_device_driver(drv)) |
| 692 | return 0; |
| 693 | |
| 694 | intf = to_usb_interface(dev); |
| 695 | usb_drv = to_usb_driver(drv); |
| 696 | |
| 697 | id = usb_match_id(intf, usb_drv->id_table); |
| 698 | if (id) |
| 699 | return 1; |
| 700 | |
| 701 | id = usb_match_dynamic_id(intf, usb_drv); |
| 702 | if (id) |
| 703 | return 1; |
| 704 | } |
| 705 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 706 | return 0; |
| 707 | } |
| 708 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 709 | #ifdef CONFIG_HOTPLUG |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 710 | static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 711 | { |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 712 | struct usb_device *usb_dev; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 713 | |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 714 | if (is_usb_device(dev)) { |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 715 | usb_dev = to_usb_device(dev); |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 716 | } else if (is_usb_interface(dev)) { |
Kay Sievers | 9f8b17e | 2007-03-13 15:59:31 +0100 | [diff] [blame] | 717 | struct usb_interface *intf = to_usb_interface(dev); |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 718 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 719 | usb_dev = interface_to_usbdev(intf); |
Kay Sievers | 5512966 | 2009-05-04 19:48:32 +0200 | [diff] [blame] | 720 | } else { |
| 721 | return 0; |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 722 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 723 | |
| 724 | if (usb_dev->devnum < 0) { |
Alan Stern | cceffe9 | 2010-02-08 09:45:12 -0500 | [diff] [blame] | 725 | /* driver is often null here; dev_dbg() would oops */ |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 726 | pr_debug("usb %s: already deleted?\n", dev_name(dev)); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 727 | return -ENODEV; |
| 728 | } |
| 729 | if (!usb_dev->bus) { |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 730 | pr_debug("usb %s: bus removed?\n", dev_name(dev)); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 731 | return -ENODEV; |
| 732 | } |
| 733 | |
| 734 | #ifdef CONFIG_USB_DEVICEFS |
| 735 | /* If this is available, userspace programs can directly read |
| 736 | * all the device descriptors we don't tell them about. Or |
Kay Sievers | 9f8b17e | 2007-03-13 15:59:31 +0100 | [diff] [blame] | 737 | * act as usermode drivers. |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 738 | */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 739 | if (add_uevent_var(env, "DEVICE=/proc/bus/usb/%03d/%03d", |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 740 | usb_dev->bus->busnum, usb_dev->devnum)) |
| 741 | return -ENOMEM; |
| 742 | #endif |
| 743 | |
| 744 | /* per-device configurations are common */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 745 | if (add_uevent_var(env, "PRODUCT=%x/%x/%x", |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 746 | le16_to_cpu(usb_dev->descriptor.idVendor), |
| 747 | le16_to_cpu(usb_dev->descriptor.idProduct), |
| 748 | le16_to_cpu(usb_dev->descriptor.bcdDevice))) |
| 749 | return -ENOMEM; |
| 750 | |
| 751 | /* class-based driver binding models */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 752 | if (add_uevent_var(env, "TYPE=%d/%d/%d", |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 753 | usb_dev->descriptor.bDeviceClass, |
| 754 | usb_dev->descriptor.bDeviceSubClass, |
| 755 | usb_dev->descriptor.bDeviceProtocol)) |
| 756 | return -ENOMEM; |
| 757 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | #else |
| 762 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 763 | static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 764 | { |
| 765 | return -ENODEV; |
| 766 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 767 | #endif /* CONFIG_HOTPLUG */ |
| 768 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 769 | /** |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 770 | * usb_register_device_driver - register a USB device (not interface) driver |
| 771 | * @new_udriver: USB operations for the device driver |
Greg Kroah-Hartman | 2143acc | 2005-11-21 14:53:03 -0800 | [diff] [blame] | 772 | * @owner: module owner of this driver. |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 773 | * |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 774 | * Registers a USB device driver with the USB core. The list of |
| 775 | * unattached devices will be rescanned whenever a new driver is |
| 776 | * added, allowing the new driver to attach to any recognized devices. |
| 777 | * Returns a negative error code on failure and 0 on success. |
| 778 | */ |
| 779 | int usb_register_device_driver(struct usb_device_driver *new_udriver, |
| 780 | struct module *owner) |
| 781 | { |
| 782 | int retval = 0; |
| 783 | |
| 784 | if (usb_disabled()) |
| 785 | return -ENODEV; |
| 786 | |
| 787 | new_udriver->drvwrap.for_devices = 1; |
| 788 | new_udriver->drvwrap.driver.name = (char *) new_udriver->name; |
| 789 | new_udriver->drvwrap.driver.bus = &usb_bus_type; |
| 790 | new_udriver->drvwrap.driver.probe = usb_probe_device; |
| 791 | new_udriver->drvwrap.driver.remove = usb_unbind_device; |
| 792 | new_udriver->drvwrap.driver.owner = owner; |
| 793 | |
| 794 | retval = driver_register(&new_udriver->drvwrap.driver); |
| 795 | |
| 796 | if (!retval) { |
| 797 | pr_info("%s: registered new device driver %s\n", |
| 798 | usbcore_name, new_udriver->name); |
| 799 | usbfs_update_special(); |
| 800 | } else { |
| 801 | printk(KERN_ERR "%s: error %d registering device " |
| 802 | " driver %s\n", |
| 803 | usbcore_name, retval, new_udriver->name); |
| 804 | } |
| 805 | |
| 806 | return retval; |
| 807 | } |
| 808 | EXPORT_SYMBOL_GPL(usb_register_device_driver); |
| 809 | |
| 810 | /** |
| 811 | * usb_deregister_device_driver - unregister a USB device (not interface) driver |
| 812 | * @udriver: USB operations of the device driver to unregister |
| 813 | * Context: must be able to sleep |
| 814 | * |
| 815 | * Unlinks the specified driver from the internal USB driver list. |
| 816 | */ |
| 817 | void usb_deregister_device_driver(struct usb_device_driver *udriver) |
| 818 | { |
| 819 | pr_info("%s: deregistering device driver %s\n", |
| 820 | usbcore_name, udriver->name); |
| 821 | |
| 822 | driver_unregister(&udriver->drvwrap.driver); |
| 823 | usbfs_update_special(); |
| 824 | } |
| 825 | EXPORT_SYMBOL_GPL(usb_deregister_device_driver); |
| 826 | |
| 827 | /** |
| 828 | * usb_register_driver - register a USB interface driver |
| 829 | * @new_driver: USB operations for the interface driver |
| 830 | * @owner: module owner of this driver. |
Randy Dunlap | 892705a | 2007-02-10 14:41:41 -0800 | [diff] [blame] | 831 | * @mod_name: module name string |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 832 | * |
| 833 | * Registers a USB interface driver with the USB core. The list of |
| 834 | * unattached interfaces will be rescanned whenever a new driver is |
| 835 | * added, allowing the new driver to attach to any recognized interfaces. |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 836 | * Returns a negative error code on failure and 0 on success. |
| 837 | * |
| 838 | * NOTE: if you want your driver to use the USB major number, you must call |
| 839 | * usb_register_dev() to enable that functionality. This function no longer |
| 840 | * takes care of that. |
| 841 | */ |
Greg Kroah-Hartman | 80f745f | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 842 | int usb_register_driver(struct usb_driver *new_driver, struct module *owner, |
| 843 | const char *mod_name) |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 844 | { |
| 845 | int retval = 0; |
| 846 | |
| 847 | if (usb_disabled()) |
| 848 | return -ENODEV; |
| 849 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 850 | new_driver->drvwrap.for_devices = 0; |
| 851 | new_driver->drvwrap.driver.name = (char *) new_driver->name; |
| 852 | new_driver->drvwrap.driver.bus = &usb_bus_type; |
| 853 | new_driver->drvwrap.driver.probe = usb_probe_interface; |
| 854 | new_driver->drvwrap.driver.remove = usb_unbind_interface; |
| 855 | new_driver->drvwrap.driver.owner = owner; |
Greg Kroah-Hartman | 80f745f | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 856 | new_driver->drvwrap.driver.mod_name = mod_name; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 857 | spin_lock_init(&new_driver->dynids.lock); |
| 858 | INIT_LIST_HEAD(&new_driver->dynids.list); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 859 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 860 | retval = driver_register(&new_driver->drvwrap.driver); |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 861 | if (retval) |
| 862 | goto out; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 863 | |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 864 | usbfs_update_special(); |
| 865 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 866 | retval = usb_create_newid_files(new_driver); |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 867 | if (retval) |
| 868 | goto out_newid; |
| 869 | |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 870 | pr_info("%s: registered new interface driver %s\n", |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 871 | usbcore_name, new_driver->name); |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 872 | |
| 873 | out: |
| 874 | return retval; |
| 875 | |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 876 | out_newid: |
| 877 | driver_unregister(&new_driver->drvwrap.driver); |
| 878 | |
| 879 | printk(KERN_ERR "%s: error %d registering interface " |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 880 | " driver %s\n", |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 881 | usbcore_name, retval, new_driver->name); |
CHENG Renquan | 0c7a2b7 | 2009-11-22 01:28:52 +0800 | [diff] [blame] | 882 | goto out; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 883 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 884 | EXPORT_SYMBOL_GPL(usb_register_driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 885 | |
| 886 | /** |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 887 | * usb_deregister - unregister a USB interface driver |
| 888 | * @driver: USB operations of the interface driver to unregister |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 889 | * Context: must be able to sleep |
| 890 | * |
| 891 | * Unlinks the specified driver from the internal USB driver list. |
| 892 | * |
| 893 | * NOTE: If you called usb_register_dev(), you still need to call |
| 894 | * usb_deregister_dev() to clean up your driver's allocated minor numbers, |
| 895 | * this * call will no longer do it for you. |
| 896 | */ |
| 897 | void usb_deregister(struct usb_driver *driver) |
| 898 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 899 | pr_info("%s: deregistering interface driver %s\n", |
| 900 | usbcore_name, driver->name); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 901 | |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 902 | usb_remove_newid_files(driver); |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 903 | driver_unregister(&driver->drvwrap.driver); |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 904 | usb_free_dynids(driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 905 | |
| 906 | usbfs_update_special(); |
| 907 | } |
Greg Kroah-Hartman | 782e70c | 2008-01-25 11:12:21 -0600 | [diff] [blame] | 908 | EXPORT_SYMBOL_GPL(usb_deregister); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 909 | |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 910 | /* Forced unbinding of a USB interface driver, either because |
| 911 | * it doesn't support pre_reset/post_reset/reset_resume or |
| 912 | * because it doesn't support suspend/resume. |
| 913 | * |
| 914 | * The caller must hold @intf's device's lock, but not its pm_mutex |
| 915 | * and not @intf->dev.sem. |
| 916 | */ |
| 917 | void usb_forced_unbind_intf(struct usb_interface *intf) |
| 918 | { |
| 919 | struct usb_driver *driver = to_usb_driver(intf->dev.driver); |
| 920 | |
| 921 | dev_dbg(&intf->dev, "forced unbind\n"); |
| 922 | usb_driver_release_interface(driver, intf); |
| 923 | |
| 924 | /* Mark the interface for later rebinding */ |
| 925 | intf->needs_binding = 1; |
| 926 | } |
| 927 | |
| 928 | /* Delayed forced unbinding of a USB interface driver and scan |
| 929 | * for rebinding. |
| 930 | * |
| 931 | * The caller must hold @intf's device's lock, but not its pm_mutex |
| 932 | * and not @intf->dev.sem. |
| 933 | * |
Alan Stern | 5096aed | 2008-08-12 14:34:14 -0400 | [diff] [blame] | 934 | * Note: Rebinds will be skipped if a system sleep transition is in |
| 935 | * progress and the PM "complete" callback hasn't occurred yet. |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 936 | */ |
| 937 | void usb_rebind_intf(struct usb_interface *intf) |
| 938 | { |
| 939 | int rc; |
| 940 | |
| 941 | /* Delayed unbind of an existing driver */ |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 942 | if (intf->dev.driver) |
| 943 | usb_forced_unbind_intf(intf); |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 944 | |
| 945 | /* Try to rebind the interface */ |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 946 | if (!intf->dev.power.is_prepared) { |
Alan Stern | 5096aed | 2008-08-12 14:34:14 -0400 | [diff] [blame] | 947 | intf->needs_binding = 0; |
| 948 | rc = device_attach(&intf->dev); |
| 949 | if (rc < 0) |
| 950 | dev_warn(&intf->dev, "rebind failed: %d\n", rc); |
| 951 | } |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Alan Stern | 9ff7843 | 2008-08-07 13:04:51 -0400 | [diff] [blame] | 954 | #ifdef CONFIG_PM |
| 955 | |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 956 | /* Unbind drivers for @udev's interfaces that don't support suspend/resume |
| 957 | * There is no check for reset_resume here because it can be determined |
| 958 | * only during resume whether reset_resume is needed. |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 959 | * |
| 960 | * The caller must hold @udev's device lock. |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 961 | */ |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 962 | static void unbind_no_pm_drivers_interfaces(struct usb_device *udev) |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 963 | { |
| 964 | struct usb_host_config *config; |
| 965 | int i; |
| 966 | struct usb_interface *intf; |
| 967 | struct usb_driver *drv; |
| 968 | |
| 969 | config = udev->actconfig; |
| 970 | if (config) { |
| 971 | for (i = 0; i < config->desc.bNumInterfaces; ++i) { |
| 972 | intf = config->interface[i]; |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 973 | |
| 974 | if (intf->dev.driver) { |
| 975 | drv = to_usb_driver(intf->dev.driver); |
| 976 | if (!drv->suspend || !drv->resume) |
| 977 | usb_forced_unbind_intf(intf); |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 983 | /* Unbind drivers for @udev's interfaces that failed to support reset-resume. |
| 984 | * These interfaces have the needs_binding flag set by usb_resume_interface(). |
| 985 | * |
| 986 | * The caller must hold @udev's device lock. |
| 987 | */ |
| 988 | static void unbind_no_reset_resume_drivers_interfaces(struct usb_device *udev) |
| 989 | { |
| 990 | struct usb_host_config *config; |
| 991 | int i; |
| 992 | struct usb_interface *intf; |
| 993 | |
| 994 | config = udev->actconfig; |
| 995 | if (config) { |
| 996 | for (i = 0; i < config->desc.bNumInterfaces; ++i) { |
| 997 | intf = config->interface[i]; |
| 998 | if (intf->dev.driver && intf->needs_binding) |
| 999 | usb_forced_unbind_intf(intf); |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | static void do_rebind_interfaces(struct usb_device *udev) |
| 1005 | { |
| 1006 | struct usb_host_config *config; |
| 1007 | int i; |
| 1008 | struct usb_interface *intf; |
| 1009 | |
| 1010 | config = udev->actconfig; |
| 1011 | if (config) { |
| 1012 | for (i = 0; i < config->desc.bNumInterfaces; ++i) { |
| 1013 | intf = config->interface[i]; |
| 1014 | if (intf->needs_binding) |
| 1015 | usb_rebind_intf(intf); |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| 1019 | |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1020 | static int usb_suspend_device(struct usb_device *udev, pm_message_t msg) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1021 | { |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 1022 | struct usb_device_driver *udriver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1023 | int status = 0; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1024 | |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 1025 | if (udev->state == USB_STATE_NOTATTACHED || |
| 1026 | udev->state == USB_STATE_SUSPENDED) |
| 1027 | goto done; |
| 1028 | |
Alan Stern | b6f6436d | 2007-05-04 11:51:54 -0400 | [diff] [blame] | 1029 | /* For devices that don't have a driver, we do a generic suspend. */ |
| 1030 | if (udev->dev.driver) |
| 1031 | udriver = to_usb_device_driver(udev->dev.driver); |
| 1032 | else { |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1033 | udev->do_remote_wakeup = 0; |
Alan Stern | b6f6436d | 2007-05-04 11:51:54 -0400 | [diff] [blame] | 1034 | udriver = &usb_generic_driver; |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 1035 | } |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1036 | status = udriver->suspend(udev, msg); |
| 1037 | |
Alan Stern | 20dfdad | 2007-05-22 11:50:17 -0400 | [diff] [blame] | 1038 | done: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1039 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1040 | return status; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1041 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1042 | |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1043 | static int usb_resume_device(struct usb_device *udev, pm_message_t msg) |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1044 | { |
| 1045 | struct usb_device_driver *udriver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1046 | int status = 0; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1047 | |
Alan Stern | 0458d5b | 2007-05-04 11:52:20 -0400 | [diff] [blame] | 1048 | if (udev->state == USB_STATE_NOTATTACHED) |
| 1049 | goto done; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1050 | |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 1051 | /* Can't resume it if it doesn't have a driver. */ |
| 1052 | if (udev->dev.driver == NULL) { |
| 1053 | status = -ENOTCONN; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1054 | goto done; |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
Alan Stern | 6d19c00 | 2010-02-12 12:21:11 +0100 | [diff] [blame] | 1057 | /* Non-root devices on a full/low-speed bus must wait for their |
| 1058 | * companion high-speed root hub, in case a handoff is needed. |
| 1059 | */ |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 1060 | if (!PMSG_IS_AUTO(msg) && udev->parent && udev->bus->hs_companion) |
Alan Stern | 6d19c00 | 2010-02-12 12:21:11 +0100 | [diff] [blame] | 1061 | device_pm_wait_for_dev(&udev->dev, |
| 1062 | &udev->bus->hs_companion->root_hub->dev); |
| 1063 | |
Alan Stern | 6bc6cff | 2007-05-04 11:53:03 -0400 | [diff] [blame] | 1064 | if (udev->quirks & USB_QUIRK_RESET_RESUME) |
| 1065 | udev->reset_resume = 1; |
| 1066 | |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1067 | udriver = to_usb_device_driver(udev->dev.driver); |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1068 | status = udriver->resume(udev, msg); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1069 | |
Alan Stern | 20dfdad | 2007-05-22 11:50:17 -0400 | [diff] [blame] | 1070 | done: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1071 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1072 | return status; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Alan Stern | 65605ae | 2008-08-12 14:33:27 -0400 | [diff] [blame] | 1075 | static int usb_suspend_interface(struct usb_device *udev, |
| 1076 | struct usb_interface *intf, pm_message_t msg) |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1077 | { |
| 1078 | struct usb_driver *driver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1079 | int status = 0; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1080 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1081 | if (udev->state == USB_STATE_NOTATTACHED || |
| 1082 | intf->condition == USB_INTERFACE_UNBOUND) |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1083 | goto done; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1084 | driver = to_usb_driver(intf->dev.driver); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1085 | |
Oliver Neukum | e78832c | 2012-01-02 15:11:48 +0100 | [diff] [blame] | 1086 | /* at this time we know the driver supports suspend */ |
| 1087 | status = driver->suspend(intf, msg); |
| 1088 | if (status && !PMSG_IS_AUTO(msg)) |
| 1089 | dev_err(&intf->dev, "suspend error %d\n", status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1090 | |
Alan Stern | 20dfdad | 2007-05-22 11:50:17 -0400 | [diff] [blame] | 1091 | done: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1092 | dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1093 | return status; |
| 1094 | } |
| 1095 | |
Alan Stern | 65605ae | 2008-08-12 14:33:27 -0400 | [diff] [blame] | 1096 | static int usb_resume_interface(struct usb_device *udev, |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1097 | struct usb_interface *intf, pm_message_t msg, int reset_resume) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1098 | { |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1099 | struct usb_driver *driver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1100 | int status = 0; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1101 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1102 | if (udev->state == USB_STATE_NOTATTACHED) |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1103 | goto done; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1104 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1105 | /* Don't let autoresume interfere with unbinding */ |
| 1106 | if (intf->condition == USB_INTERFACE_UNBINDING) |
| 1107 | goto done; |
| 1108 | |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 1109 | /* Can't resume it if it doesn't have a driver. */ |
Alan Stern | 55151d7 | 2008-08-12 14:33:59 -0400 | [diff] [blame] | 1110 | if (intf->condition == USB_INTERFACE_UNBOUND) { |
| 1111 | |
| 1112 | /* Carry out a deferred switch to altsetting 0 */ |
Alan Stern | f76b168 | 2011-06-18 20:22:23 +0200 | [diff] [blame] | 1113 | if (intf->needs_altsetting0 && !intf->dev.power.is_prepared) { |
Alan Stern | 55151d7 | 2008-08-12 14:33:59 -0400 | [diff] [blame] | 1114 | usb_set_interface(udev, intf->altsetting[0]. |
| 1115 | desc.bInterfaceNumber, 0); |
| 1116 | intf->needs_altsetting0 = 0; |
| 1117 | } |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1118 | goto done; |
Alan Stern | 55151d7 | 2008-08-12 14:33:59 -0400 | [diff] [blame] | 1119 | } |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 1120 | |
| 1121 | /* Don't resume if the interface is marked for rebinding */ |
| 1122 | if (intf->needs_binding) |
| 1123 | goto done; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1124 | driver = to_usb_driver(intf->dev.driver); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1125 | |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1126 | if (reset_resume) { |
| 1127 | if (driver->reset_resume) { |
| 1128 | status = driver->reset_resume(intf); |
| 1129 | if (status) |
| 1130 | dev_err(&intf->dev, "%s error %d\n", |
| 1131 | "reset_resume", status); |
| 1132 | } else { |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 1133 | intf->needs_binding = 1; |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1134 | dev_warn(&intf->dev, "no %s for driver %s?\n", |
| 1135 | "reset_resume", driver->name); |
| 1136 | } |
| 1137 | } else { |
Oliver Neukum | e78832c | 2012-01-02 15:11:48 +0100 | [diff] [blame] | 1138 | status = driver->resume(intf); |
| 1139 | if (status) |
| 1140 | dev_err(&intf->dev, "resume error %d\n", status); |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1141 | } |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1142 | |
| 1143 | done: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1144 | dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1145 | |
Alan Stern | 78d9a48 | 2008-06-23 16:00:40 -0400 | [diff] [blame] | 1146 | /* Later we will unbind the driver and/or reprobe, if necessary */ |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 1147 | return status; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1150 | /** |
| 1151 | * usb_suspend_both - suspend a USB device and its interfaces |
| 1152 | * @udev: the usb_device to suspend |
| 1153 | * @msg: Power Management message describing this state transition |
| 1154 | * |
| 1155 | * This is the central routine for suspending USB devices. It calls the |
| 1156 | * suspend methods for all the interface drivers in @udev and then calls |
| 1157 | * the suspend method for @udev itself. If an error occurs at any stage, |
| 1158 | * all the interfaces which were suspended are resumed so that they remain |
| 1159 | * in the same state as the device. |
| 1160 | * |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1161 | * Autosuspend requests originating from a child device or an interface |
| 1162 | * driver may be made without the protection of @udev's device lock, but |
| 1163 | * all other suspend calls will hold the lock. Usbcore will insure that |
| 1164 | * method calls do not arrive during bind, unbind, or reset operations. |
| 1165 | * However drivers must be prepared to handle suspend calls arriving at |
| 1166 | * unpredictable times. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1167 | * |
| 1168 | * This routine can run only in process context. |
| 1169 | */ |
Alan Stern | 718efa6 | 2007-03-09 15:41:13 -0500 | [diff] [blame] | 1170 | static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1171 | { |
| 1172 | int status = 0; |
Alan Stern | 571dc79 | 2010-04-09 16:03:43 -0400 | [diff] [blame] | 1173 | int i = 0, n = 0; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1174 | struct usb_interface *intf; |
| 1175 | |
Alan Stern | 1941044 | 2007-03-27 13:33:59 -0400 | [diff] [blame] | 1176 | if (udev->state == USB_STATE_NOTATTACHED || |
| 1177 | udev->state == USB_STATE_SUSPENDED) |
| 1178 | goto done; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1179 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1180 | /* Suspend all the interfaces and then udev itself */ |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1181 | if (udev->actconfig) { |
Alan Stern | 571dc79 | 2010-04-09 16:03:43 -0400 | [diff] [blame] | 1182 | n = udev->actconfig->desc.bNumInterfaces; |
| 1183 | for (i = n - 1; i >= 0; --i) { |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1184 | intf = udev->actconfig->interface[i]; |
Alan Stern | 65605ae | 2008-08-12 14:33:27 -0400 | [diff] [blame] | 1185 | status = usb_suspend_interface(udev, intf, msg); |
Alan Stern | 0af212b | 2011-06-15 16:27:43 -0400 | [diff] [blame] | 1186 | |
| 1187 | /* Ignore errors during system sleep transitions */ |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 1188 | if (!PMSG_IS_AUTO(msg)) |
Alan Stern | 0af212b | 2011-06-15 16:27:43 -0400 | [diff] [blame] | 1189 | status = 0; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1190 | if (status != 0) |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
Alan Stern | 0af212b | 2011-06-15 16:27:43 -0400 | [diff] [blame] | 1194 | if (status == 0) { |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1195 | status = usb_suspend_device(udev, msg); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1196 | |
Alan Stern | cd4376e | 2012-03-28 15:56:17 -0400 | [diff] [blame] | 1197 | /* |
| 1198 | * Ignore errors from non-root-hub devices during |
| 1199 | * system sleep transitions. For the most part, |
| 1200 | * these devices should go to low power anyway when |
| 1201 | * the entire bus is suspended. |
| 1202 | */ |
| 1203 | if (udev->parent && !PMSG_IS_AUTO(msg)) |
Alan Stern | 0af212b | 2011-06-15 16:27:43 -0400 | [diff] [blame] | 1204 | status = 0; |
| 1205 | } |
| 1206 | |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1207 | /* If the suspend failed, resume interfaces that did get suspended */ |
| 1208 | if (status != 0) { |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1209 | msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); |
Alan Stern | 571dc79 | 2010-04-09 16:03:43 -0400 | [diff] [blame] | 1210 | while (++i < n) { |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1211 | intf = udev->actconfig->interface[i]; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1212 | usb_resume_interface(udev, intf, msg, 0); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1213 | } |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1214 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1215 | /* If the suspend succeeded then prevent any more URB submissions |
| 1216 | * and flush any outstanding URBs. |
Alan Stern | 6840d25 | 2007-09-10 11:34:26 -0400 | [diff] [blame] | 1217 | */ |
Alan Stern | ef7f6c7 | 2007-04-05 16:03:49 -0400 | [diff] [blame] | 1218 | } else { |
Alan Stern | 6840d25 | 2007-09-10 11:34:26 -0400 | [diff] [blame] | 1219 | udev->can_submit = 0; |
| 1220 | for (i = 0; i < 16; ++i) { |
| 1221 | usb_hcd_flush_endpoint(udev, udev->ep_out[i]); |
| 1222 | usb_hcd_flush_endpoint(udev, udev->ep_in[i]); |
| 1223 | } |
Alan Stern | ef7f6c7 | 2007-04-05 16:03:49 -0400 | [diff] [blame] | 1224 | } |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1225 | |
Alan Stern | 1941044 | 2007-03-27 13:33:59 -0400 | [diff] [blame] | 1226 | done: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1227 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1228 | return status; |
| 1229 | } |
| 1230 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1231 | /** |
| 1232 | * usb_resume_both - resume a USB device and its interfaces |
| 1233 | * @udev: the usb_device to resume |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1234 | * @msg: Power Management message describing this state transition |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1235 | * |
| 1236 | * This is the central routine for resuming USB devices. It calls the |
| 1237 | * the resume method for @udev and then calls the resume methods for all |
| 1238 | * the interface drivers in @udev. |
| 1239 | * |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1240 | * Autoresume requests originating from a child device or an interface |
| 1241 | * driver may be made without the protection of @udev's device lock, but |
| 1242 | * all other resume calls will hold the lock. Usbcore will insure that |
| 1243 | * method calls do not arrive during bind, unbind, or reset operations. |
| 1244 | * However drivers must be prepared to handle resume calls arriving at |
| 1245 | * unpredictable times. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1246 | * |
| 1247 | * This routine can run only in process context. |
| 1248 | */ |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1249 | static int usb_resume_both(struct usb_device *udev, pm_message_t msg) |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1250 | { |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1251 | int status = 0; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1252 | int i; |
| 1253 | struct usb_interface *intf; |
| 1254 | |
Alan Stern | 1941044 | 2007-03-27 13:33:59 -0400 | [diff] [blame] | 1255 | if (udev->state == USB_STATE_NOTATTACHED) { |
| 1256 | status = -ENODEV; |
| 1257 | goto done; |
| 1258 | } |
Alan Stern | 6840d25 | 2007-09-10 11:34:26 -0400 | [diff] [blame] | 1259 | udev->can_submit = 1; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1260 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1261 | /* Resume the device */ |
| 1262 | if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1263 | status = usb_resume_device(udev, msg); |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 1264 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1265 | /* Resume the interfaces */ |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1266 | if (status == 0 && udev->actconfig) { |
| 1267 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
| 1268 | intf = udev->actconfig->interface[i]; |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 1269 | usb_resume_interface(udev, intf, msg, |
| 1270 | udev->reset_resume); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1271 | } |
| 1272 | } |
Alan Stern | c08512c | 2010-11-15 15:57:58 -0500 | [diff] [blame] | 1273 | usb_mark_last_busy(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1274 | |
Alan Stern | 1941044 | 2007-03-27 13:33:59 -0400 | [diff] [blame] | 1275 | done: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1276 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
Alan Stern | 70a1c9e | 2008-03-06 17:00:58 -0500 | [diff] [blame] | 1277 | if (!status) |
| 1278 | udev->reset_resume = 0; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1279 | return status; |
| 1280 | } |
| 1281 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1282 | #ifdef CONFIG_USB_OTG |
| 1283 | void usb_hnp_polling_work(struct work_struct *work) |
| 1284 | { |
| 1285 | int ret; |
| 1286 | struct usb_bus *bus = |
| 1287 | container_of(work, struct usb_bus, hnp_polling.work); |
| 1288 | struct usb_device *udev = bus->root_hub->children[bus->otg_port - 1]; |
Vijayavardhan Vennapusa | 1720db84 | 2012-01-18 14:16:55 +0530 | [diff] [blame] | 1289 | u8 *status = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1290 | |
Vijayavardhan Vennapusa | 1720db84 | 2012-01-18 14:16:55 +0530 | [diff] [blame] | 1291 | /* |
| 1292 | * The OTG-B device must hand back the host role to OTG PET |
| 1293 | * within 100 msec irrespective of host_request flag. |
| 1294 | */ |
| 1295 | if (bus->quick_hnp) { |
| 1296 | bus->quick_hnp = 0; |
| 1297 | goto start_hnp; |
| 1298 | } |
| 1299 | |
| 1300 | status = kmalloc(sizeof(*status), GFP_KERNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1301 | if (!status) |
Vijayavardhan Vennapusa | 1720db84 | 2012-01-18 14:16:55 +0530 | [diff] [blame] | 1302 | goto reschedule; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1303 | |
| 1304 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
| 1305 | USB_REQ_GET_STATUS, USB_DIR_IN | USB_RECIP_DEVICE, |
| 1306 | 0, OTG_STATUS_SELECTOR, status, sizeof(*status), |
| 1307 | USB_CTRL_GET_TIMEOUT); |
| 1308 | if (ret < 0) { |
| 1309 | /* Peripheral may not be supporting HNP polling */ |
| 1310 | dev_info(&udev->dev, "HNP polling failed. status %d\n", ret); |
| 1311 | goto out; |
| 1312 | } |
| 1313 | |
Vijayavardhan Vennapusa | 1720db84 | 2012-01-18 14:16:55 +0530 | [diff] [blame] | 1314 | if (!(*status & (1 << HOST_REQUEST_FLAG))) |
| 1315 | goto reschedule; |
| 1316 | |
| 1317 | start_hnp: |
| 1318 | do_unbind_rebind(udev, DO_UNBIND); |
| 1319 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); |
| 1320 | ret = usb_suspend_both(udev, PMSG_USER_SUSPEND); |
| 1321 | if (ret) |
| 1322 | dev_info(&udev->dev, "suspend failed\n"); |
| 1323 | goto out; |
| 1324 | |
| 1325 | reschedule: |
| 1326 | schedule_delayed_work(&bus->hnp_polling, |
| 1327 | msecs_to_jiffies(THOST_REQ_POLL)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1328 | out: |
| 1329 | kfree(status); |
| 1330 | } |
| 1331 | #endif |
| 1332 | |
Alan Stern | 5f677f1 | 2010-04-02 13:20:11 -0400 | [diff] [blame] | 1333 | static void choose_wakeup(struct usb_device *udev, pm_message_t msg) |
| 1334 | { |
Alan Stern | 4882662 | 2010-06-22 16:14:48 -0400 | [diff] [blame] | 1335 | int w; |
Alan Stern | 5f677f1 | 2010-04-02 13:20:11 -0400 | [diff] [blame] | 1336 | |
| 1337 | /* Remote wakeup is needed only when we actually go to sleep. |
| 1338 | * For things like FREEZE and QUIESCE, if the device is already |
| 1339 | * autosuspended then its current wakeup setting is okay. |
| 1340 | */ |
| 1341 | if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_QUIESCE) { |
| 1342 | if (udev->state != USB_STATE_SUSPENDED) |
| 1343 | udev->do_remote_wakeup = 0; |
| 1344 | return; |
| 1345 | } |
| 1346 | |
Alan Stern | 4882662 | 2010-06-22 16:14:48 -0400 | [diff] [blame] | 1347 | /* Enable remote wakeup if it is allowed, even if no interface drivers |
Alan Stern | 5f677f1 | 2010-04-02 13:20:11 -0400 | [diff] [blame] | 1348 | * actually want it. |
| 1349 | */ |
Alan Stern | 4882662 | 2010-06-22 16:14:48 -0400 | [diff] [blame] | 1350 | w = device_may_wakeup(&udev->dev); |
Alan Stern | 5f677f1 | 2010-04-02 13:20:11 -0400 | [diff] [blame] | 1351 | |
| 1352 | /* If the device is autosuspended with the wrong wakeup setting, |
| 1353 | * autoresume now so the setting can be changed. |
| 1354 | */ |
| 1355 | if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup) |
| 1356 | pm_runtime_resume(&udev->dev); |
| 1357 | udev->do_remote_wakeup = w; |
| 1358 | } |
| 1359 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1360 | /* The device lock is held by the PM core */ |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1361 | int usb_suspend(struct device *dev, pm_message_t msg) |
| 1362 | { |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1363 | struct usb_device *udev = to_usb_device(dev); |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1364 | |
Pavankumar Kondeti | 41d004c | 2012-11-09 10:54:00 +0530 | [diff] [blame] | 1365 | if (udev->bus->skip_resume) { |
| 1366 | if (udev->state == USB_STATE_SUSPENDED) { |
| 1367 | return 0; |
| 1368 | } else { |
| 1369 | dev_err(dev, "abort suspend\n"); |
| 1370 | return -EBUSY; |
| 1371 | } |
| 1372 | } |
Pavankumar Kondeti | 6f199aa | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 1373 | |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 1374 | unbind_no_pm_drivers_interfaces(udev); |
| 1375 | |
| 1376 | /* From now on we are sure all drivers support suspend/resume |
| 1377 | * but not necessarily reset_resume() |
| 1378 | * so we may still need to unbind and rebind upon resume |
| 1379 | */ |
Alan Stern | 5f677f1 | 2010-04-02 13:20:11 -0400 | [diff] [blame] | 1380 | choose_wakeup(udev, msg); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1381 | return usb_suspend_both(udev, msg); |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1382 | } |
| 1383 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1384 | /* The device lock is held by the PM core */ |
Oliver Neukum | 98d9a82 | 2012-01-11 08:38:35 +0100 | [diff] [blame] | 1385 | int usb_resume_complete(struct device *dev) |
| 1386 | { |
| 1387 | struct usb_device *udev = to_usb_device(dev); |
| 1388 | |
| 1389 | /* For PM complete calls, all we do is rebind interfaces |
| 1390 | * whose needs_binding flag is set |
| 1391 | */ |
| 1392 | if (udev->state != USB_STATE_NOTATTACHED) |
| 1393 | do_rebind_interfaces(udev); |
| 1394 | return 0; |
| 1395 | } |
| 1396 | |
| 1397 | /* The device lock is held by the PM core */ |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1398 | int usb_resume(struct device *dev, pm_message_t msg) |
| 1399 | { |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1400 | struct usb_device *udev = to_usb_device(dev); |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1401 | int status; |
| 1402 | |
Pavankumar Kondeti | 6f199aa | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 1403 | /* |
| 1404 | * Some buses would like to keep their devices in suspend |
| 1405 | * state after system resume. Their resume happen when |
| 1406 | * a remote wakeup is detected or interface driver start |
| 1407 | * I/O. |
| 1408 | */ |
| 1409 | if (udev->bus->skip_resume) |
| 1410 | return 0; |
| 1411 | |
Oliver Neukum | 98d9a82 | 2012-01-11 08:38:35 +0100 | [diff] [blame] | 1412 | /* For all calls, take the device back to full power and |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1413 | * tell the PM core in case it was autosuspended previously. |
Oliver Neukum | 1493138 | 2012-01-05 15:39:57 +0100 | [diff] [blame] | 1414 | * Unbind the interfaces that will need rebinding later, |
| 1415 | * because they fail to support reset_resume. |
| 1416 | * (This can't be done in usb_resume_interface() |
Oliver Neukum | 98d9a82 | 2012-01-11 08:38:35 +0100 | [diff] [blame] | 1417 | * above because it doesn't own the right set of locks.) |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1418 | */ |
Oliver Neukum | 98d9a82 | 2012-01-11 08:38:35 +0100 | [diff] [blame] | 1419 | status = usb_resume_both(udev, msg); |
| 1420 | if (status == 0) { |
| 1421 | pm_runtime_disable(dev); |
| 1422 | pm_runtime_set_active(dev); |
| 1423 | pm_runtime_enable(dev); |
| 1424 | unbind_no_reset_resume_drivers_interfaces(udev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1425 | } |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1426 | |
| 1427 | /* Avoid PM error messages for devices disconnected while suspended |
| 1428 | * as we'll display regular disconnect messages just a bit later. |
| 1429 | */ |
Peter Chen | 7491f13 | 2010-09-27 16:43:25 +0800 | [diff] [blame] | 1430 | if (status == -ENODEV || status == -ESHUTDOWN) |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1431 | status = 0; |
Alan Stern | 0c590e2 | 2010-01-08 12:57:14 -0500 | [diff] [blame] | 1432 | return status; |
| 1433 | } |
| 1434 | |
| 1435 | #endif /* CONFIG_PM */ |
| 1436 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1437 | #ifdef CONFIG_USB_SUSPEND |
| 1438 | |
Alan Stern | 088f7fe | 2010-01-08 12:56:54 -0500 | [diff] [blame] | 1439 | /** |
| 1440 | * usb_enable_autosuspend - allow a USB device to be autosuspended |
| 1441 | * @udev: the USB device which may be autosuspended |
| 1442 | * |
| 1443 | * This routine allows @udev to be autosuspended. An autosuspend won't |
| 1444 | * take place until the autosuspend_delay has elapsed and all the other |
| 1445 | * necessary conditions are satisfied. |
| 1446 | * |
| 1447 | * The caller must hold @udev's device lock. |
| 1448 | */ |
Alan Stern | 9e18c82 | 2010-04-02 13:22:09 -0400 | [diff] [blame] | 1449 | void usb_enable_autosuspend(struct usb_device *udev) |
Alan Stern | 088f7fe | 2010-01-08 12:56:54 -0500 | [diff] [blame] | 1450 | { |
Alan Stern | 9e18c82 | 2010-04-02 13:22:09 -0400 | [diff] [blame] | 1451 | pm_runtime_allow(&udev->dev); |
Alan Stern | 088f7fe | 2010-01-08 12:56:54 -0500 | [diff] [blame] | 1452 | } |
| 1453 | EXPORT_SYMBOL_GPL(usb_enable_autosuspend); |
| 1454 | |
| 1455 | /** |
| 1456 | * usb_disable_autosuspend - prevent a USB device from being autosuspended |
| 1457 | * @udev: the USB device which may not be autosuspended |
| 1458 | * |
| 1459 | * This routine prevents @udev from being autosuspended and wakes it up |
| 1460 | * if it is already autosuspended. |
| 1461 | * |
| 1462 | * The caller must hold @udev's device lock. |
| 1463 | */ |
Alan Stern | 9e18c82 | 2010-04-02 13:22:09 -0400 | [diff] [blame] | 1464 | void usb_disable_autosuspend(struct usb_device *udev) |
Alan Stern | 088f7fe | 2010-01-08 12:56:54 -0500 | [diff] [blame] | 1465 | { |
Alan Stern | 9e18c82 | 2010-04-02 13:22:09 -0400 | [diff] [blame] | 1466 | pm_runtime_forbid(&udev->dev); |
Alan Stern | 088f7fe | 2010-01-08 12:56:54 -0500 | [diff] [blame] | 1467 | } |
| 1468 | EXPORT_SYMBOL_GPL(usb_disable_autosuspend); |
| 1469 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1470 | /** |
| 1471 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1472 | * @udev: the usb_device to autosuspend |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1473 | * |
| 1474 | * This routine should be called when a core subsystem is finished using |
| 1475 | * @udev and wants to allow it to autosuspend. Examples would be when |
| 1476 | * @udev's device file in usbfs is closed or after a configuration change. |
| 1477 | * |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1478 | * @udev's usage counter is decremented; if it drops to 0 and all the |
| 1479 | * interfaces are inactive then a delayed autosuspend will be attempted. |
| 1480 | * The attempt may fail (see autosuspend_check()). |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1481 | * |
Alan Stern | 62e299e | 2010-01-08 12:56:19 -0500 | [diff] [blame] | 1482 | * The caller must hold @udev's device lock. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1483 | * |
| 1484 | * This routine can run only in process context. |
| 1485 | */ |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 1486 | void usb_autosuspend_device(struct usb_device *udev) |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1487 | { |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 1488 | int status; |
| 1489 | |
Ming Lei | 6ddf27c | 2010-11-15 15:57:30 -0500 | [diff] [blame] | 1490 | usb_mark_last_busy(udev); |
Alan Stern | fcc4a01 | 2010-11-15 15:57:51 -0500 | [diff] [blame] | 1491 | status = pm_runtime_put_sync_autosuspend(&udev->dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1492 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", |
| 1493 | __func__, atomic_read(&udev->dev.power.usage_count), |
| 1494 | status); |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /** |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1498 | * usb_autoresume_device - immediately autoresume a USB device and its interfaces |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1499 | * @udev: the usb_device to autoresume |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1500 | * |
| 1501 | * This routine should be called when a core subsystem wants to use @udev |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 1502 | * and needs to guarantee that it is not suspended. No autosuspend will |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1503 | * occur until usb_autosuspend_device() is called. (Note that this will |
| 1504 | * not prevent suspend events originating in the PM core.) Examples would |
| 1505 | * be when @udev's device file in usbfs is opened or when a remote-wakeup |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 1506 | * request is received. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1507 | * |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 1508 | * @udev's usage counter is incremented to prevent subsequent autosuspends. |
| 1509 | * However if the autoresume fails then the usage counter is re-decremented. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1510 | * |
Alan Stern | 62e299e | 2010-01-08 12:56:19 -0500 | [diff] [blame] | 1511 | * The caller must hold @udev's device lock. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1512 | * |
| 1513 | * This routine can run only in process context. |
| 1514 | */ |
Alan Stern | 94fcda1 | 2006-11-20 11:38:46 -0500 | [diff] [blame] | 1515 | int usb_autoresume_device(struct usb_device *udev) |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1516 | { |
| 1517 | int status; |
| 1518 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1519 | status = pm_runtime_get_sync(&udev->dev); |
| 1520 | if (status < 0) |
| 1521 | pm_runtime_put_sync(&udev->dev); |
| 1522 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", |
| 1523 | __func__, atomic_read(&udev->dev.power.usage_count), |
| 1524 | status); |
| 1525 | if (status > 0) |
| 1526 | status = 0; |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1527 | return status; |
| 1528 | } |
| 1529 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1530 | /** |
| 1531 | * usb_autopm_put_interface - decrement a USB interface's PM-usage counter |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1532 | * @intf: the usb_interface whose counter should be decremented |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1533 | * |
| 1534 | * This routine should be called by an interface driver when it is |
| 1535 | * finished using @intf and wants to allow it to autosuspend. A typical |
| 1536 | * example would be a character-device driver when its device file is |
| 1537 | * closed. |
| 1538 | * |
| 1539 | * The routine decrements @intf's usage counter. When the counter reaches |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1540 | * 0, a delayed autosuspend request for @intf's device is attempted. The |
| 1541 | * attempt may fail (see autosuspend_check()). |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1542 | * |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1543 | * This routine can run only in process context. |
| 1544 | */ |
| 1545 | void usb_autopm_put_interface(struct usb_interface *intf) |
| 1546 | { |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1547 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1548 | int status; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1549 | |
Ming Lei | 6ddf27c | 2010-11-15 15:57:30 -0500 | [diff] [blame] | 1550 | usb_mark_last_busy(udev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1551 | atomic_dec(&intf->pm_usage_cnt); |
| 1552 | status = pm_runtime_put_sync(&intf->dev); |
| 1553 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
| 1554 | __func__, atomic_read(&intf->dev.power.usage_count), |
| 1555 | status); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1556 | } |
| 1557 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); |
| 1558 | |
| 1559 | /** |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1560 | * usb_autopm_put_interface_async - decrement a USB interface's PM-usage counter |
| 1561 | * @intf: the usb_interface whose counter should be decremented |
| 1562 | * |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1563 | * This routine does much the same thing as usb_autopm_put_interface(): |
| 1564 | * It decrements @intf's usage counter and schedules a delayed |
| 1565 | * autosuspend request if the counter is <= 0. The difference is that it |
| 1566 | * does not perform any synchronization; callers should hold a private |
| 1567 | * lock and handle all synchronization issues themselves. |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1568 | * |
| 1569 | * Typically a driver would call this routine during an URB's completion |
| 1570 | * handler, if no more URBs were pending. |
| 1571 | * |
| 1572 | * This routine can run in atomic context. |
| 1573 | */ |
| 1574 | void usb_autopm_put_interface_async(struct usb_interface *intf) |
| 1575 | { |
| 1576 | struct usb_device *udev = interface_to_usbdev(intf); |
Alan Stern | fcc4a01 | 2010-11-15 15:57:51 -0500 | [diff] [blame] | 1577 | int status; |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1578 | |
Ming Lei | 6ddf27c | 2010-11-15 15:57:30 -0500 | [diff] [blame] | 1579 | usb_mark_last_busy(udev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1580 | atomic_dec(&intf->pm_usage_cnt); |
Alan Stern | fcc4a01 | 2010-11-15 15:57:51 -0500 | [diff] [blame] | 1581 | status = pm_runtime_put(&intf->dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1582 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
| 1583 | __func__, atomic_read(&intf->dev.power.usage_count), |
| 1584 | status); |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1585 | } |
| 1586 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); |
| 1587 | |
| 1588 | /** |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1589 | * usb_autopm_put_interface_no_suspend - decrement a USB interface's PM-usage counter |
| 1590 | * @intf: the usb_interface whose counter should be decremented |
| 1591 | * |
| 1592 | * This routine decrements @intf's usage counter but does not carry out an |
| 1593 | * autosuspend. |
| 1594 | * |
| 1595 | * This routine can run in atomic context. |
| 1596 | */ |
| 1597 | void usb_autopm_put_interface_no_suspend(struct usb_interface *intf) |
| 1598 | { |
| 1599 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1600 | |
Ming Lei | 6ddf27c | 2010-11-15 15:57:30 -0500 | [diff] [blame] | 1601 | usb_mark_last_busy(udev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1602 | atomic_dec(&intf->pm_usage_cnt); |
| 1603 | pm_runtime_put_noidle(&intf->dev); |
| 1604 | } |
| 1605 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_no_suspend); |
| 1606 | |
| 1607 | /** |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1608 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1609 | * @intf: the usb_interface whose counter should be incremented |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1610 | * |
| 1611 | * This routine should be called by an interface driver when it wants to |
| 1612 | * use @intf and needs to guarantee that it is not suspended. In addition, |
| 1613 | * the routine prevents @intf from being autosuspended subsequently. (Note |
| 1614 | * that this will not prevent suspend events originating in the PM core.) |
| 1615 | * This prevention will persist until usb_autopm_put_interface() is called |
| 1616 | * or @intf is unbound. A typical example would be a character-device |
| 1617 | * driver when its device file is opened. |
| 1618 | * |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1619 | * @intf's usage counter is incremented to prevent subsequent autosuspends. |
| 1620 | * However if the autoresume fails then the counter is re-decremented. |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1621 | * |
| 1622 | * This routine can run only in process context. |
| 1623 | */ |
| 1624 | int usb_autopm_get_interface(struct usb_interface *intf) |
| 1625 | { |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1626 | int status; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1627 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1628 | status = pm_runtime_get_sync(&intf->dev); |
| 1629 | if (status < 0) |
| 1630 | pm_runtime_put_sync(&intf->dev); |
| 1631 | else |
| 1632 | atomic_inc(&intf->pm_usage_cnt); |
| 1633 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
| 1634 | __func__, atomic_read(&intf->dev.power.usage_count), |
| 1635 | status); |
| 1636 | if (status > 0) |
| 1637 | status = 0; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1638 | return status; |
| 1639 | } |
| 1640 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); |
| 1641 | |
Alan Stern | 692a186 | 2006-10-30 17:07:51 -0500 | [diff] [blame] | 1642 | /** |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1643 | * usb_autopm_get_interface_async - increment a USB interface's PM-usage counter |
| 1644 | * @intf: the usb_interface whose counter should be incremented |
| 1645 | * |
| 1646 | * This routine does much the same thing as |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1647 | * usb_autopm_get_interface(): It increments @intf's usage counter and |
| 1648 | * queues an autoresume request if the device is suspended. The |
| 1649 | * differences are that it does not perform any synchronization (callers |
| 1650 | * should hold a private lock and handle all synchronization issues |
| 1651 | * themselves), and it does not autoresume the device directly (it only |
| 1652 | * queues a request). After a successful call, the device may not yet be |
| 1653 | * resumed. |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1654 | * |
| 1655 | * This routine can run in atomic context. |
| 1656 | */ |
| 1657 | int usb_autopm_get_interface_async(struct usb_interface *intf) |
| 1658 | { |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1659 | int status; |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1660 | |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1661 | status = pm_runtime_get(&intf->dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1662 | if (status < 0 && status != -EINPROGRESS) |
| 1663 | pm_runtime_put_noidle(&intf->dev); |
| 1664 | else |
Alan Stern | ccf5b80 | 2009-06-29 11:00:01 -0400 | [diff] [blame] | 1665 | atomic_inc(&intf->pm_usage_cnt); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1666 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
| 1667 | __func__, atomic_read(&intf->dev.power.usage_count), |
| 1668 | status); |
Jim Wylder | c5a4859 | 2011-09-06 21:07:20 -0500 | [diff] [blame] | 1669 | if (status > 0 || status == -EINPROGRESS) |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1670 | status = 0; |
Alan Stern | 9ac39f2 | 2008-11-12 16:19:49 -0500 | [diff] [blame] | 1671 | return status; |
| 1672 | } |
| 1673 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); |
| 1674 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1675 | /** |
| 1676 | * usb_autopm_get_interface_no_resume - increment a USB interface's PM-usage counter |
| 1677 | * @intf: the usb_interface whose counter should be incremented |
| 1678 | * |
| 1679 | * This routine increments @intf's usage counter but does not carry out an |
| 1680 | * autoresume. |
| 1681 | * |
| 1682 | * This routine can run in atomic context. |
| 1683 | */ |
| 1684 | void usb_autopm_get_interface_no_resume(struct usb_interface *intf) |
| 1685 | { |
| 1686 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1687 | |
Ming Lei | 6ddf27c | 2010-11-15 15:57:30 -0500 | [diff] [blame] | 1688 | usb_mark_last_busy(udev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1689 | atomic_inc(&intf->pm_usage_cnt); |
| 1690 | pm_runtime_get_noresume(&intf->dev); |
| 1691 | } |
| 1692 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_no_resume); |
| 1693 | |
| 1694 | /* Internal routine to check whether we may autosuspend a device. */ |
| 1695 | static int autosuspend_check(struct usb_device *udev) |
| 1696 | { |
Alan Stern | 7560d32 | 2010-04-02 13:18:50 -0400 | [diff] [blame] | 1697 | int w, i; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1698 | struct usb_interface *intf; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1699 | |
| 1700 | /* Fail if autosuspend is disabled, or any interfaces are in use, or |
| 1701 | * any interface drivers require remote wakeup but it isn't available. |
| 1702 | */ |
Alan Stern | 7560d32 | 2010-04-02 13:18:50 -0400 | [diff] [blame] | 1703 | w = 0; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1704 | if (udev->actconfig) { |
| 1705 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
| 1706 | intf = udev->actconfig->interface[i]; |
| 1707 | |
| 1708 | /* We don't need to check interfaces that are |
| 1709 | * disabled for runtime PM. Either they are unbound |
| 1710 | * or else their drivers don't support autosuspend |
| 1711 | * and so they are permanently active. |
| 1712 | */ |
| 1713 | if (intf->dev.power.disable_depth) |
| 1714 | continue; |
| 1715 | if (atomic_read(&intf->dev.power.usage_count) > 0) |
| 1716 | return -EBUSY; |
Alan Stern | 7560d32 | 2010-04-02 13:18:50 -0400 | [diff] [blame] | 1717 | w |= intf->needs_remote_wakeup; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1718 | |
| 1719 | /* Don't allow autosuspend if the device will need |
| 1720 | * a reset-resume and any of its interface drivers |
| 1721 | * doesn't include support or needs remote wakeup. |
| 1722 | */ |
| 1723 | if (udev->quirks & USB_QUIRK_RESET_RESUME) { |
| 1724 | struct usb_driver *driver; |
| 1725 | |
| 1726 | driver = to_usb_driver(intf->dev.driver); |
| 1727 | if (!driver->reset_resume || |
| 1728 | intf->needs_remote_wakeup) |
| 1729 | return -EOPNOTSUPP; |
| 1730 | } |
| 1731 | } |
| 1732 | } |
Alan Stern | 7560d32 | 2010-04-02 13:18:50 -0400 | [diff] [blame] | 1733 | if (w && !device_can_wakeup(&udev->dev)) { |
| 1734 | dev_dbg(&udev->dev, "remote wakeup needed for autosuspend\n"); |
| 1735 | return -EOPNOTSUPP; |
| 1736 | } |
| 1737 | udev->do_remote_wakeup = w; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1738 | return 0; |
| 1739 | } |
| 1740 | |
Rafael J. Wysocki | e1620d5 | 2011-03-18 19:55:36 +0100 | [diff] [blame] | 1741 | int usb_runtime_suspend(struct device *dev) |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1742 | { |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1743 | struct usb_device *udev = to_usb_device(dev); |
| 1744 | int status; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1745 | |
| 1746 | /* A USB device can be suspended if it passes the various autosuspend |
| 1747 | * checks. Runtime suspend for a USB device means suspending all the |
| 1748 | * interfaces and then the device itself. |
| 1749 | */ |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1750 | if (autosuspend_check(udev) != 0) |
| 1751 | return -EAGAIN; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1752 | |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1753 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
Alan Stern | b2c0a86 | 2011-11-04 00:52:46 +0100 | [diff] [blame] | 1754 | |
| 1755 | /* Allow a retry if autosuspend failed temporarily */ |
| 1756 | if (status == -EAGAIN || status == -EBUSY) |
| 1757 | usb_mark_last_busy(udev); |
| 1758 | |
Sarah Sharp | db7c7c0 | 2010-12-29 22:03:07 -0800 | [diff] [blame] | 1759 | /* The PM core reacts badly unless the return code is 0, |
| 1760 | * -EAGAIN, or -EBUSY, so always return -EBUSY on an error. |
| 1761 | */ |
| 1762 | if (status != 0) |
| 1763 | return -EBUSY; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1764 | return status; |
| 1765 | } |
| 1766 | |
Rafael J. Wysocki | e1620d5 | 2011-03-18 19:55:36 +0100 | [diff] [blame] | 1767 | int usb_runtime_resume(struct device *dev) |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1768 | { |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1769 | struct usb_device *udev = to_usb_device(dev); |
| 1770 | int status; |
| 1771 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1772 | /* Runtime resume for a USB device means resuming both the device |
| 1773 | * and all its interfaces. |
| 1774 | */ |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1775 | status = usb_resume_both(udev, PMSG_AUTO_RESUME); |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1776 | return status; |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1777 | } |
| 1778 | |
Rafael J. Wysocki | e1620d5 | 2011-03-18 19:55:36 +0100 | [diff] [blame] | 1779 | int usb_runtime_idle(struct device *dev) |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1780 | { |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1781 | struct usb_device *udev = to_usb_device(dev); |
| 1782 | |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1783 | /* An idle USB device can be suspended if it passes the various |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1784 | * autosuspend checks. |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1785 | */ |
Ming Lei | 63defa7 | 2010-11-15 15:56:54 -0500 | [diff] [blame] | 1786 | if (autosuspend_check(udev) == 0) |
Alan Stern | fcc4a01 | 2010-11-15 15:57:51 -0500 | [diff] [blame] | 1787 | pm_runtime_autosuspend(dev); |
Alan Stern | 9bbdf1e | 2010-01-08 12:57:28 -0500 | [diff] [blame] | 1788 | return 0; |
| 1789 | } |
| 1790 | |
Andiry Xu | 65580b43 | 2011-09-23 14:19:52 -0700 | [diff] [blame] | 1791 | int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) |
| 1792 | { |
| 1793 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
| 1794 | int ret = -EPERM; |
| 1795 | |
| 1796 | if (hcd->driver->set_usb2_hw_lpm) { |
| 1797 | ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); |
| 1798 | if (!ret) |
| 1799 | udev->usb2_hw_lpm_enabled = enable; |
| 1800 | } |
| 1801 | |
| 1802 | return ret; |
| 1803 | } |
| 1804 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1805 | #endif /* CONFIG_USB_SUSPEND */ |
| 1806 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1807 | struct bus_type usb_bus_type = { |
| 1808 | .name = "usb", |
| 1809 | .match = usb_device_match, |
| 1810 | .uevent = usb_uevent, |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1811 | }; |