From patchwork Tue Dec 3 12:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 13892314 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 DB4D1E64A84 for ; Tue, 3 Dec 2024 12:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UxwJE+MJMfiH1rzL3umObgd5ObTOQhZrUd449ekoYSM=; b=z7r+CygpCR0B6d qJVFim8K/uE3hNYY4xyFSG9AOqdYc0vOle9b/Yi2LfEET80PzclGmG3r5xE0cb3g3ed2bI0NAiQxv h+ekagWSkTXTYyftMje7E/R+UI5tlsYll4Wc7u3Y5Uboz81B84gpetXTcpsgr47CCpxaY4N8aahKc rh4hSFdrKsXXimwUl5o5TXiAiTZ/obSvss8BBOulypqUbQkd9He300JRMfjT7wjAQz1ro7+qxMz5M zaCDJvJMGRTfXyL826dgIkcPPFxC1ztv5P9XWTlVVIRf2MzuWrqb4QA3oXCIEoMSW8/d+vQd3Xjx9 6AywqtwSzLFOX+4TkdKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIRui-00000009Pc3-2hjv; Tue, 03 Dec 2024 12:22:00 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIRmu-00000009Nhq-3g8p for linux-phy@lists.infradead.org; Tue, 03 Dec 2024 12:13:58 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aadb1so6409454a12.0 for ; Tue, 03 Dec 2024 04:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733228035; x=1733832835; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uFpsvHW8LAP7lW2ogoOJaMBxsAjFS0igr/BkJ+LMT9c=; b=FfT1xiOvqPM07Wqtgxivikd+AlZmNLDoMT07+8NQ7YSZl4lROIgkUqM1wCFuqM60MB pxwVEl+ewohg9tFxrqH3L+nVxnVfJGv9KLFqlnxISKf2NGSOBgE9vml3qOFO8igH0E4w ksA1lZAe/zpvk4f1y2C06U7aTCmjoKcaf2NrWcdjdwcAntzQRwBNPJOkYcEjOYXfLIOi 1xAWlbcrDTc55qRor56Xqj9DBfRKrREwCTHQkxSQIpIU0d6WZWR5+OMXqVUuNsUvNyAX ofq4EXMAbYarc0CaVDaAG8wjKYBpIT/kRwIXumBdk0MltIst1e2/xeNRmNgrLqHxaX+1 1wZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733228035; x=1733832835; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uFpsvHW8LAP7lW2ogoOJaMBxsAjFS0igr/BkJ+LMT9c=; b=kSvzfRXhO/jzzKHcZQAsBD5tyVbLgp7Lte1CNI9t0IctiV6+kqol2SHZMxX9rsxWxj /t5Sp6totJOJu6D14JlEe1TCRuWDVmsAj2+TTlvZc1gXqFFN+bEsiUWNizVlnI+DKsOo tLRZO59V1GoAKTEcaG293//F0ZhWahF7kbtVsoSL06xTfu29zIpfrtGt35iyJVLAgWgC 4HxFwUs9deFZMmIJFzyl6+nqAUcXXxGVwaQE0l7puETYKMPtVe+t8CJgoo2+xxf9QkyN TrVs+q5NU18wzcXDU7QxM/UoTR9zexDXC1HEUMPgkuOC2ujCwUviqO4oonfJb7FIipJP XZsw== X-Forwarded-Encrypted: i=1; AJvYcCXnbDQoa4BIgwG9PSQKRNI98AqBXxNKZxXRAyFZRAS8OjQf7nw64t6gMebeqek7bbxMZ8TsRJtnYZY=@lists.infradead.org X-Gm-Message-State: AOJu0YzpwrzZFbDGyQuN+mevd7u0KjwBCr/uiUcHCM+PQ0P0h5Pg3LC/ HHc4TZmPStrUyGiocswVuHf3tUd/7Q3RVxfywY6Nt7Vlwgiar5OKSRBg1phLoSM= X-Gm-Gg: ASbGncsTRCwq3u9eJ88ZOxFFq42vLZ1qFw52Tcg27JLeSr4JXr5I+rOvLSlT0yAtyoU bMVqBCkESqopgb+PJ+SKd6HKfURcgSAT0nCeBOvPFQ6/7WIeMYyzBsbD4S6hwaKNtanKA6oEsfT K4GBdtc94rooIx7iIq2PbLvNfZkhwy5E9bQwwMjkBFDtAQYsaGflvHd9ex5qhJkdUl4DKGL93OF mghcYTjetjQG7zfdz/gNtvSR9YLHLOZkOPEZ8CdFTdDbBWiVB9Bh78BUJjtKQDd45v4ZZ2SyDbp iRnlNZ1UAHREMmHlUSDVBCtVQ+L1iBL8Dw== X-Google-Smtp-Source: AGHT+IGdrwALKg1GTwldZJOY7VYAVcWh5tQKqLrkKr8AXomCGAvvPrif7tTk5yapUjTCTN1a7cYNbg== X-Received: by 2002:a17:906:4c1:b0:aa5:427e:6c76 with SMTP id a640c23a62f3a-aa5f7aaed08mr164681466b.0.1733228035286; Tue, 03 Dec 2024 04:13:55 -0800 (PST) Received: from puffmais.c.googlers.com (64.227.90.34.bc.googleusercontent.com. [34.90.227.64]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5996c245bsm607603766b.8.2024.12.03.04.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 04:13:54 -0800 (PST) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Tue, 03 Dec 2024 12:13:56 +0000 Subject: [PATCH v2 8/8] phy: exynos5-usbdrd: allow DWC3 runtime suspend with UDC bound (E850+) MIME-Version: 1.0 Message-Id: <20241203-gs101-phy-lanes-orientation-phy-v2-8-40dcf1b7670d@linaro.org> References: <20241203-gs101-phy-lanes-orientation-phy-v2-0-40dcf1b7670d@linaro.org> In-Reply-To: <20241203-gs101-phy-lanes-orientation-phy-v2-0-40dcf1b7670d@linaro.org> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Szyprowski , Sylwester Nawrocki , Alim Akhtar Cc: Peter Griffin , Tudor Ambarus , Sam Protsenko , Will McVicker , Roy Luo , kernel-team@android.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.13.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241203_041356_956545_D24A5B58 X-CRM114-Status: GOOD ( 14.53 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org To make USB runtime suspend work when a UDC has been bound, the phy needs to inform the USBDRD controller (DWC3) that Vbus and bvalid are gone, so that it can in turn raise the respective gadget interrupt with event == DWC3_DEVICE_EVENT_DISCONNECT, which will cause the USB stack to clean up, allowing DWC3 to enter runtime suspend. On e850 and gs101 this isn't working, as the respective signals are not directly connected, and instead this driver uses override bits in the PHY IP to set those signals. It currently forcefully sets them to 'on', so the above mentioned interrupt will not be raised, preventing runtime suspend. To detect that state, update this driver to act on the TCPC's orientation signal - when orientation == NONE, Vbus is gone and we can clear the respective bits. Similarly, for other orientation values we re-enable them. This makes runtime suspend work on platforms with a TCPC (like Pixel6), while keeping compatibility with platforms without (e850-96). With runtime suspend working, USB-C cable orientation detection now also fully works on such platforms, and the link comes up as Superspeed as expected irrespective of the cable orientation and whether UDC / gadget are configured and active. Signed-off-by: André Draszik --- drivers/phy/samsung/phy-exynos5-usbdrd.c | 53 +++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung/phy-exynos5-usbdrd.c index b1914c6c806d..94e4f78340ff 100644 --- a/drivers/phy/samsung/phy-exynos5-usbdrd.c +++ b/drivers/phy/samsung/phy-exynos5-usbdrd.c @@ -1137,13 +1137,15 @@ static void exynos850_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd) reg |= LINKCTRL_BUS_FILTER_BYPASS(0xf); writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL); - reg = readl(regs_base + EXYNOS850_DRD_UTMI); - reg |= UTMI_FORCE_BVALID | UTMI_FORCE_VBUSVALID; - writel(reg, regs_base + EXYNOS850_DRD_UTMI); - - reg = readl(regs_base + EXYNOS850_DRD_HSP); - reg |= HSP_VBUSVLDEXT | HSP_VBUSVLDEXTSEL; - writel(reg, regs_base + EXYNOS850_DRD_HSP); + if (!phy_drd->sw) { + reg = readl(regs_base + EXYNOS850_DRD_UTMI); + reg |= UTMI_FORCE_BVALID | UTMI_FORCE_VBUSVALID; + writel(reg, regs_base + EXYNOS850_DRD_UTMI); + + reg = readl(regs_base + EXYNOS850_DRD_HSP); + reg |= HSP_VBUSVLDEXT | HSP_VBUSVLDEXTSEL; + writel(reg, regs_base + EXYNOS850_DRD_HSP); + } reg = readl(regs_base + EXYNOS850_DRD_SSPPLLCTL); reg &= ~SSPPLLCTL_FSEL; @@ -1408,9 +1410,44 @@ static int exynos5_usbdrd_orien_sw_set(struct typec_switch_dev *sw, enum typec_orientation orientation) { struct exynos5_usbdrd_phy *phy_drd = typec_switch_get_drvdata(sw); + int ret; + + if (phy_drd->orientation == orientation) + return 0; + + ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks); + if (ret) { + dev_err(phy_drd->dev, "Failed to enable PHY clocks(s)\n"); + return ret; + } + + scoped_guard(mutex, &phy_drd->phy_mutex) { + void __iomem * const regs_base = phy_drd->reg_phy; + unsigned int reg; + + if (orientation == TYPEC_ORIENTATION_NONE) { + reg = readl(regs_base + EXYNOS850_DRD_UTMI); + reg &= ~(UTMI_FORCE_VBUSVALID | UTMI_FORCE_BVALID); + writel(reg, regs_base + EXYNOS850_DRD_UTMI); + + reg = readl(regs_base + EXYNOS850_DRD_HSP); + reg |= HSP_VBUSVLDEXTSEL; + reg &= ~HSP_VBUSVLDEXT; + writel(reg, regs_base + EXYNOS850_DRD_HSP); + } else { + reg = readl(regs_base + EXYNOS850_DRD_UTMI); + reg |= UTMI_FORCE_VBUSVALID | UTMI_FORCE_BVALID; + writel(reg, regs_base + EXYNOS850_DRD_UTMI); + + reg = readl(regs_base + EXYNOS850_DRD_HSP); + reg |= HSP_VBUSVLDEXTSEL | HSP_VBUSVLDEXT; + writel(reg, regs_base + EXYNOS850_DRD_HSP); + } - scoped_guard(mutex, &phy_drd->phy_mutex) phy_drd->orientation = orientation; + } + + clk_bulk_disable(phy_drd->drv_data->n_clks, phy_drd->clks); return 0; }