diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index b9ed705d65..e20d2c21cb 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -4,6 +4,7 @@ */ #include "adc.h" +#include "battery.h" #include "board.h" #include "charge_manager.h" #include "chipset.h" @@ -2783,6 +2784,17 @@ static int hc_remote_flash(struct host_cmd_handler_args *args) if (p->size + sizeof(*p) > args->params_size) return EC_RES_INVALID_PARAM; +#if defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \ + defined(CONFIG_BATTERY_PRESENT_GPIO) + /* + * Do not allow PD firmware update if no battery and this port + * is sinking power, because we will lose power. + */ + if (battery_is_present() != BP_YES && + charge_manager_get_active_charge_port() == port) + return EC_RES_UNAVAILABLE; +#endif + switch (p->cmd) { case USB_PD_FW_REBOOT: pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_REBOOT, NULL, 0);