diff options
author | Peter Marheine <pmarheine@chromium.org> | 2022-02-09 13:58:45 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-02-14 07:56:34 +0000 |
commit | 3fd1887ee80978cd249ae443c9eeb38f40f02e54 (patch) | |
tree | 4dd9af6b9c7dc8dbfdfe0ae74e3bbc8e16713c2b /zephyr | |
parent | 461d6ce5cd127d45a19bbe62fe9d54dfb99dbcd1 (diff) | |
download | chrome-ec-3fd1887ee80978cd249ae443c9eeb38f40f02e54.tar.gz |
nissa/nereid: implement board_set_active_charge_port
This change makes the Nereid charger actually be enabled when the charger
task requests it, allowing the battery to charge.
BUG=b:201000844
TEST=battery now charges at ~4400 mA when charging from port C0 with PD
contract for 3A at 20V, stops charging with `chgoverride -2`
BRANCH=none
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: If22f10954c71a2d2f7f5007eeb115770a9723a02
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3449990
Reviewed-by: Andrew McRae <amcrae@google.com>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/projects/nissa/src/nereid/usbc.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/zephyr/projects/nissa/src/nereid/usbc.c b/zephyr/projects/nissa/src/nereid/usbc.c index e6d514dd8f..7cd42b4d73 100644 --- a/zephyr/projects/nissa/src/nereid/usbc.c +++ b/zephyr/projects/nissa/src/nereid/usbc.c @@ -82,7 +82,56 @@ __override bool pd_check_vbus_level(int port, enum vbus_level level) int board_set_active_charge_port(int port) { - return EC_SUCCESS; + int is_real_port = (port >= 0 && port < board_get_usb_pd_port_count()); + int i; + int old_port; + int rv; + + if (!is_real_port && port != CHARGE_PORT_NONE) + return EC_ERROR_INVAL; + + old_port = charge_manager_get_active_charge_port(); + LOG_INF("Charge update: p%d -> p%d", old_port, port); + + /* Check if port is sourcing VBUS. */ + if (port != CHARGE_PORT_NONE && charger_is_sourcing_otg_power(port)) { + LOG_WRN("Skip enable p%d: already sourcing", port); + return EC_ERROR_INVAL; + } + + /* Disable sinking on all ports except the desired one */ + for (i = 0; i < board_get_usb_pd_port_count(); i++) { + if (i == port) + continue; + + if (sm5803_vbus_sink_enable(i, 0)) + /* + * Do not early-return because this can fail during + * power-on which would put us into a loop. + */ + LOG_WRN("p%d: sink path disable failed.", i); + } + + /* Don't enable anything (stop here) if no ports were requested */ + if (port == CHARGE_PORT_NONE) + return EC_SUCCESS; + + /* + * Stop the charger IC from switching while changing ports. Otherwise, + * we can overcurrent the adapter we're switching to. (crbug.com/926056) + */ + if (old_port != CHARGE_PORT_NONE) + charger_discharge_on_ac(1); + + /* Enable requested charge port. */ + rv = sm5803_vbus_sink_enable(port, 1); + if (rv) + LOG_WRN("p%d: sink path enable failed: code %d", port, rv); + + /* Allow the charger IC to begin/continue switching. */ + charger_discharge_on_ac(0); + + return rv; } uint16_t tcpc_get_alert_status(void) |