]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
musb-new: Use time based timeouts rather then cpu-cycles based timeouts
authorHans de Goede <hdegoede@redhat.com>
Sun, 11 Jan 2015 19:34:49 +0000 (20:34 +0100)
committerMarek Vasut <marex@denx.de>
Sun, 18 Jan 2015 11:31:36 +0000 (12:31 +0100)
CPU cycle based timeouts are no good, because how long they use depends on
CPU speed. Instead use time based timeouts, and wait one second for a
device connection to show up (per the USB spec), and wait USB_TIMEOUT_MS
for various urbs to complete.

This fixes "usb start" taking for ever when no device is plugged into the
otg port.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/usb/musb-new/musb_uboot.c

index 2676f09c3844d159c5f15130ccdff6c287339aed..f8a0346f36f8a4a8fbf8a8e207ba6a0a05c69704 100644 (file)
@@ -57,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) {
@@ -71,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->dev->status & USB_ST_NOT_PROC) &&
+                get_timer(0) < timeout);
 
        return urb->status;
 }
@@ -115,7 +114,8 @@ 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");
@@ -127,8 +127,8 @@ int usb_lowlevel_init(int index, enum usb_init_type init, 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);