From 3db4c21c0f71f7a51ce5c50f0d4d3742c9ec4a65 Mon Sep 17 00:00:00 2001 From: Badhri Jagan Sridharan Date: Thu, 10 Dec 2020 23:19:11 -0800 Subject: [PATCH] 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. Reviewed-by: Heikki Krogerus Signed-off-by: Badhri Jagan Sridharan Link: https://lore.kernel.org/r/20201211071911.2205197-1-badhri@google.com Signed-off-by: Greg Kroah-Hartman --- 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 36b6ce8..6326a8f 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4804,6 +4804,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.7.4