faft: USB PD: Improvements to disconnect/connect methods
PD console devices force a disconnect/connect event by forcing
drp mode to be the opposite of the current connection. Then
the disconnect and connect states are verified. However, this
approach will not work if the other device in the connection
is in dualrole mode. If both devices are in dualrole mode then
the disconnect/connect can be checked by verifying that a power
role swap occurs when the drp mode is forced.
In addition a drp_disconnect_connect() method was added to the
Plankton device so that the same method can be called from test
scripts.
BRANCH=none
BUG=chrome-os-partner:50431
TEST=Manual
Tested with Samus and Plankton using the PDConnect script.
Change-Id: If910f3992e573f0d2a25de01e965177ea32c76fc
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/347446
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
diff --git a/server/cros/servo/pd_device.py b/server/cros/servo/pd_device.py
index 0d0d51a..f69a221 100644
--- a/server/cros/servo/pd_device.py
+++ b/server/cros/servo/pd_device.py
@@ -217,14 +217,33 @@
# Force state will be the opposite of current connect state
if self.is_src():
drp_mode = 'snk'
+ swap_state = self.utils.SNK_CONNECT
else:
drp_mode = 'src'
+ swap_state = self.utils.SRC_CONNECT
# Force disconnect
self.drp_set(drp_mode)
# Wait for disconnect time
time.sleep(disc_time_sec)
# Verify that the device is disconnected
disconnect = self.is_disconnected()
+
+ # If the other device is dualrole, then forcing dualrole mode will
+ # only cause the disconnect to appear momentarily and reconnect
+ # in the power role forced by the drp_set() call. For this case,
+ # the role swap verifies that a disconnect/connect sequence occurred.
+ if disconnect == False:
+ time.sleep(self.utils.CONNECT_TIME)
+ # Connected, verify if power role swap has ocurred
+ if swap_state == self.utils.get_pd_state(self.port):
+ # Restore default dualrole mode
+ self.drp_set('on')
+ # Restore orignal power role
+ connect = self.pr_swap()
+ if connect == False:
+ logging.warn('DRP on both devices, 2nd power swap failed')
+ return connect
+
# Restore default dualrole mode
self.drp_set('on')
# Allow enough time for protocol state machine
@@ -433,6 +452,24 @@
disc_time_sec * 1000)
self.utils.send_pd_command(disc_cmd)
+ def drp_disconnect_connect(self, disc_time_sec):
+ """Disconnect/reconnect using Plankton
+
+ Utilize Plankton disconnect/connect utility and verify
+ that both disconnect and reconnect actions were successful.
+
+ @param disc_time_sec: Time in seconds for disconnect period.
+
+ @returns True if device disconnects, then returns to a connected
+ state. False if either step fails.
+ """
+ self.cc_disconnect_connect(disc_time_sec)
+ time.sleep(disc_time_sec / 2)
+ disconnect = self.is_disconnected()
+ time.sleep(disc_time_sec / 2 + self.utils.CONNECT_TIME)
+ connect = self.is_connected()
+ return disconnect and connect
+
def drp_set(self, mode):
"""Sets dualrole mode