IDE: Fix complaints about strict aliasing in cmd_ide.c
[oweals/u-boot.git] / common / usb.c
index eef4b34a740ec1a4f9325bca26174de2453a94a3..a401c0919878b5801a947c8992b60ae331e799b0 100644 (file)
 #include <asm/4xx_pci.h>
 #endif
 
-#undef USB_DEBUG
+#ifdef DEBUG
+#define USB_DEBUG
+#define USB_HUB_DEBUG
+#endif
 
 #ifdef USB_DEBUG
 #define        USB_PRINTF(fmt, args...)        printf(fmt , ##args)
@@ -142,10 +145,14 @@ int usb_stop(void)
 /*
  * disables the asynch behaviour of the control message. This is used for data
  * transfers that uses the exclusiv access to the control and bulk messages.
+ * Returns the old value so it can be restored later.
  */
-void usb_disable_asynch(int disable)
+int usb_disable_asynch(int disable)
 {
+       int old_value = asynch_allowed;
+
        asynch_allowed = !disable;
+       return old_value;
 }
 
 
@@ -197,16 +204,21 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
        if (timeout == 0)
                return (int)size;
 
-       if (dev->status != 0) {
-               /*
-                * Let's wait a while for the timeout to elapse.
-                * It has no real use, but it keeps the interface happy.
-                */
-               wait_ms(timeout);
-               return -1;
+       /*
+        * Wait for status to update until timeout expires, USB driver
+        * interrupt handler may set the status when the USB operation has
+        * been completed.
+        */
+       while (timeout--) {
+               if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
+                       break;
+               wait_ms(1);
        }
+       if (dev->status)
+               return -1;
 
        return dev->act_len;
+
 }
 
 /*-------------------------------------------------------------------
@@ -945,8 +957,8 @@ void usb_scan_devices(void)
        /* insert "driver" if possible */
 #ifdef CONFIG_USB_KEYBOARD
        drv_usb_kbd_init();
-       USB_PRINTF("scan end\n");
 #endif
+       USB_PRINTF("scan end\n");
 }
 
 
@@ -955,8 +967,6 @@ void usb_scan_devices(void)
  * Probes device for being a hub and configurate it
  */
 
-#undef USB_HUB_DEBUG
-
 #ifdef USB_HUB_DEBUG
 #define        USB_HUB_PRINTF(fmt, args...)    printf(fmt , ##args)
 #else
@@ -1156,6 +1166,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 
        dev->children[port] = usb;
        usb->parent = dev;
+       usb->portnr = port + 1;
        /* Run it through the hoops (find a driver, etc) */
        if (usb_new_device(usb)) {
                /* Woops, disable the port */
@@ -1215,7 +1226,7 @@ int usb_hub_configure(struct usb_device *dev)
                hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
 
        for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
-               hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i];
+               hub->desc.PortPowerCtrlMask[i] = descriptor->PortPowerCtrlMask[i];
 
        dev->maxchild = descriptor->bNbrPorts;
        USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);