mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Badhri Jagan Sridharan <badhri@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Guenter Roeck <linux@roeck-us.net>
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	Badhri Jagan Sridharan <Badhri@google.com>
Subject: [PATCH 05/11 v3] staging: typec: tcpm: Follow Try.SRC exit requirements
Date: Mon, 28 Aug 2017 10:23:16 -0700	[thread overview]
Message-ID: <20170828172322.7166-5-Badhri@google.com> (raw)
In-Reply-To: <20170828172322.7166-1-Badhri@google.com>

According to spec:
" 4.5.2.2.9.2 Exiting from Try.SRC State:
The port shall transition to Attached.SRC when the SRC.Rd
state is detected on exactly one of the CC1 or CC2 pins for
at least tPDDebounce. The port shall transition to
TryWait.SNK after tDRPTry and the SRC.Rd state has not been
detected."

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
Changelog since v1:
- Corrected  tag

Changelog since v2:
- added Reviewed-by: Guenter Roeck <linux@roeck-us.net>
- fixed version/sequence numbers

 drivers/staging/typec/tcpm.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 7eed04698ebe..fc179bdea7e4 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -112,6 +112,7 @@
 	S(SRC_TRYWAIT_UNATTACHED),		\
 						\
 	S(SRC_TRY),				\
+	S(SRC_TRY_WAIT),                        \
 	S(SRC_TRY_DEBOUNCE),			\
 	S(SNK_TRYWAIT),				\
 	S(SNK_TRYWAIT_DEBOUNCE),		\
@@ -2158,6 +2159,7 @@ static void run_state_machine(struct tcpm_port *port)
 {
 	int ret;
 	enum typec_pwr_opmode opmode;
+	unsigned int msecs;
 
 	port->enter_state = port->state;
 	switch (port->state) {
@@ -2379,7 +2381,22 @@ static void run_state_machine(struct tcpm_port *port)
 	case SRC_TRY:
 		port->try_src_count++;
 		tcpm_set_cc(port, tcpm_rp_cc(port));
-		tcpm_set_state(port, SNK_TRYWAIT, PD_T_DRP_TRY);
+		port->max_wait = 0;
+		tcpm_set_state(port, SRC_TRY_WAIT, 0);
+		break;
+	case SRC_TRY_WAIT:
+		if (port->max_wait == 0) {
+			port->max_wait = jiffies +
+					 msecs_to_jiffies(PD_T_DRP_TRY);
+			msecs = PD_T_DRP_TRY;
+		} else {
+			if (time_is_after_jiffies(port->max_wait))
+				msecs = jiffies_to_msecs(port->max_wait -
+							 jiffies);
+			else
+				msecs = 0;
+		}
+		tcpm_set_state(port, SNK_TRYWAIT, msecs);
 		break;
 	case SRC_TRY_DEBOUNCE:
 		tcpm_set_state(port, SRC_ATTACHED, PD_T_PD_DEBOUNCE);
@@ -2935,12 +2952,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
 			tcpm_set_state(port, SRC_TRYWAIT, 0);
 		}
 		break;
-	case SRC_TRY:
+	case SRC_TRY_WAIT:
 		if (tcpm_port_is_source(port))
 			tcpm_set_state(port, SRC_TRY_DEBOUNCE, 0);
 		break;
 	case SRC_TRY_DEBOUNCE:
-		tcpm_set_state(port, SRC_TRY, 0);
+		tcpm_set_state(port, SRC_TRY_WAIT, 0);
 		break;
 	case SNK_TRYWAIT_DEBOUNCE:
 		if (port->vbus_present) {
@@ -3015,7 +3032,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
 	case SNK_TRYWAIT:
 		tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0);
 		break;
-
+	case SRC_TRY_WAIT:
+	case SRC_TRY_DEBOUNCE:
+		/* Do nothing, waiting for sink detection */
+		break;
 	default:
 		break;
 	}
@@ -3069,7 +3089,10 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
 	case PORT_RESET_WAIT_OFF:
 		tcpm_set_state(port, tcpm_default_state(port), 0);
 		break;
-
+	case SRC_TRY_WAIT:
+	case SRC_TRY_DEBOUNCE:
+		/* Do nothing, waiting for sink detection */
+		break;
 	default:
 		if (port->pwr_role == TYPEC_SINK &&
 		    port->attached)
-- 
2.14.1.342.g6490525c54-goog

  parent reply	other threads:[~2017-08-28 17:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 17:23 [PATCH 01/11 v3] staging: typec: tcpm: set port type callback Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 02/11 v3] staging: typec: tcpm: Check for port type for Try.SRC/Try.SNK Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 03/11 v3] staging: typec: tcpm: Prevent TCPM from looping in SRC_TRYWAIT Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 04/11 v3] staging: usb: tcpm: usb: type-c: tcpm: Check for Rp for tPDDebounce Badhri Jagan Sridharan
2017-08-28 17:23 ` Badhri Jagan Sridharan [this message]
2017-08-28 17:23 ` [PATCH 06/11 v3] staging: typec: tcpm: Comply with TryWait.SNK State Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 07/11 v3] staging: typec: tcpm: Consider port_type while determining unattached_state Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 08/11 v3] staging: typec: tcpm: add cc change handling in src states Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 09/11 v3] staging: typec: tcpm: typec: tcpm: Wait for CC debounce before PD excg Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 10/11 v3] staging: typec: tcpm: Do not send PING msgs in TCPM Badhri Jagan Sridharan
2017-08-28 17:23 ` [PATCH 11/11 v3] staging: typec: tcpm: Switch to PORT_RESET instead of SNK_UNATTACHED Badhri Jagan Sridharan

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=20170828172322.7166-5-Badhri@google.com \
    --to=badhri@google.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@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

Powered by JetHome