From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 F2CF3221FB6 for ; Thu, 10 Sep 2026 02:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789006498; cv=none; b=uGokYbftKUQ7GwLt9Qp4lxC/R64Mk6aYud+n2nxR/E06p9ZYxX7nAoL+7kPuCyMZ6n8QKegAxxgYTY+i/CgEWuoUhVKebrn7Uy0OmXXcTeDOU/Cx2Lairk8MMkctXIGXxvFrLW+/RDBM4ioJ0XxnbFRKP7wDNs+ccUKXUH0whIM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789006498; c=relaxed/simple; bh=Y3kDIGKYo7JJiZtuWRDgFGEwAgDwFAg/L0LFmsQol9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aPDplZQPwbndCosUMJ9DnrF+/moDqmf+2+8/eI5PWrKvY5NoFBBYKnIqQ+8LXbk96Aq4i/OhNIIbl34ROywJQYZvx00uBslYQRo6w/qXwkMAGQNiJROxDhqayOU8BQNRbiKJWNofSTxC5q+dvKZWFIWtdwCoCXWg/pk5aYcW7sQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JpBQ6DNP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JpBQ6DNP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C999B1F000FF; Thu, 10 Sep 2026 02:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789006496; bh=4iFnjBdA2L+oW63TSwVpdl7ZkfCcjm7Kgi5DI0t1Wf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JpBQ6DNPriVUcMo7BV3rOde1Se2u6UefE5bWqKEUP6ySz8QSQTzBc1DkfTjUwUMmk MpllTtbIzS48fUbT5o3cjZ/81SKIfqN6FI8yHeGRE4rFubHI9FDCFXBnRylpYc1HX5 vaX8I45rlNYAO4DIE7ctmNV9P+S4t9nJqorEouZDPYuFGNR/wvkHuTus5izp71hhWA Uw7HIP1eqXkQIB487Wu9opOoaAOe4Y2jRjzeHTMg5y2Vv8k3bwOf8HunkeGKnvpAHG +wvgW8osYHDxyETYbrOY+F646tjUz/vdTDBo5C+lA2Z9+J/TyLu58bD8Xuf4kH4Q1f 4/h15Fe+0iSJw== From: Sasha Levin To: stable@vger.kernel.org Cc: Xu Yang , stable , Heikki Krogerus , Amit Sunil Dhamne , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.1.y 1/2] usb: typec: tcpm: fix debug accessory mode detection for sink ports Date: Wed, 9 Sep 2026 22:14:53 -0400 Message-ID: <20260910021454.3999749-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026090802-sauciness-bleach-95a1@gregkh> References: <2026090802-sauciness-bleach-95a1@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Xu Yang [ Upstream commit f6ec9bb4acc7182b25a793ad094a764e1cb819a7 ] The port in debug accessory mode can be either a source or sink. The previous tcpm_port_is_debug() function only checked for source port. Commit 8db73e6a42b6 ("usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug") changed the detection logic to support both roles, but left some logic in _tcpm_cc_change() unchanged, This causes the state machine to transition to an incorrect state when operating as a sink in debug accessory mode. Log as below: [ 978.637541] CC1: 0 -> 5, CC2: 0 -> 5 [state TOGGLING, polarity 0, connected] [ 978.637567] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS] [ 978.637596] pending state change SRC_ATTACH_WAIT -> DEBUG_ACC_ATTACHED @ 180 ms [rev1 NONE_AMS] [ 978.647098] CC1: 5 -> 0, CC2: 5 -> 5 [state SRC_ATTACH_WAIT, polarity 0, connected] [ 978.647115] state change SRC_ATTACH_WAIT -> SRC_ATTACH_WAIT [rev1 NONE_AMS] It should go to SNK_ATTACH_WAIT instead of SRC_ATTACH_WAIT state. To fix this, add tcpm_port_is_debug_source() and tcpm_port_is_debug_sink() helper to explicitly identify the power mode in debug accessory mode. Update the state transition logic in _tcpm_cc_change() to ensure the state machine transitions comply with Type-C specification. Also update the logic in run_state_machine() to keep consistency. Fixes: 8db73e6a42b6 ("usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug") Cc: stable Signed-off-by: Xu Yang Acked-by: Heikki Krogerus Reviewed-by: Amit Sunil Dhamne Link: https://patch.msgid.link/20260424074009.2979266-1-xu.yang_2@nxp.com Signed-off-by: Greg Kroah-Hartman [Backport to 6.12: This tree lacks 8db73e6a42b6 and the associated sink debug-accessory state-machine support. Retain only the source-debug macro extraction and source-side call-site updates. Keep tcpm_port_is_debug() source-only and omit the sink-debug macro and all sink/audio attachment transitions introduced by the upstream dependency. This preserves existing detection and state transitions while providing tcpm_port_is_debug_source() for cd3b9cea675b ("usb: typec: tcpm: constrain TCPM_SOURCING_VBUS event handling"). No functions are added.] Stable-dep-of: cd3b9cea675b ("usb: typec: tcpm: constrain TCPM_SOURCING_VBUS event handling") Signed-off-by: Sasha Levin --- drivers/usb/typec/tcpm/tcpm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 6969db16f07cc..6ff7d4dbaafe2 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -522,9 +522,12 @@ static const char * const pd_rev[] = { (tcpm_cc_is_source((port)->cc2) && \ !tcpm_cc_is_source((port)->cc1))) -#define tcpm_port_is_debug(port) \ +#define tcpm_port_is_debug_source(port) \ (tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) +#define tcpm_port_is_debug(port) \ + tcpm_port_is_debug_source(port) + #define tcpm_port_is_audio(port) \ (tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2)) @@ -4023,7 +4026,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK); break; case SRC_ATTACH_WAIT: - if (tcpm_port_is_debug(port)) + if (tcpm_port_is_debug_source(port)) tcpm_set_state(port, DEBUG_ACC_ATTACHED, PD_T_CC_DEBOUNCE); else if (tcpm_port_is_audio(port)) @@ -5035,7 +5038,7 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, switch (port->state) { case TOGGLING: - if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) || + if (tcpm_port_is_debug_source(port) || tcpm_port_is_audio(port) || tcpm_port_is_source(port)) tcpm_set_state(port, SRC_ATTACH_WAIT, 0); else if (tcpm_port_is_sink(port)) @@ -5043,7 +5046,7 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, break; case SRC_UNATTACHED: case ACC_UNATTACHED: - if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) || + if (tcpm_port_is_debug_source(port) || tcpm_port_is_audio(port) || tcpm_port_is_source(port)) tcpm_set_state(port, SRC_ATTACH_WAIT, 0); break; -- 2.53.0