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: 1320223 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=windriver.com Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49xR1H5ngqz9sPF for ; Wed, 1 Jul 2020 13:05:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E9C9380270; Wed, 1 Jul 2020 05:04:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id B6B2880226; Wed, 1 Jul 2020 05:04:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from mail5.wrs.com (mail5.windriver.com [192.103.53.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 335D18044A for ; Wed, 1 Jul 2020 05:04:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jwessel@windriver.com Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id 06132mqe015051 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 30 Jun 2020 20:03:25 -0700 Received: from ala-lpggp3.wrs.com (147.11.105.124) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.3.487.0; Tue, 30 Jun 2020 20:03:10 -0700 Received: by ala-lpggp3.wrs.com (Postfix, from userid 5002) id 4801E90072D; Tue, 30 Jun 2020 20:02:39 -0700 (PDT) From: Jason Wessel To: , , CC: Subject: [RFC PATCH v3 6/6] usb.c: Add a retry in the usb_prepare_device() Date: Tue, 30 Jun 2020 20:02:39 -0700 Message-ID: <20200701030239.179114-7-jason.wessel@windriver.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200701030239.179114-1-jason.wessel@windriver.com> References: <20200701030239.179114-1-jason.wessel@windriver.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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) {