From patchwork Fri Oct 11 10:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 13832413 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA794CFD341 for ; Fri, 11 Oct 2024 10:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=5wFLn5ipQy9E1l6OF5a6sN6QfrS1Fd7bVo4vYsyzl/w=; b=bXHxKJVJYTqfoFV4tmvWWCnnaO LTpbbViun8dEih5nfyOYlqMNl2VCJhjoStJRf43GcOL+P7Y78blXF4Nh3vUDnjfG4hcdqEsfPG8Yg 4dEzZ6RT2ripwHSAhLrJEZ5DfWRKuS6NsfBSpcFxe7hZ/KVdObmiMERecpUcc/E5xAF6y0obYfjSw UdNLL7oPvwggIWq5cQ2cJdDHQLUGwQD3trAn6IwsZtfsP4n0lAvrkLO29j1BiM2q9f1cdUycNhAEV 4k9gx5/cmSIcf4q/97ZT2J0KNU9NMnpO+4rXB+4NBXzlOQGwvYhOaYZCPBv3wtVEs7LhsuP2IUSAi UlpR9Njw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szDL9-0000000G4eT-0ZMY; Fri, 11 Oct 2024 10:57:47 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szDHG-0000000G3uY-3iwp for linux-arm-kernel@bombadil.infradead.org; Fri, 11 Oct 2024 10:53:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:In-Reply-To:References; bh=5wFLn5ipQy9E1l6OF5a6sN6QfrS1Fd7bVo4vYsyzl/w=; b=cEr6SDnJht8TqGYlCcqB1f8Tbm FrHhwUjklA8pMo49jF6gEZKBp5V+92VTzGsPd3cqRSuTPipBWhN2TzPYUSL/Q6mImKbjVYEMPsanW 0M3g8MPYGttZ+W8ewYB9EnxIU/v5K/Ar4Be3VdtxKmhL7biC9Q5AWZT/MKdSPjZiOgxUwxvPi1mmb gE3NU/ds4wCVXMsWa2jU1THidXCnz+xUJqGJS0tqo0Encl7ZSdQOZ2RAV3w6VL8vdCsX1JjygC107 5XoILUSCMXCZy4bMYWgs4/QGKjGmRdScF0yM0mkrT6oAbtNm9WcdL+qgcZQLFEmCZkyIkadCs8hm1 pI8xb83A==; Received: from nyc.source.kernel.org ([147.75.193.91]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szDHD-00000005rgb-2BOZ for linux-arm-kernel@lists.infradead.org; Fri, 11 Oct 2024 10:53:45 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 73796A41786; Fri, 11 Oct 2024 10:53:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 003D0C4CECC; Fri, 11 Oct 2024 10:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728644021; bh=SMSAwURTM1d5RipIGE/rB4foIsdd0HI1hdITJc1eIWQ=; h=From:Date:Subject:To:Cc:From; b=cLErmwLayP9ONrUIcQ5NUPsnImMlfKAGPKJ94ZbYel10Dj+DNS407zuPUdOltR1yI dE/kXlW62n+LiAwl7WoS1VqzWbeal8kj9AKZKJiiAc5SjxZYmhieBXIdmTB3iEUPNf CiNfXwBJipRyhScvz9EijSkBxBloCXYUx5PK5pOqrROd534d/exqMc9UwOxIZGtuiE 4jR0DzKmL9lboZa4+81fz4Wsla1bXdMAFVlzsTKxZfY8t24yPBzPxo4Ir3sDU4UHWm ZOD7ZXdqdBvuEldcvkFJ02vCVNb/A87pmYSCjAVj5kdYfWXh+SPA/KtFNvfu+R1UGQ UTW3BFMKp1zsA== From: Roger Quadros Date: Fri, 11 Oct 2024 13:53:24 +0300 Subject: [PATCH v3] usb: dwc3: core: Fix system suspend on TI AM62 platforms MIME-Version: 1.0 Message-Id: <20241011-am62-lpm-usb-v3-1-562d445625b5@kernel.org> X-B4-Tracking: v=1; b=H4sIAKMDCWcC/13MSw6CMBSF4a2Qjq3pvWCbOmIfxgGlF2jklVYbD WHvFkbi8Jzk/xYWyDsK7JotzFN0wU1jGvkpY3VXjS1xZ9NmKLAQGnNeDRJ5Pw/8FQxvChQalLF KKJaS2VPj3jt3u6fdufCc/GfXI2zvDoEQcIQicOBagzQKQF4aVT7Ij9SfJ9+yTYr4W+u/GlNtK 5S1qC0aoEO9rusXCIoagucAAAA= To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , Nishanth Menon , Tero Kristo , Santosh Shilimkar , Thinh Nguyen Cc: Dhruva Gole , Vishal Mahaveer , msp@baylibre.com, srk@ti.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, stable@vger.kernel.org, Roger Quadros X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4130; i=rogerq@kernel.org; h=from:subject:message-id; bh=SMSAwURTM1d5RipIGE/rB4foIsdd0HI1hdITJc1eIWQ=; b=owEBbQKS/ZANAwAIAdJaa9O+djCTAcsmYgBnCQOxqBmfPC7eJ+c6SU8SoLZDV4m1FX17mmtof Pg59HytZ4OJAjMEAAEIAB0WIQRBIWXUTJ9SeA+rEFjSWmvTvnYwkwUCZwkDsQAKCRDSWmvTvnYw kxCiEACzojewd1nrTI35G+GeuXLP49y/iaIJEt2DCqrgIZY0S58KivuWPzK3Y9X/576gwoYO3kl 0NM6jUpW26tCZYFxxkT6IdaFbtwNTB7qYqAcnUFHURd46OlD06etXmtjDlLT8i9wxK1+mZDSMUP F9Pi5/ZipbtYeUVG6f7p+dNH+pqo9Vr3Q44RdThtCgaekEAJSUF00ZvV0bDJMymcOIqsvvGtxkC IeIP8fBSdx64NamC6Nimr7pYI8cP4DkMma1j1StVp/bwJ4fiZlz4lV6UAXSY27rOJkXwfSrNteE IHSBGIZP3Abml1QGT2jPjnyyjFRcHo39XrQ3L/uVDE06QoImjWZOezAQTZ821BwjfhMOrKQeXwk GkBTJwyrZ8+SrqrgdlQ1UUtsAqWtEojqpJVKLx8J7Gm4k1oqrwa6YymSIcVcseSz70rhlu0CITp vVU3wu+n8l9P1+Nmwcz1+0IITxyGjiGhwZ/hDqfuS359JypOos5OTmik2ZVFe1QktKaGpWYRUA9 YQ6vJNhomn991yh4QK76hhu57RC7uGjLGNb5EoPl2fT31zAyOkvUemJKJCKXRaGMgJmqn8vs0Gb QCXZQ2cj1gkjWLNvWUiRTeykn3uBW8jtNnwf48ODXw/tZ+ROfQcl8hKzn+rSOezSxJLcL/RNgtE DVucmURkWBVLcsA== X-Developer-Key: i=rogerq@kernel.org; a=openpgp; fpr=412165D44C9F52780FAB1058D25A6BD3BE763093 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241011_115344_032861_705E769B X-CRM114-Status: GOOD ( 15.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since commit 6d735722063a ("usb: dwc3: core: Prevent phy suspend during init"), system suspend is broken on AM62 TI platforms. Before that commit, both DWC3_GUSB3PIPECTL_SUSPHY and DWC3_GUSB2PHYCFG_SUSPHY bits (hence forth called 2 SUSPHY bits) were being set during core initialization and even during core re-initialization after a system suspend/resume. These bits are required to be set for system suspend/resume to work correctly on AM62 platforms. Since that commit, the 2 SUSPHY bits are not set for DEVICE/OTG mode if gadget driver is not loaded and started. For Host mode, the 2 SUSPHY bits are set before the first system suspend but get cleared at system resume during core re-init and are never set again. This patch resovles these two issues by ensuring the 2 SUSPHY bits are set before system suspend and restored to the original state during system resume. Cc: stable@vger.kernel.org # v6.9+ Fixes: 6d735722063a ("usb: dwc3: core: Prevent phy suspend during init") Link: https://lore.kernel.org/all/1519dbe7-73b6-4afc-bfe3-23f4f75d772f@kernel.org/ Signed-off-by: Roger Quadros Acked-by: Thinh Nguyen Tested-by: Markus Schneider-Pargmann Reviewed-by: Dhruva Gole Reported-by: William McVicker Signed-off-by: Roger Quadros --- Changes in v3: - Fix single line comment style - add DWC3_GUSB3PIPECTL_SUSPHY to documentation of susphy_state - Added Acked-by tag - Link to v2: https://lore.kernel.org/r/20241009-am62-lpm-usb-v2-1-da26c0cd2b1e@kernel.org Changes in v2: - Fix comment style - Use both USB3 and USB2 SUSPHY bits to determine susphy_state during system suspend/resume. - Restore SUSPHY bits at system resume regardless if it was set or cleared before system suspend. - Link to v1: https://lore.kernel.org/r/20241001-am62-lpm-usb-v1-1-9916b71165f7@kernel.org --- drivers/usb/dwc3/core.c | 19 +++++++++++++++++++ drivers/usb/dwc3/core.h | 3 +++ 2 files changed, 22 insertions(+) --- base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc change-id: 20240923-am62-lpm-usb-f420917bd707 Best regards, diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 9eb085f359ce..ca77f0b186c4 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2336,6 +2336,11 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) u32 reg; int i; + dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) & + DWC3_GUSB2PHYCFG_SUSPHY) || + (dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)) & + DWC3_GUSB3PIPECTL_SUSPHY); + switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: if (pm_runtime_suspended(dwc->dev)) @@ -2387,6 +2392,15 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) break; } + if (!PMSG_IS_AUTO(msg)) { + /* + * TI AM62 platform requires SUSPHY to be + * enabled for system suspend to work. + */ + if (!dwc->susphy_state) + dwc3_enable_susphy(dwc, true); + } + return 0; } @@ -2454,6 +2468,11 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) break; } + if (!PMSG_IS_AUTO(msg)) { + /* restore SUSPHY state to that before system suspend. */ + dwc3_enable_susphy(dwc, dwc->susphy_state); + } + return 0; } diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index c71240e8f7c7..31de4b57ae7c 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1150,6 +1150,8 @@ struct dwc3_scratchpad_array { * @sys_wakeup: set if the device may do system wakeup. * @wakeup_configured: set if the device is configured for remote wakeup. * @suspended: set to track suspend event due to U3/L2. + * @susphy_state: state of DWC3_GUSB2PHYCFG_SUSPHY + DWC3_GUSB3PIPECTL_SUSPHY + * before PM suspend. * @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. @@ -1382,6 +1384,7 @@ struct dwc3 { unsigned sys_wakeup:1; unsigned wakeup_configured:1; unsigned suspended:1; + unsigned susphy_state:1; u16 imod_interval;