summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-05-26 14:10:22 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-06-19 21:03:30 -0700
commitcdaca7c97eaefe93ab3a0148a954b2f139f5caad (patch)
tree7628f281393c06dbc653732f4b8a71477cdd9378
parent5ce3d325381f2f3bce0be4a83454944271c3b27c (diff)
downloadchrome-ec-cdaca7c97eaefe93ab3a0148a954b2f139f5caad.tar.gz
Add system_can_boot_ap API
This API checks battery charge level and current power supply to determine whether the AP has enough power to boot or not. BUG=b:38462249 BRANCH=none TEST=make buildall Change-Id: I489f7ea92f230701b8f18c94d3e698aad90b4a03 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/517272
-rw-r--r--common/system.c30
-rw-r--r--include/system.h8
2 files changed, 38 insertions, 0 deletions
diff --git a/common/system.c b/common/system.c
index 8e1a123b39..597fc3e59b 100644
--- a/common/system.c
+++ b/common/system.c
@@ -4,6 +4,8 @@
*/
/* System module for Chrome EC : common functions */
+#include "battery.h"
+#include "charge_manager.h"
#include "clock.h"
#include "common.h"
#include "console.h"
@@ -1290,3 +1292,31 @@ int host_command_reboot(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_REBOOT_EC,
host_command_reboot,
EC_VER_MASK(0));
+
+int system_can_boot_ap(void)
+{
+ int power_good = 0;
+ int soc = -1;
+ int pow = -1;
+
+#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
+ /* Require a minimum battery level to power on. If battery isn't
+ * present, battery_state_of_charge_abs returns false. */
+ if (battery_state_of_charge_abs(&soc) == EC_SUCCESS &&
+ soc >= CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
+ power_good = 1;
+#endif
+
+#ifdef CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW
+ if (!power_good) {
+ pow = charge_manager_get_power_limit_uw() / 1000;
+ if (pow >= CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW)
+ power_good = 1;
+ }
+#endif
+ if (!power_good)
+ CPRINTS("Not enough power to boot AP: charge=%d power=%d\n",
+ soc, pow);
+
+ return power_good;
+}
diff --git a/include/system.h b/include/system.h
index f40feb0e37..10c10ccf52 100644
--- a/include/system.h
+++ b/include/system.h
@@ -529,4 +529,12 @@ static inline void system_print_extended_version_info(void)
{
}
#endif
+
+/**
+ * Check if the system can supply enough power to boot AP
+ *
+ * @return true if the system is powered enough or false otherwise
+ */
+int system_can_boot_ap(void);
+
#endif /* __CROS_EC_SYSTEM_H */