summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-09-10 12:36:02 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-09-20 23:29:00 +0000
commit60554b14ea792cb647b5f6959b5bd532064ca809 (patch)
tree9789907dcc2273ab970aa1c04d65a2a3e9c0e8c8
parentc02b0386f6b0cdbfab2212b80c2dba5980714a75 (diff)
downloadchrome-ec-60554b14ea792cb647b5f6959b5bd532064ca809.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/1236850 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--common/charge_manager.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c
index afe1fc21ed..76c9d4e436 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -231,6 +231,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.
*
@@ -241,24 +270,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)