Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1720737 > unrolled thread

[PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements

Started byBadhri Jagan Sridharan <badhri@google.com>
First post2017-08-27 07:30 +0200
Last post2017-08-27 19:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements Badhri Jagan Sridharan <badhri@google.com> - 2017-08-27 07:30 +0200
    Re: [PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC  exit requirements Guenter Roeck <linux@roeck-us.net> - 2017-08-27 19:30 +0200

#1720737 — [PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements

FromBadhri Jagan Sridharan <badhri@google.com>
Date2017-08-27 07:30 +0200
Subject[PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements
Message-ID<uiYiZ-3gw-5@gated-at.bofh.it>
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>
---
 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

[toc] | [next] | [standalone]


#1720885 — Re: [PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements

FromGuenter Roeck <linux@roeck-us.net>
Date2017-08-27 19:30 +0200
SubjectRe: [PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements
Message-ID<uj9xL-2j1-11@gated-at.bofh.it>
In reply to#1720737
On Sat, Aug 26, 2017 at 10:25:07PM -0700, Badhri Jagan Sridharan wrote:
> 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>

> ---
>  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
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web