linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: typec: tcpm: Stay in SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS till Rp is seen
@ 2020-11-25  1:48 Badhri Jagan Sridharan
  2020-11-25 14:17 ` Guenter Roeck
  2020-11-26 12:01 ` Heikki Krogerus
  0 siblings, 2 replies; 3+ messages in thread
From: Badhri Jagan Sridharan @ 2020-11-25  1:48 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan

TD.4.7.3. Try SNK DRP Connect Try.SRC DRP fails. The compliance
tester mimics being a Try.SRC USB-C port.
The failure is due to TCPM exiting SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS
when VBUS is not present eventhough when SNK.Rp is seen. Exit to
SRC_TRYWAIT from SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS only when SNK.Rp
is not seen for PD_T_TRY_CC_DEBOUNCE.

From the spec:
The port shall then transition to Attached.SNK when the SNK.Rp state
is detected on exactly one of the CC1 or CC2 pins for at least
tTryCCDebounce and VBUS is detected. Alternatively, the port shall
transition to TryWait.SRC if SNK.Rp state is not detected for
tTryCCDebounce.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 18 +++++++++++++-----
 include/linux/usb/pd.h        |  1 +
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 4aac0efdb720..b2cffa00d737 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3124,15 +3124,13 @@ static void run_state_machine(struct tcpm_port *port)
 		break;
 	case SNK_TRY_WAIT_DEBOUNCE:
 		tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS,
-			       PD_T_PD_DEBOUNCE);
+			       PD_T_TRY_CC_DEBOUNCE);
 		break;
 	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
-		if (port->vbus_present && tcpm_port_is_sink(port)) {
+		if (port->vbus_present && tcpm_port_is_sink(port))
 			tcpm_set_state(port, SNK_ATTACHED, 0);
-		} else {
-			tcpm_set_state(port, SRC_TRYWAIT, 0);
+		else
 			port->max_wait = 0;
-		}
 		break;
 	case SRC_TRYWAIT:
 		tcpm_set_cc(port, tcpm_rp_cc(port));
@@ -4053,6 +4051,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
 		if (!tcpm_port_is_sink(port))
 			tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0);
 		break;
+	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
+		if (!tcpm_port_is_sink(port))
+			tcpm_set_state(port, SRC_TRYWAIT, PD_T_TRY_CC_DEBOUNCE);
+		else
+			tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS, 0);
+		break;
 	case SNK_TRYWAIT:
 		/* Do nothing, waiting for tCCDebounce */
 		break;
@@ -4139,6 +4143,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
 	case SNK_TRYWAIT_DEBOUNCE:
 		/* Do nothing, waiting for Rp */
 		break;
+	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
+		if (port->vbus_present && tcpm_port_is_sink(port))
+			tcpm_set_state(port, SNK_ATTACHED, 0);
+		break;
 	case SRC_TRY_WAIT:
 	case SRC_TRY_DEBOUNCE:
 		/* Do nothing, waiting for sink detection */
diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
index 3a805e2ecbc9..63a66dd5d832 100644
--- a/include/linux/usb/pd.h
+++ b/include/linux/usb/pd.h
@@ -484,6 +484,7 @@ static inline unsigned int rdo_max_power(u32 rdo)
 
 #define PD_T_CC_DEBOUNCE	200	/* 100 - 200 ms */
 #define PD_T_PD_DEBOUNCE	20	/* 10 - 20 ms */
+#define PD_T_TRY_CC_DEBOUNCE	15	/* 10 - 20 ms */
 
 #define PD_N_CAPS_COUNT		(PD_T_NO_RESPONSE / PD_T_SEND_SOURCE_CAP)
 #define PD_N_HARD_RESET_COUNT	2
-- 
2.29.2.454.gaff20da3a2-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: tcpm: Stay in SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS till Rp is seen
  2020-11-25  1:48 [PATCH] usb: typec: tcpm: Stay in SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS till Rp is seen Badhri Jagan Sridharan
