From patchwork Wed Mar 17 15:19:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Loureiro?= X-Patchwork-Id: 1454784 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=SJSW1Wla; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0v3t4kzVz9sVm for ; Thu, 18 Mar 2021 02:20:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 930CE82815; Wed, 17 Mar 2021 16:20:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SJSW1Wla"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 36DC082843; Wed, 17 Mar 2021 16:20:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 72CFD82807 for ; Wed, 17 Mar 2021 16:20:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joaofl@gmail.com Received: by mail-ed1-x52b.google.com with SMTP id bf3so2737880edb.6 for ; Wed, 17 Mar 2021 08:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hYqJgOgXgJ4FXWoPSFII4vWqZl5P2BPncXdfNQqYP0I=; b=SJSW1WlaorHkQZcizJ3bNO4fbiAb/Hi7BRfrz80Jby8AXMbnRLoxlL/1f41w+JsWIq J87aynj/imF4GUCIYVj0erIyEMdnFlbCg1AcL43+w1UiCLLtK+aR1J9Yf7xWXm9Ksr4g wJaauJLnNap08EsWAY3Or49C9UyJSW2Kgu/tMANYo2C8qfKHQ907ibNdt8OCNZa/hYSy tAi78Dv6iSTptno9CtSB368vbn8kyuIPz9gJ+u1SheWMpy0JDvRqaw4y8mEHK7OhFdtC dwbb9LlNJcGDw9E2s+pTXz8xteWS6OBZn7hSpI51bPuvW3lra2wi6eBzJhVUS+eefSKy mqUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hYqJgOgXgJ4FXWoPSFII4vWqZl5P2BPncXdfNQqYP0I=; b=MHBx8fzoV2dLLqCNYJTW/168nMBoVTEkL9q3IzhjL8NATEV7oRyOMMZHt+fvNqb/Zi s/lH2WgeweNYoU/rPHGQIwjHr+qT2tixQ/sPNyGjUHexICXmpIEQ4LFXKxl+S/qstT+Y pkRLhFLErklHPknCdHKmIMfbPZTUkjIQunF5FvNJ7tmjP5dXCV78NdzEJnnz2BKHnfqz p2jInBkWtRUWxXa12jnB6ewJa6ZXaC6bfjOJfPEaPs+kU0Ycm3mrfbrFO57PMXst6dOK 6gCaYHK3/DdlfzjGt5ow733t8j1IdkvwpmoaWzxJqLsjMR63QD33KtGjW3dNFskYsfWA vCmw== X-Gm-Message-State: AOAM531gJVia7PV798LsXTTzpZlQdrkMI19GBwDBSIVmhGCHvO3+AA5/ 1S6oYOl9eNumln0h+WECWr21ISL0xPI= X-Google-Smtp-Source: ABdhPJxR5HjqPDdm9warBloHOEc3e+WNWWqCw6Nqow4n7B0nFI0IwHWE6C+WGXlno3eWCQzgCzIDFA== X-Received: by 2002:aa7:cb82:: with SMTP id r2mr42872998edt.209.1615994409775; Wed, 17 Mar 2021 08:20:09 -0700 (PDT) Received: from localhost.localdomain (137-141-145-85.ftth.glasoperator.nl. [85.145.141.137]) by smtp.googlemail.com with ESMTPSA id t17sm13150813edr.36.2021.03.17.08.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 08:20:08 -0700 (PDT) From: =?utf-8?q?Jo=C3=A3o_Loureiro?= To: u-boot@lists.denx.de Cc: lukma@denx.de, marex@denx.de, =?utf-8?q?Jo=C3=A3o_Loureiro?= Subject: [PATCH] Avoid delay when inializing USB peripheral by dwc2 Date: Wed, 17 Mar 2021 16:19:37 +0100 Message-Id: <20210317151937.703119-1-joaofl@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.4 at phobos.denx.de X-Virus-Status: Clean When `usb start` is called on the terminal, the dwc2 driver will try to start every USB device as host first, even if it is explicitly configured as peripheral in the device tree (`dr_mode = "peripheral"`). So to avoid am unwanted 15 seconds delay when initializing the usb (one second per channel = 1s x 15), this patch adds a check to the initialization, and will skip host initialization of the device is explicitly set as peripheral. The checking is already and correctly done similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver. Signed-off-by: João Loureiro --- drivers/usb/host/dwc2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index ec643e9f45..7990060f3c 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv) #endif dwc_otg_core_init(dev); - dwc_otg_core_host_init(dev, regs); + + if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) { + dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping host_init.\n",\ + dev->name, usb_get_dr_mode(dev_ofnode(dev))); + } else { + dwc_otg_core_host_init(dev, regs); + } clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA | DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |