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>
This commit is contained in:
Todd Broch
2014-11-06 02:34:47 -08:00
committed by chrome-internal-fetch
parent 56d92341f3
commit 84681349f4
6 changed files with 26 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 */

View File

@@ -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

View File

@@ -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;

View File

@@ -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.