summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.
*