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> |
| 26 | #include <linux/usb.h> |
Alan Stern | bd85928 | 2006-09-19 10:14:07 -0400 | [diff] [blame] | 27 | #include <linux/workqueue.h> |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 28 | #include "hcd.h" |
| 29 | #include "usb.h" |
| 30 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 31 | static int usb_match_one_id(struct usb_interface *interface, |
| 32 | const struct usb_device_id *id); |
| 33 | |
| 34 | struct usb_dynid { |
| 35 | struct list_head node; |
| 36 | struct usb_device_id id; |
| 37 | }; |
| 38 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_HOTPLUG |
| 40 | |
| 41 | /* |
| 42 | * Adds a new dynamic USBdevice ID to this driver, |
| 43 | * and cause the driver to probe for all devices again. |
| 44 | */ |
| 45 | static ssize_t store_new_id(struct device_driver *driver, |
| 46 | const char *buf, size_t count) |
| 47 | { |
| 48 | struct usb_driver *usb_drv = to_usb_driver(driver); |
| 49 | struct usb_dynid *dynid; |
| 50 | u32 idVendor = 0; |
| 51 | u32 idProduct = 0; |
| 52 | int fields = 0; |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 53 | int retval = 0; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 54 | |
| 55 | fields = sscanf(buf, "%x %x", &idVendor, &idProduct); |
| 56 | if (fields < 2) |
| 57 | return -EINVAL; |
| 58 | |
| 59 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 60 | if (!dynid) |
| 61 | return -ENOMEM; |
| 62 | |
| 63 | INIT_LIST_HEAD(&dynid->node); |
| 64 | dynid->id.idVendor = idVendor; |
| 65 | dynid->id.idProduct = idProduct; |
| 66 | dynid->id.match_flags = USB_DEVICE_ID_MATCH_DEVICE; |
| 67 | |
| 68 | spin_lock(&usb_drv->dynids.lock); |
| 69 | list_add_tail(&usb_drv->dynids.list, &dynid->node); |
| 70 | spin_unlock(&usb_drv->dynids.lock); |
| 71 | |
| 72 | if (get_driver(driver)) { |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 73 | retval = driver_attach(driver); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 74 | put_driver(driver); |
| 75 | } |
| 76 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 77 | if (retval) |
| 78 | return retval; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 79 | return count; |
| 80 | } |
| 81 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); |
| 82 | |
| 83 | static int usb_create_newid_file(struct usb_driver *usb_drv) |
| 84 | { |
| 85 | int error = 0; |
| 86 | |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 87 | if (usb_drv->no_dynamic_id) |
| 88 | goto exit; |
| 89 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 90 | if (usb_drv->probe != NULL) |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 91 | error = sysfs_create_file(&usb_drv->drvwrap.driver.kobj, |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 92 | &driver_attr_new_id.attr); |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 93 | exit: |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 94 | return error; |
| 95 | } |
| 96 | |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 97 | static void usb_remove_newid_file(struct usb_driver *usb_drv) |
| 98 | { |
| 99 | if (usb_drv->no_dynamic_id) |
| 100 | return; |
| 101 | |
| 102 | if (usb_drv->probe != NULL) |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 103 | sysfs_remove_file(&usb_drv->drvwrap.driver.kobj, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 104 | &driver_attr_new_id.attr); |
| 105 | } |
| 106 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 107 | static void usb_free_dynids(struct usb_driver *usb_drv) |
| 108 | { |
| 109 | struct usb_dynid *dynid, *n; |
| 110 | |
| 111 | spin_lock(&usb_drv->dynids.lock); |
| 112 | list_for_each_entry_safe(dynid, n, &usb_drv->dynids.list, node) { |
| 113 | list_del(&dynid->node); |
| 114 | kfree(dynid); |
| 115 | } |
| 116 | spin_unlock(&usb_drv->dynids.lock); |
| 117 | } |
| 118 | #else |
| 119 | static inline int usb_create_newid_file(struct usb_driver *usb_drv) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
| 123 | |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 124 | static void usb_remove_newid_file(struct usb_driver *usb_drv) |
| 125 | { |
| 126 | } |
| 127 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 128 | static inline void usb_free_dynids(struct usb_driver *usb_drv) |
| 129 | { |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | static const struct usb_device_id *usb_match_dynamic_id(struct usb_interface *intf, |
| 134 | struct usb_driver *drv) |
| 135 | { |
| 136 | struct usb_dynid *dynid; |
| 137 | |
| 138 | spin_lock(&drv->dynids.lock); |
| 139 | list_for_each_entry(dynid, &drv->dynids.list, node) { |
| 140 | if (usb_match_one_id(intf, &dynid->id)) { |
| 141 | spin_unlock(&drv->dynids.lock); |
| 142 | return &dynid->id; |
| 143 | } |
| 144 | } |
| 145 | spin_unlock(&drv->dynids.lock); |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 150 | /* called from driver core with dev locked */ |
| 151 | static int usb_probe_device(struct device *dev) |
| 152 | { |
| 153 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
| 154 | struct usb_device *udev; |
| 155 | int error = -ENODEV; |
| 156 | |
| 157 | dev_dbg(dev, "%s\n", __FUNCTION__); |
| 158 | |
| 159 | if (!is_usb_device(dev)) /* Sanity check */ |
| 160 | return error; |
| 161 | |
| 162 | udev = to_usb_device(dev); |
| 163 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 164 | /* TODO: Add real matching code */ |
| 165 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 166 | /* The device should always appear to be in use |
| 167 | * unless the driver suports autosuspend. |
| 168 | */ |
| 169 | udev->pm_usage_cnt = !(udriver->supports_autosuspend); |
| 170 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 171 | error = udriver->probe(udev); |
| 172 | return error; |
| 173 | } |
| 174 | |
| 175 | /* called from driver core with dev locked */ |
| 176 | static int usb_unbind_device(struct device *dev) |
| 177 | { |
| 178 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
| 179 | |
| 180 | udriver->disconnect(to_usb_device(dev)); |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /* called from driver core with dev locked */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 186 | static int usb_probe_interface(struct device *dev) |
| 187 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 188 | struct usb_driver *driver = to_usb_driver(dev->driver); |
| 189 | struct usb_interface *intf; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 190 | struct usb_device *udev; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 191 | const struct usb_device_id *id; |
| 192 | int error = -ENODEV; |
| 193 | |
| 194 | dev_dbg(dev, "%s\n", __FUNCTION__); |
| 195 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 196 | if (is_usb_device(dev)) /* Sanity check */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 197 | return error; |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 198 | |
| 199 | intf = to_usb_interface(dev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 200 | udev = interface_to_usbdev(intf); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 201 | |
| 202 | id = usb_match_id(intf, driver->id_table); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 203 | if (!id) |
| 204 | id = usb_match_dynamic_id(intf, driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 205 | if (id) { |
| 206 | dev_dbg(dev, "%s - got id\n", __FUNCTION__); |
| 207 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 208 | error = usb_autoresume_device(udev, 1); |
| 209 | if (error) |
| 210 | return error; |
| 211 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 212 | /* Interface "power state" doesn't correspond to any hardware |
| 213 | * state whatsoever. We use it to record when it's bound to |
| 214 | * a driver that may start I/0: it's not frozen/quiesced. |
| 215 | */ |
| 216 | mark_active(intf); |
| 217 | intf->condition = USB_INTERFACE_BINDING; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 218 | |
| 219 | /* The interface should always appear to be in use |
| 220 | * unless the driver suports autosuspend. |
| 221 | */ |
| 222 | intf->pm_usage_cnt = !(driver->supports_autosuspend); |
| 223 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 224 | error = driver->probe(intf, id); |
| 225 | if (error) { |
| 226 | mark_quiesced(intf); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 227 | intf->needs_remote_wakeup = 0; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 228 | intf->condition = USB_INTERFACE_UNBOUND; |
| 229 | } else |
| 230 | intf->condition = USB_INTERFACE_BOUND; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 231 | |
| 232 | usb_autosuspend_device(udev, 1); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | return error; |
| 236 | } |
| 237 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 238 | /* called from driver core with dev locked */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 239 | static int usb_unbind_interface(struct device *dev) |
| 240 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 241 | struct usb_driver *driver = to_usb_driver(dev->driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 242 | struct usb_interface *intf = to_usb_interface(dev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 243 | struct usb_device *udev; |
| 244 | int error; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 245 | |
| 246 | intf->condition = USB_INTERFACE_UNBINDING; |
| 247 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 248 | /* Autoresume for set_interface call below */ |
| 249 | udev = interface_to_usbdev(intf); |
| 250 | error = usb_autoresume_device(udev, 1); |
| 251 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 252 | /* release all urbs for this interface */ |
| 253 | usb_disable_interface(interface_to_usbdev(intf), intf); |
| 254 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 255 | driver->disconnect(intf); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 256 | |
| 257 | /* reset other interface state */ |
| 258 | usb_set_interface(interface_to_usbdev(intf), |
| 259 | intf->altsetting[0].desc.bInterfaceNumber, |
| 260 | 0); |
| 261 | usb_set_intfdata(intf, NULL); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 262 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 263 | intf->condition = USB_INTERFACE_UNBOUND; |
| 264 | mark_quiesced(intf); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 265 | intf->needs_remote_wakeup = 0; |
| 266 | |
| 267 | if (!error) |
| 268 | usb_autosuspend_device(udev, 1); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 273 | /** |
| 274 | * usb_driver_claim_interface - bind a driver to an interface |
| 275 | * @driver: the driver to be bound |
| 276 | * @iface: the interface to which it will be bound; must be in the |
| 277 | * usb device's active configuration |
| 278 | * @priv: driver data associated with that interface |
| 279 | * |
| 280 | * This is used by usb device drivers that need to claim more than one |
| 281 | * interface on a device when probing (audio and acm are current examples). |
| 282 | * No device driver should directly modify internal usb_interface or |
| 283 | * usb_device structure members. |
| 284 | * |
| 285 | * Few drivers should need to use this routine, since the most natural |
| 286 | * way to bind to an interface is to return the private data from |
| 287 | * the driver's probe() method. |
| 288 | * |
| 289 | * Callers must own the device lock and the driver model's usb_bus_type.subsys |
| 290 | * writelock. So driver probe() entries don't need extra locking, |
| 291 | * but other call contexts may need to explicitly claim those locks. |
| 292 | */ |
| 293 | int usb_driver_claim_interface(struct usb_driver *driver, |
| 294 | struct usb_interface *iface, void* priv) |
| 295 | { |
| 296 | struct device *dev = &iface->dev; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 297 | struct usb_device *udev = interface_to_usbdev(iface); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 298 | int retval = 0; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 299 | |
| 300 | if (dev->driver) |
| 301 | return -EBUSY; |
| 302 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 303 | dev->driver = &driver->drvwrap.driver; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 304 | usb_set_intfdata(iface, priv); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 305 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 306 | usb_pm_lock(udev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 307 | iface->condition = USB_INTERFACE_BOUND; |
| 308 | mark_active(iface); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 309 | iface->pm_usage_cnt = !(driver->supports_autosuspend); |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 310 | usb_pm_unlock(udev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 311 | |
| 312 | /* if interface was already added, bind now; else let |
| 313 | * the future device_add() bind it, bypassing probe() |
| 314 | */ |
| 315 | if (device_is_registered(dev)) |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 316 | retval = device_bind_driver(dev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 317 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 318 | return retval; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 319 | } |
| 320 | EXPORT_SYMBOL(usb_driver_claim_interface); |
| 321 | |
| 322 | /** |
| 323 | * usb_driver_release_interface - unbind a driver from an interface |
| 324 | * @driver: the driver to be unbound |
| 325 | * @iface: the interface from which it will be unbound |
| 326 | * |
| 327 | * This can be used by drivers to release an interface without waiting |
| 328 | * for their disconnect() methods to be called. In typical cases this |
| 329 | * also causes the driver disconnect() method to be called. |
| 330 | * |
| 331 | * This call is synchronous, and may not be used in an interrupt context. |
| 332 | * Callers must own the device lock and the driver model's usb_bus_type.subsys |
| 333 | * writelock. So driver disconnect() entries don't need extra locking, |
| 334 | * but other call contexts may need to explicitly claim those locks. |
| 335 | */ |
| 336 | void usb_driver_release_interface(struct usb_driver *driver, |
| 337 | struct usb_interface *iface) |
| 338 | { |
| 339 | struct device *dev = &iface->dev; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 340 | struct usb_device *udev = interface_to_usbdev(iface); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 341 | |
| 342 | /* this should never happen, don't release something that's not ours */ |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 343 | if (!dev->driver || dev->driver != &driver->drvwrap.driver) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 344 | return; |
| 345 | |
| 346 | /* don't release from within disconnect() */ |
| 347 | if (iface->condition != USB_INTERFACE_BOUND) |
| 348 | return; |
| 349 | |
| 350 | /* don't release if the interface hasn't been added yet */ |
| 351 | if (device_is_registered(dev)) { |
| 352 | iface->condition = USB_INTERFACE_UNBINDING; |
| 353 | device_release_driver(dev); |
| 354 | } |
| 355 | |
| 356 | dev->driver = NULL; |
| 357 | usb_set_intfdata(iface, NULL); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 358 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 359 | usb_pm_lock(udev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 360 | iface->condition = USB_INTERFACE_UNBOUND; |
| 361 | mark_quiesced(iface); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 362 | iface->needs_remote_wakeup = 0; |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 363 | usb_pm_unlock(udev); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 364 | } |
| 365 | EXPORT_SYMBOL(usb_driver_release_interface); |
| 366 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 367 | /* returns 0 if no match, 1 if match */ |
| 368 | static int usb_match_one_id(struct usb_interface *interface, |
| 369 | const struct usb_device_id *id) |
| 370 | { |
| 371 | struct usb_host_interface *intf; |
| 372 | struct usb_device *dev; |
| 373 | |
| 374 | /* proc_connectinfo in devio.c may call us with id == NULL. */ |
| 375 | if (id == NULL) |
| 376 | return 0; |
| 377 | |
| 378 | intf = interface->cur_altsetting; |
| 379 | dev = interface_to_usbdev(interface); |
| 380 | |
| 381 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && |
| 382 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) |
| 383 | return 0; |
| 384 | |
| 385 | if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && |
| 386 | id->idProduct != le16_to_cpu(dev->descriptor.idProduct)) |
| 387 | return 0; |
| 388 | |
| 389 | /* No need to test id->bcdDevice_lo != 0, since 0 is never |
| 390 | greater than any unsigned number. */ |
| 391 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && |
| 392 | (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice))) |
| 393 | return 0; |
| 394 | |
| 395 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && |
| 396 | (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice))) |
| 397 | return 0; |
| 398 | |
| 399 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && |
| 400 | (id->bDeviceClass != dev->descriptor.bDeviceClass)) |
| 401 | return 0; |
| 402 | |
| 403 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && |
| 404 | (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) |
| 405 | return 0; |
| 406 | |
| 407 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && |
| 408 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) |
| 409 | return 0; |
| 410 | |
Alan Stern | 93c8bf4 | 2006-10-18 16:41:51 -0400 | [diff] [blame] | 411 | /* The interface class, subclass, and protocol should never be |
| 412 | * checked for a match if the device class is Vendor Specific, |
| 413 | * unless the match record specifies the Vendor ID. */ |
| 414 | if (dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC && |
| 415 | !(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && |
| 416 | (id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS | |
| 417 | USB_DEVICE_ID_MATCH_INT_SUBCLASS | |
| 418 | USB_DEVICE_ID_MATCH_INT_PROTOCOL))) |
| 419 | return 0; |
| 420 | |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 421 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && |
| 422 | (id->bInterfaceClass != intf->desc.bInterfaceClass)) |
| 423 | return 0; |
| 424 | |
| 425 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && |
| 426 | (id->bInterfaceSubClass != intf->desc.bInterfaceSubClass)) |
| 427 | return 0; |
| 428 | |
| 429 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && |
| 430 | (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) |
| 431 | return 0; |
| 432 | |
| 433 | return 1; |
| 434 | } |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 435 | /** |
| 436 | * usb_match_id - find first usb_device_id matching device or interface |
| 437 | * @interface: the interface of interest |
| 438 | * @id: array of usb_device_id structures, terminated by zero entry |
| 439 | * |
| 440 | * usb_match_id searches an array of usb_device_id's and returns |
| 441 | * the first one matching the device or interface, or null. |
| 442 | * This is used when binding (or rebinding) a driver to an interface. |
| 443 | * Most USB device drivers will use this indirectly, through the usb core, |
| 444 | * but some layered driver frameworks use it directly. |
| 445 | * These device tables are exported with MODULE_DEVICE_TABLE, through |
| 446 | * modutils, to support the driver loading functionality of USB hotplugging. |
| 447 | * |
| 448 | * What Matches: |
| 449 | * |
| 450 | * The "match_flags" element in a usb_device_id controls which |
| 451 | * members are used. If the corresponding bit is set, the |
| 452 | * value in the device_id must match its corresponding member |
| 453 | * in the device or interface descriptor, or else the device_id |
| 454 | * does not match. |
| 455 | * |
| 456 | * "driver_info" is normally used only by device drivers, |
| 457 | * but you can create a wildcard "matches anything" usb_device_id |
| 458 | * as a driver's "modules.usbmap" entry if you provide an id with |
| 459 | * only a nonzero "driver_info" field. If you do this, the USB device |
| 460 | * driver's probe() routine should use additional intelligence to |
| 461 | * decide whether to bind to the specified interface. |
| 462 | * |
| 463 | * What Makes Good usb_device_id Tables: |
| 464 | * |
| 465 | * The match algorithm is very simple, so that intelligence in |
| 466 | * driver selection must come from smart driver id records. |
| 467 | * Unless you have good reasons to use another selection policy, |
| 468 | * provide match elements only in related groups, and order match |
| 469 | * specifiers from specific to general. Use the macros provided |
| 470 | * for that purpose if you can. |
| 471 | * |
| 472 | * The most specific match specifiers use device descriptor |
| 473 | * data. These are commonly used with product-specific matches; |
| 474 | * the USB_DEVICE macro lets you provide vendor and product IDs, |
| 475 | * and you can also match against ranges of product revisions. |
| 476 | * These are widely used for devices with application or vendor |
| 477 | * specific bDeviceClass values. |
| 478 | * |
| 479 | * Matches based on device class/subclass/protocol specifications |
| 480 | * are slightly more general; use the USB_DEVICE_INFO macro, or |
| 481 | * its siblings. These are used with single-function devices |
| 482 | * where bDeviceClass doesn't specify that each interface has |
| 483 | * its own class. |
| 484 | * |
| 485 | * Matches based on interface class/subclass/protocol are the |
| 486 | * most general; they let drivers bind to any interface on a |
| 487 | * multiple-function device. Use the USB_INTERFACE_INFO |
| 488 | * macro, or its siblings, to match class-per-interface style |
Alan Stern | 93c8bf4 | 2006-10-18 16:41:51 -0400 | [diff] [blame] | 489 | * devices (as recorded in bInterfaceClass). |
| 490 | * |
| 491 | * Note that an entry created by USB_INTERFACE_INFO won't match |
| 492 | * any interface if the device class is set to Vendor-Specific. |
| 493 | * This is deliberate; according to the USB spec the meanings of |
| 494 | * the interface class/subclass/protocol for these devices are also |
| 495 | * vendor-specific, and hence matching against a standard product |
| 496 | * class wouldn't work anyway. If you really want to use an |
| 497 | * interface-based match for such a device, create a match record |
| 498 | * that also specifies the vendor ID. (Unforunately there isn't a |
| 499 | * standard macro for creating records like this.) |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 500 | * |
| 501 | * Within those groups, remember that not all combinations are |
| 502 | * meaningful. For example, don't give a product version range |
| 503 | * without vendor and product IDs; or specify a protocol without |
| 504 | * its associated class and subclass. |
| 505 | */ |
| 506 | const struct usb_device_id *usb_match_id(struct usb_interface *interface, |
| 507 | const struct usb_device_id *id) |
| 508 | { |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 509 | /* proc_connectinfo in devio.c may call us with id == NULL. */ |
| 510 | if (id == NULL) |
| 511 | return NULL; |
| 512 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 513 | /* It is important to check that id->driver_info is nonzero, |
| 514 | since an entry that is all zeroes except for a nonzero |
| 515 | id->driver_info is the way to create an entry that |
| 516 | indicates that the driver want to examine every |
| 517 | device and interface. */ |
| 518 | for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || |
| 519 | id->driver_info; id++) { |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 520 | if (usb_match_one_id(interface, id)) |
| 521 | return id; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | return NULL; |
| 525 | } |
Greg Kroah-Hartman | b87ba0a | 2006-03-20 13:17:13 -0800 | [diff] [blame] | 526 | EXPORT_SYMBOL_GPL_FUTURE(usb_match_id); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 527 | |
Adrian Bunk | 8bb22d2 | 2006-11-21 22:02:54 +0100 | [diff] [blame] | 528 | 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] | 529 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 530 | /* devices and interfaces are handled separately */ |
| 531 | if (is_usb_device(dev)) { |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 532 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 533 | /* interface drivers never match devices */ |
| 534 | if (!is_usb_device_driver(drv)) |
| 535 | return 0; |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 536 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 537 | /* TODO: Add real matching code */ |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 538 | return 1; |
| 539 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 540 | } else { |
| 541 | struct usb_interface *intf; |
| 542 | struct usb_driver *usb_drv; |
| 543 | const struct usb_device_id *id; |
| 544 | |
| 545 | /* device drivers never match interfaces */ |
| 546 | if (is_usb_device_driver(drv)) |
| 547 | return 0; |
| 548 | |
| 549 | intf = to_usb_interface(dev); |
| 550 | usb_drv = to_usb_driver(drv); |
| 551 | |
| 552 | id = usb_match_id(intf, usb_drv->id_table); |
| 553 | if (id) |
| 554 | return 1; |
| 555 | |
| 556 | id = usb_match_dynamic_id(intf, usb_drv); |
| 557 | if (id) |
| 558 | return 1; |
| 559 | } |
| 560 | |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 561 | return 0; |
| 562 | } |
| 563 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 564 | #ifdef CONFIG_HOTPLUG |
| 565 | |
| 566 | /* |
| 567 | * This sends an uevent to userspace, typically helping to load driver |
| 568 | * or other modules, configure the device, and more. Drivers can provide |
| 569 | * a MODULE_DEVICE_TABLE to help with module loading subtasks. |
| 570 | * |
| 571 | * We're called either from khubd (the typical case) or from root hub |
| 572 | * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle |
| 573 | * delays in event delivery. Use sysfs (and DEVPATH) to make sure the |
| 574 | * device (and this configuration!) are still present. |
| 575 | */ |
| 576 | static int usb_uevent(struct device *dev, char **envp, int num_envp, |
| 577 | char *buffer, int buffer_size) |
| 578 | { |
| 579 | struct usb_interface *intf; |
| 580 | struct usb_device *usb_dev; |
| 581 | struct usb_host_interface *alt; |
| 582 | int i = 0; |
| 583 | int length = 0; |
| 584 | |
| 585 | if (!dev) |
| 586 | return -ENODEV; |
| 587 | |
| 588 | /* driver is often null here; dev_dbg() would oops */ |
| 589 | pr_debug ("usb %s: uevent\n", dev->bus_id); |
| 590 | |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 591 | if (is_usb_device(dev)) { |
| 592 | usb_dev = to_usb_device(dev); |
| 593 | alt = NULL; |
| 594 | } else { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 595 | intf = to_usb_interface(dev); |
| 596 | usb_dev = interface_to_usbdev(intf); |
| 597 | alt = intf->cur_altsetting; |
| 598 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 599 | |
| 600 | if (usb_dev->devnum < 0) { |
| 601 | pr_debug ("usb %s: already deleted?\n", dev->bus_id); |
| 602 | return -ENODEV; |
| 603 | } |
| 604 | if (!usb_dev->bus) { |
| 605 | pr_debug ("usb %s: bus removed?\n", dev->bus_id); |
| 606 | return -ENODEV; |
| 607 | } |
| 608 | |
| 609 | #ifdef CONFIG_USB_DEVICEFS |
| 610 | /* If this is available, userspace programs can directly read |
| 611 | * all the device descriptors we don't tell them about. Or |
| 612 | * even act as usermode drivers. |
| 613 | * |
| 614 | * FIXME reduce hardwired intelligence here |
| 615 | */ |
| 616 | if (add_uevent_var(envp, num_envp, &i, |
| 617 | buffer, buffer_size, &length, |
| 618 | "DEVICE=/proc/bus/usb/%03d/%03d", |
| 619 | usb_dev->bus->busnum, usb_dev->devnum)) |
| 620 | return -ENOMEM; |
| 621 | #endif |
| 622 | |
| 623 | /* per-device configurations are common */ |
| 624 | if (add_uevent_var(envp, num_envp, &i, |
| 625 | buffer, buffer_size, &length, |
| 626 | "PRODUCT=%x/%x/%x", |
| 627 | le16_to_cpu(usb_dev->descriptor.idVendor), |
| 628 | le16_to_cpu(usb_dev->descriptor.idProduct), |
| 629 | le16_to_cpu(usb_dev->descriptor.bcdDevice))) |
| 630 | return -ENOMEM; |
| 631 | |
| 632 | /* class-based driver binding models */ |
| 633 | if (add_uevent_var(envp, num_envp, &i, |
| 634 | buffer, buffer_size, &length, |
| 635 | "TYPE=%d/%d/%d", |
| 636 | usb_dev->descriptor.bDeviceClass, |
| 637 | usb_dev->descriptor.bDeviceSubClass, |
| 638 | usb_dev->descriptor.bDeviceProtocol)) |
| 639 | return -ENOMEM; |
| 640 | |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 641 | if (!is_usb_device(dev)) { |
| 642 | |
| 643 | if (add_uevent_var(envp, num_envp, &i, |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 644 | buffer, buffer_size, &length, |
| 645 | "INTERFACE=%d/%d/%d", |
| 646 | alt->desc.bInterfaceClass, |
| 647 | alt->desc.bInterfaceSubClass, |
| 648 | alt->desc.bInterfaceProtocol)) |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 649 | return -ENOMEM; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 650 | |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 651 | if (add_uevent_var(envp, num_envp, &i, |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 652 | buffer, buffer_size, &length, |
| 653 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", |
| 654 | le16_to_cpu(usb_dev->descriptor.idVendor), |
| 655 | le16_to_cpu(usb_dev->descriptor.idProduct), |
| 656 | le16_to_cpu(usb_dev->descriptor.bcdDevice), |
| 657 | usb_dev->descriptor.bDeviceClass, |
| 658 | usb_dev->descriptor.bDeviceSubClass, |
| 659 | usb_dev->descriptor.bDeviceProtocol, |
| 660 | alt->desc.bInterfaceClass, |
| 661 | alt->desc.bInterfaceSubClass, |
| 662 | alt->desc.bInterfaceProtocol)) |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 663 | return -ENOMEM; |
| 664 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 665 | |
| 666 | envp[i] = NULL; |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | #else |
| 672 | |
| 673 | static int usb_uevent(struct device *dev, char **envp, |
| 674 | int num_envp, char *buffer, int buffer_size) |
| 675 | { |
| 676 | return -ENODEV; |
| 677 | } |
| 678 | |
| 679 | #endif /* CONFIG_HOTPLUG */ |
| 680 | |
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 | * usb_register_device_driver - register a USB device (not interface) driver |
| 683 | * @new_udriver: USB operations for the device driver |
Greg Kroah-Hartman | 2143acc | 2005-11-21 14:53:03 -0800 | [diff] [blame] | 684 | * @owner: module owner of this driver. |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 685 | * |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 686 | * Registers a USB device driver with the USB core. The list of |
| 687 | * unattached devices will be rescanned whenever a new driver is |
| 688 | * added, allowing the new driver to attach to any recognized devices. |
| 689 | * Returns a negative error code on failure and 0 on success. |
| 690 | */ |
| 691 | int usb_register_device_driver(struct usb_device_driver *new_udriver, |
| 692 | struct module *owner) |
| 693 | { |
| 694 | int retval = 0; |
| 695 | |
| 696 | if (usb_disabled()) |
| 697 | return -ENODEV; |
| 698 | |
| 699 | new_udriver->drvwrap.for_devices = 1; |
| 700 | new_udriver->drvwrap.driver.name = (char *) new_udriver->name; |
| 701 | new_udriver->drvwrap.driver.bus = &usb_bus_type; |
| 702 | new_udriver->drvwrap.driver.probe = usb_probe_device; |
| 703 | new_udriver->drvwrap.driver.remove = usb_unbind_device; |
| 704 | new_udriver->drvwrap.driver.owner = owner; |
| 705 | |
| 706 | retval = driver_register(&new_udriver->drvwrap.driver); |
| 707 | |
| 708 | if (!retval) { |
| 709 | pr_info("%s: registered new device driver %s\n", |
| 710 | usbcore_name, new_udriver->name); |
| 711 | usbfs_update_special(); |
| 712 | } else { |
| 713 | printk(KERN_ERR "%s: error %d registering device " |
| 714 | " driver %s\n", |
| 715 | usbcore_name, retval, new_udriver->name); |
| 716 | } |
| 717 | |
| 718 | return retval; |
| 719 | } |
| 720 | EXPORT_SYMBOL_GPL(usb_register_device_driver); |
| 721 | |
| 722 | /** |
| 723 | * usb_deregister_device_driver - unregister a USB device (not interface) driver |
| 724 | * @udriver: USB operations of the device driver to unregister |
| 725 | * Context: must be able to sleep |
| 726 | * |
| 727 | * Unlinks the specified driver from the internal USB driver list. |
| 728 | */ |
| 729 | void usb_deregister_device_driver(struct usb_device_driver *udriver) |
| 730 | { |
| 731 | pr_info("%s: deregistering device driver %s\n", |
| 732 | usbcore_name, udriver->name); |
| 733 | |
| 734 | driver_unregister(&udriver->drvwrap.driver); |
| 735 | usbfs_update_special(); |
| 736 | } |
| 737 | EXPORT_SYMBOL_GPL(usb_deregister_device_driver); |
| 738 | |
| 739 | /** |
| 740 | * usb_register_driver - register a USB interface driver |
| 741 | * @new_driver: USB operations for the interface driver |
| 742 | * @owner: module owner of this driver. |
| 743 | * |
| 744 | * Registers a USB interface driver with the USB core. The list of |
| 745 | * unattached interfaces will be rescanned whenever a new driver is |
| 746 | * added, allowing the new driver to attach to any recognized interfaces. |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 747 | * Returns a negative error code on failure and 0 on success. |
| 748 | * |
| 749 | * NOTE: if you want your driver to use the USB major number, you must call |
| 750 | * usb_register_dev() to enable that functionality. This function no longer |
| 751 | * takes care of that. |
| 752 | */ |
Greg Kroah-Hartman | 2143acc | 2005-11-21 14:53:03 -0800 | [diff] [blame] | 753 | int usb_register_driver(struct usb_driver *new_driver, struct module *owner) |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 754 | { |
| 755 | int retval = 0; |
| 756 | |
| 757 | if (usb_disabled()) |
| 758 | return -ENODEV; |
| 759 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 760 | new_driver->drvwrap.for_devices = 0; |
| 761 | new_driver->drvwrap.driver.name = (char *) new_driver->name; |
| 762 | new_driver->drvwrap.driver.bus = &usb_bus_type; |
| 763 | new_driver->drvwrap.driver.probe = usb_probe_interface; |
| 764 | new_driver->drvwrap.driver.remove = usb_unbind_interface; |
| 765 | new_driver->drvwrap.driver.owner = owner; |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 766 | spin_lock_init(&new_driver->dynids.lock); |
| 767 | INIT_LIST_HEAD(&new_driver->dynids.list); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 768 | |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 769 | retval = driver_register(&new_driver->drvwrap.driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 770 | |
| 771 | if (!retval) { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 772 | pr_info("%s: registered new interface driver %s\n", |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 773 | usbcore_name, new_driver->name); |
| 774 | usbfs_update_special(); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 775 | usb_create_newid_file(new_driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 776 | } else { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 777 | printk(KERN_ERR "%s: error %d registering interface " |
| 778 | " driver %s\n", |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 779 | usbcore_name, retval, new_driver->name); |
| 780 | } |
| 781 | |
| 782 | return retval; |
| 783 | } |
Greg Kroah-Hartman | b87ba0a | 2006-03-20 13:17:13 -0800 | [diff] [blame] | 784 | EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 785 | |
| 786 | /** |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 787 | * usb_deregister - unregister a USB interface driver |
| 788 | * @driver: USB operations of the interface driver to unregister |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 789 | * Context: must be able to sleep |
| 790 | * |
| 791 | * Unlinks the specified driver from the internal USB driver list. |
| 792 | * |
| 793 | * NOTE: If you called usb_register_dev(), you still need to call |
| 794 | * usb_deregister_dev() to clean up your driver's allocated minor numbers, |
| 795 | * this * call will no longer do it for you. |
| 796 | */ |
| 797 | void usb_deregister(struct usb_driver *driver) |
| 798 | { |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 799 | pr_info("%s: deregistering interface driver %s\n", |
| 800 | usbcore_name, driver->name); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 801 | |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 802 | usb_remove_newid_file(driver); |
Greg Kroah-Hartman | 733260f | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 803 | usb_free_dynids(driver); |
Alan Stern | 8bb54ab | 2006-07-01 22:08:49 -0400 | [diff] [blame] | 804 | driver_unregister(&driver->drvwrap.driver); |
Greg Kroah-Hartman | ddae41b | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 805 | |
| 806 | usbfs_update_special(); |
| 807 | } |
Greg Kroah-Hartman | b87ba0a | 2006-03-20 13:17:13 -0800 | [diff] [blame] | 808 | EXPORT_SYMBOL_GPL_FUTURE(usb_deregister); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 809 | |
| 810 | #ifdef CONFIG_PM |
| 811 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 812 | /* Caller has locked udev's pm_mutex */ |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 813 | 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] | 814 | { |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 815 | struct usb_device_driver *udriver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 816 | int status = 0; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 817 | |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 818 | if (udev->state == USB_STATE_NOTATTACHED || |
| 819 | udev->state == USB_STATE_SUSPENDED) |
| 820 | goto done; |
| 821 | |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 822 | /* For devices that don't have a driver, we do a standard suspend. */ |
| 823 | if (udev->dev.driver == NULL) { |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 824 | udev->do_remote_wakeup = 0; |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 825 | status = usb_port_suspend(udev); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 826 | goto done; |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 827 | } |
| 828 | |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 829 | udriver = to_usb_device_driver(udev->dev.driver); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 830 | status = udriver->suspend(udev, msg); |
| 831 | |
| 832 | done: |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 833 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 834 | if (status == 0) |
| 835 | udev->dev.power.power_state.event = msg.event; |
| 836 | return status; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 837 | } |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 838 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 839 | /* Caller has locked udev's pm_mutex */ |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 840 | static int usb_resume_device(struct usb_device *udev) |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 841 | { |
| 842 | struct usb_device_driver *udriver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 843 | int status = 0; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 844 | |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 845 | if (udev->state == USB_STATE_NOTATTACHED || |
| 846 | udev->state != USB_STATE_SUSPENDED) |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 847 | goto done; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 848 | |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 849 | /* Can't resume it if it doesn't have a driver. */ |
| 850 | if (udev->dev.driver == NULL) { |
| 851 | status = -ENOTCONN; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 852 | goto done; |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 855 | udriver = to_usb_device_driver(udev->dev.driver); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 856 | status = udriver->resume(udev); |
| 857 | |
| 858 | done: |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 859 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 860 | if (status == 0) |
| 861 | udev->dev.power.power_state.event = PM_EVENT_ON; |
| 862 | return status; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 865 | /* Caller has locked intf's usb_device's pm mutex */ |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 866 | static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg) |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 867 | { |
| 868 | struct usb_driver *driver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 869 | int status = 0; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 870 | |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 871 | /* with no hardware, USB interfaces only use FREEZE and ON states */ |
| 872 | if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED || |
| 873 | !is_active(intf)) |
| 874 | goto done; |
| 875 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 876 | if (intf->condition == USB_INTERFACE_UNBOUND) /* This can't happen */ |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 877 | goto done; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 878 | driver = to_usb_driver(intf->dev.driver); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 879 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 880 | if (driver->suspend && driver->resume) { |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 881 | status = driver->suspend(intf, msg); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 882 | if (status == 0) |
| 883 | mark_quiesced(intf); |
| 884 | else if (!interface_to_usbdev(intf)->auto_pm) |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 885 | dev_err(&intf->dev, "%s error %d\n", |
| 886 | "suspend", status); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 887 | } else { |
| 888 | // FIXME else if there's no suspend method, disconnect... |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 889 | // Not possible if auto_pm is set... |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 890 | dev_warn(&intf->dev, "no suspend for driver %s?\n", |
| 891 | driver->name); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 892 | mark_quiesced(intf); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 893 | } |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 894 | |
| 895 | done: |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 896 | // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 897 | if (status == 0) |
| 898 | intf->dev.power.power_state.event = msg.event; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 899 | return status; |
| 900 | } |
| 901 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 902 | /* Caller has locked intf's usb_device's pm_mutex */ |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 903 | static int usb_resume_interface(struct usb_interface *intf) |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 904 | { |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 905 | struct usb_driver *driver; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 906 | int status = 0; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 907 | |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 908 | if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED || |
| 909 | is_active(intf)) |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 910 | goto done; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 911 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 912 | /* Don't let autoresume interfere with unbinding */ |
| 913 | if (intf->condition == USB_INTERFACE_UNBINDING) |
| 914 | goto done; |
| 915 | |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 916 | /* Can't resume it if it doesn't have a driver. */ |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 917 | if (intf->condition == USB_INTERFACE_UNBOUND) { |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 918 | status = -ENOTCONN; |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 919 | goto done; |
Alan Stern | 1c5df7e | 2006-07-01 22:13:50 -0400 | [diff] [blame] | 920 | } |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 921 | driver = to_usb_driver(intf->dev.driver); |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 922 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 923 | if (driver->resume) { |
| 924 | status = driver->resume(intf); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 925 | if (status) |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 926 | dev_err(&intf->dev, "%s error %d\n", |
| 927 | "resume", status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 928 | else |
| 929 | mark_active(intf); |
| 930 | } else { |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 931 | dev_warn(&intf->dev, "no resume for driver %s?\n", |
| 932 | driver->name); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 933 | mark_active(intf); |
| 934 | } |
| 935 | |
| 936 | done: |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 937 | // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status); |
Alan Stern | 2bf4086 | 2006-07-01 22:12:19 -0400 | [diff] [blame] | 938 | if (status == 0) |
| 939 | intf->dev.power.power_state.event = PM_EVENT_ON; |
| 940 | return status; |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 941 | } |
| 942 | |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 943 | /* Internal routine to check whether we may autosuspend a device. */ |
| 944 | static int autosuspend_check(struct usb_device *udev) |
| 945 | { |
| 946 | int i; |
| 947 | struct usb_interface *intf; |
| 948 | |
| 949 | /* For autosuspend, fail fast if anything is in use. |
| 950 | * Also fail if any interfaces require remote wakeup but it |
| 951 | * isn't available. */ |
| 952 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); |
| 953 | if (udev->pm_usage_cnt > 0) |
| 954 | return -EBUSY; |
| 955 | if (udev->actconfig) { |
| 956 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
| 957 | intf = udev->actconfig->interface[i]; |
| 958 | if (!is_active(intf)) |
| 959 | continue; |
| 960 | if (intf->pm_usage_cnt > 0) |
| 961 | return -EBUSY; |
| 962 | if (intf->needs_remote_wakeup && |
| 963 | !udev->do_remote_wakeup) { |
| 964 | dev_dbg(&udev->dev, "remote wakeup needed " |
| 965 | "for autosuspend\n"); |
| 966 | return -EOPNOTSUPP; |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | return 0; |
| 971 | } |
| 972 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 973 | /** |
| 974 | * usb_suspend_both - suspend a USB device and its interfaces |
| 975 | * @udev: the usb_device to suspend |
| 976 | * @msg: Power Management message describing this state transition |
| 977 | * |
| 978 | * This is the central routine for suspending USB devices. It calls the |
| 979 | * suspend methods for all the interface drivers in @udev and then calls |
| 980 | * the suspend method for @udev itself. If an error occurs at any stage, |
| 981 | * all the interfaces which were suspended are resumed so that they remain |
| 982 | * in the same state as the device. |
| 983 | * |
| 984 | * If an autosuspend is in progress (@udev->auto_pm is set), the routine |
| 985 | * checks first to make sure that neither the device itself or any of its |
| 986 | * active interfaces is in use (pm_usage_cnt is greater than 0). If they |
| 987 | * are, the autosuspend fails. |
| 988 | * |
| 989 | * If the suspend succeeds, the routine recursively queues an autosuspend |
| 990 | * request for @udev's parent device, thereby propagating the change up |
| 991 | * the device tree. If all of the parent's children are now suspended, |
| 992 | * the parent will autosuspend in turn. |
| 993 | * |
| 994 | * The suspend method calls are subject to mutual exclusion under control |
| 995 | * of @udev's pm_mutex. Many of these calls are also under the protection |
| 996 | * of @udev's device lock (including all requests originating outside the |
| 997 | * USB subsystem), but autosuspend requests generated by a child device or |
| 998 | * interface driver may not be. Usbcore will insure that the method calls |
| 999 | * do not arrive during bind, unbind, or reset operations. However, drivers |
| 1000 | * must be prepared to handle suspend calls arriving at unpredictable times. |
| 1001 | * The only way to block such calls is to do an autoresume (preventing |
| 1002 | * autosuspends) while holding @udev's device lock (preventing outside |
| 1003 | * suspends). |
| 1004 | * |
| 1005 | * The caller must hold @udev->pm_mutex. |
| 1006 | * |
| 1007 | * This routine can run only in process context. |
| 1008 | */ |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1009 | int usb_suspend_both(struct usb_device *udev, pm_message_t msg) |
| 1010 | { |
| 1011 | int status = 0; |
| 1012 | int i = 0; |
| 1013 | struct usb_interface *intf; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1014 | struct usb_device *parent = udev->parent; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1015 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1016 | cancel_delayed_work(&udev->autosuspend); |
| 1017 | if (udev->state == USB_STATE_NOTATTACHED) |
| 1018 | return 0; |
| 1019 | if (udev->state == USB_STATE_SUSPENDED) |
| 1020 | return 0; |
| 1021 | |
| 1022 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); |
| 1023 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1024 | if (udev->auto_pm) { |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1025 | status = autosuspend_check(udev); |
| 1026 | if (status < 0) |
| 1027 | return status; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /* Suspend all the interfaces and then udev itself */ |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1031 | if (udev->actconfig) { |
| 1032 | for (; i < udev->actconfig->desc.bNumInterfaces; i++) { |
| 1033 | intf = udev->actconfig->interface[i]; |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1034 | status = usb_suspend_interface(intf, msg); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1035 | if (status != 0) |
| 1036 | break; |
| 1037 | } |
| 1038 | } |
| 1039 | if (status == 0) |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1040 | status = usb_suspend_device(udev, msg); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1041 | |
| 1042 | /* If the suspend failed, resume interfaces that did get suspended */ |
| 1043 | if (status != 0) { |
| 1044 | while (--i >= 0) { |
| 1045 | intf = udev->actconfig->interface[i]; |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1046 | usb_resume_interface(intf); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1047 | } |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1048 | |
| 1049 | /* If the suspend succeeded, propagate it up the tree */ |
| 1050 | } else if (parent) |
| 1051 | usb_autosuspend_device(parent, 0); |
| 1052 | |
| 1053 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1054 | return status; |
| 1055 | } |
| 1056 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1057 | /** |
| 1058 | * usb_resume_both - resume a USB device and its interfaces |
| 1059 | * @udev: the usb_device to resume |
| 1060 | * |
| 1061 | * This is the central routine for resuming USB devices. It calls the |
| 1062 | * the resume method for @udev and then calls the resume methods for all |
| 1063 | * the interface drivers in @udev. |
| 1064 | * |
| 1065 | * Before starting the resume, the routine calls itself recursively for |
| 1066 | * the parent device of @udev, thereby propagating the change up the device |
| 1067 | * tree and assuring that @udev will be able to resume. If the parent is |
| 1068 | * unable to resume successfully, the routine fails. |
| 1069 | * |
| 1070 | * The resume method calls are subject to mutual exclusion under control |
| 1071 | * of @udev's pm_mutex. Many of these calls are also under the protection |
| 1072 | * of @udev's device lock (including all requests originating outside the |
| 1073 | * USB subsystem), but autoresume requests generated by a child device or |
| 1074 | * interface driver may not be. Usbcore will insure that the method calls |
| 1075 | * do not arrive during bind, unbind, or reset operations. However, drivers |
| 1076 | * must be prepared to handle resume calls arriving at unpredictable times. |
| 1077 | * The only way to block such calls is to do an autoresume (preventing |
| 1078 | * other autoresumes) while holding @udev's device lock (preventing outside |
| 1079 | * resumes). |
| 1080 | * |
| 1081 | * The caller must hold @udev->pm_mutex. |
| 1082 | * |
| 1083 | * This routine can run only in process context. |
| 1084 | */ |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1085 | int usb_resume_both(struct usb_device *udev) |
| 1086 | { |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1087 | int status = 0; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1088 | int i; |
| 1089 | struct usb_interface *intf; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1090 | struct usb_device *parent = udev->parent; |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1091 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1092 | cancel_delayed_work(&udev->autosuspend); |
| 1093 | if (udev->state == USB_STATE_NOTATTACHED) |
| 1094 | return -ENODEV; |
| 1095 | |
| 1096 | /* Propagate the resume up the tree, if necessary */ |
| 1097 | if (udev->state == USB_STATE_SUSPENDED) { |
| 1098 | if (parent) { |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1099 | usb_pm_lock(parent); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1100 | parent->auto_pm = 1; |
| 1101 | status = usb_resume_both(parent); |
| 1102 | } else { |
| 1103 | |
| 1104 | /* We can't progagate beyond the USB subsystem, |
| 1105 | * so if a root hub's controller is suspended |
| 1106 | * then we're stuck. */ |
| 1107 | if (udev->dev.parent->power.power_state.event != |
| 1108 | PM_EVENT_ON) |
| 1109 | status = -EHOSTUNREACH; |
| 1110 | } |
Alan Stern | 592fbbe | 2006-09-19 10:08:43 -0400 | [diff] [blame] | 1111 | if (status == 0) |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1112 | status = usb_resume_device(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1113 | if (parent) |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1114 | usb_pm_unlock(parent); |
Alan Stern | 592fbbe | 2006-09-19 10:08:43 -0400 | [diff] [blame] | 1115 | } else { |
| 1116 | |
| 1117 | /* Needed only for setting udev->dev.power.power_state.event |
| 1118 | * and for possible debugging message. */ |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1119 | status = usb_resume_device(udev); |
Alan Stern | 114b368 | 2006-07-01 22:13:04 -0400 | [diff] [blame] | 1120 | } |
| 1121 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1122 | /* Now the parent won't suspend until we are finished */ |
| 1123 | |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1124 | if (status == 0 && udev->actconfig) { |
| 1125 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
| 1126 | intf = udev->actconfig->interface[i]; |
Stephen Hemminger | d5ec168 | 2006-11-14 10:06:17 -0800 | [diff] [blame] | 1127 | usb_resume_interface(intf); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1128 | } |
| 1129 | } |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1130 | |
| 1131 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1132 | return status; |
| 1133 | } |
| 1134 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1135 | #ifdef CONFIG_USB_SUSPEND |
| 1136 | |
| 1137 | /** |
| 1138 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1139 | * @udev: the usb_device to autosuspend |
| 1140 | * @dec_usage_cnt: flag to decrement @udev's PM-usage counter |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1141 | * |
| 1142 | * This routine should be called when a core subsystem is finished using |
| 1143 | * @udev and wants to allow it to autosuspend. Examples would be when |
| 1144 | * @udev's device file in usbfs is closed or after a configuration change. |
| 1145 | * |
| 1146 | * @dec_usage_cnt should be 1 if the subsystem previously incremented |
| 1147 | * @udev's usage counter (such as by passing 1 to usb_autoresume_device); |
| 1148 | * otherwise it should be 0. |
| 1149 | * |
| 1150 | * If the usage counter for @udev or any of its active interfaces is greater |
| 1151 | * than 0, the autosuspend request will not be queued. (If an interface |
| 1152 | * driver does not support autosuspend then its usage counter is permanently |
| 1153 | * positive.) Likewise, if an interface driver requires remote-wakeup |
| 1154 | * capability during autosuspend but remote wakeup is disabled, the |
| 1155 | * autosuspend will fail. |
| 1156 | * |
| 1157 | * Often the caller will hold @udev's device lock, but this is not |
| 1158 | * necessary. |
| 1159 | * |
| 1160 | * This routine can run only in process context. |
| 1161 | */ |
| 1162 | void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt) |
| 1163 | { |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1164 | usb_pm_lock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1165 | udev->pm_usage_cnt -= dec_usage_cnt; |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1166 | if (autosuspend_check(udev) == 0) |
Alan Stern | bd85928 | 2006-09-19 10:14:07 -0400 | [diff] [blame] | 1167 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1168 | USB_AUTOSUSPEND_DELAY); |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1169 | usb_pm_unlock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1170 | // dev_dbg(&udev->dev, "%s: cnt %d\n", |
| 1171 | // __FUNCTION__, udev->pm_usage_cnt); |
| 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * usb_autoresume_device - immediately autoresume a USB device and its interfaces |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1176 | * @udev: the usb_device to autoresume |
| 1177 | * @inc_usage_cnt: flag to increment @udev's PM-usage counter |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1178 | * |
| 1179 | * This routine should be called when a core subsystem wants to use @udev |
| 1180 | * and needs to guarantee that it is not suspended. In addition, the |
| 1181 | * caller can prevent @udev from being autosuspended subsequently. (Note |
| 1182 | * that this will not prevent suspend events originating in the PM core.) |
| 1183 | * Examples would be when @udev's device file in usbfs is opened (autosuspend |
| 1184 | * should be prevented until the file is closed) or when a remote-wakeup |
| 1185 | * request is received (later autosuspends should not be prevented). |
| 1186 | * |
| 1187 | * @inc_usage_cnt should be 1 to increment @udev's usage counter and prevent |
| 1188 | * autosuspends. This prevention will persist until the usage counter is |
| 1189 | * decremented again (such as by passing 1 to usb_autosuspend_device). |
| 1190 | * Otherwise @inc_usage_cnt should be 0 to leave the usage counter unchanged. |
| 1191 | * Regardless, if the autoresume fails then the usage counter is not |
| 1192 | * incremented. |
| 1193 | * |
| 1194 | * Often the caller will hold @udev's device lock, but this is not |
| 1195 | * necessary (and attempting it might cause deadlock). |
| 1196 | * |
| 1197 | * This routine can run only in process context. |
| 1198 | */ |
| 1199 | int usb_autoresume_device(struct usb_device *udev, int inc_usage_cnt) |
| 1200 | { |
| 1201 | int status; |
| 1202 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1203 | usb_pm_lock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1204 | udev->pm_usage_cnt += inc_usage_cnt; |
| 1205 | udev->auto_pm = 1; |
| 1206 | status = usb_resume_both(udev); |
| 1207 | if (status != 0) |
| 1208 | udev->pm_usage_cnt -= inc_usage_cnt; |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1209 | usb_pm_unlock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1210 | // dev_dbg(&udev->dev, "%s: status %d cnt %d\n", |
| 1211 | // __FUNCTION__, status, udev->pm_usage_cnt); |
| 1212 | return status; |
| 1213 | } |
| 1214 | |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1215 | /* Internal routine to adjust an interface's usage counter and change |
| 1216 | * its device's autosuspend state. |
| 1217 | */ |
| 1218 | static int usb_autopm_do_interface(struct usb_interface *intf, |
| 1219 | int inc_usage_cnt) |
| 1220 | { |
| 1221 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1222 | int status = 0; |
| 1223 | |
| 1224 | usb_pm_lock(udev); |
| 1225 | if (intf->condition == USB_INTERFACE_UNBOUND) |
| 1226 | status = -ENODEV; |
| 1227 | else { |
| 1228 | intf->pm_usage_cnt += inc_usage_cnt; |
| 1229 | if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { |
| 1230 | udev->auto_pm = 1; |
| 1231 | status = usb_resume_both(udev); |
| 1232 | if (status != 0) |
| 1233 | intf->pm_usage_cnt -= inc_usage_cnt; |
| 1234 | } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0) |
| 1235 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, |
| 1236 | USB_AUTOSUSPEND_DELAY); |
| 1237 | } |
| 1238 | usb_pm_unlock(udev); |
| 1239 | return status; |
| 1240 | } |
| 1241 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1242 | /** |
| 1243 | * usb_autopm_put_interface - decrement a USB interface's PM-usage counter |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1244 | * @intf: the usb_interface whose counter should be decremented |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1245 | * |
| 1246 | * This routine should be called by an interface driver when it is |
| 1247 | * finished using @intf and wants to allow it to autosuspend. A typical |
| 1248 | * example would be a character-device driver when its device file is |
| 1249 | * closed. |
| 1250 | * |
| 1251 | * The routine decrements @intf's usage counter. When the counter reaches |
| 1252 | * 0, a delayed autosuspend request for @intf's device is queued. When |
| 1253 | * the delay expires, if @intf->pm_usage_cnt is still <= 0 along with all |
| 1254 | * the other usage counters for the sibling interfaces and @intf's |
| 1255 | * usb_device, the device and all its interfaces will be autosuspended. |
| 1256 | * |
| 1257 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The |
| 1258 | * core will not change its value other than the increment and decrement |
| 1259 | * in usb_autopm_get_interface and usb_autopm_put_interface. The driver |
| 1260 | * may use this simple counter-oriented discipline or may set the value |
| 1261 | * any way it likes. |
| 1262 | * |
| 1263 | * If the driver has set @intf->needs_remote_wakeup then autosuspend will |
| 1264 | * take place only if the device's remote-wakeup facility is enabled. |
| 1265 | * |
| 1266 | * Suspend method calls queued by this routine can arrive at any time |
| 1267 | * while @intf is resumed and its usage counter is equal to 0. They are |
| 1268 | * not protected by the usb_device's lock but only by its pm_mutex. |
| 1269 | * Drivers must provide their own synchronization. |
| 1270 | * |
| 1271 | * This routine can run only in process context. |
| 1272 | */ |
| 1273 | void usb_autopm_put_interface(struct usb_interface *intf) |
| 1274 | { |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1275 | int status; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1276 | |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1277 | status = usb_autopm_do_interface(intf, -1); |
| 1278 | // dev_dbg(&intf->dev, "%s: status %d cnt %d\n", |
| 1279 | // __FUNCTION__, status, intf->pm_usage_cnt); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1280 | } |
| 1281 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); |
| 1282 | |
| 1283 | /** |
| 1284 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter |
Henrik Kretzschmar | 701f35a | 2006-09-25 17:00:56 -0700 | [diff] [blame] | 1285 | * @intf: the usb_interface whose counter should be incremented |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1286 | * |
| 1287 | * This routine should be called by an interface driver when it wants to |
| 1288 | * use @intf and needs to guarantee that it is not suspended. In addition, |
| 1289 | * the routine prevents @intf from being autosuspended subsequently. (Note |
| 1290 | * that this will not prevent suspend events originating in the PM core.) |
| 1291 | * This prevention will persist until usb_autopm_put_interface() is called |
| 1292 | * or @intf is unbound. A typical example would be a character-device |
| 1293 | * driver when its device file is opened. |
| 1294 | * |
| 1295 | * The routine increments @intf's usage counter. So long as the counter |
| 1296 | * is greater than 0, autosuspend will not be allowed for @intf or its |
| 1297 | * usb_device. When the driver is finished using @intf it should call |
| 1298 | * usb_autopm_put_interface() to decrement the usage counter and queue |
| 1299 | * a delayed autosuspend request (if the counter is <= 0). |
| 1300 | * |
| 1301 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The |
| 1302 | * core will not change its value other than the increment and decrement |
| 1303 | * in usb_autopm_get_interface and usb_autopm_put_interface. The driver |
| 1304 | * may use this simple counter-oriented discipline or may set the value |
| 1305 | * any way it likes. |
| 1306 | * |
| 1307 | * Resume method calls generated by this routine can arrive at any time |
| 1308 | * while @intf is suspended. They are not protected by the usb_device's |
| 1309 | * lock but only by its pm_mutex. Drivers must provide their own |
| 1310 | * synchronization. |
| 1311 | * |
| 1312 | * This routine can run only in process context. |
| 1313 | */ |
| 1314 | int usb_autopm_get_interface(struct usb_interface *intf) |
| 1315 | { |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1316 | int status; |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1317 | |
Alan Stern | af4f760 | 2006-10-30 17:06:45 -0500 | [diff] [blame] | 1318 | status = usb_autopm_do_interface(intf, 1); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1319 | // dev_dbg(&intf->dev, "%s: status %d cnt %d\n", |
| 1320 | // __FUNCTION__, status, intf->pm_usage_cnt); |
| 1321 | return status; |
| 1322 | } |
| 1323 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); |
| 1324 | |
Alan Stern | 692a186 | 2006-10-30 17:07:51 -0500 | [diff] [blame] | 1325 | /** |
| 1326 | * usb_autopm_set_interface - set a USB interface's autosuspend state |
| 1327 | * @intf: the usb_interface whose state should be set |
| 1328 | * |
| 1329 | * This routine sets the autosuspend state of @intf's device according |
| 1330 | * to @intf's usage counter, which the caller must have set previously. |
| 1331 | * If the counter is <= 0, the device is autosuspended (if it isn't |
| 1332 | * already suspended and if nothing else prevents the autosuspend). If |
| 1333 | * the counter is > 0, the device is autoresumed (if it isn't already |
| 1334 | * awake). |
| 1335 | */ |
| 1336 | int usb_autopm_set_interface(struct usb_interface *intf) |
| 1337 | { |
| 1338 | int status; |
| 1339 | |
| 1340 | status = usb_autopm_do_interface(intf, 0); |
| 1341 | // dev_dbg(&intf->dev, "%s: status %d cnt %d\n", |
| 1342 | // __FUNCTION__, status, intf->pm_usage_cnt); |
| 1343 | return status; |
| 1344 | } |
| 1345 | EXPORT_SYMBOL_GPL(usb_autopm_set_interface); |
| 1346 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1347 | #endif /* CONFIG_USB_SUSPEND */ |
| 1348 | |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1349 | static int usb_suspend(struct device *dev, pm_message_t message) |
| 1350 | { |
| 1351 | int status; |
| 1352 | |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1353 | if (is_usb_device(dev)) { |
| 1354 | struct usb_device *udev = to_usb_device(dev); |
| 1355 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1356 | usb_pm_lock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1357 | udev->auto_pm = 0; |
| 1358 | status = usb_suspend_both(udev, message); |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1359 | usb_pm_unlock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1360 | } else |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1361 | status = 0; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1362 | return status; |
| 1363 | } |
| 1364 | |
| 1365 | static int usb_resume(struct device *dev) |
| 1366 | { |
| 1367 | int status; |
| 1368 | |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1369 | if (is_usb_device(dev)) { |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1370 | struct usb_device *udev = to_usb_device(dev); |
| 1371 | |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1372 | usb_pm_lock(udev); |
Alan Stern | 645daaa | 2006-08-30 15:47:02 -0400 | [diff] [blame] | 1373 | udev->auto_pm = 0; |
| 1374 | status = usb_resume_both(udev); |
Alan Stern | e0318eb | 2006-09-26 14:50:20 -0400 | [diff] [blame] | 1375 | usb_pm_unlock(udev); |
Alan Stern | a8e7c56 | 2006-07-01 22:11:02 -0400 | [diff] [blame] | 1376 | |
| 1377 | /* Rebind drivers that had no suspend method? */ |
| 1378 | } else |
| 1379 | status = 0; |
Alan Stern | 1cc8a25 | 2006-07-01 22:10:15 -0400 | [diff] [blame] | 1380 | return status; |
| 1381 | } |
| 1382 | |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1383 | #endif /* CONFIG_PM */ |
| 1384 | |
| 1385 | struct bus_type usb_bus_type = { |
| 1386 | .name = "usb", |
| 1387 | .match = usb_device_match, |
| 1388 | .uevent = usb_uevent, |
| 1389 | #ifdef CONFIG_PM |
Alan Stern | 782da72 | 2006-07-01 22:09:35 -0400 | [diff] [blame] | 1390 | .suspend = usb_suspend, |
| 1391 | .resume = usb_resume, |
Alan Stern | 36e56a3 | 2006-07-01 22:08:06 -0400 | [diff] [blame] | 1392 | #endif |
| 1393 | }; |