MLK-16013-37 staging: typec: Power swap force discharge for source
authorLi Jun <jun.li@nxp.com>
Fri, 28 Jul 2017 10:20:42 +0000 (18:20 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:36:22 +0000 (15:36 -0500)
VBus off only means the vbus falls to be below 4v, we can use vbus
force discharge and vbus low alarm to go forward.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
drivers/staging/typec/tcpm.c

index eaa79d3..0bfd4c3 100644 (file)
@@ -3071,7 +3071,13 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
                break;
 
        case PR_SWAP_SRC_SNK_TRANSITION_OFF:
-               tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF, 0);
+               /*
+                * At this moment, vbus may only fall to be below 4v,
+                * we need wait tPSSourceOff and let vbus discharge
+                * finished.
+                */
+               if (!port->tcpc->vbus_discharge)
+                       tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF, 0);
                break;
 
        case PR_SWAP_SNK_SRC_SINK_OFF:
@@ -3110,8 +3116,16 @@ static void _tcpm_vbus_discharge(struct tcpm_port *port, bool on)
 {
        tcpm_log_force(port, "%s force discharge", on ? "Enable":"Disable");
 
+       /*
+        * By vbus discharge and low alarm, now we can disable
+        * vbus discharge.
+        */
        if (port->tcpc && port->tcpc->vbus_discharge)
                port->tcpc->vbus_discharge(port->tcpc, false);
+
+       /* We can transit to PR_SWAP_SRC_SNK_SOURCE_OFF safely */
+       if (port->state == PR_SWAP_SRC_SNK_TRANSITION_OFF)
+               tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF, 0);
 }
 
 static void tcpm_pd_event_handler(struct work_struct *work)