From nobody Mon Feb 9 16:36:32 2026 Received: from smtp1.tecnico.ulisboa.pt (smtp1.tecnico.ulisboa.pt [193.136.128.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B13435FF75; Tue, 27 Jan 2026 15:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.136.128.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527314; cv=none; b=aQQuf+P2lAiCRC+tMOar8uenjx2TTJb8gaepYqpam1Gt9Z5jJCYp5ezwP6XMGfeoyJFR4ehRHMaFU3b/6r1csA0ej/hSLZ35cVTb6ixqfPBwy9+dWT7cCYQVIFK4o5E2Pn8Z/LEsHCbRLHVm3x5Upe36L88byI1HNI6dPh4bIhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527314; c=relaxed/simple; bh=crMkHAz58/P3KOZ7XNFwuRiIVyBlBe6XUwar7XMSc+Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QRlEK9dthulE53Wdhdo/aZbAQx0ijWHH3W1IHZIKQz+WZqInXOOtKIZ3VpJFfGJqoh92UrxZ2Apobf8gXUDsiWO+emc4ZENfyYkjfuPXcMA0GYm/++28RGYgOhJCaxsYsx2GDFefqiLuOdhyRvVh5Kfhs4Xez/Pioc9dPUY44rQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt; spf=pass smtp.mailfrom=tecnico.ulisboa.pt; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b=lvOoVZrj; arc=none smtp.client-ip=193.136.128.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b="lvOoVZrj" Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTP id 51F8060020E2; Tue, 27 Jan 2026 15:12:11 +0000 (WET) X-Virus-Scanned: by amavis-2.13.0 (20230106) (Debian) at tecnico.ulisboa.pt Received: from smtp1.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp1.tecnico.ulisboa.pt [127.0.0.1]) (amavis, port 10025) with LMTP id NtwtBI58voT3; Tue, 27 Jan 2026 15:12:09 +0000 (WET) Received: from mail1.tecnico.ulisboa.pt (mail1.ist.utl.pt [IPv6:2001:690:2100:1::b3dd:b9ac]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTPS id 5F06A6002306; Tue, 27 Jan 2026 15:12:08 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecnico.ulisboa.pt; s=mail2; t=1769526728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eTz8SZs3WThSgHMDMFip4KxZygxWXRhKo2bE8wjby9M=; b=lvOoVZrj0+6FrLhJHDM2DCVQdOUFJecK92LjorU7ifI+C0Mvd0QAe2lSbJamX6DpABkwnB gbL6Ntj1u5yS2ARSWGI9BXNh4fqC65hDYBgXozHLf4PQIQKSHee1uyR4HHi0hbncckaMVT nQtaa6bpIPi5bnP7MoA2rJw6HlCG3GyyLUrjhnkg6YXlkMgknZZ/i+0d1s6Nk3IbgTgtlu GLDmjUYyjNwukfamwS42LYnMdq9XS4DxQzXpEpejaK+JOR/V6/ydWxmhDNYm+VHEj0U9fh Ajlt12WJYSEpilTC/z2ptnL1xOraHu1vAx/+imF23NrQH7LJWytE+ovwtpy5JQ== Received: from [192.168.2.110] (unknown [148.63.39.39]) (Authenticated sender: ist187313) by mail1.tecnico.ulisboa.pt (Postfix) with ESMTPSA id 083073600DD; Tue, 27 Jan 2026 15:12:08 +0000 (WET) From: Diogo Ivo Date: Tue, 27 Jan 2026 15:11:47 +0000 Subject: [PATCH v2 1/6] phy: tegra: xusb: Fix USB2 port regulator disable logic Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-diogo-tegra_phy-v2-1-787b9eed3ed5@tecnico.ulisboa.pt> References: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> In-Reply-To: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , JC Kuo , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, Diogo Ivo , stable@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769526725; l=2198; i=diogo.ivo@tecnico.ulisboa.pt; s=20240529; h=from:subject:message-id; bh=crMkHAz58/P3KOZ7XNFwuRiIVyBlBe6XUwar7XMSc+Y=; b=DghMWBQc0iCO8oYZES6tibmHzkTLhvT406Glm+R0oVLioUVqxkG6rBc679D0IDjGc5WrdexYC bYwXH4zUn/iAVj84vqWFRScSiXuXt1FSmXjdmkqxLbjI4rw83VqWkXr X-Developer-Key: i=diogo.ivo@tecnico.ulisboa.pt; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= The USB2 PHY mode handling on Tegra210 incorrectly relied on regulator_is_enabled() when determining whether the VBUS supply should be disabled during role changes. This is because regulator_is_enabled() reports exactly what is states and not if there is an unbalanced number of calls between regulator_enable() and regulator_disable(). For example, regulator_is_enabled() always reports true on a fixed-regulator with no enable gpio, which is the case on the Pixel C. This then leads to the PHY driver wrongfully calling regulator_disable() when transitioning from USB_ROLE_DEVICE to USB_ROLE_NONE since the driver did not previously call the corresponding regulator_enable(). Fix this by keeping track of the current role and updating the logic to disable the regulator only when the previous role was USB_ROLE_HOST. Cc: stable@vger.kernel.org Signed-off-by: Diogo Ivo --- v1->v2: - Do not fix typo in comment --- drivers/phy/tegra/xusb-tegra210.c | 4 +++- drivers/phy/tegra/xusb.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-teg= ra210.c index 3409924498e9..3abdf0182d67 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -1936,12 +1936,14 @@ static int tegra210_usb2_phy_set_mode(struct phy *p= hy, enum phy_mode mode, * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not * be enabled. */ - if (regulator_is_enabled(port->supply)) + if (port->role =3D=3D USB_ROLE_HOST) regulator_disable(port->supply); =20 tegra210_xusb_padctl_id_override(padctl, false); tegra210_xusb_padctl_vbus_override(padctl, false); } + + port->role =3D submode; } =20 mutex_unlock(&padctl->lock); diff --git a/drivers/phy/tegra/xusb.h b/drivers/phy/tegra/xusb.h index d2b5f9565132..273af147dfd3 100644 --- a/drivers/phy/tegra/xusb.h +++ b/drivers/phy/tegra/xusb.h @@ -317,6 +317,7 @@ struct tegra_xusb_usb2_port { enum usb_dr_mode mode; bool internal; int usb3_port_fake; + enum usb_role role; }; =20 static inline struct tegra_xusb_usb2_port * --=20 2.52.0 From nobody Mon Feb 9 16:36:32 2026 Received: from smtp1.tecnico.ulisboa.pt (smtp1.tecnico.ulisboa.pt [193.136.128.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DCF735CBCA; Tue, 27 Jan 2026 15:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.136.128.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527312; cv=none; b=VADZUgXS+DO4iOt47EzZs558y6zufHQgN/QHk5Re41WCSdGHuI8HtDK4aoyeyiZjBXtVz0Q3MhGKDvlEnbk+5S1OYrCbZ4J48LYVxhicc26qSH4YlWBGDLJSTJ3jqy/KMJ1jhTKhqGvzZIriNo8qwpObq80SfwpuA8ZEEm3FrEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527312; c=relaxed/simple; bh=tPxLgImUSfLaPO0hTIiojepsSdUOwrfSQUsTniiVYsM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iwgYO+NSqKBVPL+dR3RVhEAJD9ml8/0UVT2ZdSd2X3+LittwoumIDCQd634grmGHsvS7z6QDJE87jQA7ffKtZba6R8c3WM0ByH4vk7DtgjputsgI+LPMrFf6F+rOctPrt/K6PsmgZyq9ToUAWfK7/79SPNEk58yu+FEiZIWvr/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt; spf=pass smtp.mailfrom=tecnico.ulisboa.pt; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b=CNBbIwBk; arc=none smtp.client-ip=193.136.128.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b="CNBbIwBk" Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTP id 5DB75600086A; Tue, 27 Jan 2026 15:12:11 +0000 (WET) X-Virus-Scanned: by amavis-2.13.0 (20230106) (Debian) at tecnico.ulisboa.pt Received: from smtp1.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp1.tecnico.ulisboa.pt [127.0.0.1]) (amavis, port 10025) with LMTP id lWw2rW8RwuwY; Tue, 27 Jan 2026 15:12:09 +0000 (WET) Received: from mail1.tecnico.ulisboa.pt (mail1.ist.utl.pt [193.136.128.10]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTPS id ABE236002307; Tue, 27 Jan 2026 15:12:08 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecnico.ulisboa.pt; s=mail2; t=1769526728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V0ixqb1WmQNGUgreQanqk1a+bFFp4h/i7hFLQvfziag=; b=CNBbIwBkCSTZbT4CWZdM+DSeMHTH1ylUgotr24CkI9OfQDo7P8woRbtOVCMKcMhihTYR0t DnIvtnzoa59ivt8UzQhGJj+H+7XSPePszgZSFFwEUGu18G/acDw5NPPjFquLr4uyABWT8A 2pvJ4ZScImp5XJc9kv7HL1Q6iFJcKsa888VKEkI5k6DsMt+/2u53ajsihZupsjyrO/8ynZ 2jZhwmD8wV+ks0wwRlK3ILVUWzbB6z2qr5w4Q5H6tOZ4m8lJbWJs+eP1gogJCNP32d8+aT iTRiisQp2+vnaMxicF9005WfDJ2WrauyZsml6nAE5Cy9PqgZ22midOLfCIweyw== Received: from [192.168.2.110] (unknown [148.63.39.39]) (Authenticated sender: ist187313) by mail1.tecnico.ulisboa.pt (Postfix) with ESMTPSA id 586353600FC; Tue, 27 Jan 2026 15:12:08 +0000 (WET) From: Diogo Ivo Date: Tue, 27 Jan 2026 15:11:48 +0000 Subject: [PATCH v2 2/6] usb: xhci: tegra: Remove redundant mutex when setting phy mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-diogo-tegra_phy-v2-2-787b9eed3ed5@tecnico.ulisboa.pt> References: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> In-Reply-To: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , JC Kuo , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, Diogo Ivo X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769526725; l=1033; i=diogo.ivo@tecnico.ulisboa.pt; s=20240529; h=from:subject:message-id; bh=tPxLgImUSfLaPO0hTIiojepsSdUOwrfSQUsTniiVYsM=; b=aaqsA3rbn08ZXBt45VmehvpQaYP+AdUvjAwXu//GfD98G9fWXZi5Z+r+bS6F+oCyZKHlHf3l6 0amw7mlT1pPDbSPq6fAIxwDEDeCDafVvh0VFU/BPG10byRsmRFvz3tg X-Developer-Key: i=diogo.ivo@tecnico.ulisboa.pt; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= As the PHY subsystem already synchronizes concurrent accesses to a PHY instance with a core-internal mutex remove the driver specific mutex synchronization. Signed-off-by: Diogo Ivo --- v1->v2: - New patch --- drivers/usb/host/xhci-tegra.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 8b492871d21d..927861ca14f2 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -1357,15 +1357,11 @@ static void tegra_xhci_id_work(struct work_struct *= work) =20 dev_dbg(tegra->dev, "host mode %s\n", str_on_off(tegra->host_mode)); =20 - mutex_lock(&tegra->lock); - if (tegra->host_mode) phy_set_mode_ext(phy, PHY_MODE_USB_OTG, USB_ROLE_HOST); else phy_set_mode_ext(phy, PHY_MODE_USB_OTG, USB_ROLE_NONE); =20 - mutex_unlock(&tegra->lock); - tegra->otg_usb3_port =3D tegra_xusb_padctl_get_usb3_companion(tegra->padc= tl, tegra->otg_usb2_port); =20 --=20 2.52.0 From nobody Mon Feb 9 16:36:32 2026 Received: from smtp1.tecnico.ulisboa.pt (smtp1.tecnico.ulisboa.pt [193.136.128.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3630360729; Tue, 27 Jan 2026 15:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.136.128.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527313; cv=none; b=JpRWzjsfrf6Ni4IOxdxf144+nacr3Ho7a7yM5CKTpwoPc7nL4+yz8S8C/wcrn9VvnT6Y43XHlAxQEkIo4ZtGCf77XKIwepcffUhfVIL+yRs8SVgAPxBP4u6bhNVDqRmvYgO5kiwkGeVyZxP+U5/jywCuW7fehhvyfwYr7v1jjv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527313; c=relaxed/simple; bh=vcYmsrJOWfPzE+KTUK50ZYnuiBcAecSsYwnN4BaRBo0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fdEreUnFN+B8kxvEASyL+RUJJtxzIQhWDDkCAJ0e/muoHgPgCEk71sfwfeitAQ735xmb82gPBbr/F4JBLDOyDSJ6DFj7kNSfxwQYSAmvCnWmVu86AHmivR/RAajl68gK9kCkn/UNxQDrRrQWNuZ9QX/lNBvmJPkFf6IKvBH8erQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt; spf=pass smtp.mailfrom=tecnico.ulisboa.pt; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b=S+gdGUao; arc=none smtp.client-ip=193.136.128.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b="S+gdGUao" Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTP id 4A4476000877; Tue, 27 Jan 2026 15:12:11 +0000 (WET) X-Virus-Scanned: by amavis-2.13.0 (20230106) (Debian) at tecnico.ulisboa.pt Received: from smtp1.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp1.tecnico.ulisboa.pt [127.0.0.1]) (amavis, port 10025) with LMTP id C_c04pEVdt2E; Tue, 27 Jan 2026 15:12:09 +0000 (WET) Received: from mail1.tecnico.ulisboa.pt (mail1.ist.utl.pt [193.136.128.10]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTPS id F05BB60022EA; Tue, 27 Jan 2026 15:12:08 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecnico.ulisboa.pt; s=mail2; t=1769526729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z4NnWV6yd5QghHP/nbiwEc5aw4U9XE9qIaLHOxudmmY=; b=S+gdGUaopdDzGGNligYh4mVmJKcPzKNJdzjZptEmtljoeDPaYPxH77vn+nR3qpmBms6Xx3 c7rEehUnD7tbZvbRJ4DWH+c3bGk//ZnCwGa5xDCka/AyMI1uYQrgH1vaATcpZpoifaeXzc YQjIZcZzlmSz3tWxf9HsUK2GFCz8vVswykEKxB7tts2hWzQ5BIyT4ws/qBO8w+ZfvSGeB5 4VBmCnrnI94nQUn5Qij2/LRlB/LT28s051FGbsl8kvjjul6p06MdOArWchZX4j/Fsz7sAf i7DCDBu/iqqDX+Ohuo6aoVFsm5poh3qnFZQGC3ffGFVCbr2WdsGAs23dKVTWzg== Received: from [192.168.2.110] (unknown [148.63.39.39]) (Authenticated sender: ist187313) by mail1.tecnico.ulisboa.pt (Postfix) with ESMTPSA id A3C653600FD; Tue, 27 Jan 2026 15:12:08 +0000 (WET) From: Diogo Ivo Date: Tue, 27 Jan 2026 15:11:49 +0000 Subject: [PATCH v2 3/6] phy: tegra: xusb: Fix ordering issue when switching roles on USB2 ports Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-diogo-tegra_phy-v2-3-787b9eed3ed5@tecnico.ulisboa.pt> References: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> In-Reply-To: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , JC Kuo , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, Diogo Ivo X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769526725; l=5656; i=diogo.ivo@tecnico.ulisboa.pt; s=20240529; h=from:subject:message-id; bh=vcYmsrJOWfPzE+KTUK50ZYnuiBcAecSsYwnN4BaRBo0=; b=SeiFWe/6BZMApaQ1jOCui6fb/63JZz31FZUD6Y7pNti/dVjxS+hyP4rKQrJfQWBuuF1zXjxwh wnpOx/K0UfqDhJM0carsgtjF45QM9m7QBw1pBBHzqa4mxDXYqShN+OF X-Developer-Key: i=diogo.ivo@tecnico.ulisboa.pt; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= The current implementation of USB2 role switching on Tegra relies on whichever the previous USB controller driver was using the PHY to first "yield" it back to USB_ROLE_NONE before the next controller configures it for the new role. However, no mechanism to guarantee this ordering was implemented, and currently, in the general case, the configuration functions tegra_xhci_id_work() and tegra_xudc_usb_role_sw_work() end up running in the same order regardless of the transition being HOST->DEVICE or DEVICE->HOST, leading to one of these transitions ending up in a non-working state due to the new configuration being clobbered by the previous controller driver setting USB_ROLE_NONE after the fact. Fix this by introducing a helper that waits for the USB2 port=E2=80=99s cur= rent role to become USB_ROLE_NONE and add it in the configuration functions above before setting the role to either USB_ROLE_HOST or USB_ROLE_DEVICE. The specific parameters of the helper function were determined based on my testing on a Tegra210 platform, Smaug, with some extra slack added in. With these parameters I never observed any timeout in role switching. As mentioned, this was tested on a Tegra210 platform. However, due to the similar approach in Tegra186 it is likely that not only this problem exists there but that this patch also fixes it. Signed-off-by: Diogo Ivo --- v1->v2: - Edit commit message and add code comment explaining origin of wait parameters in tegra_xusb_usb2_port_wait_role_none() - Export tegra_xusb_usb2_port_wait_role_none() - Fix NULL pointer dereference in error message - Remove extra blank line --- drivers/phy/tegra/xusb.c | 30 ++++++++++++++++++++++++++++++ drivers/usb/gadget/udc/tegra-xudc.c | 4 ++++ drivers/usb/host/xhci-tegra.c | 14 ++++++++++---- include/linux/phy/tegra/xusb.h | 1 + 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c index c89df95aa6ca..03fd6269fdbe 100644 --- a/drivers/phy/tegra/xusb.c +++ b/drivers/phy/tegra/xusb.c @@ -740,6 +740,36 @@ static void tegra_xusb_parse_usb_role_default_mode(str= uct tegra_xusb_port *port) } } =20 +/* + * Helper function that waits for the port's role to become USB_ROLE_NONE.= As the + * TRMs do not specify how long the transition is expected to take the sle= ep duration + * and number of retries were determined empirically on a Tegra210 platfor= m, with some + * extra slack added in. + */ +bool tegra_xusb_usb2_port_wait_role_none(struct tegra_xusb_padctl *padctl,= int index) +{ + struct tegra_xusb_usb2_port *usb2 =3D tegra_xusb_find_usb2_port(padctl, + index); + int retries =3D 5; + + if (!usb2) { + dev_err(padctl->dev, "no port found for USB2 lane %u\n", index); + return false; + } + + do { + if (usb2->role =3D=3D USB_ROLE_NONE) + return true; + + usleep_range(50, 60); + } while (retries--); + + dev_err(&usb2->base.dev, "timed out waiting for USB_ROLE_NONE"); + + return false; +} +EXPORT_SYMBOL_GPL(tegra_xusb_usb2_port_wait_role_none); + static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) { struct tegra_xusb_port *port =3D &usb2->base; diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/t= egra-xudc.c index 9d2007f448c0..24b0a9ce75d9 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -698,8 +698,12 @@ static void tegra_xudc_restore_port_speed(struct tegra= _xudc *xudc) =20 static void tegra_xudc_device_mode_on(struct tegra_xudc *xudc) { + int port =3D tegra_xusb_padctl_get_port_number(xudc->curr_utmi_phy); int err; =20 + if (!tegra_xusb_usb2_port_wait_role_none(xudc->padctl, port)) + return; + pm_runtime_get_sync(xudc->dev); =20 tegra_phy_xusb_utmi_pad_power_on(xudc->curr_utmi_phy); diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 927861ca14f2..b51afb4036b5 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -1352,15 +1352,21 @@ static void tegra_xhci_id_work(struct work_struct *= work) struct tegra_xusb_mbox_msg msg; struct phy *phy =3D tegra_xusb_get_phy(tegra, "usb2", tegra->otg_usb2_port); + enum usb_role role =3D USB_ROLE_NONE; u32 status; int ret; =20 dev_dbg(tegra->dev, "host mode %s\n", str_on_off(tegra->host_mode)); =20 - if (tegra->host_mode) - phy_set_mode_ext(phy, PHY_MODE_USB_OTG, USB_ROLE_HOST); - else - phy_set_mode_ext(phy, PHY_MODE_USB_OTG, USB_ROLE_NONE); + if (tegra->host_mode) { + if (!tegra_xusb_usb2_port_wait_role_none(tegra->padctl, + tegra->otg_usb2_port)) + return; + + role =3D USB_ROLE_HOST; + } + + phy_set_mode_ext(phy, PHY_MODE_USB_OTG, role); =20 tegra->otg_usb3_port =3D tegra_xusb_padctl_get_usb3_companion(tegra->padc= tl, tegra->otg_usb2_port); diff --git a/include/linux/phy/tegra/xusb.h b/include/linux/phy/tegra/xusb.h index 6ca51e0080ec..a0d3d5b7cf33 100644 --- a/include/linux/phy/tegra/xusb.h +++ b/include/linux/phy/tegra/xusb.h @@ -33,5 +33,6 @@ int tegra_xusb_padctl_disable_phy_sleepwalk(struct tegra_= xusb_padctl *padctl, st int tegra_xusb_padctl_enable_phy_wake(struct tegra_xusb_padctl *padctl, st= ruct phy *phy); int tegra_xusb_padctl_disable_phy_wake(struct tegra_xusb_padctl *padctl, s= truct phy *phy); bool tegra_xusb_padctl_remote_wake_detected(struct tegra_xusb_padctl *padc= tl, struct phy *phy); +bool tegra_xusb_usb2_port_wait_role_none(struct tegra_xusb_padctl *padctl,= int index); =20 #endif /* PHY_TEGRA_XUSB_H */ --=20 2.52.0 From nobody Mon Feb 9 16:36:32 2026 Received: from smtp1.tecnico.ulisboa.pt (smtp1.tecnico.ulisboa.pt [193.136.128.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 437DE35FF58; Tue, 27 Jan 2026 15:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.136.128.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527312; cv=none; b=Ilsev150w7fEibjL5qcS7GHulMj7hdHmovCB7y1Xh3X0dWSgoE92TotKBKnihvWMXUN3zJigKbcqwQxlpG2RyjZAz/HqiErLDojUEA6C7T1LqY7AJxtynFE8UASVFySC9lJ205gElWpW4zmg5JoiKYfpio3xMRFrvwS+G7Dk1TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527312; c=relaxed/simple; bh=WZilSxlFB7epi0aPRUnYdCJn7ILjtGGF0QOrx/FScJY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WbE7lhAxNxOxKCSuf3RV3z74ILDxZLxzrjLQOYIq8snxegMyiXHm7R6OTT3+oGuR4KjDOkhYv8NeDJuJf56psnBXJ1VS+Rfpz5/4N+jHSAPwp7aASW77doZzfVm9u4iR0R7hw+9vX87dZKbRujc8suPy4lqAw00jqaW0+7MvScc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt; spf=pass smtp.mailfrom=tecnico.ulisboa.pt; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b=PR+4ap7F; arc=none smtp.client-ip=193.136.128.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b="PR+4ap7F" Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTP id A531860020E3; Tue, 27 Jan 2026 15:12:11 +0000 (WET) X-Virus-Scanned: by amavis-2.13.0 (20230106) (Debian) at tecnico.ulisboa.pt Received: from smtp1.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp1.tecnico.ulisboa.pt [127.0.0.1]) (amavis, port 10025) with LMTP id CJAPZUso6mnf; Tue, 27 Jan 2026 15:12:09 +0000 (WET) Received: from mail1.tecnico.ulisboa.pt (mail1.ist.utl.pt [IPv6:2001:690:2100:1::b3dd:b9ac]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTPS id 42DC76001422; Tue, 27 Jan 2026 15:12:09 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecnico.ulisboa.pt; s=mail2; t=1769526729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p/MLeeQxVGvcYKcpkt+rdaf/nImropKuqiiYGTIb9iQ=; b=PR+4ap7FX9KspWZ5Myo2psscS0GjMZ8ksEebCwXWvbA6dT2OO+NPjokdW9UFGlwvYmz+3f rWZWh6rbToRgZQgT6+jWcJ84uUertGtTcfPBGCcd1uebT3unx+TzrJJaSBN0sqPhy8keOU AQ+Csjy5+UycPAivuaExuV04Sgq7x/MLbzo+AyiHfEM2ONkZNqxiJYXfDiigxVK/tDIcH2 TajDVegaJcRyAZSdag6jAKqJd3hppgJr4ux0KFUJgaHZdWeuGCVbGmMruSBJRHcupAU1ua PqXhAXRjbuhToekUbO5RyJrOGee8S8/efEYZ1gP/ftQr6RApJcNspxEmjAZLQA== Received: from [192.168.2.110] (unknown [148.63.39.39]) (Authenticated sender: ist187313) by mail1.tecnico.ulisboa.pt (Postfix) with ESMTPSA id E8B233600FE; Tue, 27 Jan 2026 15:12:08 +0000 (WET) From: Diogo Ivo Date: Tue, 27 Jan 2026 15:11:50 +0000 Subject: [PATCH v2 4/6] phy: tegra: xusb: Add ID override support to padctl Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-diogo-tegra_phy-v2-4-787b9eed3ed5@tecnico.ulisboa.pt> References: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> In-Reply-To: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , JC Kuo , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, Diogo Ivo X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769526725; l=3173; i=diogo.ivo@tecnico.ulisboa.pt; s=20240529; h=from:subject:message-id; bh=WZilSxlFB7epi0aPRUnYdCJn7ILjtGGF0QOrx/FScJY=; b=SSX8pTTLSNB0iUI793ypY55f5XwsHkMKA2+nJ6SI4/PlZVfdJhQvieS+7RfQ7kdaY/2sVln/A 1RYoYqcVBaUBBpo9i50imMu9Ol455+Ouqm1fNHW0BLrb+6sp7EWlayS X-Developer-Key: i=diogo.ivo@tecnico.ulisboa.pt; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= In preparation to move the XUSB PHY .set_mode() callback into a common implementation introduce a generic id_override callback in tegra_xusb_padctl_ops that delegates to a SoC-specific implementation and register Tegra210 with the new callback. Signed-off-by: Diogo Ivo --- v1->v2: - New patch --- drivers/phy/tegra/xusb-tegra210.c | 1 + drivers/phy/tegra/xusb.c | 10 ++++++++++ drivers/phy/tegra/xusb.h | 1 + include/linux/phy/tegra/xusb.h | 2 ++ 4 files changed, 14 insertions(+) diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-teg= ra210.c index 3abdf0182d67..be03a17afd7e 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -3262,6 +3262,7 @@ static const struct tegra_xusb_padctl_ops tegra210_xu= sb_padctl_ops =3D { .usb3_set_lfps_detect =3D tegra210_usb3_set_lfps_detect, .hsic_set_idle =3D tegra210_hsic_set_idle, .vbus_override =3D tegra210_xusb_padctl_vbus_override, + .id_override =3D tegra210_xusb_padctl_id_override, .utmi_port_reset =3D tegra210_utmi_port_reset, }; =20 diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c index 03fd6269fdbe..0443465bcf50 100644 --- a/drivers/phy/tegra/xusb.c +++ b/drivers/phy/tegra/xusb.c @@ -1498,6 +1498,16 @@ int tegra_xusb_padctl_set_vbus_override(struct tegra= _xusb_padctl *padctl, } EXPORT_SYMBOL_GPL(tegra_xusb_padctl_set_vbus_override); =20 +int tegra_xusb_padctl_set_id_override(struct tegra_xusb_padctl *padctl, + bool val) +{ + if (padctl->soc->ops->id_override) + return padctl->soc->ops->id_override(padctl, val); + + return -ENOTSUPP; +} +EXPORT_SYMBOL_GPL(tegra_xusb_padctl_set_id_override); + int tegra_phy_xusb_utmi_port_reset(struct phy *phy) { struct tegra_xusb_lane *lane =3D phy_get_drvdata(phy); diff --git a/drivers/phy/tegra/xusb.h b/drivers/phy/tegra/xusb.h index 273af147dfd3..08053a730d54 100644 --- a/drivers/phy/tegra/xusb.h +++ b/drivers/phy/tegra/xusb.h @@ -411,6 +411,7 @@ struct tegra_xusb_padctl_ops { int (*usb3_set_lfps_detect)(struct tegra_xusb_padctl *padctl, unsigned int index, bool enable); int (*vbus_override)(struct tegra_xusb_padctl *padctl, bool set); + int (*id_override)(struct tegra_xusb_padctl *padctl, bool set); int (*utmi_port_reset)(struct phy *phy); void (*utmi_pad_power_on)(struct phy *phy); void (*utmi_pad_power_down)(struct phy *phy); diff --git a/include/linux/phy/tegra/xusb.h b/include/linux/phy/tegra/xusb.h index a0d3d5b7cf33..116d0c6609cb 100644 --- a/include/linux/phy/tegra/xusb.h +++ b/include/linux/phy/tegra/xusb.h @@ -21,6 +21,8 @@ int tegra_xusb_padctl_usb3_set_lfps_detect(struct tegra_x= usb_padctl *padctl, unsigned int port, bool enable); int tegra_xusb_padctl_set_vbus_override(struct tegra_xusb_padctl *padctl, bool val); +int tegra_xusb_padctl_set_id_override(struct tegra_xusb_padctl *padctl, + bool val); void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy); void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy); int tegra_phy_xusb_utmi_port_reset(struct phy *phy); --=20 2.52.0 From nobody Mon Feb 9 16:36:32 2026 Received: from smtp2.tecnico.ulisboa.pt (smtp2.tecnico.ulisboa.pt [193.136.128.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57765366557; Tue, 27 Jan 2026 15:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.136.128.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527221; cv=none; b=BMCwzSEFwnzi9F65/4jVQNYZJl4OfQhGYlfITyvpAQ3sjlJBr0+JWUfqbBeL+HnI1IqUKu3T+0UXgH6Po/jQdp5JZZmY4Jkkb9MhKHdfT6vrHWRpkhA8GbuQEUn413WupkKabCuTq8S2jRkBnnHYLY4//LTpZTpt160z3NFT8pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769527221; c=relaxed/simple; bh=GuLPCfskwTOvgnNKi9cjUvTBN+Sa7OELObnaGrhYDbU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sPlWJeTFIsM982+ZOskfxRQ/0sYG7tBAj0/ry2lxQ27sMPs2KigAofBxaOD24vgdfLOsTHaakt4boXaHG/WM8EHRFPFdX+aYSjqpywg13QLt5XYPMLeFsPyZu9ELev/GYyAqIj/ddJcEYJ4XGNpLQBkNyHjIVmyUE3bp8+O8PQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt; spf=pass smtp.mailfrom=tecnico.ulisboa.pt; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b=iTejJR7s; arc=none smtp.client-ip=193.136.128.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b="iTejJR7s" Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.tecnico.ulisboa.pt (Postfix) with ESMTP id 29FDE2453EF; Tue, 27 Jan 2026 15:12:12 +0000 (WET) X-Virus-Scanned: by amavis-2.13.0 (20230106) (Debian) at tecnico.ulisboa.pt Received: from smtp2.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp2.tecnico.ulisboa.pt [127.0.0.1]) (amavis, port 10025) with LMTP id cj4eJioOxVXt; Tue, 27 Jan 2026 15:12:09 +0000 (WET) Received: from mail1.tecnico.ulisboa.pt (mail1.ist.utl.pt [193.136.128.10]) by smtp2.tecnico.ulisboa.pt (Postfix) with ESMTPS id 8F1842453EE; Tue, 27 Jan 2026 15:12:09 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecnico.ulisboa.pt; s=mail2; t=1769526729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xywWPSSJeE7/ySdTQdTarvhlOsXV6YLbYuG11kBglJk=; b=iTejJR7ssu6Khd9Vy/t+HAZNg4cQxLMgC4YrSCh3yQdxm2qcjcdkGpkrKtUDAhQkKK+hWn zQJjyQ+8h3rk590gvVuXgvFfgVwJIam98AcyRN0LAkG7JGhEhPk+hi+6oxk5Zro/+cm/Cn GpnpUwv8Fl7TgZI5D6wVeEhb6Vg1OAPGmuahdXVQdXxu3JikAledM688Gor0fmglrbe2p/ dd1ssMlqUmyK8QJeO4j5PLIMRYyzqp7sBWfSkxVJeAe4InCz6ErJkvI+07tkqJvr7Nuzfw SeT+lKvXbm7/7XaYwtM12/EfvEtRP3LiG47Mvu+Gp9t8YzdF8/MDNYs19HQb5Q== Received: from [192.168.2.110] (unknown [148.63.39.39]) (Authenticated sender: ist187313) by mail1.tecnico.ulisboa.pt (Postfix) with ESMTPSA id 3BCF13600DD; Tue, 27 Jan 2026 15:12:09 +0000 (WET) From: Diogo Ivo Date: Tue, 27 Jan 2026 15:11:51 +0000 Subject: [PATCH v2 5/6] phy: tegra: xusb: Move .set_mode() to a shared location Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-diogo-tegra_phy-v2-5-787b9eed3ed5@tecnico.ulisboa.pt> References: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> In-Reply-To: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , JC Kuo , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, Diogo Ivo X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769526726; l=4781; i=diogo.ivo@tecnico.ulisboa.pt; s=20240529; h=from:subject:message-id; bh=GuLPCfskwTOvgnNKi9cjUvTBN+Sa7OELObnaGrhYDbU=; b=171OfqnYPDcvwBjDnd3uexeGnD/275rBxLptc7VCceMdyqH3G9pYLltePOUhLvDE/JFrmg5BC 9KRdkzGVpL/Bj47BLUyGu1Qak6q8Na62KgkTC7pz+it7dKavNRvImEB X-Developer-Key: i=diogo.ivo@tecnico.ulisboa.pt; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= As both Tegra210 and Tegra186 can have a common XUSB .set_mode() implementation move it to a location where it can be used by both platforms. Move Tegra210 to this common implementation. While at it fix a typo in a comment. Signed-off-by: Diogo Ivo --- v1->v2: - New patch --- drivers/phy/tegra/xusb-tegra210.c | 43 +----------------------------------= ---- drivers/phy/tegra/xusb.c | 40 ++++++++++++++++++++++++++++++++++++ drivers/phy/tegra/xusb.h | 2 ++ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-teg= ra210.c index be03a17afd7e..14e24296641b 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -1910,47 +1910,6 @@ static int tegra210_xusb_padctl_id_override(struct t= egra_xusb_padctl *padctl, return 0; } =20 -static int tegra210_usb2_phy_set_mode(struct phy *phy, enum phy_mode mode, - int submode) -{ - struct tegra_xusb_lane *lane =3D phy_get_drvdata(phy); - struct tegra_xusb_padctl *padctl =3D lane->pad->padctl; - struct tegra_xusb_usb2_port *port =3D tegra_xusb_find_usb2_port(padctl, - lane->index); - int err =3D 0; - - mutex_lock(&padctl->lock); - - dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode); - - if (mode =3D=3D PHY_MODE_USB_OTG) { - if (submode =3D=3D USB_ROLE_HOST) { - tegra210_xusb_padctl_id_override(padctl, true); - - err =3D regulator_enable(port->supply); - } else if (submode =3D=3D USB_ROLE_DEVICE) { - tegra210_xusb_padctl_vbus_override(padctl, true); - } else if (submode =3D=3D USB_ROLE_NONE) { - /* - * When port is peripheral only or role transitions to - * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not - * be enabled. - */ - if (port->role =3D=3D USB_ROLE_HOST) - regulator_disable(port->supply); - - tegra210_xusb_padctl_id_override(padctl, false); - tegra210_xusb_padctl_vbus_override(padctl, false); - } - - port->role =3D submode; - } - - mutex_unlock(&padctl->lock); - - return err; -} - static int tegra210_usb2_phy_power_on(struct phy *phy) { struct tegra_xusb_lane *lane =3D phy_get_drvdata(phy); @@ -2174,7 +2133,7 @@ static const struct phy_ops tegra210_usb2_phy_ops =3D= { .exit =3D tegra210_usb2_phy_exit, .power_on =3D tegra210_usb2_phy_power_on, .power_off =3D tegra210_usb2_phy_power_off, - .set_mode =3D tegra210_usb2_phy_set_mode, + .set_mode =3D tegra_xusb_usb2_phy_set_mode, .owner =3D THIS_MODULE, }; =20 diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c index 0443465bcf50..2327275740f8 100644 --- a/drivers/phy/tegra/xusb.c +++ b/drivers/phy/tegra/xusb.c @@ -770,6 +770,46 @@ bool tegra_xusb_usb2_port_wait_role_none(struct tegra_= xusb_padctl *padctl, int i } EXPORT_SYMBOL_GPL(tegra_xusb_usb2_port_wait_role_none); =20 +int tegra_xusb_usb2_phy_set_mode(struct phy *phy, enum phy_mode mode, int = submode) +{ + struct tegra_xusb_lane *lane =3D phy_get_drvdata(phy); + struct tegra_xusb_padctl *padctl =3D lane->pad->padctl; + struct tegra_xusb_usb2_port *port =3D tegra_xusb_find_usb2_port(padctl, + lane->index); + int err =3D 0; + + mutex_lock(&padctl->lock); + + dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode); + + if (mode =3D=3D PHY_MODE_USB_OTG) { + if (submode =3D=3D USB_ROLE_HOST) { + tegra_xusb_padctl_set_id_override(padctl, true); + + err =3D regulator_enable(port->supply); + } else if (submode =3D=3D USB_ROLE_DEVICE) { + tegra_xusb_padctl_set_vbus_override(padctl, true); + } else if (submode =3D=3D USB_ROLE_NONE) { + /* + * When port is peripheral only or role transitions to + * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not + * enabled. + */ + if (port->role =3D=3D USB_ROLE_HOST) + regulator_disable(port->supply); + + tegra_xusb_padctl_set_id_override(padctl, false); + tegra_xusb_padctl_set_vbus_override(padctl, false); + } + + port->role =3D submode; + } + + mutex_unlock(&padctl->lock); + + return err; +} + static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) { struct tegra_xusb_port *port =3D &usb2->base; diff --git a/drivers/phy/tegra/xusb.h b/drivers/phy/tegra/xusb.h index 08053a730d54..36cc87ae757e 100644 --- a/drivers/phy/tegra/xusb.h +++ b/drivers/phy/tegra/xusb.h @@ -501,6 +501,8 @@ struct tegra_xusb_lane *tegra_xusb_find_lane(struct teg= ra_xusb_padctl *padctl, const char *name, unsigned int index); =20 +int tegra_xusb_usb2_phy_set_mode(struct phy *phy, enum phy_mode mode, int = submode); + #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SO= C) extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc; #endif --=20 2.52.0 From nobody Mon Feb 9 16:36:32 2026 Received: from smtp1.tecnico.ulisboa.pt (smtp1.tecnico.ulisboa.pt [193.136.128.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B00535D5E0; Tue, 27 Jan 2026 15:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.136.128.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526746; cv=none; b=lCVrjZ2S4AJ/jVgr/DBmcNLim5xSEhEpJ6JKSzY5IsXFdF9+xsO5uscGW4wx6nHIZk7KK0QSWjH04UTot8SSNYfkVjewIzNMOeNHS9jvB4vY/Wu2cpbJhIY9rIHEFIoy1DZ9Y1BhPvEr6VMxklXCv8u5sGLFeYAdL3ceG/y2FOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526746; c=relaxed/simple; bh=xJHxYT+TadYewpoKOTjiaran92WN2DeuJBljdTuOCy4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EEv63y79tYKvE85gA5QW6gX/nJ6t4sG0ftSymx/XSynaY7dZfgKi8QRsIjjFwyPsudmzxRmqenU6BFzVTB61/Eq+iQjaFnXfjKGVdN/0rQ6lFkf2Kt+sOuXsX0e3vcewFiyJBJE4D9Dy/37tguMChCzKYcnm5uvzB3FnM1vsYY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt; spf=pass smtp.mailfrom=tecnico.ulisboa.pt; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b=i3t8NFHO; arc=none smtp.client-ip=193.136.128.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tecnico.ulisboa.pt Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tecnico.ulisboa.pt header.i=@tecnico.ulisboa.pt header.b="i3t8NFHO" Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTP id E152F6002307; Tue, 27 Jan 2026 15:12:12 +0000 (WET) X-Virus-Scanned: by amavis-2.13.0 (20230106) (Debian) at tecnico.ulisboa.pt Received: from smtp1.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp1.tecnico.ulisboa.pt [127.0.0.1]) (amavis, port 10025) with LMTP id bTCuZ5QEIXsH; Tue, 27 Jan 2026 15:12:10 +0000 (WET) Received: from mail1.tecnico.ulisboa.pt (mail1.ist.utl.pt [IPv6:2001:690:2100:1::b3dd:b9ac]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTPS id D6DFE6000257; Tue, 27 Jan 2026 15:12:09 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecnico.ulisboa.pt; s=mail2; t=1769526729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bZcC7nVQPcaOVfYrZtm+vknrQUeM733TEL9ACJo10WQ=; b=i3t8NFHOtmH/eAyaSjIfAFwqblPVHBbcBsCy7WEwCTlp9jNJ6X/IQuMKuiZ+S7KjI5zfYS GNFV/MnGGz39XEwTZggQy1rN8DhRc1ttTIyQcJ3Iut3WnNhrREOn4ZWVF81EFfhIGr/Ewq B+FFDTYC9W445sZkkcQ4SCo0OwV38BSF6pfCEroVOiHhFKwWJCJA2x7PB+YYsRa4mEVTrJ XAGVTFWfedWHq8GC3MY/O61+Mlzt7JqW24dzUI9XEZnGJGtCrumjfE8qdDbpAyVnFrT1LG RbNc1gFBQNE9XGBqoWEA+RHA2pyGH2XOzS3nwvYZn4w5EeHqMiY/N14Xmj8lxA== Received: from [192.168.2.110] (unknown [148.63.39.39]) (Authenticated sender: ist187313) by mail1.tecnico.ulisboa.pt (Postfix) with ESMTPSA id 8711E3600A6; Tue, 27 Jan 2026 15:12:09 +0000 (WET) From: Diogo Ivo Date: Tue, 27 Jan 2026 15:11:52 +0000 Subject: [PATCH v2 6/6] phy: tegra: xusb: Move T186 .set_mode() to common implementation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260127-diogo-tegra_phy-v2-6-787b9eed3ed5@tecnico.ulisboa.pt> References: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> In-Reply-To: <20260127-diogo-tegra_phy-v2-0-787b9eed3ed5@tecnico.ulisboa.pt> To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , JC Kuo , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, Diogo Ivo X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769526726; l=4050; i=diogo.ivo@tecnico.ulisboa.pt; s=20240529; h=from:subject:message-id; bh=xJHxYT+TadYewpoKOTjiaran92WN2DeuJBljdTuOCy4=; b=gaXGWJCSZfLtbD9smDMa7VQ2DugogGFT2gb4MjcM5WKZvEh96PE0vSbkt8/rnsGicaYnaDmwo i+3AaC7EUlrCCSYfmE13tj6KQbGjysGrDqpcx4hAp/S8sTOHnXmZi0F X-Developer-Key: i=diogo.ivo@tecnico.ulisboa.pt; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= Move the Tegra186 PHY .set_mode() callback to a common implementation. In order to do this first revert cefc1caee9dd. Signed-off-by: Diogo Ivo --- v1->v2: - New patch --- drivers/phy/tegra/xusb-tegra186.c | 73 ++++++-----------------------------= ---- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/drivers/phy/tegra/xusb-tegra186.c b/drivers/phy/tegra/xusb-teg= ra186.c index bec9616c4a2e..bf678829245d 100644 --- a/drivers/phy/tegra/xusb-tegra186.c +++ b/drivers/phy/tegra/xusb-tegra186.c @@ -786,15 +786,13 @@ static int tegra186_xusb_padctl_vbus_override(struct = tegra_xusb_padctl *padctl, } =20 static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padc= tl, - struct tegra_xusb_usb2_port *port, bool status) + bool status) { - u32 value, id_override; - int err =3D 0; + u32 value; =20 dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear"); =20 value =3D padctl_readl(padctl, USB2_VBUS_ID); - id_override =3D value & ID_OVERRIDE(~0); =20 if (status) { if (value & VBUS_OVERRIDE) { @@ -805,68 +803,16 @@ static int tegra186_xusb_padctl_id_override(struct te= gra_xusb_padctl *padctl, value =3D padctl_readl(padctl, USB2_VBUS_ID); } =20 - if (id_override !=3D ID_OVERRIDE_GROUNDED) { - value &=3D ~ID_OVERRIDE(~0); - value |=3D ID_OVERRIDE_GROUNDED; - padctl_writel(padctl, value, USB2_VBUS_ID); - - err =3D regulator_enable(port->supply); - if (err) { - dev_err(padctl->dev, "Failed to enable regulator: %d\n", err); - return err; - } - } + value &=3D ~ID_OVERRIDE(~0); + value |=3D ID_OVERRIDE_GROUNDED; } else { - if (id_override =3D=3D ID_OVERRIDE_GROUNDED) { - /* - * The regulator is disabled only when the role transitions - * from USB_ROLE_HOST to USB_ROLE_NONE. - */ - err =3D regulator_disable(port->supply); - if (err) { - dev_err(padctl->dev, "Failed to disable regulator: %d\n", err); - return err; - } - - value &=3D ~ID_OVERRIDE(~0); - value |=3D ID_OVERRIDE_FLOATING; - padctl_writel(padctl, value, USB2_VBUS_ID); - } + value &=3D ~ID_OVERRIDE(~0); + value |=3D ID_OVERRIDE_FLOATING; } =20 - return 0; -} - -static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode, - int submode) -{ - struct tegra_xusb_lane *lane =3D phy_get_drvdata(phy); - struct tegra_xusb_padctl *padctl =3D lane->pad->padctl; - struct tegra_xusb_usb2_port *port =3D tegra_xusb_find_usb2_port(padctl, - lane->index); - int err =3D 0; - - mutex_lock(&padctl->lock); + padctl_writel(padctl, value, USB2_VBUS_ID); =20 - dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode); - - if (mode =3D=3D PHY_MODE_USB_OTG) { - if (submode =3D=3D USB_ROLE_HOST) { - err =3D tegra186_xusb_padctl_id_override(padctl, port, true); - if (err) - goto out; - } else if (submode =3D=3D USB_ROLE_DEVICE) { - tegra186_xusb_padctl_vbus_override(padctl, true); - } else if (submode =3D=3D USB_ROLE_NONE) { - err =3D tegra186_xusb_padctl_id_override(padctl, port, false); - if (err) - goto out; - tegra186_xusb_padctl_vbus_override(padctl, false); - } - } -out: - mutex_unlock(&padctl->lock); - return err; + return 0; } =20 static int tegra186_utmi_phy_power_on(struct phy *phy) @@ -1017,7 +963,7 @@ static const struct phy_ops utmi_phy_ops =3D { .exit =3D tegra186_utmi_phy_exit, .power_on =3D tegra186_utmi_phy_power_on, .power_off =3D tegra186_utmi_phy_power_off, - .set_mode =3D tegra186_utmi_phy_set_mode, + .set_mode =3D tegra_xusb_usb2_phy_set_mode, .owner =3D THIS_MODULE, }; =20 @@ -1578,6 +1524,7 @@ static const struct tegra_xusb_padctl_ops tegra186_xu= sb_padctl_ops =3D { .suspend_noirq =3D tegra186_xusb_padctl_suspend_noirq, .resume_noirq =3D tegra186_xusb_padctl_resume_noirq, .vbus_override =3D tegra186_xusb_padctl_vbus_override, + .id_override =3D tegra186_xusb_padctl_id_override, .utmi_pad_power_on =3D tegra186_utmi_pad_power_on, .utmi_pad_power_down =3D tegra186_utmi_pad_power_down, }; --=20 2.52.0