linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init
@ 2020-12-11  7:19 Badhri Jagan Sridharan
  2020-12-11  8:43 ` Heikki Krogerus
  2020-12-11 15:15 ` Guenter Roeck
  0 siblings, 2 replies; 3+ messages in thread
From: Badhri Jagan Sridharan @ 2020-12-11  7:19 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan

During init, vbus_vsafe0v does not get updated till the first
connect as a sink. This causes TCPM to be stuck in SRC_ATTACH_WAIT
state while booting with a sink (For instance: a headset) connected.

[    1.429168] Start toggling
[    1.439907] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected]
[    1.445242] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected]
[   53.358528] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[   53.358564] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]

Fix this by updating vbus_vsafe0v based on vbus_present status
on boot.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index cedc6cf82d61..58a6302c549f 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -4794,6 +4794,24 @@ static void tcpm_init(struct tcpm_port *port)
 	if (port->vbus_present)
 		port->vbus_never_low = true;
 
+	/*
+	 * 1. When vbus_present is true, voltage on VBUS is already at VSAFE5V.
+	 * So implicitly vbus_vsafe0v = false.
+	 *
+	 * 2. When vbus_present is false and TCPC does NOT support querying
+	 * vsafe0v status, then, it's best to assume vbus is at VSAFE0V i.e.
+	 * vbus_vsafe0v is true.
+	 *
+	 * 3. When vbus_present is false and TCPC does support querying vsafe0v,
+	 * then, query tcpc for vsafe0v status.
+	 */
+	if (port->vbus_present)
+		port->vbus_vsafe0v = false;
+	else if (!port->tcpc->is_vbus_vsafe0v)
+		port->vbus_vsafe0v = true;
+	else
+		port->vbus_vsafe0v = port->tcpc->is_vbus_vsafe0v(port->tcpc);
+
 	tcpm_set_state(port, tcpm_default_state(port), 0);
 
 	if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0)
-- 
2.29.2.576.ga3fc446d84-goog


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

* Re: [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init
  2020-12-11  7:19 [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init Badhri Jagan Sridharan
@ 2020-12-11  8:43 ` Heikki Krogerus
  2020-12-11 15:15 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2020-12-11  8:43 UTC (permalink / raw)
  To: Badhri Jagan Sridharan
  Cc: Guenter Roeck, Greg Kroah-Hartman, linux-usb, linux-kernel

On Thu, Dec 10, 2020 at 11:19:11PM -0800, Badhri Jagan Sridharan wrote:
> During init, vbus_vsafe0v does not get updated till the first
> connect as a sink. This causes TCPM to be stuck in SRC_ATTACH_WAIT
> state while booting with a sink (For instance: a headset) connected.
> 
> [    1.429168] Start toggling
> [    1.439907] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected]
> [    1.445242] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected]
> [   53.358528] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> [   53.358564] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> 
> Fix this by updating vbus_vsafe0v based on vbus_present status
> on boot.
> 
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

One nitpick bellow, but it's so minor that you can ignore it if you
like. FWIW:

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

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index cedc6cf82d61..58a6302c549f 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4794,6 +4794,24 @@ static void tcpm_init(struct tcpm_port *port)
>  	if (port->vbus_present)
>  		port->vbus_never_low = true;
>  
> +	/*
> +	 * 1. When vbus_present is true, voltage on VBUS is already at VSAFE5V.
> +	 * So implicitly vbus_vsafe0v = false.
> +	 *
> +	 * 2. When vbus_present is false and TCPC does NOT support querying
> +	 * vsafe0v status, then, it's best to assume vbus is at VSAFE0V i.e.
> +	 * vbus_vsafe0v is true.
> +	 *
> +	 * 3. When vbus_present is false and TCPC does support querying vsafe0v,
> +	 * then, query tcpc for vsafe0v status.
> +	 */
> +	if (port->vbus_present)
> +		port->vbus_vsafe0v = false;
> +	else if (!port->tcpc->is_vbus_vsafe0v)
> +		port->vbus_vsafe0v = true;
> +	else
> +		port->vbus_vsafe0v = port->tcpc->is_vbus_vsafe0v(port->tcpc);

Couldn't that be the other way around?

        ...
	else if (port->tcpc->is_vbus_vsafe0v)
		port->vbus_vsafe0v = port->tcpc->is_vbus_vsafe0v(port->tcpc);
	else
		port->vbus_vsafe0v = true;
        ...

>  	tcpm_set_state(port, tcpm_default_state(port), 0);
>  
>  	if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0)
> -- 
> 2.29.2.576.ga3fc446d84-goog

thanks,

-- 
heikki

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

* Re: [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init
  2020-12-11  7:19 [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init Badhri Jagan Sridharan
  2020-12-11  8:43 ` Heikki Krogerus
@ 2020-12-11 15:15 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2020-12-11 15:15 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel

On 12/10/20 11:19 PM, Badhri Jagan Sridharan wrote:
> During init, vbus_vsafe0v does not get updated till the first
> connect as a sink. This causes TCPM to be stuck in SRC_ATTACH_WAIT
> state while booting with a sink (For instance: a headset) connected.
> 
> [    1.429168] Start toggling
> [    1.439907] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected]
> [    1.445242] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected]
> [   53.358528] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> [   53.358564] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> 
> Fix this by updating vbus_vsafe0v based on vbus_present status
> on boot.
> 
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

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

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index cedc6cf82d61..58a6302c549f 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4794,6 +4794,24 @@ static void tcpm_init(struct tcpm_port *port)
>  	if (port->vbus_present)
>  		port->vbus_never_low = true;
>  
> +	/*
> +	 * 1. When vbus_present is true, voltage on VBUS is already at VSAFE5V.
> +	 * So implicitly vbus_vsafe0v = false.
> +	 *
> +	 * 2. When vbus_present is false and TCPC does NOT support querying
> +	 * vsafe0v status, then, it's best to assume vbus is at VSAFE0V i.e.
> +	 * vbus_vsafe0v is true.
> +	 *
> +	 * 3. When vbus_present is false and TCPC does support querying vsafe0v,
> +	 * then, query tcpc for vsafe0v status.
> +	 */
> +	if (port->vbus_present)
> +		port->vbus_vsafe0v = false;
> +	else if (!port->tcpc->is_vbus_vsafe0v)
> +		port->vbus_vsafe0v = true;
> +	else
> +		port->vbus_vsafe0v = port->tcpc->is_vbus_vsafe0v(port->tcpc);
> +
>  	tcpm_set_state(port, tcpm_default_state(port), 0);
>  
>  	if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0)
> 


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11  7:19 [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init Badhri Jagan Sridharan
2020-12-11  8:43 ` Heikki Krogerus
2020-12-11 15:15 ` Guenter Roeck

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