Skip to contentSkip to conversation

musb: add timeout via CONFIG_MUSB_TIMEOUT

PATCH New Mike Frysinger 2 participants 3 messages Feb 10, 2009 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 musb: add timeout via CONFIG_MUSB_TIMEOUT

From: Bryan Wu <[email protected]>

CC Ravi Babu <[email protected]>
CC Swaminathan S <[email protected]>
CC Thomas Abraham <[email protected]>
CC Ajay Kumar Gupta <[email protected]>
CC Remy Bohmer <[email protected]>
---
 drivers/usb/musb_hcd.c |   31 +++++++++++++++++++++++++++++++
 drivers/usb/musb_hcd.h |    4 ++++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/usb/musb_hcd.c +31 -0
index 352a0d4..19d978b 100644
@@ -111,6 +111,7 @@ static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
 {
 	u16 csr;
 	int result = 1;
+	int timeout = CONFIG_MUSB_TIMEOUT;
 
 	while (result > 0) {
 		csr = readw(&musbr->txcsr);
@@ -152,7 +153,17 @@ static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
 			}
 			break;
 		}
+
+		/* Check the timeout */
+		if (--timeout)
+			udelay(1);
+		else {
+			dev->status = USB_ST_CRC_ERR;
+			result = -1;
+			break;
+		}
 	}
+
 	return result;
 }
 
@@ -162,6 +173,7 @@ static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
 static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
 {
 	u16 csr;
+	int timeout = CONFIG_MUSB_TIMEOUT;
 
 	do {
 		if (check_stall(ep, 1)) {
@@ -174,6 +186,15 @@ static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
 			dev->status = USB_ST_CRC_ERR;
 			return 0;
 		}
+
+		/* Check the timeout */
+		if (--timeout)
+			udelay(1);
+		else {
+			dev->status = USB_ST_CRC_ERR;
+			return -1;
+		}
+
 	} while (csr & MUSB_TXCSR_TXPKTRDY);
 	return 1;
 }
@@ -184,6 +205,7 @@ static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
 static u8 wait_until_rxep_ready(struct usb_device *dev, u8 ep)
 {
 	u16 csr;
+	int timeout = CONFIG_MUSB_TIMEOUT;
 
 	do {
 		if (check_stall(ep, 0)) {
@@ -196,6 +218,15 @@ static u8 wait_until_rxep_ready(struct usb_device *dev, u8 ep)
 			dev->status = USB_ST_CRC_ERR;
 			return 0;
 		}
+
+		/* Check the timeout */
+		if (--timeout)
+			udelay(1);
+		else {
+			dev->status = USB_ST_CRC_ERR;
+			return -1;
+		}
+
 	} while (!(csr & MUSB_RXCSR_RXPKTRDY));
 	return 1;
 }
drivers/usb/musb_hcd.h +4 -0
index bb83311..b7f571d 100644
@@ -30,6 +30,10 @@
 extern unsigned char new[];
 #endif
 
+#ifndef CONFIG_MUSB_TIMEOUT
+# define CONFIG_MUSB_TIMEOUT 100000
+#endif
+
 /* This defines the endpoint number used for control transfers */
 #define MUSB_CONTROL_EP 0
 
Signature · 1 line
1.6.1.2
#1 lore raw

PATCH 1/1 musb: add timeout via CONFIG_MUSB_TIMEOUT

Hello Mike,

2009/2/10 Mike Frysinger <[email protected]>:

Quoted 7 lines

From: Bryan Wu <[email protected]>

drivers/usb/musb_hcd.c +1 -0
+       int timeout = CONFIG_MUSB_TIMEOUT;
 
       while (result > 0) {
               csr = readw(&musbr->txcsr);

drivers/usb/musb_hcd.c static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask) · line 159

Quoted 7 lines
drivers/usb/musb_hcd.c +4 -0
@@ -152,7 +153,17 @@ static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
                       }
                       break;
               }
+
+               /* Check the timeout */
+               if (--timeout)
+                       udelay(1);

Hmm, I might be mistaken, but looking at this patch you seem to want to timeout at CONFIG_MUSB_TIMEOUT,
but actually the timeout ends at CONFIG_MUSB_TIMEOUT-1. Shouldn't it be: if (timeout--) instead of if (--timeout) ??? (some remark applies to all instances in this patch...)

Kind Regards,

Remy

#2 lore raw

PATCH 1/1 musb: add timeout via CONFIG_MUSB_TIMEOUT

Quoted 5 lines · On Tuesday 10 February 2009 15:11:55 Remy Bohmer wrote:

2009/2/10 Mike Frysinger:

Quoted 4 lines

From: Bryan Wu <[email protected]>

+ int timeout = CONFIG_MUSB_TIMEOUT;

Quoted 16 lines

drivers/usb/musb_hcd.c static int wait_until_ep0_ready(struct usb_device · line 159

Quoted 10 lines
       while (result > 0) {
               csr = readw(&musbr->txcsr);
drivers/usb/musb_hcd.c +4 -0
@@ -152,7 +153,17 @@ static int wait_until_ep0_ready(struct usb_device
 *dev, u32 bit_mask) }
                       break;
               }
+
+               /* Check the timeout */
+               if (--timeout)
+                       udelay(1);

Hmm, I might be mistaken, but looking at this patch you seem to want to timeout at CONFIG_MUSB_TIMEOUT,
but actually the timeout ends at CONFIG_MUSB_TIMEOUT-1. Shouldn't it be: if (timeout--) instead of if (--timeout) ??? (some remark applies to all instances in this patch...)

looks that way. i was hoping for feedback about the concept from the TI guys who wrote the musb driver to see if this method is ok or they prefer something different ;).
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090210/a895db74/attachment.pgp