From a08c2d579e099580c033f99e56b2130ff8383a97 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Thu, 23 Oct 2014 17:31:21 -0700 Subject: pd: for DP mode, only enter mode if device is DFP_U capable Added return parameter to enter mode functions. For DP mode on samus and fruitpie, only send enter mode if device is a DP sink (DFP_U). BUG=none BRANCH=samus TEST=make buildall. tested a simpler version of this with a third-party DFP_D capable device and verified we don't send enter mode. Change-Id: I5caf008b7b3711232aeb1a1012cde2022584109b Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/225288 Reviewed-by: Todd Broch Reviewed-by: Vincent Palatin --- board/fruitpie/usb_pd_policy.c | 10 ++++++++-- board/samus_pd/usb_pd_policy.c | 10 ++++++++-- common/usb_pd_policy.c | 4 +++- include/usb_pd.h | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/board/fruitpie/usb_pd_policy.c b/board/fruitpie/usb_pd_policy.c index aa63911cc9..e99e195804 100644 --- a/board/fruitpie/usb_pd_policy.c +++ b/board/fruitpie/usb_pd_policy.c @@ -191,9 +191,15 @@ int pd_vdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload) return pd_custom_vdm(port, cnt, payload, rpayload); } -static void svdm_enter_dp_mode(int port, uint32_t mode_caps) +static int svdm_enter_dp_mode(int port, uint32_t mode_caps) { - CPRINTF("Entering mode w/ vdo = %08x\n", mode_caps); + /* Only enter mode if device is DFP_D capable */ + if (mode_caps & MODE_DP_SNK) { + CPRINTF("Entering mode w/ vdo = %08x\n", mode_caps); + return 0; + } + + return -1; } static int dp_on; diff --git a/board/samus_pd/usb_pd_policy.c b/board/samus_pd/usb_pd_policy.c index 507c6d3bce..ea297b8c13 100644 --- a/board/samus_pd/usb_pd_policy.c +++ b/board/samus_pd/usb_pd_policy.c @@ -243,9 +243,15 @@ static void svdm_safe_dp_mode(int port) board_set_usb_mux(port, TYPEC_MUX_NONE, pd_get_polarity(port)); } -static void svdm_enter_dp_mode(int port, uint32_t mode_caps) +static int svdm_enter_dp_mode(int port, uint32_t mode_caps) { - svdm_safe_dp_mode(port); + /* Only enter mode if device is DFP_D capable */ + if (mode_caps & MODE_DP_SNK) { + svdm_safe_dp_mode(port); + return 0; + } + + return -1; } static int dp_on; diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index 87f6984c88..3149934d33 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -132,7 +132,9 @@ static int dfp_enter_mode(int port, uint32_t *payload) if (!AMODE_VALID(port)) return 0; - modep->fx->enter(port, modep->mode_caps); + if (modep->fx->enter(port, modep->mode_caps) == -1) + return 0; + payload[0] = VDO(modep->fx->svid, 1, CMD_ENTER_MODE | VDO_OPOS((modep->index + 1))); diff --git a/include/usb_pd.h b/include/usb_pd.h index 2184f19230..986f5ef47d 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -130,7 +130,7 @@ struct svdm_svid_data { struct svdm_amode_fx { uint16_t svid; - void (*enter)(int port, uint32_t mode_caps); + int (*enter)(int port, uint32_t mode_caps); int (*status)(int port, uint32_t *payload); int (*config)(int port, uint32_t *payload); int (*attention)(int port, uint32_t *payload); -- cgit v1.2.1