From 4293de83e09a0a9ee24e422e09f7012c7a6a751e Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Mon, 4 May 2015 15:57:42 -0700 Subject: pd: fix PDO selection for low voltage boards When the policy of the board is to select lowest voltage providing enough power, the current algorithm ignores the fact that the board input current limit might be lower than the charger maximum current for a particular voltage level leading to the possibility of selected a voltage with a lower available power. Signed-off-by: Vincent Palatin BRANCH=none BUG=none TEST=set a Ryu board with the following configuration : PD_PREFER_LOW_VOLTAGE PD_MAX_POWER_MW 24000 PD_MAX_CURRENT_MA 1000 PD_MAX_VOLTAGE_MV 20000 connect it a Zinger (offering 3A @ 20V, 3A @ 12V and 3A @ 5V), see it selecting 20V rather 12V before the patch. Change-Id: I8c0589bb5e5705c4d8a6035120d1cdfaacaa14df Reviewed-on: https://chromium-review.googlesource.com/269262 Reviewed-by: Vic Yang Reviewed-by: Alec Berg Commit-Queue: Vincent Palatin Tested-by: Vincent Palatin --- common/usb_pd_policy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index 96cf970a30..21d4f1b0e1 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -72,6 +72,7 @@ static int pd_find_pdo_index(int cnt, uint32_t *src_caps, int max_mv) uw = 250000 * (src_caps[i] & 0x3FF); } else { ma = (src_caps[i] & 0x3FF) * 10; + ma = MIN(ma, PD_MAX_CURRENT_MA); uw = ma * mv; } #ifdef PD_PREFER_LOW_VOLTAGE -- cgit v1.2.1