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 <victoryang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/242670
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vic Yang
2015-01-22 12:57:15 -08:00
committed by ChromeOS Commit Bot
parent a6479508e2
commit 55e9d8a0c1
2 changed files with 17 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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;
}