From patchwork Wed Jul 1 03:02:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wessel X-Patchwork-Id: 240528 List-Id: U-Boot discussion From: jason.wessel at windriver.com (Jason Wessel) Date: Tue, 30 Jun 2020 20:02:39 -0700 Subject: [RFC PATCH v3 6/6] usb.c: Add a retry in the usb_prepare_device() In-Reply-To: <20200701030239.179114-1-jason.wessel@windriver.com> References: <20200701030239.179114-1-jason.wessel@windriver.com> Message-ID: <20200701030239.179114-7-jason.wessel@windriver.com> I have found through testing some USB 2 composite mouse/keyboard devices do not response to the usb_set_address call immediately following the port reset. It can take anywhere from 2ms to 20ms. This patch adds a retry and delay for usb_prepare_device() and allows all the USB keyboards I tried to function properly. Signed-off-by: Jason Wessel --- common/usb.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/usb.c b/common/usb.c index ba83bb960b..fb091440cc 100644 --- a/common/usb.c +++ b/common/usb.c @@ -1054,6 +1054,15 @@ static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read, dev->devnum = addr; err = usb_set_address(dev); /* set address */ + /* Retry for old composite keyboard/mouse usb2 hardware */ + int i = 0; + while (err < 0 && i <= 40) { + i += 20; + mdelay(20); + err = usb_set_address(dev); /* set address */ + } + if (i > 0) + debug("usb_set_address delay: %i\n", i); if (err < 0) debug("\n usb_set_address return < 0\n"); if (err < 0 && dev->status != 0) {