summaryrefslogtreecommitdiff
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
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>
-rw-r--r--board/dingdong/usb_pd_policy.c2
-rw-r--r--board/hoho/usb_pd_policy.c2
-rw-r--r--board/samus_pd/usb_pd_policy.c6
-rw-r--r--common/usb_pd_policy.c25
-rw-r--r--common/usb_pd_protocol.c2
-rw-r--r--include/usb_pd.h3
6 files changed, 26 insertions, 14 deletions
diff --git a/board/dingdong/usb_pd_policy.c b/board/dingdong/usb_pd_policy.c
index 1cd9a7a5f0..181bc5a17f 100644
--- a/board/dingdong/usb_pd_policy.c
+++ b/board/dingdong/usb_pd_policy.c
@@ -215,7 +215,7 @@ static int svdm_enter_mode(int port, uint32_t *payload)
return 1;
}
-int pd_alt_mode(void)
+int pd_alt_mode(int port)
{
return alt_mode;
}
diff --git a/board/hoho/usb_pd_policy.c b/board/hoho/usb_pd_policy.c
index 252bef6ac7..a5c333ef10 100644
--- a/board/hoho/usb_pd_policy.c
+++ b/board/hoho/usb_pd_policy.c
@@ -214,7 +214,7 @@ static int svdm_enter_mode(int port, uint32_t *payload)
return 1;
}
-int pd_alt_mode(void)
+int pd_alt_mode(int port)
{
return alt_mode;
}
diff --git a/board/samus_pd/usb_pd_policy.c b/board/samus_pd/usb_pd_policy.c
index b30a46b71b..0425ef66a9 100644
--- a/board/samus_pd/usb_pd_policy.c
+++ b/board/samus_pd/usb_pd_policy.c
@@ -265,7 +265,8 @@ static int dp_on;
static int svdm_dp_status(int port, uint32_t *payload)
{
- payload[0] = VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_STATUS);
+ payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
+ CMD_DP_STATUS | VDO_OPOS(pd_alt_mode(port)));
payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
0, /* HPD level ... not applicable */
0, /* exit DP? ... no */
@@ -281,7 +282,8 @@ static int svdm_dp_config(int port, uint32_t *payload)
{
board_set_usb_mux(port, TYPEC_MUX_DP, pd_get_polarity(port));
dp_on = 1;
- payload[0] = VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_CONFIG);
+ payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
+ CMD_DP_CONFIG | VDO_OPOS(pd_alt_mode(port)));
payload[1] = VDO_DP_CFG(MODE_DP_PIN_E, /* sink pins */
MODE_DP_PIN_E, /* src pins */
1, /* DPv1.3 signaling */
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
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 77e383aea5..4bfd8b69e0 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -2000,7 +2000,7 @@ static int remote_flashing(int argc, char **argv)
void pd_send_hpd(int port, enum hpd_event hpd)
{
uint32_t data[1];
- int opos = pd_alt_mode();
+ int opos = pd_alt_mode(port);
if (!opos)
return;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 8b2a7171ec..848586aea7 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -817,9 +817,10 @@ void board_flip_usb_mux(int port);
/**
* Determine if in alternate mode or not.
*
+ * @param port port number.
* @return object position of mode chosen in alternate mode otherwise zero.
*/
-int pd_alt_mode(void);
+int pd_alt_mode(int port);
/**
* Send hpd over USB PD.