summaryrefslogtreecommitdiff
path: root/common/usb_pd_policy.c
diff options
context:
space:
mode:
authorTodd Broch <tbroch@chromium.org>2014-11-06 02:34:47 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-11 00:11:18 +0000
commit84681349f444a9596d38117b41e8a279bb52a856 (patch)
treee53c17bcb712f8a41521bd60c54dae994d28797c /common/usb_pd_policy.c
parent56d92341f39570ea0f3e3ae2600b9710f79b6c3c (diff)
downloadchrome-ec-84681349f444a9596d38117b41e8a279bb52a856.tar.gz
pd: Send proper OPOS for DP status & config.
Once a mode is entered object position (OPOS ... AKA alternate mode) field in the VDM header should always track that mode. CL fixes DP status & config messages which did not add the correct OPOS. In fixing I mapped to the UFPs function pd_alt_mode which for the DFP did require the addition of port parameter. Finally I cleaned up code to use this function throughout common policy layer where previously I'd just accessed the pe structure directly. BRANCH=samus_pd BUG=none TEST=manual, compiles, insert hoho/dingdong into samus and see OPOS=1 from samus for enter, dp_config, dp_status SVDMs Change-Id: I66448c3386be01bae58768632da216aff41a9a30 Signed-off-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/228130 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'common/usb_pd_policy.c')
-rw-r--r--common/usb_pd_policy.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index eb7de25777..11f8c35620 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -113,6 +113,15 @@ static int dfp_consume_modes(int port, int cnt, uint32_t *payload)
return (pe[port].svid_idx < pe[port].svid_cnt);
}
+int pd_alt_mode(int port)
+{
+ if (!AMODE_VALID(port))
+ /* zero is reserved */
+ return 0;
+
+ return pe[port].amode.index + 1;
+}
+
/* TODO(tbroch) this function likely needs to move up the stack to where system
* policy decisions are made. */
static int dfp_enter_mode(int port, uint32_t *payload)
@@ -138,8 +147,7 @@ static int dfp_enter_mode(int port, uint32_t *payload)
return 0;
payload[0] = VDO(modep->fx->svid, 1,
- CMD_ENTER_MODE |
- VDO_OPOS((modep->index + 1)));
+ CMD_ENTER_MODE | VDO_OPOS(pd_alt_mode(port)));
return 1;
}
@@ -155,9 +163,9 @@ static void dfp_consume_attention(int port, uint32_t *payload)
svid, pe[port].amode.fx->svid);
return;
}
- if (opos != pe[port].amode.index + 1) {
+ if (opos != pd_alt_mode(port)) {
CPRINTF("PE ERR: opos s:%d != m:%d\n",
- opos, pe[port].amode.index + 1);
+ opos, pd_alt_mode(port));
return;
}
if (pe[port].amode.fx->attention)
@@ -174,7 +182,7 @@ int pd_exit_mode(int port, uint32_t *payload)
if (payload)
payload[0] = VDO(modep->fx->svid, 1,
- CMD_EXIT_MODE | VDO_OPOS((modep->index + 1)));
+ CMD_EXIT_MODE | VDO_OPOS(pd_alt_mode(port)));
modep->index = -1;
return 1;
}
@@ -200,7 +208,7 @@ static void dump_pe(int port)
return;
}
- ccprintf("MODE[%d]: svid:%04x caps:%08x\n", pe[port].amode.index + 1,
+ ccprintf("MODE[%d]: svid:%04x caps:%08x\n", pd_alt_mode(port),
pe[port].amode.fx->svid, pe[port].amode.mode_caps);
}
@@ -314,7 +322,7 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
rsize = pe[port].amode.fx->status(port,
payload);
payload[0] |=
- VDO_OPOS((pe[port].amode.index + 1));
+ VDO_OPOS(pd_alt_mode(port));
} else {
rsize = 0;
}
@@ -401,7 +409,8 @@ void pd_usb_billboard_deferred(void)
#if defined(CONFIG_USB_PD_ALT_MODE) && !defined(CONFIG_USB_PD_ALT_MODE_DFP) \
&& !defined(CONFIG_USB_PD_SIMPLE_DFP)
- if (!pd_alt_mode())
+ /* port always zero for these UFPs */
+ if (!pd_alt_mode(0))
usb_connect();
#endif