From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70C86344DB7 for ; Fri, 24 Apr 2026 21:24:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777065892; cv=none; b=VZ40UbMybcBdlQ9/wMxMVcJy7O5jxdDi6a34t53oDoXlz2/XxbU6IE5F1/sPYU6Kj2ykh4RYpz0hEdTAA0xBDLQk3fBCv+u8X9NV1oE/2cnd8ndp+abf7Q/VomjK4afSJEQmr4X4m62Qydg1PPzxhxBzyUD4ygVq0/nH6atlma8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777065892; c=relaxed/simple; bh=OOvCfNvP/t9snDp0xVHuGAvs/3wkRapGCm8Nkw6btaI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FGYBy88zLgx4k+eNubTRI/UhQCwygIHNy20bxNdhmZdjsyrVpqShXPdjgIk1dl5Uo8IWDfkOewOtUylE9tKBhPt19OpnZ3szk+5cyr7/wlF6RUZK+VUy89NRoh9umiiBdHzJ3SoULVz9WexBkxlfhZaiHMimJm/LPrNNTzkDMUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dY/+1xtx; arc=none smtp.client-ip=209.85.210.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dY/+1xtx" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-7dccb8644c4so2729281a34.0 for ; Fri, 24 Apr 2026 14:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777065889; x=1777670689; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=iJNaihlk3IRG5/RkBM+hnzAM1yk0Bb5wvtfDGLFoLmg=; b=dY/+1xtx+SuuEEFMy/nyh1hV0VYfqpre0zlY6Bale8cZz0M3edtnJlFm5fXXU9U6Bq wWknaXzBWyFeiNwkYLWzb/s2+Vgufruy/D5AiBRb+l4D7q+2veCOoBMPmBt0qwRObXXD B9IlaiBBgNbxTvKpwUt6Ht8H28aBqv1U9h08epaK92kdYeAi0BikoLoSBXrn8wYilOS7 9IAfX83cFuRWTjVfAhRIMTRMf8OKg0mwd3B73rriWJ0EATF4mSnVqcgHmhHNJ7igo0Qc FhPux1joKW+DLHLuzXrHq9oQ7gEt4YEJ1PDUkKhLBfVB4Z5gYxcr2dRdCNJgUi50mJA/ W1jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777065889; x=1777670689; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iJNaihlk3IRG5/RkBM+hnzAM1yk0Bb5wvtfDGLFoLmg=; b=OL3B+QiNfelNjM4/V8wbppc8WM4Jfjl1VhWfRsuZE1BypZOitBF1ulK7Qpq0UbwCGA 1ngrAiGuAr10sdj2DIYhPmWUdRQNXnFhbnj7rYBTAWt3/TabOa5RRaUfSPbf1BX5+JrW kyfUW2uazaa492XILU5h2jA7MNMmJq+tZnSZOboqi7iUH9XU4HFeqD2rZJVWlg6GehYe NxjUP1ERxtlanyVjWI9KMV+fm6uAw5LZgy7sHd835+grPN8AKURgzjzLYWr3ntzffme+ Dzam0I2Y/cLjyXbUJEJ+RL96rCl/SoH/agn1KupKWQysk4tsCwzDASxiwMGndK/mtXhh 9Hog== X-Forwarded-Encrypted: i=1; AFNElJ8aYAs3GeIFkW7JNP2lSU8rzqr1m0XsVLh4+W1JSgy+xQPA9j8ywUyhwqtxTyaUVAW8Pb7gM95TC2ASaK4=@vger.kernel.org X-Gm-Message-State: AOJu0YwfZWLtYE/iH3ZvTgjqtRTxsjD3HLgx+zpQCgVfPn/vEnthYouY W9C5t1MciJr3tM3npMssZ+cy+wXcA5nFiivcTQZpyjeMjVsZGxdq3qAxLRtrVPvhEQ== X-Gm-Gg: AeBDiesXLnsdgMMB3mXrp1r/oqp22GEv+fa4vI4GadutXado3SY3JXKTBo96k3jVns4 aKzWyVqwl8jicU5SzRfm8kuZ7qJ8cK0WQ7w6+9Tv/4kj1kv5hSqdSKTkaryCnowOCabRBXe2Y5u BC5QpOX2vnSQYRg4Enk4D1qffa9p/wSSeXNVa4PosZNylibWe+DpGVmHD+5xHjtbdtZEuhq346v Fk/99Lc77eBymqxDhKZO3yiY1cS9Cjyt/fm8/sjOSf/+UF+1fpaLKp5hv+dy/cSCbRlI2s4fohE 6eIrRxV2HNaS5hlcdeI1gmCodgNHacObm+iZEsZd173MN/btC3mhWgQ9GCGkeEY6OzEVnhRjHMs KAq/98aYchOmRjqzcC4cBrZhaV0DYhohZY157v3VW5eSyUiISH1AtmJOgtWR2BVsXbTT4xzK5WM bYkM9aES0t2wcnoRx8o6yTjuVlWL+X/m2cUxovTBZHgDOLpBUgnCT3LBVQGfUB/ueoKkxBB5H23 IF1JyLLDPnyuuYHA3/G X-Received: by 2002:a05:6820:f026:b0:694:97ca:9ecf with SMTP id 006d021491bc7-69497caa1abmr10550455eaf.31.1777065888893; Fri, 24 Apr 2026 14:24:48 -0700 (PDT) Received: from ?IPV6:2600:1700:4570:89a0:8f46:c3fb:92e2:2f40? ([2600:1700:4570:89a0:8f46:c3fb:92e2:2f40]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-69489e52aacsm9895971eaf.9.2026.04.24.14.24.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Apr 2026 14:24:48 -0700 (PDT) Message-ID: <79039de4-aa33-430c-b004-ae98b2541f63@google.com> Date: Fri, 24 Apr 2026 14:24:44 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] usb: typec: tcpm: fix debug accessory mode detection for sink ports To: Xu Yang , badhri@google.com, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, m.grzeschik@pengutronix.de Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com References: <20260424074009.2979266-1-xu.yang_2@nxp.com> From: Amit Sunil Dhamne Content-Language: en-US In-Reply-To: <20260424074009.2979266-1-xu.yang_2@nxp.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/24/26 12:40 AM, Xu Yang wrote: > 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@vger.kernel.org > Signed-off-by: Xu Yang Reviewed-by: Amit Sunil Dhamne BR, Amit > > --- > Changes in v2: > - update tcpm_port_is_debug() in run_state_machine() as well > as suggested by Amit > --- > drivers/usb/typec/tcpm/tcpm.c | 25 ++++++++++++++++--------- > 1 file changed, 16 insertions(+), 9 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index dfbb94ddc98a..6d258efae6f0 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -732,9 +732,14 @@ static const char * const pd_rev[] = { > (tcpm_cc_is_source((port)->cc2) && \ > !tcpm_cc_is_source((port)->cc1))) > > +#define tcpm_port_is_debug_source(port) \ > + (tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) > + > +#define tcpm_port_is_debug_sink(port) \ > + (tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2)) > + > #define tcpm_port_is_debug(port) \ > - ((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \ > - (tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2))) > + (tcpm_port_is_debug_source(port) || tcpm_port_is_debug_sink(port)) > > #define tcpm_port_is_audio(port) \ > (tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2)) > @@ -5176,7 +5181,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, > port->timings.cc_debounce_time); > else if (tcpm_port_is_audio(port)) > @@ -5434,7 +5439,7 @@ static void run_state_machine(struct tcpm_port *port) > tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC); > break; > case SNK_ATTACH_WAIT: > - if (tcpm_port_is_debug(port)) > + if (tcpm_port_is_debug_sink(port)) > tcpm_set_state(port, DEBUG_ACC_ATTACHED, > PD_T_CC_DEBOUNCE); > else if (tcpm_port_is_audio(port)) > @@ -5454,7 +5459,7 @@ static void run_state_machine(struct tcpm_port *port) > if (tcpm_port_is_disconnected(port)) > tcpm_set_state(port, SNK_UNATTACHED, > PD_T_PD_DEBOUNCE); > - else if (tcpm_port_is_debug(port)) > + else if (tcpm_port_is_debug_sink(port)) > tcpm_set_state(port, DEBUG_ACC_ATTACHED, > PD_T_CC_DEBOUNCE); > else if (tcpm_port_is_audio(port)) > @@ -6360,10 +6365,10 @@ 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)) > + else if (tcpm_port_is_debug_sink(port) || tcpm_port_is_sink(port)) > tcpm_set_state(port, SNK_ATTACH_WAIT, 0); > break; > case CHECK_CONTAMINANT: > @@ -6371,9 +6376,11 @@ 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); > + else if (tcpm_port_is_debug_sink(port)) > + tcpm_set_state(port, SNK_ATTACH_WAIT, 0); > break; > case SRC_ATTACH_WAIT: > if (tcpm_port_is_disconnected(port) || > @@ -6395,7 +6402,7 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, > } > break; > case SNK_UNATTACHED: > - if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) || > + if (tcpm_port_is_debug_sink(port) || tcpm_port_is_audio(port) || > tcpm_port_is_sink(port)) > tcpm_set_state(port, SNK_ATTACH_WAIT, 0); > break;