summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/usb_pd_dual_role.c50
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c5
-rw-r--r--include/usb_pd.h13
3 files changed, 43 insertions, 25 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
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 335ab7b3fb..0c3767263d 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -595,8 +595,7 @@ static void pd_update_pd_comm(void)
* The init function disabled PD comm on startup. Need this
* hook to enable PD comm when the battery level is enough.
*/
- if (pd_disabled_on_init &&
- usb_get_battery_soc() >= CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC) {
+ if (pd_disabled_on_init && pd_is_battery_capable()) {
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
pd_comm_enable(i, 1);
pd_disabled_on_init = 0;
@@ -621,7 +620,7 @@ static bool pd_comm_allowed_by_policy(void)
if (IS_ENABLED(CONFIG_VBOOT_EFS2))
return true;
- if (usb_get_battery_soc() >= CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC)
+ if (pd_is_battery_capable())
return true;
pd_disabled_on_init = 1;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 46222ea14a..0fea201e9e 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -995,8 +995,17 @@ enum pd_data_role pd_get_data_role(int port);
*/
enum pd_power_role pd_get_power_role(int port);
-/*
- * Return true if PD is capable of trying as source else false
+/**
+ * Check if the battery is capable of powering the system
+ *
+ * @return true if capable of, else false.
+ */
+bool pd_is_battery_capable(void);
+
+/**
+ * Check if PD is capable of trying as source
+ *
+ * @return true if capable of, else false.
*/
bool pd_is_try_source_capable(void);