mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Grzeschik <m.grzeschik@pengutronix.de>
To: Badhri Jagan Sridharan <badhri@google.com>,
	 Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Michael Grzeschik <m.grzeschik@pengutronix.de>
Subject: [PATCH] usb: typec: tcpm: detect orientation in debug acc mode
Date: Mon, 05 May 2025 13:06:16 +0200	[thread overview]
Message-ID: <20250505-tcpm-v1-1-e6142985a012@pengutronix.de> (raw)

For the debug accessory case, the orientation can be detected by reading
the cc resistor values. The will be TYPEC_CC_RP_DEF and TYPEC_CC_RP_1_5
in sink mode and TYPEC_CC_RA TYPEC_CC_RD in src mode.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
 drivers/usb/typec/tcpm/tcpm.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 784fa23102f90..478e9c80fc8c2 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -611,6 +611,12 @@ static const char * const pd_rev[] = {
 #define tcpm_port_is_sink(port) \
 	(tcpm_cc_is_sink((port)->cc1) || tcpm_cc_is_sink((port)->cc2))
 
+#define tcpm_port_is_debug_pol_cc1(port) \
+	((tcpm_port_is_sink(port) && \
+	 (port->cc2 == TYPEC_CC_RP_DEF && port->cc1 == TYPEC_CC_RP_1_5)) || \
+	 (!tcpm_port_is_sink(port) && \
+	 (port->cc2 == TYPEC_CC_RA && port->cc1 == TYPEC_CC_RD)))
+
 #define tcpm_cc_is_source(cc) ((cc) == TYPEC_CC_RD)
 #define tcpm_cc_is_audio(cc) ((cc) == TYPEC_CC_RA)
 #define tcpm_cc_is_open(cc) ((cc) == TYPEC_CC_OPEN)
@@ -4569,8 +4575,11 @@ static int tcpm_acc_attach(struct tcpm_port *port)
 	if (tcpm_port_is_audio(port))
 		state = TYPEC_MODE_AUDIO;
 
-	if (tcpm_port_is_debug(port))
+	if (tcpm_port_is_debug(port)) {
+		port->polarity = tcpm_port_is_debug_pol_cc1(port) ?
+					TYPEC_POLARITY_CC1 : TYPEC_POLARITY_CC2;
 		state = TYPEC_MODE_DEBUG;
+	}
 
 	ret = tcpm_set_roles(port, true, state, role, data);
 	if (ret < 0)

---
base-commit: 588d032e9e566997db3213dee145dbe3bda297b6
change-id: 20250505-tcpm-41b4ba7ea0ec

Best regards,
-- 
Michael Grzeschik <m.grzeschik@pengutronix.de>


             reply	other threads:[~2025-05-05 11:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 11:06 Michael Grzeschik [this message]
2025-05-05 11:21 ` Greg Kroah-Hartman
2025-05-05 11:27   ` Michael Grzeschik
2025-05-05 13:06     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250505-tcpm-v1-1-e6142985a012@pengutronix.de \
    --to=m.grzeschik@pengutronix.de \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®