Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2713909pxv; Sun, 11 Jul 2021 23:34:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMa73TeIec7Y2p4DCAYrvXmBbm+Eg/qTbwDoRojVZKlosol+tJoq+G1mq4JR4ULWa5cE1n X-Received: by 2002:a17:906:131a:: with SMTP id w26mr27074064ejb.46.1626071654002; Sun, 11 Jul 2021 23:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071653; cv=none; d=google.com; s=arc-20160816; b=cvXOSUiTX0+XrGgUATxrVxNGSyRZaC+oqU7PCa1HTFZK1JB3ucspIJKMnmSVLqVhjE NIRH02PtTEh9F7omVjTkjrZbSHUpmcs+P7vJt7ZNydPc1ogHAdIoVudWMKjbd+pstsId UfDHida3qmn8oLrNBRYmKGPJc4kW57WaFQb0jsMLLJVMQDAPDXJBUQovVBKMkOzdTk1f vOVxvtdivc/dkr1XBs9NfeF23HK7gB1jm/SL/1LVCBsJJKSqCMJ5N5OAXr9aoxGbvZuL NGIbMdT9lzKwAEUc+C+ugFNOlH3OsnCifek1Ua0nm72kQd57Q38Z0NGHyRGblYz1csyH Y9ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7Fc/TpOYi88w5FoyD2cUHn/8ND5+VmAD4MGtXv5YFkw=; b=B/lfvqcxqQ12FH9n6NuUUv2Z0DH3vRi1UEgu9yaIe1QhLPdj19eYMw6AgYowvSwjGZ u0YoOTJ4ZNsLzB/p4Fuy6i/RXlIwPR8XKWlgmQ1uq79YQcAEeMadVrJAQd5+xNpNlvaE ZZJoDIu1A/GIGJwtlF1XRR8XeRD7EzgV2JiwEm7/RKWs3mf1HrOTCXADE4O/bCYZKhou RarfHxnHX79D/J46N379LvbgMBybYdwoe2FF+py+CV3qbtC24bpghV8snVP4UQEkwz4S JkCVrTf2o6ZiR0sDWJOsW72I2xOCK229aXovXj2jgLTfLidgdKjG5pSGq94T5iZjIsMn k63g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DSttgglk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw2si15697654ejc.730.2021.07.11.23.33.46; Sun, 11 Jul 2021 23:34:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DSttgglk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236843AbhGLGfa (ORCPT + 99 others); Mon, 12 Jul 2021 02:35:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:52884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237194AbhGLGaj (ORCPT ); Mon, 12 Jul 2021 02:30:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0122260234; Mon, 12 Jul 2021 06:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071270; bh=DTsqfGGCL9VOafpkVib0Rh7O8WKK/FsWCZavde3L+mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSttgglkN21jPCX86cRF7R6LZsUjVauQhCtpEi1w5Rp1bgFRJjbJuuEaXptE+kErD hbzluNsI91ku//ooNOoWLYmUVpubyIX0OqmAcxMqGmL4A0eoLcdR/TTvHj1TT5+tbZ MYmEDD3PYqtm2Jo3QZ2wrb8qs3sK6g0l7NnjJLCM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= , Sasha Levin Subject: [PATCH 5.4 305/348] usb: dwc2: Dont reset the core after setting turnaround time Date: Mon, 12 Jul 2021 08:11:29 +0200 Message-Id: <20210712060744.160413013@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Clément Lassieur [ Upstream commit aafe93516b8567ab5864e1f4cd3eeabc54fb0e5a ] Every time the hub signals a reset while we (device) are hsotg->connected, dwc2_hsotg_core_init_disconnected() is called, which in turn calls dwc2_hs_phy_init(). GUSBCFG.USBTrdTim is cleared upon Core Soft Reset, so if hsotg->params.phy_utmi_width is 8-bit, the value of GUSBCFG.USBTrdTim (the default one: 0x5, corresponding to 16-bit) is always different from hsotg->params.phy_utmi_width, thus dwc2_core_reset() is called every time (usbcfg != usbcfg_old), which causes 2 issues: 1) The call to dwc2_core_reset() does another reset 300us after the initial Chirp K of the first reset (which should last at least Tuch = 1ms), and messes up the High-speed Detection Handshake: both hub and device drive current into the D+ and D- lines at the same time. 2) GUSBCFG.USBTrdTim is cleared by the second reset, so its value is always the default one (0x5). Setting GUSBCFG.USBTrdTim after the potential call to dwc2_core_reset() fixes both issues. It is now set even when select_phy is false because the cost of the Core Soft Reset is removed. Fixes: 1e868545f2bb ("usb: dwc2: gadget: Move gadget phy init into core phy init") Signed-off-by: Clément Lassieur Link: https://lore.kernel.org/r/20210603155921.940651-1-clement@lassieur.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/dwc2/core.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 78a4925aa118..093980481c4d 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -1152,15 +1152,6 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16); if (hsotg->params.phy_utmi_width == 16) usbcfg |= GUSBCFG_PHYIF16; - - /* Set turnaround time */ - if (dwc2_is_device_mode(hsotg)) { - usbcfg &= ~GUSBCFG_USBTRDTIM_MASK; - if (hsotg->params.phy_utmi_width == 16) - usbcfg |= 5 << GUSBCFG_USBTRDTIM_SHIFT; - else - usbcfg |= 9 << GUSBCFG_USBTRDTIM_SHIFT; - } break; default: dev_err(hsotg->dev, "FS PHY selected at HS!\n"); @@ -1182,6 +1173,24 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) return retval; } +static void dwc2_set_turnaround_time(struct dwc2_hsotg *hsotg) +{ + u32 usbcfg; + + if (hsotg->params.phy_type != DWC2_PHY_TYPE_PARAM_UTMI) + return; + + usbcfg = dwc2_readl(hsotg, GUSBCFG); + + usbcfg &= ~GUSBCFG_USBTRDTIM_MASK; + if (hsotg->params.phy_utmi_width == 16) + usbcfg |= 5 << GUSBCFG_USBTRDTIM_SHIFT; + else + usbcfg |= 9 << GUSBCFG_USBTRDTIM_SHIFT; + + dwc2_writel(hsotg, usbcfg, GUSBCFG); +} + int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) { u32 usbcfg; @@ -1199,6 +1208,9 @@ int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) retval = dwc2_hs_phy_init(hsotg, select_phy); if (retval) return retval; + + if (dwc2_is_device_mode(hsotg)) + dwc2_set_turnaround_time(hsotg); } if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && -- 2.30.2