summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@google.com>2015-01-22 12:57:15 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-24 01:46:02 +0000
commit55e9d8a0c19c8864065d7d09e2ada0e7c27cf414 (patch)
treeb98ed359effaca95f92d4d2f440f60073ec3aaf0
parenta6479508e2b14c502fada6e1300600dd49e237eb (diff)
downloadchrome-ec-55e9d8a0c19c8864065d7d09e2ada0e7c27cf414.tar.gz
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>
-rw-r--r--board/ryu/usb_pd_config.h3
-rw-r--r--common/usb_pd_policy.c14
2 files changed, 17 insertions, 0 deletions
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;
}