Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2840369pxv; Mon, 12 Jul 2021 03:15:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLhegWwdHD3ezFi6Hblq42/aw0fKCrRiZIuY+Pim48hti4POX5A4wSCjhJ7vASqmXkNA2C X-Received: by 2002:a05:6402:51c7:: with SMTP id r7mr2797302edd.150.1626084914364; Mon, 12 Jul 2021 03:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084914; cv=none; d=google.com; s=arc-20160816; b=xniTCc/DSR0tMRG6ItoZz2/GLdXvEgD9gjqnEYhIHJ86U9ldZf4gkY872ppz6Jty1W +nclwQqJF1Wo7Bfbmt3QaSLU3iUZVTsoD8XIHDAA7BGxybg6Yhyh24MszEj6xOhwyeA4 hVNEKiNDSjR5PhSnOgk5pXTBEIj3BIBrqcY7/oiEHyV1nMMGmK84gejWZBAXbEoPJE7m H19OVmSdb5OzvKdZnU1UEFWIPHJ53gW9P42+Q346Mj9d5vhWX9UYSGOMMB2nO+ffFaHU ulqin963XSPhe5TGxstA7977mkdevTN6eQqqlpCYQZFUN0BMBBUikJDeMoKDqR+oBLgA Xq9Q== 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=XFccWvzq4QHhRgJWhKcYIzhUVTyLw53hmS0vnZnNONI=; b=p//5VLwvCM+eRyoDqq+p3uYIQVRvd7pR74nW4VHlHY1VcdXqJWh/8QB4DqV7KqYTEE hUfWznfBc18kTTo3ZQ3A6N4hteUeSr3InoqTnUGuH/QEU318B2teZapNSRAoI9p+MqjH p4cr52yrcDLxsIFcNsMQcXZO1DBucdsgFHPPGzEhrlkusDVQjhEHC8BWFPVPzfO6ug7y eJSaPGafJnW09xz1SjVBq+ZOYxLs6KU7rJEGhrtFENBWKMLyoKebvVbvhSszdKC+kEyT buOX9PIoiRwnY6WZ15h9zKXWSIoreICIRDTRNnY8laP6m72ppQ2WjBxPRlSNm2Q9GJWX ksdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2wIXLXfN; 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 y18si2335425edo.360.2021.07.12.03.14.51; Mon, 12 Jul 2021 03:15:14 -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=2wIXLXfN; 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 S1354228AbhGLIDo (ORCPT + 99 others); Mon, 12 Jul 2021 04:03:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:34004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345270AbhGLHZO (ORCPT ); Mon, 12 Jul 2021 03:25:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 539626113B; Mon, 12 Jul 2021 07:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626074522; bh=BxHwDuV56DoQxQglk3mxcCOPIw5dgd0dvHM0XdlZGM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2wIXLXfNASRvqjogryI6i+HKvvrQNx1ENySrl/HaW9p7LiWGyl1MoywJwKzpCDKCi 1xjN3ROuWBCugPDrQVxw8s6O2PAcmZyCW7kThMY7CtJjO3AXkford5dMY3O1MvkjSZ Z7m9vKBlZJ2z4rgA9cu9kqHHaXsO3KmN64pFovXM= 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.12 607/700] usb: dwc2: Dont reset the core after setting turnaround time Date: Mon, 12 Jul 2021 08:11:30 +0200 Message-Id: <20210712061040.513033251@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@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 fec17a2d2447..15911ac7582b 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -1167,15 +1167,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"); @@ -1197,6 +1188,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; @@ -1214,6 +1223,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