All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off
@ 2022-01-26  2:00 Badhri Jagan Sridharan
  2022-01-26  2:00 ` [PATCH v2 2/2] usb: typec: tcpm: Do not disconnect when receiving VSAFE0V Badhri Jagan Sridharan
  2022-01-26  3:34 ` [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: Badhri Jagan Sridharan @ 2022-01-26  2:00 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Kyle Tso, stable, Badhri Jagan Sridharan

With some chargers, vbus might momentarily raise above VSAFE5V and fall
back to 0V before tcpm gets to read port->tcpc->get_vbus. This will
report a VBUS off event causing TCPM to transition to SNK_UNATTACHED
where it should be waiting in either SNK_ATTACH_WAIT or SNK_DEBOUNCED
state. This patch makes TCPM avoid vbus off events while in
SNK_ATTACH_WAIT or SNK_DEBOUNCED state.

Stub from the spec:
    "4.5.2.2.4.2 Exiting from AttachWait.SNK State
    A Sink shall transition to Unattached.SNK when the state of both
    the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
    A DRP shall transition to Unattached.SRC when the state of both
    the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."

[23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
[23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
[23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
[23.300579] VBUS off
[23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
[23.301014] VBUS VSAFE0V
[23.301111] Start toggling

Fixes: f0690a25a140b8 ("staging: typec: USB Type-C Port Manager (tcpm)")
Cc: stable@vger.kernel.org
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
Changes since v1:
- Fix typos stated by Guenter Roeck.
---
 drivers/usb/typec/tcpm/tcpm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 59d4fa2443f2..3bf79f52bd34 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -5156,7 +5156,8 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
 	case SNK_TRYWAIT_DEBOUNCE:
 		break;
 	case SNK_ATTACH_WAIT:
-		tcpm_set_state(port, SNK_UNATTACHED, 0);
+	case SNK_DEBOUNCED:
+		/* Do nothing, as TCPM is still waiting for vbus to reach VSAFE5V to connect */
 		break;
 
 	case SNK_NEGOTIATE_CAPABILITIES:
-- 
2.35.0.rc0.227.g00780c9af4-goog


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

* [PATCH v2 2/2] usb: typec: tcpm: Do not disconnect when receiving VSAFE0V
  2022-01-26  2:00 [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Badhri Jagan Sridharan
@ 2022-01-26  2:00 ` Badhri Jagan Sridharan
  2022-01-26  3:34 ` [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: Badhri Jagan Sridharan @ 2022-01-26  2:00 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Kyle Tso, stable, Badhri Jagan Sridharan

With some chargers, vbus might momentarily raise above VSAFE5V and fall
back to 0V causing VSAFE0V to be triggered. This will report a VBUS off
event causing TCPM to transition to SNK_UNATTACHED state where it
should be waiting in either SNK_ATTACH_WAIT or SNK_DEBOUNCED state.
This patch makes TCPM avoid VSAFE0V events while in SNK_ATTACH_WAIT
or SNK_DEBOUNCED state.

Stub from the spec:
    "4.5.2.2.4.2 Exiting from AttachWait.SNK State
    A Sink shall transition to Unattached.SNK when the state of both
    the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
    A DRP shall transition to Unattached.SRC when the state of both
    the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."

[23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
[23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
[23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
[23.300579] VBUS off
[23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
[23.301014] VBUS VSAFE0V
[23.301111] Start toggling

Fixes: f0690a25a140b8 ("staging: typec: USB Type-C Port Manager (tcpm)")
Cc: stable@vger.kernel.org
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
Changes since v1:
- Fix typos stated by Guenter Roeck.
---
 drivers/usb/typec/tcpm/tcpm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 3bf79f52bd34..0e0985355a14 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -5264,6 +5264,10 @@ static void _tcpm_pd_vbus_vsafe0v(struct tcpm_port *port)
 	case PR_SWAP_SNK_SRC_SOURCE_ON:
 		/* Do nothing, vsafe0v is expected during transition */
 		break;
+	case SNK_ATTACH_WAIT:
+	case SNK_DEBOUNCED:
+		/* Do nothing, still waiting for VSAFE5V to connect */
+		break;
 	default:
 		if (port->pwr_role == TYPEC_SINK && port->auto_vbus_discharge_enabled)
 			tcpm_set_state(port, SNK_UNATTACHED, 0);
-- 
2.35.0.rc0.227.g00780c9af4-goog


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

* Re: [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off
  2022-01-26  2:00 [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Badhri Jagan Sridharan
  2022-01-26  2:00 ` [PATCH v2 2/2] usb: typec: tcpm: Do not disconnect when receiving VSAFE0V Badhri Jagan Sridharan
@ 2022-01-26  3:34 ` Guenter Roeck
  2022-01-26  4:07   ` Badhri Jagan Sridharan
  1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2022-01-26  3:34 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Kyle Tso, stable

On 1/25/22 18:00, Badhri Jagan Sridharan wrote:
> With some chargers, vbus might momentarily raise above VSAFE5V and fall
> back to 0V before tcpm gets to read port->tcpc->get_vbus. This will
> report a VBUS off event causing TCPM to transition to SNK_UNATTACHED
> where it should be waiting in either SNK_ATTACH_WAIT or SNK_DEBOUNCED
> state. This patch makes TCPM avoid vbus off events while in
> SNK_ATTACH_WAIT or SNK_DEBOUNCED state.
> 
> Stub from the spec:
>      "4.5.2.2.4.2 Exiting from AttachWait.SNK State
>      A Sink shall transition to Unattached.SNK when the state of both
>      the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
>      A DRP shall transition to Unattached.SRC when the state of both
>      the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."
> 
> [23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
> [23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
> [23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
> [23.300579] VBUS off
> [23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
> [23.301014] VBUS VSAFE0V
> [23.301111] Start toggling
> 
> Fixes: f0690a25a140b8 ("staging: typec: USB Type-C Port Manager (tcpm)")
> Cc: stable@vger.kernel.org
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

Why did you drop the Reviewed-by/Acked-by tags ?

Guenter

> ---
> Changes since v1:
> - Fix typos stated by Guenter Roeck.
> ---
>   drivers/usb/typec/tcpm/tcpm.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 59d4fa2443f2..3bf79f52bd34 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -5156,7 +5156,8 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
>   	case SNK_TRYWAIT_DEBOUNCE:
>   		break;
>   	case SNK_ATTACH_WAIT:
> -		tcpm_set_state(port, SNK_UNATTACHED, 0);
> +	case SNK_DEBOUNCED:
> +		/* Do nothing, as TCPM is still waiting for vbus to reach VSAFE5V to connect */
>   		break;
>   
>   	case SNK_NEGOTIATE_CAPABILITIES:


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

* Re: [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off
  2022-01-26  3:34 ` [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Guenter Roeck
@ 2022-01-26  4:07   ` Badhri Jagan Sridharan
  0 siblings, 0 replies; 4+ messages in thread
From: Badhri Jagan Sridharan @ 2022-01-26  4:07 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Heikki Krogerus, Greg Kroah-Hartman, USB, LKML, Kyle Tso, stable

My bad ! Apologies .. fixing it in V3..


On Tue, Jan 25, 2022 at 7:34 PM Guenter Roeck <linux@roeck-us.net> wrote:
>
> On 1/25/22 18:00, Badhri Jagan Sridharan wrote:
> > With some chargers, vbus might momentarily raise above VSAFE5V and fall
> > back to 0V before tcpm gets to read port->tcpc->get_vbus. This will
> > report a VBUS off event causing TCPM to transition to SNK_UNATTACHED
> > where it should be waiting in either SNK_ATTACH_WAIT or SNK_DEBOUNCED
> > state. This patch makes TCPM avoid vbus off events while in
> > SNK_ATTACH_WAIT or SNK_DEBOUNCED state.
> >
> > Stub from the spec:
> >      "4.5.2.2.4.2 Exiting from AttachWait.SNK State
> >      A Sink shall transition to Unattached.SNK when the state of both
> >      the CC1 and CC2 pins is SNK.Open for at least tPDDebounce.
> >      A DRP shall transition to Unattached.SRC when the state of both
> >      the CC1 and CC2 pins is SNK.Open for at least tPDDebounce."
> >
> > [23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected]
> > [23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS]
> > [23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS]
> > [23.300579] VBUS off
> > [23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS]
> > [23.301014] VBUS VSAFE0V
> > [23.301111] Start toggling
> >
> > Fixes: f0690a25a140b8 ("staging: typec: USB Type-C Port Manager (tcpm)")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
>
> Why did you drop the Reviewed-by/Acked-by tags ?
>
> Guenter
>
> > ---
> > Changes since v1:
> > - Fix typos stated by Guenter Roeck.
> > ---
> >   drivers/usb/typec/tcpm/tcpm.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > index 59d4fa2443f2..3bf79f52bd34 100644
> > --- a/drivers/usb/typec/tcpm/tcpm.c
> > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > @@ -5156,7 +5156,8 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
> >       case SNK_TRYWAIT_DEBOUNCE:
> >               break;
> >       case SNK_ATTACH_WAIT:
> > -             tcpm_set_state(port, SNK_UNATTACHED, 0);
> > +     case SNK_DEBOUNCED:
> > +             /* Do nothing, as TCPM is still waiting for vbus to reach VSAFE5V to connect */
> >               break;
> >
> >       case SNK_NEGOTIATE_CAPABILITIES:
>

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

end of thread, other threads:[~2022-01-26  4:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26  2:00 [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Badhri Jagan Sridharan
2022-01-26  2:00 ` [PATCH v2 2/2] usb: typec: tcpm: Do not disconnect when receiving VSAFE0V Badhri Jagan Sridharan
2022-01-26  3:34 ` [PATCH v2 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off Guenter Roeck
2022-01-26  4:07   ` Badhri Jagan Sridharan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.