From patchwork Sun Oct 17 12:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 12564293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B18AC433F5 for ; Sun, 17 Oct 2021 12:59:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CFE761054 for ; Sun, 17 Oct 2021 12:59:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343514AbhJQNBa (ORCPT ); Sun, 17 Oct 2021 09:01:30 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46033 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242268AbhJQNB3 (ORCPT ); Sun, 17 Oct 2021 09:01:29 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 5DCD95C0109; Sun, 17 Oct 2021 08:59:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 17 Oct 2021 08:59:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm2; bh=knU1y68hFncbUMmEzLqabx16z9 8FUfXq7euHxu34Zfk=; b=ck+WM73arOovdlimiqQK6Q6U73xPANY4l8bU8u4mpU 7WkO/IzofiY8/F790PtkAT8FCf0va1CKQ1M/tOFVn/te876pZbyx9GqX8/1yEntq +oCHHxrAcKU0EX7M6ADLCH02sT959VlxTopO25mZZ1c6hZaF1FPR4ksGtKt65QMm wZyW3GdcJrztWBCUbotLSt4ievmQQ6iiDeu42iLitYtPqZWg62XwdKmHvttu2Rvo IiekldIqGvZgfEFz396LUNw9KYdA1gRhejiCI4FKXkop9h0lDvPb5fRRq+QucZmj RQZcMf1A1znnHjBLug2SmEmb6GElsyAYuSf+Je7MPMTg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=knU1y68hFncbUMmEz Lqabx16z98FUfXq7euHxu34Zfk=; b=CGGsaPCgs+DGc7wcFucl+0LR+EJliQxUe JljDfa+H3ZHePBlc9Cl8R++65BACuH+dWKxVrnsrcE+IxqXib1KXMYpMqj5PG39r oHqnTZ0FnIWkhWFI7H1055EyrCsK8A5AwJ9azYP8/d64OMJgytFJepnqCLIYF8YE z/39C2d7It254wSuXTYGpO3iehrO0lYEFEc9YWRnAX4fXeQjxZdYQESPMqIH842E ppbrJsHBhuAZbyM2tnmBc8rlEOFWRO7gkJYxjOqQ8YkxXrEEpmVOldLhMXQByqBI MAYR3rZ5Eodm3rXJCQSiscdyyQ4AqPk7ewfOO9OHKlxbkc1VpRVMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddukedgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcurfgv thgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvghrnh epuefgleekvddtjefffeejheevleefveekgfduudfhgefhfeegtdehveejfefffffgnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvghnse hsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Oct 2021 08:59:15 -0400 (EDT) From: Sven Peter To: Felipe Balbi Cc: Sven Peter , Rob Herring , Greg Kroah-Hartman , Hector Martin , Alyssa Rosenzweig , Mark Kettenis , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] dt-bindings: usb: dwc3: Document role-switch-reset-quirk Date: Sun, 17 Oct 2021 14:59:03 +0200 Message-Id: <20211017125904.69076-1-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The dwc3 controller on the Apple M1 must be reset whenever a device is unplugged from the root port and triggers a role switch notification. Document the quirk to enable this behavior. Signed-off-by: Sven Peter --- Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml index 25ac2c93dc6c..9635e20cab68 100644 --- a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml @@ -226,6 +226,12 @@ properties: avoid -EPROTO errors with usbhid on some devices (Hikey 970). type: boolean + snps,role-switch-reset-quirk: + description: + When set, DWC3 will be reset and reinitialized whenever a role switch + is performed. + type: boolean + snps,is-utmi-l1-suspend: description: True when DWC3 asserts output signal utmi_l1_suspend_n, false when From patchwork Sun Oct 17 12:59:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 12564295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71C8DC433FE for ; Sun, 17 Oct 2021 12:59:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AAD160F93 for ; Sun, 17 Oct 2021 12:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343614AbhJQNBb (ORCPT ); Sun, 17 Oct 2021 09:01:31 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:37813 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343588AbhJQNBa (ORCPT ); Sun, 17 Oct 2021 09:01:30 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 10EBA5C00E2; Sun, 17 Oct 2021 08:59:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 17 Oct 2021 08:59:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=LJblaVYUkTeH0 MmRDFNp1xity1LQsYJVL4syXm9P04M=; b=XFMJk086YUIMt+lsbbcwqt79XOmJf hp5jabGkiRU9O+GJ2RVopEUv0CCGXu5MhouTWRPv29r9V2dQnqyIXbtFiXZBjBdW mLY/E4Pd2V6NbtL94PINnJtX3dq+bhdKZoEZXfrMFBLPlI9gHRFjwHvG56uTqZju VzKnYTQDNI4ZJ1zMrawkGBVSRTHBcSSr1GVdBl2B3iNH9U11vHlXqJZTROTAnWEq c1OtM+MJbRPQYH9HUYfDrgm3ls+BdKveqhGbDmjAN3jU4EVH5yQq2jiXHi7lT92W maaLMkLwH1ef0MJb4JkpzNLeaMPxx8IBiZ4F9yfJxPj/VR1L6C5ULpWMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=LJblaVYUkTeH0MmRDFNp1xity1LQsYJVL4syXm9P04M=; b=LifgrM8R nwnzrLewEnaZyMIhkkEjjfQEfoOWmBzf8mIRsngVHC2Yp2YJRtixiiRpZb1JoWcg D+0u7KnvZPzMb64Dbe3KOGAyMxW5AEHuq3Pv8DWEHaoTumAY5hRGLUPlifm0l/dA cLrcm5f+c/WnX8oqEH/jH5Xp3KcgvKtFDp+XlPc+28fk8IQIOt4P25qQpFI5feTt vOIV54ZJYxyEOq5xFKia/1yzWzY/x0zwNg5Mqdfwtt9fL574pWx5nQZLIwzVfr6+ jYI5v3jpY4Y1MegJEhamOjyvFdgP54eomYB/79Y23hZG12XSFIF3kfZbUDN3gfbL 3A3wkGma8YLQrw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddukedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcu rfgvthgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvg hrnheptedvkeetleeuffffhfekteetffeggffgveehieelueefvddtueffveevlefhfeej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvg hnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Oct 2021 08:59:19 -0400 (EDT) From: Sven Peter To: Felipe Balbi Cc: Sven Peter , Greg Kroah-Hartman , Hector Martin , Alyssa Rosenzweig , Mark Kettenis , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] usb: dwc3: Add role-switch-reset-quirk logic Date: Sun, 17 Oct 2021 14:59:04 +0200 Message-Id: <20211017125904.69076-2-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211017125904.69076-1-sven@svenpeter.dev> References: <20211017125904.69076-1-sven@svenpeter.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org As mad as it sounds, the dwc3 controller present on the Apple M1 must be reset and reinitialized whenever a device is unplugged from the root port and triggers a role switch notification from the USB PD controller. This is required for at least two reasons: - The USB2 D+/D- lines are connected through a stateful eUSB2 repeater which in turn is controlled by a variant of the TI TPS6598x USB PD chip. When the USB PD controller detects a hotplug event it resets the eUSB2 repeater. Afterwards, no new device is recognized before the DWC3 core and PHY are reset as well. - It's possible to completely break the dwc3 controller by switching it to device mode and unplugging the cable at just the wrong time. Even a CORESOFTRESET is not enough to allow new devices again. The only workaround is to trigger a hard reset of the entire dwc3 core. This also happens when running macOS on these machines. Signed-off-by: Sven Peter --- drivers/usb/dwc3/core.c | 40 +++++++++++++++++++++++++++++++++++++--- drivers/usb/dwc3/core.h | 6 ++++++ drivers/usb/dwc3/drd.c | 7 +++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 643239d7d370..444b45e9cb92 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -116,6 +116,8 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) } static int dwc3_core_soft_reset(struct dwc3 *dwc); +static void dwc3_core_exit(struct dwc3 *dwc); +static int dwc3_core_init_for_resume(struct dwc3 *dwc); static void __dwc3_set_mode(struct work_struct *work) { @@ -131,10 +133,11 @@ static void __dwc3_set_mode(struct work_struct *work) if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) dwc3_otg_update(dwc, 0); - if (!dwc->desired_dr_role) + if (!dwc->desired_dr_role && !dwc->role_switch_reset_quirk) goto out; - if (dwc->desired_dr_role == dwc->current_dr_role) + if (dwc->desired_dr_role == dwc->current_dr_role && + !dwc->role_switch_reset_quirk) goto out; if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) @@ -159,6 +162,34 @@ static void __dwc3_set_mode(struct work_struct *work) break; } + if (dwc->role_switch_reset_quirk) { + if (dwc->current_dr_role) { + dwc->current_dr_role = 0; + dwc3_core_exit(dwc); + } + + if (dwc->desired_dr_role) { + /* + * the first call to __dwc3_set_mode comes from + * dwc3_drd_init. In that case dwc3_core_init has been + * called but dwc->current_dr_role is zero such that + * we must not reinitialize the core again here. + */ + if (dwc->role_switch_reset_quirk_initialized) { + ret = dwc3_core_init_for_resume(dwc); + if (ret) { + dev_err(dwc->dev, + "failed to reinitialize core\n"); + goto out; + } + } + + dwc->role_switch_reset_quirk_initialized = 1; + } else { + goto out; + } + } + /* For DRD host or device mode only */ if (dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG) { reg = dwc3_readl(dwc->regs, DWC3_GCTL); @@ -1425,6 +1456,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->dis_split_quirk = device_property_read_bool(dev, "snps,dis-split-quirk"); + dwc->role_switch_reset_quirk = device_property_read_bool(dev, + "snps,role-switch-reset-quirk"); + dwc->lpm_nyet_threshold = lpm_nyet_threshold; dwc->tx_de_emphasis = tx_de_emphasis; @@ -1744,7 +1778,6 @@ static int dwc3_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_PM static int dwc3_core_init_for_resume(struct dwc3 *dwc) { int ret; @@ -1771,6 +1804,7 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc) return ret; } +#ifdef CONFIG_PM static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) { unsigned long flags; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index ee854697c300..04b1b9c2bbed 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1086,6 +1086,9 @@ struct dwc3_scratchpad_array { * 3 - Reserved * @dis_metastability_quirk: set to disable metastability quirk. * @dis_split_quirk: set to disable split boundary. + * @role_switch_reset_quirk: set to force reinitialization after any role switch + * @role_switch_reset_quirk_initialized: set to true after the first role switch + * which is triggered from dwc3_drd_init directly * @imod_interval: set the interrupt moderation interval in 250ns * increments or 0 to disable. * @max_cfg_eps: current max number of IN eps used across all USB configs. @@ -1299,6 +1302,9 @@ struct dwc3 { unsigned dis_split_quirk:1; unsigned async_callbacks:1; + unsigned role_switch_reset_quirk:1; + unsigned role_switch_reset_quirk_initialized:1; + u16 imod_interval; int max_cfg_eps; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index d7f76835137f..403e88a72f0e 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -506,6 +506,9 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, break; } + if (dwc->role_switch_reset_quirk && role == USB_ROLE_NONE) + mode = 0; + dwc3_set_mode(dwc, mode); return 0; } @@ -534,6 +537,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct usb_role_switch *sw) role = USB_ROLE_DEVICE; break; } + + if (dwc->role_switch_reset_quirk && !dwc->current_dr_role) + role = USB_ROLE_NONE; + spin_unlock_irqrestore(&dwc->lock, flags); return role; }