usb: introduce usb_reenumerate_device()

This function implements a logical reset which will cause the device
to be reenumerated in the USB stack, without physically being
disconnected from the bus.

This is useful for device-firmware-upload cases where we can't use
usb_reset_device() as it would bring the device back to full reset
state.

Signed-off-by: Inaky Perez-Gonzalez <[EMAIL PROTECTED]>

---
 drivers/usb/core/hub.c |   33 +++++++++++++++++++++++++++++++++
 include/linux/usb.h    |    1 +
 2 files changed, 34 insertions(+)

Index: linux.cg/drivers/usb/core/hub.c
===================================================================
--- linux.cg.orig/drivers/usb/core/hub.c        2006-09-07 
15:04:14.000000000 -0700
+++ linux.cg/drivers/usb/core/hub.c     2006-09-07 15:05:06.000000000 -0700
@@ -3075,3 +3075,36 @@
        return ret;
 }
 EXPORT_SYMBOL(usb_reset_composite_device);
+
+
+/**
+ * usb_reenumerate_device - Reenumerate a USB device
+ *
+ * @usb_dev: USB device that needs to be reset.
+ *
+ * Disconnects the device from the USB bus (without physically doing
+ * so), forcing a reenumearation. This is useful for
+ * device-firmware-upload cases where we can't use usb_reset_device()
+ * as it would bring the device back to full reset state.
+ */
+int usb_reenumerate_device(struct usb_device *usb_dev)
+{
+       struct usb_device *parent_hdev = usb_dev->parent;
+       struct usb_hub *parent_hub;
+
+       if (usb_dev->state == USB_STATE_NOTATTACHED ||
+           usb_dev->state == USB_STATE_SUSPENDED) {
+               dev_dbg(&usb_dev->dev,
+                       "device reenumeration not allowed in state %d\n",
+                       usb_dev->state);
+               return -EINVAL;
+       }
+       if (!parent_hdev) {
+               /* this requires hcd-specific logic; see OHCI hc_restart() */
+               dev_dbg(&udev->dev, "%s for root hub!\n", __FUNCTION__);
+               return -EISDIR;
+       }
+       parent_hub = hdev_to_hub(parent_hdev);
+       hub_port_logical_disconnect(parent_hub, usb_dev->portnum);
+}
+EXPORT_SYMBOL_GPL(usb_reenumerate_device);
Index: linux.cg/include/linux/usb.h
===================================================================
--- linux.cg.orig/include/linux/usb.h   2006-09-07 15:04:14.000000000 -0700
+++ linux.cg/include/linux/usb.h        2006-09-07 15:05:06.000000000 -0700
@@ -406,6 +406,7 @@
 extern int usb_reset_device(struct usb_device *dev);
 extern int usb_reset_composite_device(struct usb_device *dev,
                struct usb_interface *iface);
+extern int usb_reenumerate_device(struct usb_device *usb_dev);

 extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to