This implements the reset device function for the USB storage driver as
well as anything else that wants to use it.

I've also attached a minor patch to UHCI to use the correct delay for
resetting the root hub ports according to the USB spec.

After you've called usb_reset_device, the struct usb_device you had before
is invalid. So finish up what you need to before calling the routine.

JE

diff -ur linux-2.3.99-pre4-5.orig/drivers/usb/hub.c 
linux-2.3.99-pre4-5.patch/drivers/usb/hub.c
--- linux-2.3.99-pre4-5.orig/drivers/usb/hub.c  Mon Apr 10 11:43:44 2000
+++ linux-2.3.99-pre4-5.patch/drivers/usb/hub.c Mon Apr 10 17:59:23 2000
@@ -614,5 +614,28 @@
        usb_deregister(&hub_driver);
 } /* usb_hub_cleanup() */
 
+int usb_reset_device(struct usb_device *dev)
+{
+       struct usb_device *parent = dev->parent;
+       int i;
 
+       if (!parent) {
+               err("attempting to reset root hub!");
+               return -EINVAL;
+       }
+
+       for (i = 0; i < parent->maxchild; i++) {
+               if (parent->children[i] == dev) {
+                       usb_set_port_feature(parent, i + 1,
+                               USB_PORT_FEAT_RESET);
+
+                       usb_disconnect(&dev);
+                       usb_hub_port_connect_change(parent, i);
+
+                       return 0;
+               }
+       }
+
+       return -ENOENT;
+}
 
diff -ur linux-2.3.99-pre4-5.orig/drivers/usb/usb.c 
linux-2.3.99-pre4-5.patch/drivers/usb/usb.c
--- linux-2.3.99-pre4-5.orig/drivers/usb/usb.c  Mon Apr 10 11:43:44 2000
+++ linux-2.3.99-pre4-5.patch/drivers/usb/usb.c Mon Apr 10 17:59:39 2000
@@ -1876,6 +1876,7 @@
 EXPORT_SYMBOL(usb_init_root_hub);
 EXPORT_SYMBOL(usb_root_hub_string);
 EXPORT_SYMBOL(usb_new_device);
+EXPORT_SYMBOL(usb_reset_device);
 EXPORT_SYMBOL(usb_connect);
 EXPORT_SYMBOL(usb_disconnect);
 EXPORT_SYMBOL(usb_release_bandwidth);
diff -ur linux-2.3.99-pre4-5.orig/include/linux/usb.h 
linux-2.3.99-pre4-5.patch/include/linux/usb.h
--- linux-2.3.99-pre4-5.orig/include/linux/usb.h        Mon Apr 10 11:43:47 2000
+++ linux-2.3.99-pre4-5.patch/include/linux/usb.h       Mon Apr 10 17:53:48 2000
@@ -710,6 +710,7 @@
  * Send and receive control messages..
  */
 int usb_new_device(struct usb_device *dev);
+int usb_reset_device(struct usb_device *dev);
 int usb_set_address(struct usb_device *dev);
 int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
        unsigned char descindex, void *buf, int size);
--- linux-2.3.99-pre4-5.orig/drivers/usb/uhci.c Mon Apr 10 11:43:44 2000
+++ linux-2.3.99-pre4-5.patch/drivers/usb/uhci.c        Mon Apr 10 18:06:36 2000
@@ -1595,7 +1595,7 @@
                        OK(0);
                case RH_PORT_RESET:
                        SET_RH_PORTSTAT(USBPORTSC_PR);
-                       wait_ms(10);
+                       wait_ms(50);    /* USB v1.1 7.1.7.3 */
                        uhci->rh.c_p_r[wIndex - 1] = 1;
                        CLR_RH_PORTSTAT(USBPORTSC_PR);
                        udelay(10);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to