From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 6C6B83314D0 for ; Thu, 23 Apr 2026 22:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776984657; cv=none; b=D5k6RIfKTi3xU6lx2QaZ8FD64lFWVOrERoJfmmDyBmCp2uBtG1VG8Lghb73t/oF/RLfx+/4o1rNkww/T+0YB1maRwWhp4t4Wg6zANJIa01eZblN4YPSW5xkO+V/7mlsxPcjxB9ZMOd+GsrDo1kgD2btBzqPJvDRdPbOtiL2S0zk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776984657; c=relaxed/simple; bh=sBD6hfqqD5vDkj/PJwKkm6tZsvxEyPBUfmc+YlBlfto=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ea1a9c0Y+tx3WtPBvWgdje0b2lBJLHxim13TD8oawGW6cqIOZCvfm9A0Xd76FuPD6Mm9Dw/JXKj8T/8KKociRF1OPy4TE9Mf38TWSJeSi0HXtbck6vd/08tLenCjR2uMQVGMCCeLSKzWmwe34pFaWK4EVcv1wswen2ZWC0MAWaU= 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=oEFWk4kb; arc=none smtp.client-ip=74.125.82.176 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="oEFWk4kb" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-2b6b0500e06so11536313eec.1 for ; Thu, 23 Apr 2026 15:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776984654; x=1777589454; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=lMXf2gnDkRB+s69+bOFp0A+RG1TpxXUu3x/474wh+4M=; b=oEFWk4kb9Y+LpS2lovqmq2xpNyf1AMEppZm6EoS2eSuvAs3sHB+31EjccXeXn1r8Mm /ehvnFLlDulsiw0h9ah4pP/jFrHB/z8w/nMQcbH4x/NzWaR5mizGidbOh7X9j+r7pc4y Zr9szlMaYiufXY1WwGnzct5yPok27ORhmXgTwK01fjuC7uIg45Tyo2e+xkNHTLq/F+LT WmIHSb9qHNQQ0awVbUBBBUztXTkf1CwkoVm2YQ3X/M1/PHky4AF3CTpJ05QmeGJKjSDh jZIZAWRtZQUcANs1YUlT90bB4TO4x+T3mxmW/GmBGSs1SfnIv1pID4i4LE2idACC262X LOFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776984654; x=1777589454; h=content-transfer-encoding:in-reply-to:from:content-language :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=lMXf2gnDkRB+s69+bOFp0A+RG1TpxXUu3x/474wh+4M=; b=YDTgswQb5EWN2+M5PITWQ7G6ONzFKUt2XmaFz7NC8EP/9bmjhUf2xxQEcfwuc/DSHD djOiu4Pofkf53Ho/A8PT3DI/lMiKPj+keMcOUkFt68mA6NT7Cw6Tgd6GeESd3s0bUx2b afkTE/3/YsM7G4LO8gW/5pqGcVFF3zzNZLA+zq0R9W8jc+6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657714d1mr15215495eec.12.1776984653739; Thu, 23 Apr 2026 15:50:53 -0700 (PDT) Received: from ?IPV6:2a00:79e0:2e7c:8:5cd3:e624:64db:3649? ([2a00:79e0:2e7c:8:5cd3:e624:64db:3649]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e53d2cff04sm28541858eec.23.2026.04.23.15.50.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Apr 2026 15:50:53 -0700 (PDT) Message-ID: Date: Thu, 23 Apr 2026 15:50:51 -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] 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: <20260420030317.425022-1-xu.yang_2@nxp.com> Content-Language: en-US From: Amit Sunil Dhamne In-Reply-To: <20260420030317.425022-1-xu.yang_2@nxp.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Xu, On 4/19/26 8:03 PM, 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. > > Fixes: 8db73e6a42b6 ("usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug") > Cc: stable@vger.kernel.org > Signed-off-by: Xu Yang > --- > drivers/usb/typec/tcpm/tcpm.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index dfbb94ddc98a..1ee00025de56 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)) > @@ -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; Thanks for submitting the patch. Please can you also add changes in run_state_machine()? I think we can replace tcpm_port_is_debug() in SNK_ATTACH_WAIT case with tcpm_port_is_debug_sink(). Also, similar changes for SRC_ATTACH_WAIT case. BR, Amit