summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Fagerburg <pfagerburg@chromium.org>2019-11-13 14:00:37 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-15 22:35:17 +0000
commit5e182ed5f641d42dc43fe2c897bf91d47f6470f8 (patch)
treea9b075e0bd63ca15f8e10aeea28445f6b07eecce
parent24eb7b805927e482d2cbdca2505734e6ae64700c (diff)
downloadchrome-ec-5e182ed5f641d42dc43fe2c897bf91d47f6470f8.tar.gz
chgstv2: stop charging when battery temp exceeds specs
Add a check for the battery temperature in the safe range to charge the battery, and if it isn't, stop charging. The battery information defines minimum and maximum temperatures for discharge and for charge. The state machine already checks if the battery temperature is outside of the range for discharge (as part of is_battery_critical) and will shut down the system completely if the battery temperature is out of range. However, the temperature range for charging is usually tigheter than for discharging, and it can be safe to discharge, but unsafe to charge. For example, Kohaku specifies a maximum charge temperature of 55 C, and a maximum discharge temperature of 60 C. If the battery is at 57 C, we don't want to charge, but it's still OK to use the system. The check is enabled by CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS. BUG=b:140596424 BRANCH=None TEST=`make buildall -j` builds with no errors. No boards have enabled CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS, so no effect. Change-Id: I3b76eab942ca3ef3871f0909395e91634db5640e Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1914510 Reviewed-by: Scott Collyer <scollyer@chromium.org>
-rw-r--r--common/charge_state_v2.c29
-rw-r--r--include/config.h3
2 files changed, 32 insertions, 0 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index b02b6ca819..6e6cc6c7d7 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1476,6 +1476,25 @@ const struct batt_params *charger_current_battery_params(void)
return &curr.batt;
}
+#ifdef CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+/* Determine if the battery is outside of allowable temperature range */
+static int battery_outside_charging_temperature(void)
+{
+ const struct battery_info *batt_info = battery_get_info();
+ /* battery temp in 0.1 deg C */
+ int batt_temp_c = DECI_KELVIN_TO_CELSIUS(curr.batt.temperature);
+
+ if (curr.batt.flags & BATT_FLAG_BAD_TEMPERATURE)
+ return 0;
+
+ if ((batt_temp_c > batt_info->charging_max_c) ||
+ (batt_temp_c < batt_info->charging_min_c)) {
+ return 1;
+ }
+ return 0;
+}
+#endif
+
/*****************************************************************************/
/* Hooks */
void charger_init(void)
@@ -1809,6 +1828,16 @@ wait_for_it:
}
#endif
+#ifdef CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+ if (battery_outside_charging_temperature()) {
+ curr.requested_current = 0;
+ curr.requested_voltage = 0;
+ curr.batt.flags &= ~BATT_FLAG_WANT_CHARGE;
+ if (curr.state != ST_DISCHARGE)
+ curr.state = ST_IDLE;
+ }
+#endif
+
#ifdef CONFIG_CHARGE_MANAGER
if (curr.batt.state_of_charge >=
CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
diff --git a/include/config.h b/include/config.h
index 921eb0f4c9..cc12e94673 100644
--- a/include/config.h
+++ b/include/config.h
@@ -496,6 +496,9 @@
/* Perform a battery cut-off when we reach the battery critical level */
#undef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF
+/* If the battery is too hot or too cold, stop charging */
+#undef CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+
/*
* Support battery cut-off as host command and console command.
*