diff options
author | li feng <li1.feng@intel.com> | 2021-04-29 21:26:17 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-01 03:07:48 +0000 |
commit | 01ef01d06be623269cf286c580d39e1f0e3a78d4 (patch) | |
tree | c4397d9aae192186e8700be985a260c2e6db779c /common/usb_common.c | |
parent | 7b08eda737c78d7bbf7e64b27e4c2a69c46b334f (diff) | |
download | chrome-ec-01ef01d06be623269cf286c580d39e1f0e3a78d4.tar.gz |
tcpc: Add common routine to check power
This comment is from CL:1123314:
We do not want to allow depthcharge to suspend the PD port for a
firmware upgrade if there is not enough battery power to last during
the full firmware upgrade.
A common routine is created to check power:
pd_firmware_upgrade_check_power_readiness() in usb_common.c.
Firmware upgrade which needs to suspend PD port should check
this function to make sure there is enough power.
BUG=none
BRANCH=none
TEST=make -j buildall
Signed-off-by: li feng <li1.feng@intel.com>
Change-Id: I47910a4d82da9b569c297ad2cd399a2faf4cf98a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2862556
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'common/usb_common.c')
-rw-r--r-- | common/usb_common.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/common/usb_common.c b/common/usb_common.c index 7a21eb1676..2e1030ea9a 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -38,6 +38,14 @@ #define CPRINTF(format, args...) #endif +/* + * If we are trying to upgrade PD firmwares (TCPC chips, retimer, etc), we + * need to ensure the battery has enough charge for this process. 100mAh + * is about 5% of most batteries, and it should be enough charge to get us + * through the EC jump to RW and PD upgrade. + */ +#define MIN_BATTERY_FOR_PD_UPGRADE_MAH 100 /* mAH */ + __overridable void board_vbus_present_change(void) { } @@ -122,6 +130,39 @@ int remote_flashing(int argc, char **argv) } #endif /* defined(CONFIG_CMD_PD) && defined(CONFIG_CMD_PD_FLASH) */ +bool pd_firmware_upgrade_check_power_readiness(int port) +{ + if (IS_ENABLED(HAS_TASK_CHARGER)) { + struct batt_params batt = { 0 }; + /* + * Cannot rely on the EC's active charger data as the + * EC may just rebooted into RW and has not necessarily + * picked the active charger yet. Charger task may not + * initialized, so check battery directly. + * Prevent the upgrade if the battery doesn't have enough + * charge to finish the upgrade. + */ + battery_get_params(&batt); + if (batt.flags & BATT_FLAG_BAD_REMAINING_CAPACITY || + batt.remaining_capacity < + MIN_BATTERY_FOR_PD_UPGRADE_MAH) { + CPRINTS("C%d: Cannot suspend for upgrade, not " + "enough battery (%dmAh)!", + port, batt.remaining_capacity); + return false; + } + } else { + /* VBUS is present on the port (it is either a + * source or sink) to provide power, so don't allow + * PD firmware upgrade on the port. + */ + if (pd_is_vbus_present(port)) + return false; + } + + return true; +} + int usb_get_battery_soc(void) { #if defined(CONFIG_CHARGER) |