summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-01-09 11:00:47 -0800
committerAlec Berg <alecaberg@chromium.org>2015-01-10 23:43:43 +0000
commit8fbb6e8070bbe4dacbca44f48c49fe548a5c3e39 (patch)
tree6d3d5cba0fa980aba6be8ae1be246e93941210aa
parentd83bd6b892e696c13f3584b5d3e1e0f51aafe710 (diff)
downloadchrome-ec-8fbb6e8070bbe4dacbca44f48c49fe548a5c3e39.tar.gz
pd: fix possible redundant requests (again)
Another fix for redundant requests. This time there can be redundant requests if the maximum allowed voltage changes, but we still fall into the samus PDO index and therefore are asking for the same voltage. This fixes by checking the voltage value we actually request vs. the max value we can request. BUG=none BRANCH=samus TEST=samus to samus was causing redundant requests and now it's not. Change-Id: Ie49add1a42b86de97cee87f9d4637dd0578e2ce3 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/239950 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org>
-rw-r--r--common/usb_pd_policy.c10
-rw-r--r--common/usb_pd_protocol.c19
-rw-r--r--include/usb_pd.h1
3 files changed, 13 insertions, 17 deletions
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 05c9363de8..f555288267 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -117,24 +117,16 @@ int pd_build_request(int cnt, uint32_t *src_caps, uint32_t *rdo,
pd_extract_pdo_power(src_caps[pdo_index], ma, mv);
uw = *ma * *mv;
+ /* Mismatch bit set if less power offered than the operating power */
if (uw < (1000 * PD_OPERATING_POWER_MW))
flags |= RDO_CAP_MISMATCH;
if ((src_caps[pdo_index] & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
int mw = uw / 1000;
*rdo = RDO_BATT(pdo_index + 1, mw, mw, flags);
- CPRINTF("Request [%d] %dmV %dmW",
- pdo_index, *mv, mw);
} else {
*rdo = RDO_FIXED(pdo_index + 1, *ma, *ma, flags);
- CPRINTF("Request [%d] %dmV %dmA",
- pdo_index, *mv, *ma);
}
- /* Mismatch bit set if less power offered than the operating power */
- if (flags & RDO_CAP_MISMATCH)
- CPRINTF(" Mismatch");
- CPRINTF("\n");
-
return EC_SUCCESS;
}
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 9db9b8bd75..d54c20dcac 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -890,7 +890,6 @@ static void pd_store_src_cap(int port, int cnt, uint32_t *src_caps)
static void pd_send_request_msg(int port, int always_send_request)
{
uint32_t rdo, curr_limit, supply_voltage;
- int request_mv;
int res;
#ifdef CONFIG_CHARGE_MANAGER
@@ -903,12 +902,6 @@ static void pd_send_request_msg(int port, int always_send_request)
/* Build and send request RDO */
/* If this port is not actively charging, select vSafe5V */
- request_mv = charging ? pd_get_max_voltage() : PD_MIN_MV;
-
- /* Don't re-request the same voltage */
- if (!always_send_request && pd[port].prev_request_mv == request_mv)
- return;
-
res = pd_build_request(pd_src_cap_cnt[port], pd_src_caps[port],
&rdo, &curr_limit, &supply_voltage,
charging ? PD_REQUEST_MAX : PD_REQUEST_VSAFE5V);
@@ -920,9 +913,19 @@ static void pd_send_request_msg(int port, int always_send_request)
*/
return;
+ /* Don't re-request the same voltage */
+ if (!always_send_request && pd[port].prev_request_mv == supply_voltage)
+ return;
+
+ CPRINTF("Request [%d] %dmV %dmA", RDO_POS(rdo),
+ supply_voltage, curr_limit);
+ if (rdo & RDO_CAP_MISMATCH)
+ CPRINTF(" Mismatch");
+ CPRINTF("\n");
+
pd[port].curr_limit = curr_limit;
pd[port].supply_voltage = supply_voltage;
- pd[port].prev_request_mv = request_mv;
+ pd[port].prev_request_mv = supply_voltage;
res = send_request(port, rdo);
if (res >= 0)
set_state(port, PD_STATE_SNK_REQUESTED);
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 67c049dcf0..a84736cdae 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -76,6 +76,7 @@ enum pd_errors {
/* RDO : Request Data Object */
#define RDO_OBJ_POS(n) (((n) & 0x7) << 28)
+#define RDO_POS(rdo) (((rdo) >> 28) & 0x7)
#define RDO_GIVE_BACK (1 << 27)
#define RDO_CAP_MISMATCH (1 << 26)
#define RDO_COMM_CAP (1 << 25)