From ddc5bfd3d0921a80dbb987025f06b8cbf773a640 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Wed, 3 Dec 2014 22:23:55 -0800 Subject: [PATCH] pd: do not allow FW update on active charging port if no battery Do not allow remote PD firmware update of a device that is providing us power when we have no battery (or else we will lose power). BUG=none BRANCH=samus TEST=attach a zinger that has an old FW to samus with no battery and see that host attempts to update FW but PD MCU does not allow it. Change-Id: Iaf816dc44017d9c65a2b248ea8536d7c03898910 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/233752 Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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);