Skip to contentSkip to conversation

usb: typec: tcpm: Update vbus_vsafe0v on init

PATCH In review Badhri Jagan Sridharan 3 participants 3 messages Dec 11, 2020

Subsystems (3)
lore
Share & tools
lore

Badhri Jagan Sridharan

author maintainer
#0 lore raw

PATCH 1/1 usb: typec: tcpm: Update vbus_vsafe0v on init

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.

---
 drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +18 -0
index cedc6cf82d61..58a6302c549f 100644
@@ -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)
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · 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]
Quoted 4 lines

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

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

Quoted 19 lines
---
 drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +7 -0
index cedc6cf82d61..58a6302c549f 100644
@@ -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.

drivers/usb/typec/tcpm/tcpm.c static void tcpm_init(struct tcpm_port *port) · line 4813

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10 -0
+	 *
+	 * 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;
        ...
Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +0 -0
 	tcpm_set_state(port, tcpm_default_state(port), 0);
 
 	if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0)
Signature · 1 line
2.29.2.576.ga3fc446d84-goog

thanks,

Signature · 1 line
heikki
Reviewed-by on v1 1/1
#2 lore raw
In reply to Badhri Jagan Sridharan
Quoted 10 lines · 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]
Quoted 4 lines

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

Quoted 34 lines
---
 drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +18 -0
index cedc6cf82d61..58a6302c549f 100644
@@ -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)