From 55e9d8a0c19c8864065d7d09e2ada0e7c27cf414 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Thu, 22 Jan 2015 12:57:15 -0800 Subject: [PATCH] ryu: Choose low input voltage whenever possible To achieve higher power efficiency, we want the input voltage to be as low as possible. If the PD source advertise several choices over PD_MAX_POWER_MW, choose the one with the lowest voltage. BRANCH=Ryu BUG=None TEST=Plug in Ryu to Zinger and check that 12V is selected. Change-Id: Id8c4da65bfd3dfd174e1fd5528af9f7df7da2a74 Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/242670 Reviewed-by: Alec Berg Commit-Queue: Vic Yang Tested-by: Vic Yang Reviewed-by: Vincent Palatin --- board/ryu/usb_pd_config.h | 3 +++ common/usb_pd_policy.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/board/ryu/usb_pd_config.h b/board/ryu/usb_pd_config.h index 94f34752dc..4985454675 100644 --- a/board/ryu/usb_pd_config.h +++ b/board/ryu/usb_pd_config.h @@ -183,4 +183,7 @@ static inline int pd_snk_is_vbus_provided(int port) #define PD_MAX_CURRENT_MA 3000 #define PD_MAX_VOLTAGE_MV 20000 +/* The lower the input voltage, the higher the power efficiency. */ +#define PD_PREFER_LOW_VOLTAGE + #endif /* __USB_PD_CONFIG_H */ diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index fc1884e991..6e5f32c3d5 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -50,6 +50,9 @@ static int pd_find_pdo_index(int cnt, uint32_t *src_caps, int max_mv) { int i, uw, max_uw = 0, mv, ma; int ret = -1; +#ifdef PD_PREFER_LOW_VOLTAGE + int cur_mv; +#endif /* max_mv of -1 represents max limit */ if (max_mv == -1) @@ -71,10 +74,21 @@ static int pd_find_pdo_index(int cnt, uint32_t *src_caps, int max_mv) ma = (src_caps[i] & 0x3FF) * 10; uw = ma * mv; } +#ifdef PD_PREFER_LOW_VOLTAGE + if (mv > max_mv) + continue; + uw = MIN(uw, PD_MAX_POWER_MW * 1000); + if ((uw > max_uw) || ((uw == max_uw) && mv < cur_mv)) { + ret = i; + max_uw = uw; + cur_mv = mv; + } +#else if ((uw > max_uw) && (mv <= max_mv)) { ret = i; max_uw = uw; } +#endif } return ret; }