summaryrefslogtreecommitdiff
path: root/common/usb_pd_dual_role.c
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2020-10-08 10:07:17 -0700
committerCommit Bot <commit-bot@chromium.org>2020-10-17 03:13:01 +0000
commit3a8f417306a69e12794b38ea2a01d2f1cc7eb5f5 (patch)
treef4c3a9a2c1e69ad15ff02b47e43b4c68973ba78b /common/usb_pd_dual_role.c
parentfca847fa644cfeb5182801a9dde08c0260faa05b (diff)
downloadchrome-ec-3a8f417306a69e12794b38ea2a01d2f1cc7eb5f5.tar.gz
TCPMv2: Use a common function to check if the battery is capable
Move the battery checks to a common function, which is used to enable Try.SRC and enable PD comm for CONFIG_SYSTEM_LOCKED. BRANCH=None BUG=b:169453974 TEST=On a board with battery which takes longer time to enable its discharge FET, cut off the battery and booted the board. Checked on startup the Try.SRC was disabled and the PD comm was disabled. When the battery discharge FET became active, PD comm was enabled. Change-Id: I236d5f8a462ece056b4adedd0b6e6ef1e402966c Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2461942 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/usb_pd_dual_role.c')
-rw-r--r--common/usb_pd_dual_role.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/common/usb_pd_dual_role.c b/common/usb_pd_dual_role.c
index aad8d56768..5fc19f91fe 100644
--- a/common/usb_pd_dual_role.c
+++ b/common/usb_pd_dual_role.c
@@ -345,31 +345,22 @@ int pd_charge_from_device(uint16_t vid, uint16_t pid)
(pid == USB_PID1_APPLE || pid == USB_PID2_APPLE));
}
-#ifdef CONFIG_USB_PD_TRY_SRC
-bool pd_is_try_source_capable(void)
+bool pd_is_battery_capable(void)
{
- int i;
- uint8_t try_src = 0;
- bool new_try_src;
+ bool capable;
- for (i = 0; i < board_get_usb_pd_port_count(); i++)
- try_src |= (pd_get_dual_role(i) == PD_DRP_TOGGLE_ON);
-
- /*
- * Enable try source when dual-role toggling AND battery is present
- * and at some minimum percentage.
- */
- new_try_src = (try_src &&
- usb_get_battery_soc() >= CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC);
+ /* Battery is present and at some minimum percentage. */
+ capable = (usb_get_battery_soc() >=
+ CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC);
#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
/*
- * Don't attempt Try.Src if the battery is in the disconnect state. The
- * discharge FET may not be enabled and so attempting Try.Src may cut
- * off our only power source at the time.
+ * Not capable if the battery is in the disconnect state. The discharge
+ * FET may not be enabled and so attempting being a SRC may cut off
+ * our only power source at the time.
*/
- new_try_src &= (battery_get_disconnect_state() ==
- BATTERY_NOT_DISCONNECTED);
+ capable &= (battery_get_disconnect_state() ==
+ BATTERY_NOT_DISCONNECTED);
#elif defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
defined(CONFIG_BATTERY_PRESENT_GPIO)
/*
@@ -377,9 +368,28 @@ bool pd_is_try_source_capable(void)
* check if battery is present with its state of charge.
* Also check if battery is initialized and ready to provide power.
*/
- new_try_src &= (battery_is_present() == BP_YES);
+ capable &= (battery_is_present() == BP_YES);
#endif /* CONFIG_BATTERY_PRESENT_[CUSTOM|GPIO] */
+ return capable;
+}
+
+#ifdef CONFIG_USB_PD_TRY_SRC
+bool pd_is_try_source_capable(void)
+{
+ int i;
+ uint8_t try_src = 0;
+ bool new_try_src;
+
+ for (i = 0; i < board_get_usb_pd_port_count(); i++)
+ try_src |= (pd_get_dual_role(i) == PD_DRP_TOGGLE_ON);
+
+ /*
+ * Enable try source when dual-role toggling AND battery is capable
+ * of powering the whole system.
+ */
+ new_try_src = (try_src && pd_is_battery_capable());
+
#if CONFIG_DEDICATED_CHARGE_PORT_COUNT > 0
/*
* If a dedicated supplier is present, power is not a concern and