linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Badhri Jagan Sridharan <badhri@google.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Badhri Jagan Sridharan <badhri@google.com>
Subject: [PATCH v6 03/14] usb: typec: tcpci: update ROLE_CONTROL for DRP
Date: Mon, 31 Aug 2020 19:59:16 -0700	[thread overview]
Message-ID: <20200901025927.3596190-4-badhri@google.com> (raw)
In-Reply-To: <20200901025927.3596190-1-badhri@google.com>

ROLE_CONTROL register would not have the actual CC terminations
unless the port does not set ROLE_CONTROL.DRP. For DRP ports,
CC_STATUS.cc1/cc2 indicates the final terminations applied
when TCPC enters potential_connect_as_source/_sink.
For DRP ports, infer port role from CC_STATUS and set corresponding
CC terminations before setting the orientation.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
Changes since v1:
 - Changing patch version to v6 to fix version number confusion.
---
 drivers/usb/typec/tcpm/tcpci.c | 37 +++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 7d36d5e2d3f7..7d9491ba62fb 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -191,12 +191,47 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
 	unsigned int reg;
 	int ret;
+	enum typec_cc_status cc1, cc2;
 
-	/* Keep the disconnect cc line open */
+	/* Obtain Rp setting from role control */
 	ret = regmap_read(tcpci->regmap, TCPC_ROLE_CTRL, &reg);
 	if (ret < 0)
 		return ret;
 
+	ret = tcpci_get_cc(tcpc, &cc1, &cc2);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * When port has drp toggling enabled, ROLE_CONTROL would only have the initial
+	 * terminations for the toggling and does not indicate the final cc
+	 * terminations when ConnectionResult is 0 i.e. drp toggling stops and
+	 * the connection is resolbed. Infer port role from TCPC_CC_STATUS based on the
+	 * terminations seen. The port role is then used to set the cc terminations.
+	 */
+	if (reg & TCPC_ROLE_CTRL_DRP) {
+		/* Disable DRP for the OPEN setting to take effect */
+		reg = reg & ~TCPC_ROLE_CTRL_DRP;
+
+		if (polarity == TYPEC_POLARITY_CC2) {
+			reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT);
+			/* Local port is source */
+			if (cc2 == TYPEC_CC_RD)
+				/* Role control would have the Rp setting when DRP was enabled */
+				reg |= TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+			else
+				reg |= TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT;
+		} else {
+			reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT);
+			/* Local port is source */
+			if (cc1 == TYPEC_CC_RD)
+				/* Role control would have the Rp setting when DRP was enabled */
+				reg |= TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+			else
+				reg |= TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT;
+		}
+	}
+
 	if (polarity == TYPEC_POLARITY_CC2)
 		reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT;
 	else
-- 
2.28.0.402.g5ffc5be6b7-goog


  parent reply	other threads:[~2020-09-01  2:59 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01  2:59 [PATCH v6 00/14] TCPM support for FRS and AutoDischarge Disconnect Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 01/14] usb: typec: tcpci: Add register definitions to tcpci Badhri Jagan Sridharan
2020-09-15 12:10   ` Heikki Krogerus
2020-09-01  2:59 ` [PATCH v6 02/14] usb: typec: tcpci: Add support when hidden tx registers are inaccessible Badhri Jagan Sridharan
2020-09-15 12:11   ` Heikki Krogerus
2020-09-01  2:59 ` Badhri Jagan Sridharan [this message]
2020-09-15 12:12   ` [PATCH v6 03/14] usb: typec: tcpci: update ROLE_CONTROL for DRP Heikki Krogerus
2020-09-01  2:59 ` [PATCH v6 04/14] usb: typec: tcpci: Add a getter method to retrieve tcpm_port reference Badhri Jagan Sridharan
2020-09-15 12:16   ` Heikki Krogerus
2020-09-01  2:59 ` [PATCH v6 05/14] usb: typec: tcpci: Add set_vbus tcpci callback Badhri Jagan Sridharan
2020-09-15 12:22   ` Heikki Krogerus
2020-09-16  9:07     ` Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 06/14] dt-bindings: usb: Maxim type-c controller device tree binding document Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 07/14] usb: typec: tcpci_maxim: Chip level TCPC driver Badhri Jagan Sridharan
2020-09-15 12:43   ` Heikki Krogerus
2020-09-16  9:34     ` Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 08/14] dt-bindings: connector: Add property to set initial current cap for FRS Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 09/14] usb: typec: tcpm: Add support for Sink Fast Role SWAP(FRS) Badhri Jagan Sridharan
2020-09-15 13:20   ` Heikki Krogerus
2020-09-17 10:23     ` Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 10/14] usb: typec: tcpci: Implement callbacks for FRS Badhri Jagan Sridharan
2020-09-15 13:23   ` Heikki Krogerus
2020-09-01  2:59 ` [PATCH v6 11/14] usb: typec: tcpci_maxim: Add support for Sink FRS Badhri Jagan Sridharan
2020-09-15 13:25   ` Heikki Krogerus
2020-09-01  2:59 ` [PATCH v6 12/14] usb: typec: tcpm: Implement enabling Auto Discharge disconnect support Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 13/14] usb: typec: tcpci: Implement Auto discharge disconnect callbacks Badhri Jagan Sridharan
2020-09-01  2:59 ` [PATCH v6 14/14] usb: typec: tcpci_maxim: Implemnent set_auto_vbus_discharge_threshold Badhri Jagan Sridharan
2020-09-15 12:09 ` [PATCH v6 00/14] TCPM support for FRS and AutoDischarge Disconnect Heikki Krogerus
2020-09-15 16:57   ` Badhri Jagan Sridharan
2020-09-15 13:33 ` Heikki Krogerus
2020-09-15 16:59   ` Badhri Jagan Sridharan
2020-09-16 11:05 ` 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=20200901025927.3596190-4-badhri@google.com \
    --to=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 \
    --cc=linux@roeck-us.net \
    /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;
as well as URLs for NNTP newsgroup(s).