summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorli feng <li1.feng@intel.com>2021-04-28 21:21:58 -0700
committerCommit Bot <commit-bot@chromium.org>2021-05-03 04:14:46 +0000
commitc08a4f19644bc3cc57b325e027bfa3eeac17a37b (patch)
treefba555ad3f9163ba44092c5a2d432d251b478afc
parentfb0108e6173072149c43f8ddbfd9a8488a4604dd (diff)
downloadchrome-ec-c08a4f19644bc3cc57b325e027bfa3eeac17a37b.tar.gz
retimer: check power for firmware upgrade
Before retimer firmware update, check power, if battery is not present, or battery level is low (<5%), not allow PD suspend/performing retimer firmware update process. BUG=b:185320314 BRANCH=none TEST=On Voxel DVT, AC only, no battery, boot up system and confirm NDA PD port is not suspended, and retimer firmware update is not performed. DA port has correct device functions. TEST=On Voxel DVT, battery is low (< 5%), boot up system and confirmed NDA PD ports is not suspended, and retimer firmware update is not performed; DA port has correct device functions. TEST=On Voxel DVT, when battery level >=5%, confirmed NDA PD port can be suspended and retimer is scanned. DA port has correct device functions; device tested are DP dongle, TBT dock and USB4 device. Signed-off-by: li feng <li1.feng@intel.com> Change-Id: I1c5b2bc54b2f6307503f82112f28bbc8d6b0591a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2858283 Reviewed-by: Keith Short <keithshort@chromium.org> (cherry picked from commit 7499e5b0472f142cb3cec7af8d35903ed96f74a5) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2865025 Tested-by: Keith Short <keithshort@chromium.org> Commit-Queue: Zhuohao Lee <zhuohao@chromium.org>
-rw-r--r--common/usbc/usb_retimer_fw_update.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/common/usbc/usb_retimer_fw_update.c b/common/usbc/usb_retimer_fw_update.c
index 5d420ad991..2634081e2e 100644
--- a/common/usbc/usb_retimer_fw_update.c
+++ b/common/usbc/usb_retimer_fw_update.c
@@ -3,7 +3,6 @@
* found in the LICENSE file.
*/
-#include "atomic.h"
#include <stdbool.h>
#include <stdint.h>
#include "compile_time_macros.h"
@@ -52,8 +51,8 @@
/* Track current port AP requested to update retimer firmware */
static int cur_port;
static int last_op; /* Operation received from AP via ACPI_WRITE */
-/* MUX value returned to ACPI_READ */
-static int last_mux_result = USB_RETIMER_FW_UPDATE_INVALID_MUX;
+/* Operation result returned to ACPI_READ */
+static int last_result;
int usb_retimer_fw_update_get_result(void)
{
@@ -61,6 +60,11 @@ int usb_retimer_fw_update_get_result(void)
switch (last_op) {
case USB_RETIMER_FW_UPDATE_SUSPEND_PD:
+ if (last_result == USB_RETIMER_FW_UPDATE_ERR) {
+ result = last_result;
+ break;
+ }
+ /* fall through */
case USB_RETIMER_FW_UPDATE_RESUME_PD:
result = pd_is_port_enabled(cur_port);
break;
@@ -72,7 +76,7 @@ int usb_retimer_fw_update_get_result(void)
case USB_RETIMER_FW_UPDATE_SET_SAFE:
case USB_RETIMER_FW_UPDATE_SET_TBT:
case USB_RETIMER_FW_UPDATE_DISCONNECT:
- result = last_mux_result;
+ result = last_result;
break;
default:
break;
@@ -91,6 +95,16 @@ void usb_retimer_fw_update_process_op_cb(int port)
{
switch (last_op) {
case USB_RETIMER_FW_UPDATE_SUSPEND_PD:
+ last_result = 0;
+ /*
+ * Do not perform retimer firmware update process
+ * if battery is not present, or battery level is low.
+ */
+ if (!pd_firmware_upgrade_check_power_readiness(port)) {
+ last_result = USB_RETIMER_FW_UPDATE_ERR;
+ break;
+ }
+
/*
* If the port has entered low power mode, the PD task
* is paused and will not complete processing of
@@ -104,26 +118,26 @@ void usb_retimer_fw_update_process_op_cb(int port)
pd_set_suspend(port, RESUME);
break;
case USB_RETIMER_FW_UPDATE_GET_MUX:
- last_mux_result = usb_mux_get(port);
+ last_result = usb_mux_get(port);
break;
case USB_RETIMER_FW_UPDATE_SET_USB:
usb_mux_set(port, USB_PD_MUX_USB_ENABLED,
USB_SWITCH_CONNECT, pd_get_polarity(port));
- last_mux_result = usb_mux_get(port);
+ last_result = usb_mux_get(port);
break;
case USB_RETIMER_FW_UPDATE_SET_SAFE:
usb_mux_set_safe_mode(port);
- last_mux_result = usb_mux_get(port);
+ last_result = usb_mux_get(port);
break;
case USB_RETIMER_FW_UPDATE_SET_TBT:
usb_mux_set(port, USB_PD_MUX_TBT_COMPAT_ENABLED,
USB_SWITCH_CONNECT, pd_get_polarity(port));
- last_mux_result = usb_mux_get(port);
+ last_result = usb_mux_get(port);
break;
case USB_RETIMER_FW_UPDATE_DISCONNECT:
usb_mux_set(port, USB_PD_MUX_NONE,
USB_SWITCH_DISCONNECT, pd_get_polarity(port));
- last_mux_result = usb_mux_get(port);
+ last_result = usb_mux_get(port);
break;
default:
break;
@@ -145,7 +159,7 @@ void usb_retimer_fw_update_process_op(int port, int op)
break;
/* Operations can't be processed in ISR, defer to later */
case USB_RETIMER_FW_UPDATE_GET_MUX:
- last_mux_result = USB_RETIMER_FW_UPDATE_INVALID_MUX;
+ last_result = USB_RETIMER_FW_UPDATE_INVALID_MUX;
tc_usb_firmware_fw_update_run(port);
break;
case USB_RETIMER_FW_UPDATE_SUSPEND_PD:
@@ -158,9 +172,9 @@ void usb_retimer_fw_update_process_op(int port, int op)
case USB_RETIMER_FW_UPDATE_SET_TBT:
case USB_RETIMER_FW_UPDATE_DISCONNECT:
if (pd_is_port_enabled(port)) {
- last_mux_result = USB_RETIMER_FW_UPDATE_ERR;
+ last_result = USB_RETIMER_FW_UPDATE_ERR;
} else {
- last_mux_result = USB_RETIMER_FW_UPDATE_INVALID_MUX;
+ last_result = USB_RETIMER_FW_UPDATE_INVALID_MUX;
tc_usb_firmware_fw_update_limited_run(port);
}
break;