[U-Boot] [PATCH v3 7/8] usb_stor_BBB_transport: Do not delay when not required

Benoît Thébaudeau benoit.thebaudeau at advansee.com
Thu Aug 9 23:53:51 CEST 2012


There is a 5-ms delay in usb_stor_BBB_transport, which occurs every 10 kiB of
data for fragmented fatload usb, i.e. roughly 500 ms of delay per MiB. This adds
up to quite a bit of delay if you're loading a large ramdisk.

The purpose of this delay should be to debounce the 5-V/100-mA USB power up.
This patch skips the delay if the device has already been queried as ready.

Signed-off-by: Jim Shimer <mgi2475 at motorola.com>

Rework following the review:
 - Rebase against the latest u-boot-usb master.
 - Replace typedef with #define.
 - Use the existing flags struct field instead of adding a new field.
 - Remove the setter function.
 - Remove the typecasts.
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau at advansee.com>

Cc: Marek Vasut <marex at denx.de>
Cc: Ilya Yanok <ilya.yanok at cogentembedded.com>
Cc: Stefan Herbrechtsmeier <stefan at herbrechtsmeier.net>
Cc: Jim Shimer <mgi2475 at motorola.com>
---
Changes for v2: N/A.
Changes for v3:
 - New patch.

 .../common/usb_storage.c                           |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git u-boot-usb-8d5fb14.orig/common/usb_storage.c u-boot-usb-8d5fb14/common/usb_storage.c
index f0798b2..b000f09 100644
--- u-boot-usb-8d5fb14.orig/common/usb_storage.c
+++ u-boot-usb-8d5fb14/common/usb_storage.c
@@ -136,6 +136,7 @@ struct us_data {
 	struct usb_device *pusb_dev;	 /* this usb_device */
 
 	unsigned int	flags;			/* from filter initially */
+#	define USB_READY	(1 << 0)
 	unsigned char	ifnum;			/* interface number */
 	unsigned char	ep_in;			/* in endpoint */
 	unsigned char	ep_out;			/* out ....... */
@@ -698,7 +699,8 @@ int usb_stor_BBB_transport(ccb *srb, struct us_data *us)
 		usb_stor_BBB_reset(us);
 		return USB_STOR_TRANSPORT_FAILED;
 	}
-	mdelay(5);
+	if (!(us->flags & USB_READY))
+		mdelay(5);
 	pipein = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
 	pipeout = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
 	/* DATA phase + error handling */
@@ -963,8 +965,10 @@ static int usb_test_unit_ready(ccb *srb, struct us_data *ss)
 		srb->cmd[1] = srb->lun << 5;
 		srb->datalen = 0;
 		srb->cmdlen = 12;
-		if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
+		if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD) {
+			ss->flags |= USB_READY;
 			return 0;
+		}
 		usb_request_sense(srb, ss);
 		mdelay(100);
 	} while (retries--);
@@ -1114,6 +1118,7 @@ retry_it:
 		blks -= smallblks;
 		buf_addr += srb->datalen;
 	} while (blks != 0);
+	ss->flags &= ~USB_READY;
 
 	USB_STOR_PRINTF("usb_read: end startblk %lx, blccnt %x buffer %lx\n",
 			start, smallblks, buf_addr);
@@ -1193,6 +1198,7 @@ retry_it:
 		blks -= smallblks;
 		buf_addr += srb->datalen;
 	} while (blks != 0);
+	ss->flags &= ~USB_READY;
 
 	USB_STOR_PRINTF("usb_write: end startblk %lx, blccnt %x buffer %lx\n",
 			start, smallblks, buf_addr);
@@ -1404,6 +1410,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
 		cap[0] = 2880;
 		cap[1] = 0x200;
 	}
+	ss->flags &= ~USB_READY;
 	USB_STOR_PRINTF("Read Capacity returns: 0x%lx, 0x%lx\n", cap[0],
 			cap[1]);
 #if 0


More information about the U-Boot mailing list