musb-new: Fix interrupt transfers not working
[oweals/u-boot.git] / drivers / usb / musb-new / musb_uboot.c
index c2400328a365ebe8c2d269743368db1ac64f4c71..28500bf1578bf36329f73f12123a38e53bacc0df 100644 (file)
@@ -4,7 +4,6 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 
-#define __UBOOT__
 #include <usb.h>
 #include "linux-compat.h"
 #include "usb-compat.h"
@@ -58,13 +57,11 @@ static struct urb *construct_urb(struct usb_device *dev, int endpoint_type,
        return &urb;
 }
 
-#define MUSB_HOST_TIMEOUT      0x3ffffff
-
 static int submit_urb(struct usb_hcd *hcd, struct urb *urb)
 {
        struct musb *host = hcd->hcd_priv;
        int ret;
-       int timeout;
+       unsigned long timeout;
 
        ret = musb_urb_enqueue(hcd, urb, 0);
        if (ret < 0) {
@@ -72,12 +69,13 @@ static int submit_urb(struct usb_hcd *hcd, struct urb *urb)
                return ret;
        }
 
-       timeout = MUSB_HOST_TIMEOUT;
+       timeout = get_timer(0) + USB_TIMEOUT_MS(urb->pipe);
        do {
                if (ctrlc())
                        return -EIO;
                host->isr(0, host);
-       } while ((urb->dev->status & USB_ST_NOT_PROC) && --timeout);
+       } while (urb->status == -EINPROGRESS &&
+                get_timer(0) < timeout);
 
        return urb->status;
 }
@@ -112,11 +110,12 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
        return submit_urb(&hcd, urb);
 }
 
-int usb_lowlevel_init(int index, void **controller)
+int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
 {
        u8 power;
        void *mbase;
-       int timeout = MUSB_HOST_TIMEOUT;
+       /* USB spec says it may take up to 1 second for a device to connect */
+       unsigned long timeout = get_timer(0) + 1000;
 
        if (!host) {
                printf("MUSB host is not registered\n");
@@ -128,8 +127,8 @@ int usb_lowlevel_init(int index, void **controller)
        do {
                if (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_HM)
                        break;
-       } while (--timeout);
-       if (!timeout)
+       } while (get_timer(0) < timeout);
+       if (get_timer(0) >= timeout)
                return -ENODEV;
 
        power = musb_readb(mbase, MUSB_POWER);
@@ -204,7 +203,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 
 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 {
-       /* TODO: implement me */
+       if (driver->disconnect)
+               driver->disconnect(&gadget->g);
+       if (driver->unbind)
+               driver->unbind(&gadget->g);
        return 0;
 }
 #endif /* CONFIG_MUSB_GADGET */