From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 643262BDC26 for ; Thu, 14 May 2026 18:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.210.45 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778783898; cv=pass; b=MHhegQ1SNDMAA9saL6hYfAnmkqsYKpywWHRpQZTFXDhBjqVrQShgcuHajPOgn2bgHhJMrnBRT/4HF4eYsVc9lgp8L31duJhGCrzWYXBWtC5aOW74SQmYRXVvBGvC0c0YBbrzhcUJaBNW/6gtcp+ey4QSRluXX11OITYVHHpPmuM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778783898; c=relaxed/simple; bh=QmmK3gZXRGs6+Ov33ViGi5VndHouGarK1Vb3M71UiFM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=NJlAPWxiYS0NNFtRfzO70z5XwKcEs975Z/NoUhfAwV9oYE6iLBqixIZZ187o4pVQ6kcwNw7elwBfdTWSQhrUDkYdxf8AD8TO+NocXqE5Nvd45Tb9B/LXDnWKGE/YI28rMuL8blfavo8BXlWUBekp/tk1ZFbIe6l1Ysexhx+oSbk= ARC-Authentication-Results:i=2; 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=QOPEbyXU; arc=pass smtp.client-ip=209.85.210.45 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="QOPEbyXU" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7dca5f64e86so6582709a34.0 for ; Thu, 14 May 2026 11:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778783896; cv=none; d=google.com; s=arc-20240605; b=LwG0ZqKU0F7peY/VRYDeYgLSECYJIo0a5BlNpkBV7MoVC829+RLX2M1cJfflSiu5TU 2rVt/fK8lehZOsNFR+3UMYd/H3RnD9EGSTrbmO0C5gftKZiAOJ8WU1d3hPO5Vs6J0Odi 19kx6Vt18PnlfbzipohykeyQrZU0UeswUpMzpaK0/05D1HCHy7QdM69VOe7y3/YsRjz7 f2Fit+JN7iQDpmi0jGDdVvqi4GfC/wtcKxdWsH9N4G/s1pWeprd+ozY6qrkqXZWKPCkQ b6iYrP2QUfm2Lo+GNbMiKqKUvYOh6PE9hJMG0hFSp6NckbB92yL+E+ryk0RDqnJCLQE4 Y1bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8d3m45v6Iw/R68LfgUS67OuzNpSS1/BQBBitSivrqSE=; fh=Hi+/Fz1wnVSMnUqYYLHOf5ZbQqnI+HemUoHwW0E9fJE=; b=Xqnwqtjoi5Azh1E9QkgBk8mBUptHLedNt9gXt8P3Xj3SDiP3Au4Bx8LZPUeN5LgtbC o+uGqS4InzyhH9i9+k9phkE1RfWeLrGxuvRYF52MMf2rw6Cs0J5weDHpubkbmWuk5Uxj Ccz0u1r/BokhqR96E3hlcSmkbc7zO4pvpqW9pyLtnMD8pSiMzzGlcr8eIXSAzzTUBbUq clpoaFADuGboDnICThcBU/b8KDxTfgZw5sutDR623bU02jvD8gM4pyQR2khZ6RTGaCZj ACE7Y3Q/9l0ePmrq5b8S4Coh2kVwsJ3SklWLCDehjYxYE5iA6UqrroXuvqnCz+h2oD2/ LzVg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778783896; x=1779388696; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8d3m45v6Iw/R68LfgUS67OuzNpSS1/BQBBitSivrqSE=; b=QOPEbyXUN9AtspgiutVp515+/SiqtiEcQoKK8wUdKV8yBY3/sEIOcDR61oqAipKuAU MijtJZyhlJ4qC4w3xnUFKR7nJIWFGRZa+FFnWcbsRebXgpG7wPeycOklD0eC9ICvn1Y7 aBR00hjBGya3bailIrPC5vFfzPoHMjzE3w5KIGb31+kojgRNAiZhqtEDVt2OKEdkws/S oQVjEJfIPK+kg8CEaM9q5MM4oon+mux8k1LacgvSny4gZFL3/vqLPXsdxEGDJ1345SHG hgDabuM0ZjKWEDSlimPc6ALWGDyMnyEeEMomQStncAPDktinJ8jK3CJRDWOhwJwNcMJl 2nfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778783896; x=1779388696; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8d3m45v6Iw/R68LfgUS67OuzNpSS1/BQBBitSivrqSE=; b=CXRolBf4DSdzfbk5dgoydtMqqyjj8uDkot5q4sI2bdai6lzHFJvLKzKbPZd/kMX/lD Yf0oaqNyOV9og8q+9NVkVxtdEmIDLvgEv1REu39RCp3foUOTqzfcj4f1LJpuJC9TdeB2 qJ3OdCbne+Pr/fbA81fwMpnB4tVcGLSV3BBj3q64MW9FqPu4PeDlpmZI1YMCnHfRhTff azYIXlAO/WCDbw+J3+i6AcAsfUaSWGpWMh/bumOC4jPJ28V9kNSEHlQHNnmgLkbk+axD DTZKyiJsrpLiFFXkaPg8g7aMhpEUOXyGF+T091pMojv274SNZuMAZ6jj3xeDrRBpbMPZ XhGw== X-Forwarded-Encrypted: i=1; AFNElJ+0OrdWMn33z8KphOri7wm3atxys7CutfJiwNHyQh9ikAaxh2/X9qrYWqlICkOQnN/lbvCl5oXP6DCfKcM=@vger.kernel.org X-Gm-Message-State: AOJu0YzWZz1UUng+50IBI6muTnWsKJQwrj3JPAq83f/y+do1ubxAEByv 9xv1QvPw+d8jCRLFm/lRcxZ6mvoQdKduw/TKXy76vBca7Zuqqbl6qgVrR5EA1k0FWQpbeVEeV/p 7p0+fjPw/7BaGGWWpjCkwUz+2EFqbu3WCkmaL8vYs X-Gm-Gg: Acq92OFL6VdHrJ9guRqc8oz8gwfkyY1eWZhMfmd1xeMP1Vxs/hXKPeWVBMi1ZA4bTKL qowZdwiBI30zrIa6cwpEy527nhzYc4sLLowA6uqvZSMHQPgQYrEiiYzJtJmGcPBY589Bwwfnf6C 3uDxdn1G57Oytciu56GD9gcgQQNLNOysiQIhieehNl4sZD/nsLx690+AqzdVm6g1brF1A9Fg135 tlcFtYk5qH9vlaD47lf+HbW5nE4aNhuzQYJNq78kmDNZv1PqeOhGh7GShyDvYgX+n4Pvbq+v9oF 041i+kqkD9/JTb54u4GN1Z9jB67a0JvobUErA1lYQKKd0ObI X-Received: by 2002:a05:6820:221e:b0:694:9a0a:6fa9 with SMTP id 006d021491bc7-69c94319189mr457604eaf.26.1778783895868; Thu, 14 May 2026 11:38:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260424074009.2979266-1-xu.yang_2@nxp.com> In-Reply-To: From: Badhri Jagan Sridharan Date: Thu, 14 May 2026 11:37:38 -0700 X-Gm-Features: AVHnY4KBVyf-SG8Xkj5bjhwsikanhfJWOZBg7c_1lmiP6TpWVoU1BDbUjw6MAe0 Message-ID: Subject: Re: [PATCH v2] usb: typec: tcpm: fix debug accessory mode detection for sink ports To: Heikki Krogerus Cc: Xu Yang , gregkh@linuxfoundation.org, m.grzeschik@pengutronix.de, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 27, 2026 at 2:33=E2=80=AFAM Heikki Krogerus wrote: > > On Fri, Apr 24, 2026 at 03:40:09PM +0800, 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 role= s, > > but left some logic in _tcpm_cc_change() unchanged, This causes the sta= te > > 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, co= nnected] > > [ 978.637567] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS] > > [ 978.637596] pending state change SRC_ATTACH_WAIT -> DEBUG_ACC_ATTACH= ED @ 180 ms [rev1 NONE_AMS] > > [ 978.647098] CC1: 5 -> 0, CC2: 5 -> 5 [state SRC_ATTACH_WAIT, polarit= y 0, connected] > > [ 978.647115] state change SRC_ATTACH_WAIT -> SRC_ATTACH_WAIT [rev1 NO= NE_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_sin= k() > > helper to explicitly identify the power mode in debug accessory mode. > > Update the state transition logic in _tcpm_cc_change() to ensure the st= ate > > machine transitions comply with Type-C specification. Also update the l= ogic > > 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 > > FWIW: > > Acked-by: Heikki Krogerus Reviewed-by: Badhri Jagan Sridharan > > > --- > > 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/tcp= m.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[] =3D { > > (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 *p= ort) > > 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 *p= ort) > > 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 *p= ort) > > 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 *p= ort, 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_si= nk(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 *po= rt, 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 *por= t, 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(p= ort) || > > tcpm_port_is_sink(port)) > > tcpm_set_state(port, SNK_ATTACH_WAIT, 0); > > break; > > -- > > 2.34.1 > > thanks, > > -- > heikki