From 0e2176304f3af2b78e8e0b12dab8feb82abccd8f Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Mon, 22 Jun 2015 10:57:16 -0700 Subject: oak: glados: fix USB PD power and data swap refactoring Fix USB PD check power and data swap functions after those functions have been refactored and the args changed. BUG=chrome-os-partner:41739 BRANCH=none TEST=make -j buildall Change-Id: I746774563d475710dc23c7290328fab150eaac6a Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/280993 Reviewed-by: Vincent Palatin --- board/glados/usb_pd_policy.c | 26 +++++++++++++++++++------- board/oak/usb_pd_policy.c | 26 +++++++++++++++++++------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/board/glados/usb_pd_policy.c b/board/glados/usb_pd_policy.c index d5e0a235a9..43caba815e 100644 --- a/board/glados/usb_pd_policy.c +++ b/board/glados/usb_pd_policy.c @@ -156,18 +156,30 @@ void pd_execute_data_swap(int port, int data_role) /* TODO: need to open/close D+/D- switch based on role */ } -void pd_check_pr_role(int port, int pr_role, int partner_pr_swap) +void pd_check_pr_role(int port, int pr_role, int flags) { - /* If sink, and dual role toggling is on, then switch to source */ - if (partner_pr_swap && pr_role == PD_ROLE_SINK && - pd_get_dual_role() == PD_DRP_TOGGLE_ON) - pd_request_power_swap(port); + /* + * If partner is dual-role power and dualrole toggling is on, consider + * if a power swap is necessary. + */ + if ((flags & PD_FLAGS_PARTNER_DR_POWER) && + pd_get_dual_role() == PD_DRP_TOGGLE_ON) { + /* + * If we are a sink and partner is not externally powered, then + * swap to become a source. If we are source and partner is + * externally powered, swap to become a sink. + */ + int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; + if ((!partner_extpower && pr_role == PD_ROLE_SINK) || + (partner_extpower && pr_role == PD_ROLE_SOURCE)) + pd_request_power_swap(port); + } } -void pd_check_dr_role(int port, int dr_role, int partner_dr_swap) +void pd_check_dr_role(int port, int dr_role, int flags) { /* If UFP, try to switch to DFP */ - if (partner_dr_swap && dr_role == PD_ROLE_UFP) + if ((flags & PD_FLAGS_PARTNER_DR_DATA) && dr_role == PD_ROLE_UFP) pd_request_data_swap(port); } /* ----------------- Vendor Defined Messages ------------------ */ diff --git a/board/oak/usb_pd_policy.c b/board/oak/usb_pd_policy.c index 10665c08e9..26911a8e0f 100644 --- a/board/oak/usb_pd_policy.c +++ b/board/oak/usb_pd_policy.c @@ -155,18 +155,30 @@ void pd_execute_data_swap(int port, int data_role) { } -void pd_check_pr_role(int port, int pr_role, int partner_pr_swap) +void pd_check_pr_role(int port, int pr_role, int flags) { - /* If sink, and dual role toggling is on, then switch to source */ - if (partner_pr_swap && pr_role == PD_ROLE_SINK && - pd_get_dual_role() == PD_DRP_TOGGLE_ON) - pd_request_power_swap(port); + /* + * If partner is dual-role power and dualrole toggling is on, consider + * if a power swap is necessary. + */ + if ((flags & PD_FLAGS_PARTNER_DR_POWER) && + pd_get_dual_role() == PD_DRP_TOGGLE_ON) { + /* + * If we are a sink and partner is not externally powered, then + * swap to become a source. If we are source and partner is + * externally powered, swap to become a sink. + */ + int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; + if ((!partner_extpower && pr_role == PD_ROLE_SINK) || + (partner_extpower && pr_role == PD_ROLE_SOURCE)) + pd_request_power_swap(port); + } } -void pd_check_dr_role(int port, int dr_role, int partner_dr_swap) +void pd_check_dr_role(int port, int dr_role, int flags) { /* If UFP, try to switch to DFP */ - if (partner_dr_swap && dr_role == PD_ROLE_UFP) + if ((flags & PD_FLAGS_PARTNER_DR_DATA) && dr_role == PD_ROLE_UFP) pd_request_data_swap(port); } /* ----------------- Vendor Defined Messages ------------------ */ -- cgit v1.2.1