diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-09-10 12:36:02 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-20 21:29:59 -0700 |
commit | d5b9b8c12570a57def102d0039f0aef379582fb0 (patch) | |
tree | 378292bdfdfd502a32ba725300cf219b066bda73 | |
parent | fd3f9b9a304bb4838bd0b015981e1798b15552f6 (diff) | |
download | chrome-ec-d5b9b8c12570a57def102d0039f0aef379582fb0.tar.gz |
Make USB_PD_POWER_INFO detect inactive supplier
Currently, CMD_USB_PD_POWER_INFO does not report a supplier if the
available current is 0. This causes a dedicated charger (a barrel
jack adapter) to be ignored by the command if it's not the active
supplier.
This change allows a supplier which has 0 current to be reported
by the command as long as there is no other supplier with positive
current on the same port. With this change, the host can detect
a BJ adapter's physical presence regardless of its charging status.
In other words, a supplier with positive current always supersedes
whatever supplier with zero current.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=chromium:841944,b:111667665,b:111777351
BRANCH=none
TEST=Verify ectool usbpdpower 1 return 'Port 1: Disconnected' and
'Port 1: SNK (not charging)' without and with a BJ adapter connected
respectively on Fizz.
Change-Id: I22ba5f147209177c0c9cac87a123d4c3d0f2ec68
Reviewed-on: https://chromium-review.googlesource.com/1217607
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/charge_manager.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c index 315610328b..08bd3d1b0a 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -233,6 +233,35 @@ static int charge_manager_get_source_current(int port) } } +/* + * Find a supplier considering available current, voltage, power, and priority. + */ +static enum charge_supplier find_supplier(int port, enum charge_supplier sup, + int min_cur) +{ + int i; + for (i = 0; i < CHARGE_SUPPLIER_COUNT; ++i) { + if (available_charge[i][port].current <= min_cur || + available_charge[i][port].voltage <= 0) + /* Doesn't meet volt or current requirement. Skip it. */ + continue; + if (sup == CHARGE_SUPPLIER_NONE) + /* Haven't found any yet. Take it unconditionally. */ + sup = i; + else if (supplier_priority[sup] < supplier_priority[i]) + /* There is already a higher priority supplier. */ + continue; + else if (supplier_priority[i] < supplier_priority[sup]) + /* This has a higher priority. Take it. */ + sup = i; + else if (POWER(available_charge[i][port]) > + POWER(available_charge[sup][port])) + /* Priority is tie. Take it if power is higher. */ + sup = i; + } + return sup; +} + /** * Fills passed power_info structure with current info about the passed port. * @@ -243,24 +272,17 @@ static void charge_manager_fill_power_info(int port, struct ec_response_usb_pd_power_info *r) { int sup = CHARGE_SUPPLIER_NONE; - int i; /* Determine supplier information to show. */ - if (port == charge_port) + if (port == charge_port) { sup = charge_supplier; - else - /* Find highest priority supplier */ - for (i = 0; i < CHARGE_SUPPLIER_COUNT; ++i) - if (available_charge[i][port].current > 0 && - available_charge[i][port].voltage > 0 && - (sup == CHARGE_SUPPLIER_NONE || - supplier_priority[i] < - supplier_priority[sup] || - (supplier_priority[i] == - supplier_priority[sup] && - POWER(available_charge[i][port]) > - POWER(available_charge[sup][port])))) - sup = i; + } else { + /* Consider available current */ + sup = find_supplier(port, sup, 0); + if (sup == CHARGE_SUPPLIER_NONE) + /* Ignore available current */ + sup = find_supplier(port, sup, -1); + } /* Fill in power role */ if (charge_port == port) |