@ 2020-11-25 14:17 ` Guenter Roeck
  2020-11-26 12:01 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2020-11-25 14:17 UTC (permalink / raw)
  To: Badhri Jagan Sridharan
  Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel

On Tue, Nov 24, 2020 at 05:48:04PM -0800, Badhri Jagan Sridharan wrote:
> TD.4.7.3. Try SNK DRP Connect Try.SRC DRP fails. The compliance
> tester mimics being a Try.SRC USB-C port.
> The failure is due to TCPM exiting SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS
> when VBUS is not present eventhough when SNK.Rp is seen. Exit to
> SRC_TRYWAIT from SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS only when SNK.Rp
> is not seen for PD_T_TRY_CC_DEBOUNCE.
> 
> From the spec:
> The port shall then transition to Attached.SNK when the SNK.Rp state
> is detected on exactly one of the CC1 or CC2 pins for at least
> tTryCCDebounce and VBUS is detected. Alternatively, the port shall
> transition to TryWait.SRC if SNK.Rp state is not detected for
> tTryCCDebounce.
> 
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 18 +++++++++++++-----
>  include/linux/usb/pd.h        |  1 +
>  2 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 4aac0efdb720..b2cffa00d737 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3124,15 +3124,13 @@ static void run_state_machine(struct tcpm_port *port)
>  		break;
>  	case SNK_TRY_WAIT_DEBOUNCE:
>  		tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS,
> -			       PD_T_PD_DEBOUNCE);
> +			       PD_T_TRY_CC_DEBOUNCE);
>  		break;
>  	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
> -		if (port->vbus_present && tcpm_port_is_sink(port)) {
> +		if (port->vbus_present && tcpm_port_is_sink(port))
>  			tcpm_set_state(port, SNK_ATTACHED, 0);
> -		} else {
> -			tcpm_set_state(port, SRC_TRYWAIT, 0);
> +		else
>  			port->max_wait = 0;
> -		}
>  		break;
>  	case SRC_TRYWAIT:
>  		tcpm_set_cc(port, tcpm_rp_cc(port));
> @@ -4053,6 +4051,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
>  		if (!tcpm_port_is_sink(port))
>  			tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0);
>  		break;
> +	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
> +		if (!tcpm_port_is_sink(port))
> +			tcpm_set_state(port, SRC_TRYWAIT, PD_T_TRY_CC_DEBOUNCE);
> +		else
> +			tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS, 0);
> +		break;
>  	case SNK_TRYWAIT:
>  		/* Do nothing, waiting for tCCDebounce */
>  		break;
> @@ -4139,6 +4143,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
>  	case SNK_TRYWAIT_DEBOUNCE:
>  		/* Do nothing, waiting for Rp */
>  		break;
> +	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
> +		if (port->vbus_present && tcpm_port_is_sink(port))
> +			tcpm_set_state(port, SNK_ATTACHED, 0);
> +		break;
>  	case SRC_TRY_WAIT:
>  	case SRC_TRY_DEBOUNCE:
>  		/* Do nothing, waiting for sink detection */
> diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> index 3a805e2ecbc9..63a66dd5d832 100644
> --- a/include/linux/usb/pd.h
> +++ b/include/linux/usb/pd.h
> @@ -484,6 +484,7 @@ static inline unsigned int rdo_max_power(u32 rdo)
>  
>  #define PD_T_CC_DEBOUNCE	200	/* 100 - 200 ms */
>  #define PD_T_PD_DEBOUNCE	20	/* 10 - 20 ms */
> +#define PD_T_TRY_CC_DEBOUNCE	15	/* 10 - 20 ms */
>  
>  #define PD_N_CAPS_COUNT		(PD_T_NO_RESPONSE / PD_T_SEND_SOURCE_CAP)
>  #define PD_N_HARD_RESET_COUNT	2
> -- 
> 2.29.2.454.gaff20da3a2-goog
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: tcpm: Stay in SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS till Rp is seen
  2020-11-25  1:48 [PATCH] usb: typec: tcpm: Stay in SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS till Rp is seen Badhri Jagan Sridharan
  2020-11-25 14:17 ` Guenter Roeck
