summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Broch <tbroch@chromium.org>2015-01-16 11:14:51 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-30 03:28:32 +0000
commitb97937248879e9557d3f8453addcbaa237edf517 (patch)
treedcd89902cb161f90243a3299e03d5c7d15f5fc29
parent7489e0ded41413780962046cb3b473500943fba7 (diff)
downloadchrome-ec-b97937248879e9557d3f8453addcbaa237edf517.tar.gz
pd: refactor object position index.
Renaming this to 'opos' for consistency with USP-PD specifications 'object position' in VDM header. Signed-off-by: Todd Broch <tbroch@chromium.org> BRANCH=samus BUG=chrome-os-partner:35495 TEST=manual, On hoho 1. Still successfully enter default mode DP 2. Using ectool's pdgetmode pdsetmode can successfully enter/exit other modes 3. Works across hard & soft resets Original-Change-Id: I08cb8e003ced4de481adcb503bcba3437ebb1ab7 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/243464 (cherry picked from commit 3850a013f1bf39919633ea9e6a19d2800b52ef2c) Signed-off-by: Todd Broch <tbroch@chromium.org> Change-Id: I395a36eee8f4403707dde08053ff98a2dbe6a3a6 Reviewed-on: https://chromium-review.googlesource.com/244230 Reviewed-by: Alec Berg <alecaberg@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org> Commit-Queue: Todd Broch <tbroch@chromium.org>
-rw-r--r--common/usb_pd_policy.c31
-rw-r--r--include/ec_commands.h2
-rw-r--r--include/usb_pd.h5
-rw-r--r--util/ectool.c4
4 files changed, 19 insertions, 23 deletions
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 9aa0e7e083..3c6900c532 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -165,12 +165,9 @@ unsigned pd_get_max_voltage(void)
static struct pd_policy pe[PD_PORT_COUNT];
-#define AMODE_VALID(port) (pe[port].amode.index != -1)
-
void pd_dfp_pe_init(int port)
{
memset(&pe[port], 0, sizeof(struct pd_policy));
- pe[port].amode.index = -1;
}
static void dfp_consume_identity(int port, uint32_t *payload)
@@ -253,11 +250,7 @@ static void dfp_consume_modes(int port, int cnt, uint32_t *payload)
int pd_alt_mode(int port)
{
- if (!AMODE_VALID(port))
- /* zero is reserved */
- return 0;
-
- return pe[port].amode.index + 1;
+ return pe[port].amode.opos;
}
/* Enter default mode or attempt to enter mode via svid & index arguments */
@@ -276,12 +269,12 @@ static int dfp_enter_mode(int port, uint32_t *payload, int use_payload)
continue;
modep->fx = &supported_modes[i];
modep->mode_caps = pe[port].svids[j].mode_vdo[0];
- modep->index = (opos && (opos < 7)) ? opos - 1 : 0;
+ modep->opos = (opos && (opos < 7)) ? opos : 1;
done = 1;
break;
}
}
- if (!AMODE_VALID(port))
+ if (!modep->opos)
return 0;
if (modep->fx->enter(port, modep->mode_caps) == -1)
@@ -297,7 +290,7 @@ static void dfp_consume_attention(int port, uint32_t *payload)
int svid = PD_VDO_VID(payload[0]);
int opos = PD_VDO_OPOS(payload[0]);
- if (!AMODE_VALID(port))
+ if (!pe[port].amode.opos)
return;
if (svid != pe[port].amode.fx->svid) {
CPRINTF("PE ERR: svid s:0x%04x != m:0x%04x\n",
@@ -327,7 +320,7 @@ uint32_t pd_dfp_exit_mode(int port)
* to exit all modes.
*/
if (pd_is_connected(port)) {
- modep->index = -1;
+ modep->opos = 0;
return VDO(modep->fx->svid, 1,
(CMD_EXIT_MODE | VDO_OPOS(pd_alt_mode(port))));
} else {
@@ -373,7 +366,7 @@ static void dump_pe(int port)
pe[port].svids[i].mode_vdo[j]);
ccprintf("\n");
}
- if (!AMODE_VALID(port)) {
+ if (!modep->opos) {
ccprintf("No mode chosen yet.\n");
return;
}
@@ -488,9 +481,9 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
* TODO(crosbug.com/p/33946): Fix won't allow multiple
* mode entry.
*/
- if (!AMODE_VALID(port))
+ if (!pe[port].amode.opos)
dfp_enter_mode(port, payload, 1);
- if (AMODE_VALID(port)) {
+ if (pe[port].amode.opos) {
rsize = pe[port].amode.fx->status(port,
payload);
payload[0] |= VDO_OPOS(pd_alt_mode(port));
@@ -500,14 +493,14 @@ int pd_svdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
/* DP status response & UFP's DP attention have same
payload */
dfp_consume_attention(port, payload);
- if (AMODE_VALID(port))
+ if (pe[port].amode.opos)
rsize = pe[port].amode.fx->config(port,
payload);
else
rsize = 0;
break;
case CMD_DP_CONFIG:
- if (AMODE_VALID(port) &&
+ if (pe[port].amode.opos &&
pe[port].amode.fx->post_config)
pe[port].amode.fx->post_config(port);
/* no response after DFPs ack */
@@ -628,9 +621,9 @@ static int hc_remote_pd_get_amode(struct host_cmd_handler_args *args)
r->active = 0;
memcpy(r->vdo, pe[p->port].svids[p->svid_idx].mode_vdo, 24);
- if (AMODE_VALID(p->port) && pe[p->port].amode.fx->svid == r->svid) {
+ if (pe[p->port].amode.opos && pe[p->port].amode.fx->svid == r->svid) {
r->active = 1;
- r->idx = pd_alt_mode(p->port) - 1;
+ r->opos = pd_alt_mode(p->port);
}
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 18e9e454f7..926e317eee 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -2930,7 +2930,7 @@ struct ec_params_usb_pd_get_mode_request {
struct ec_params_usb_pd_get_mode_response {
uint16_t svid; /* SVID */
uint8_t active; /* Active SVID */
- uint8_t idx; /* Index of active mode VDO. Ignored if !active */
+ uint8_t opos; /* Object Position */
uint32_t vdo[6]; /* Mode VDOs */
} __packed;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 14b83ae41b..27c3ae1740 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -189,9 +189,12 @@ extern const struct svdm_response svdm_rsp;
extern const struct svdm_amode_fx supported_modes[];
extern const int supported_modes_cnt;
+/* DFP data needed to support alternate mode entry and exit */
struct svdm_amode_data {
const struct svdm_amode_fx *fx;
- int index;
+ /* VDM object position */
+ int opos;
+ /* mode capabilities specific to SVID amode. */
uint32_t mode_caps;
};
diff --git a/util/ectool.c b/util/ectool.c
index f98a98a943..de1b378fdc 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -876,7 +876,7 @@ static int in_gfu_mode(int *opos, int port)
}
}
- return r->active && ((r->idx + 1) == *opos);
+ return r->active && (r->opos == *opos);
}
/**
@@ -1168,7 +1168,7 @@ int cmd_pd_get_amode(int argc, char *argv[])
printf("%cSVID:0x%04x ", (r->active) ? '*' : ' ',
r->svid);
for (i = 0; i < PDO_MODES; i++) {
- printf("%c0x%08x ", (r->active && (r->idx == i)) ?
+ printf("%c0x%08x ", (r->active && (r->opos == i + 1)) ?
'*' : ' ', r->vdo[i]);
}
printf("\n");