From 8a9d0cae28c77be4ce1013802ea6f8713b3e5033 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Tue, 4 Nov 2014 13:00:22 -0800 Subject: pd: for request message, add operational and max current For request message, add the operational and max current for each board. If the requested power is less than the operational power required, then set mismatch bit. BUG=none BRANCH=samus TEST=make buildall. load onto samus, plug in zinger and see that request 20V, operational current 3000mA and max current of 3000mA. Change-Id: I4df45d88b7e060f66ff5b806f6fe30803f1afcf7 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/227393 Reviewed-by: Todd Broch Reviewed-by: Vincent Palatin --- board/hoho/usb_pd_policy.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'board/hoho/usb_pd_policy.c') diff --git a/board/hoho/usb_pd_policy.c b/board/hoho/usb_pd_policy.c index b1279d76a9..252bef6ac7 100644 --- a/board/hoho/usb_pd_policy.c +++ b/board/hoho/usb_pd_policy.c @@ -25,6 +25,11 @@ const uint32_t pd_src_pdo[] = {}; const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); +/* Define typical operating power and max power */ +#define OPERATING_POWER_MW 1000 +#define MAX_POWER_MW 1500 +#define MAX_CURRENT_MA 300 + /* Fake PDOs : we just want our pre-defined voltages */ const uint32_t pd_snk_pdo[] = { PDO_FIXED(5000, 500, 0), @@ -43,6 +48,8 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo, int i; int ma; int set_mv = select_mv; + int max; + uint32_t flags; /* Default to 5V */ if (set_mv <= 0) @@ -58,11 +65,19 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo, if (i < 0) return -EC_ERROR_UNKNOWN; - /* request all the power ... */ + /* build rdo for desired power */ ma = 10 * (src_caps[i] & 0x3FF); - *rdo = RDO_FIXED(i + 1, ma, ma, 0); - CPRINTF("Request [%d] %dV %dmA\n", i, set_mv/1000, ma); - *curr_limit = ma; + max = MIN(ma, MAX_CURRENT_MA); + flags = (max * set_mv) < (1000 * OPERATING_POWER_MW) ? + RDO_CAP_MISMATCH : 0; + *rdo = RDO_FIXED(i + 1, max, max, 0); + CPRINTF("Request [%d] %dV %dmA", i, set_mv/1000, max); + /* Mismatch bit set if less power offered than the operating power */ + if (flags & RDO_CAP_MISMATCH) + CPRINTF(" Mismatch"); + CPRINTF("\n"); + + *curr_limit = max; *supply_voltage = set_mv; return EC_SUCCESS; } -- cgit v1.2.1