@ 2020-11-26 12:01 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2020-11-26 12:01 UTC (permalink / raw)
  To: Badhri Jagan Sridharan
  Cc: Guenter Roeck, Greg Kroah-Hartman, linux-usb, linux-kernel

On Tue, Nov 24, 2020 at 05:48:04PM -0800, Badhri Jagan Sridharan wrote:
> TD.4.7.3. Try SNK DRP Connect Try.SRC DRP fails. The compliance
> tester mimics being a Try.SRC USB-C port.
> The failure is due to TCPM exiting SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS
> when VBUS is not present eventhough when SNK.Rp is seen. Exit to
> SRC_TRYWAIT from SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS only when SNK.Rp
> is not seen for PD_T_TRY_CC_DEBOUNCE.
> 
> >From the spec:
> The port shall then transition to Attached.SNK when the SNK.Rp state
> is detected on exactly one of the CC1 or CC2 pins for at least
> tTryCCDebounce and VBUS is detected. Alternatively, the port shall
> transition to TryWait.SRC if SNK.Rp state is not detected for
> tTryCCDebounce.
> 
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 18 +++++++++++++-----
>  include/linux/usb/pd.h        |  1 +
>  2 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 4aac0efdb720..b2cffa00d737 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3124,15 +3124,13 @@ static void run_state_machine(struct tcpm_port *port)
>  		break;
>  	case SNK_TRY_WAIT_DEBOUNCE:
>  		tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS,
> -			       PD_T_PD_DEBOUNCE);
> +			       PD_T_TRY_CC_DEBOUNCE);
>  		break;
>  	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
> -		if (port->vbus_present && tcpm_port_is_sink(port)) {
> +		if (port->vbus_present && tcpm_port_is_sink(port))
>  			tcpm_set_state(port, SNK_ATTACHED, 0);
> -		} else {
> -			tcpm_set_state(port, SRC_TRYWAIT, 0);
> +		else
>  			port->max_wait = 0;
> -		}
>  		break;
>  	case SRC_TRYWAIT:
>  		tcpm_set_cc(port, tcpm_rp_cc(port));
> @@ -4053,6 +4051,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
>  		if (!tcpm_port_is_sink(port))
>  			tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0);
>  		break;
> +	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
> +		if (!tcpm_port_is_sink(port))
> +			tcpm_set_state(port, SRC_TRYWAIT, PD_T_TRY_CC_DEBOUNCE);
> +		else
> +			tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS, 0);
> +		break;
>  	case SNK_TRYWAIT:
>  		/* Do nothing, waiting for tCCDebounce */
>  		break;
> @@ -4139,6 +4143,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
>  	case SNK_TRYWAIT_DEBOUNCE:
>  		/* Do nothing, waiting for Rp */
>  		break;
> +	case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
> +		if (port->vbus_present && tcpm_port_is_sink(port))
> +			tcpm_set_state(port, SNK_ATTACHED, 0);
> +		break;
>  	case SRC_TRY_WAIT:
>  	case SRC_TRY_DEBOUNCE:
>  		/* Do nothing, waiting for sink detection */
> diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> index 3a805e2ecbc9..63a66dd5d832 100644
> --- a/include/linux/usb/pd.h
> +++ b/include/linux/usb/pd.h
> @@ -484,6 +484,7 @@ static inline unsigned int rdo_max_power(u32 rdo)
>  
>  #define PD_T_CC_DEBOUNCE	200	/* 100 - 200 ms */
>  #define PD_T_PD_DEBOUNCE	20	/* 10 - 20 ms */
> +#define PD_T_TRY_CC_DEBOUNCE	15	/* 10 - 20 ms */
>  
>  #define PD_N_CAPS_COUNT		(PD_T_NO_RESPONSE / PD_T_SEND_SOURCE_CAP)
>  #define PD_N_HARD_RESET_COUNT	2
> -- 
> 2.29.2.454.gaff20da3a2-goog

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-26 12:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  1:48 [PATCH] usb: typec: tcpm: Stay in SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS till Rp is seen Badhri Jagan Sridharan
2020-11-25 14:17 ` Guenter Roeck
2020-11-26 12:01 ` Heikki Krogerus

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