From patchwork Thu Apr 3 22:43:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 878148 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 4C8C8161320 for ; Thu, 3 Apr 2025 22:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743720199; cv=none; b=ndFVRBQbPp+imapbEXP6NHVGAL5rPHzxF4cOSL+4ew6qUmXQz+Oee1JJZYO5t4XbE/G8hocSqOidDfq8L652bdvxyxg8F5C0y2QYMi7EsYz6NBGEQxamI/kYYLwyv79nrvZRnSxsa2b29fP9AwOfrQW+7M7RNCGhm7xZB+NpMFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743720199; c=relaxed/simple; bh=/saiKlT+3nmRcPtPTyQ7Fq6w/dSPk17B+vlnsaZ2f04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kIxqDkrXmS7QDwNUsHNVdXf8Na6c90lQn7X3C9D/Z+0a1/r4VJbDB4VVbo65yogrJtzceVlCvuNiz4UEAlDROA8r2XWdRxyEP7zGCT07X9UXnDkHN26a6Uz96BLfbGxHqL2A+fBMqo0fJMTRmaEdVbHEWc1M5Rn1GCmQ1vVSZCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1u0THG-0000kC-33; Fri, 04 Apr 2025 00:43:14 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0THF-003AjT-12; Fri, 04 Apr 2025 00:43:13 +0200 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1u0THF-004aMT-0r; Fri, 04 Apr 2025 00:43:13 +0200 From: Michael Grzeschik Date: Fri, 04 Apr 2025 00:43:04 +0200 Subject: [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250404-ml-topic-tcpm-v1-1-b99f44badce8@pengutronix.de> References: <20250404-ml-topic-tcpm-v1-0-b99f44badce8@pengutronix.de> In-Reply-To: <20250404-ml-topic-tcpm-v1-0-b99f44badce8@pengutronix.de> To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1106; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=/saiKlT+3nmRcPtPTyQ7Fq6w/dSPk17B+vlnsaZ2f04=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBn7w8AB0xtDmVdQ63eqoS/5SMgGMx/cVpi2FNpP uJGVRcLnX6JAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZ+8PAAAKCRC/aVhE+XH0 qw/4D/9VtUPkv0vKOOuv9jvL/8fZLg8Q3h9mwuuT/7980eplpTU+4yhl5MrtTCob/AXEX+EVHn0 s93le7o29mERLkrPsWcsRRGG58KsDydZZODyU8SVO1r6eqDztEOSbSW5trLl5Vs/Qb0mQP8L5w9 1xCcCJPQqZJieoRLniMAJ7IkTHxH0RyW0uLuuYcZGM9xVhl2TnPsBNuS8hF4Hgn9aB6BL09p42Y m2beP342DermQ96pgJq0irNhgdS7SRHGNrxPy6e6SRNCZGojjqWamdDXw6j7T1APoDu3TVuFN39 NCU3F0u4BcF//5hl+x2/6uPgvbqu9QUJPf8O6aeB+p4TAcbUcg27sDLX4kPS6IO1zr4/ag7E+pV D53lbkijrJ89+DQeuc3wrh/e/CHWFI08iucSOhWH8ayTJSbRTRJQ9JlLwlbmCSWD3t/NgN/ZTY3 gJnLu4ADqW3CIg1vzDyMDrfoyw6Y6TLJbfasC4T5+k8eOdJU/APJWSrtf9mKV9et3iZwx5K+Le+ sjvAB18qkpD9kpMLTg9z+twTxAa/ajzuKKf3D6iVuXiiG84bU9HlPz+fyCn3Ul+NrJpXSwQt+Rw /XXUXRAOHILTHnIuyH6UAG4xgiP3fdBduRLMknwu1ubkhu1H9GGBWSmoeoG2T49b2JNCGsoMj9Y EeJMAsr/sBMbBaw== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org Since the function tcpm_acc_attach is not setting the data and role for for the sink case we extend it to check for it first. Signed-off-by: Michael Grzeschik --- drivers/usb/typec/tcpm/tcpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index a99db4e025cd0..839697c14265e 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4551,12 +4551,17 @@ static void tcpm_snk_detach(struct tcpm_port *port) static int tcpm_acc_attach(struct tcpm_port *port) { int ret; + enum typec_role role; + enum typec_data_role data; if (port->attached) return 0; - ret = tcpm_set_roles(port, true, TYPEC_SOURCE, - tcpm_data_role_for_source(port)); + role = tcpm_port_is_sink(port) ? TYPEC_SINK : TYPEC_SOURCE; + data = tcpm_port_is_sink(port) ? tcpm_data_role_for_sink(port) + : tcpm_data_role_for_source(port); + + ret = tcpm_set_roles(port, true, role, data); if (ret < 0) return ret; From patchwork Thu Apr 3 22:43:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 878149 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 4C9171A841E for ; Thu, 3 Apr 2025 22:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743720198; cv=none; b=hckprYkIl5XEjsOA0leXuk8H4klHXfO6mwB9j2iRqbLwKjfzzJkmwb4beZYTKo/CzXAj6p+gS9rDOXdRTZJNBsV/06hB4KW/8/v7O2U7XSL0vIrC4ydU/kIjTIeO5h7I4RE+CclLihv49TNFddj8SH7qQgau/gUJUl4DhLoP11s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743720198; c=relaxed/simple; bh=LYXJIzRnYdWGQG63lalgRJrJIO4AjB8nfLP/vU6Wr8g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hlw566icTQrmjGYfeDiVHMlIg34JepX96vUkVG/RP28PBmCxCLDlj2YKnXlffu246rkqnKF6t8IIyLReMNvqBAVPhUknRDxfk+uFX2/5N1mpumH1LMsXO5zn6wXN1rIXIg4hQznpgJru/me9PT2V+UncSD0XjhBkViyLYocmwb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1u0THG-0000kE-33; Fri, 04 Apr 2025 00:43:14 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0THF-003AjV-15; Fri, 04 Apr 2025 00:43:13 +0200 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1u0THF-004aMT-0s; Fri, 04 Apr 2025 00:43:13 +0200 From: Michael Grzeschik Date: Fri, 04 Apr 2025 00:43:05 +0200 Subject: [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250404-ml-topic-tcpm-v1-2-b99f44badce8@pengutronix.de> References: <20250404-ml-topic-tcpm-v1-0-b99f44badce8@pengutronix.de> In-Reply-To: <20250404-ml-topic-tcpm-v1-0-b99f44badce8@pengutronix.de> To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3938; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=LYXJIzRnYdWGQG63lalgRJrJIO4AjB8nfLP/vU6Wr8g=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBn7w8ABKLXszu7I3Ym9gFIxPtY8yQ26+DC+WKH7 yVXdha0y/mJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZ+8PAAAKCRC/aVhE+XH0 q1WED/wIIiuQbFJy7Qhejvw4D8q9hMOwncUlGZhfLTBTUHqJhWWy3nP+XJFxB5/h2EqkGKWgnA0 6JsxaGxAwPrQmaZ4CixjbBVSVQq/6UR3YNG5M04uvMGYjKjdDs8tBfsq/XQdYQvO7Vdc3eGf/W3 IFLVXuQg0cqBujG8EgvTSlr6Zf3Fy86kSNiDtuNWppytEuAirm0sFx+t+/pVfOnQOK4fxkewtd6 VnnpjB9gBaMTDbcwBXaJnPrNhXMGbIYKPGmcvIDspDxNiT9GhdW55dGYx36iXUSQJK3aXw0/lBi 6lftkPhaCIYAABzaEMEiLJnD/LYGkBmmZWURMPdrk1WQiYdELZD/Ao9kuKkkmXliV5amzvpYRKP 63PCZ6EeS4Pr33TxwbcrlCtIjhy5Vrg9YdIpNQ/x26+H9qSu8mtKZLjCChV4Q8/ISVZtbNCcReB 7jOxZyRJSiEwTfeu56FLeHKhvJfEPOm/rxwRNcMLVkFz24V+hbdFSVaPVsPcFiZpfPydNoFqN3K gRnQVD/rHtpiv4jXiB1lmdw4vlgJ0HzpRmEdZmgLxMkaOBf1VKlY3viE/hhkBm+sJ1p40rGEBPd 1KQuGZZtABjVc7C5Zddcw7V4xDUXxYQtTqvCA+qK+fPaFTHKy+oof/Qh8NIvFZwk8ltyKn0Tu+q M3SyYimtBIJe73w== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org This patch extends the is_debug macro to cover the sink case (ufp). It also handles the transition to access the DEBUG_ACC_ATTACHED state in the sink case. It also handles the debounce case in which the cc pins are not immediately valid after the plug event. Signed-off-by: Michael Grzeschik --- drivers/usb/typec/tcpm/tcpm.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 839697c14265e..01714a42f848a 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -67,6 +67,7 @@ \ S(ACC_UNATTACHED), \ S(DEBUG_ACC_ATTACHED), \ + S(DEBUG_ACC_DEBOUNCE), \ S(AUDIO_ACC_ATTACHED), \ S(AUDIO_ACC_DEBOUNCE), \ \ @@ -621,7 +622,8 @@ static const char * const pd_rev[] = { !tcpm_cc_is_source((port)->cc1))) #define tcpm_port_is_debug(port) \ - (tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) + ((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \ + (tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2))) #define tcpm_port_is_audio(port) \ (tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2)) @@ -4969,7 +4971,13 @@ 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 ((port->cc1 == TYPEC_CC_OPEN && + if (tcpm_port_is_debug(port)) + tcpm_set_state(port, DEBUG_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); + else if (tcpm_port_is_audio(port)) + tcpm_set_state(port, AUDIO_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); + else if ((port->cc1 == TYPEC_CC_OPEN && port->cc2 != TYPEC_CC_OPEN) || (port->cc1 != TYPEC_CC_OPEN && port->cc2 == TYPEC_CC_OPEN)) @@ -4983,6 +4991,12 @@ 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)) + tcpm_set_state(port, DEBUG_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); + else if (tcpm_port_is_audio(port)) + tcpm_set_state(port, AUDIO_ACC_ATTACHED, + PD_T_CC_DEBOUNCE); else if (port->vbus_present) tcpm_set_state(port, tcpm_try_src(port) ? SRC_TRY @@ -5281,7 +5295,10 @@ static void run_state_machine(struct tcpm_port *port) /* Accessory states */ case ACC_UNATTACHED: tcpm_acc_detach(port); - tcpm_set_state(port, SRC_UNATTACHED, 0); + if (port->port_type == TYPEC_PORT_SRC) + tcpm_set_state(port, SRC_UNATTACHED, 0); + else + tcpm_set_state(port, SNK_UNATTACHED, 0); break; case DEBUG_ACC_ATTACHED: case AUDIO_ACC_ATTACHED: @@ -5289,6 +5306,7 @@ static void run_state_machine(struct tcpm_port *port) if (ret < 0) tcpm_set_state(port, ACC_UNATTACHED, 0); break; + case DEBUG_ACC_DEBOUNCE: case AUDIO_ACC_DEBOUNCE: tcpm_set_state(port, ACC_UNATTACHED, port->timings.cc_debounce_time); break; @@ -5880,7 +5898,8 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, } break; case SNK_UNATTACHED: - if (tcpm_port_is_sink(port)) + if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) || + tcpm_port_is_sink(port)) tcpm_set_state(port, SNK_ATTACH_WAIT, 0); break; case SNK_ATTACH_WAIT: @@ -5943,7 +5962,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, case DEBUG_ACC_ATTACHED: if (cc1 == TYPEC_CC_OPEN || cc2 == TYPEC_CC_OPEN) - tcpm_set_state(port, ACC_UNATTACHED, 0); + tcpm_set_state(port, DEBUG_ACC_DEBOUNCE, 0); + break; + + case DEBUG_ACC_DEBOUNCE: + if (tcpm_port_is_debug(port)) + tcpm_set_state(port, DEBUG_ACC_ATTACHED, 0); break; case SNK_TRY: