diff options
author | lu.zhang <lu.zhang@bitland.corp-partner.google.com> | 2019-01-14 10:49:43 +0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2019-02-13 06:20:28 +0000 |
commit | 4d450a6f4e86ead5255914a9d70107ceb45a4d09 (patch) | |
tree | b6f900329044492f279bd9a6a839b8aa868020e9 | |
parent | 147a5cae414f22bfe1a3e0b1503647c66bbfa4da (diff) | |
download | chrome-ec-4d450a6f4e86ead5255914a9d70107ceb45a4d09.tar.gz |
coral:enable battery cutoff when shutdown_on_critical_battery
The machine can't power on when the soc of battery is 0% with AC adapter
plugging in and this behavior is not consistent as usual. The power
consumption is very low when battery is cutoff, so let battery cutoff
instead of EC hibernate to try to avoid battery soc dropping to 0%.
However, it would take more than 1 hour to consume 1% battery power
in G3 state. we also need prevent from hibernating in chipset_task
if battery soc <= BATTERY_LEVEL_SHUTDOWN to get chance to cutoff the
battery.
BRANCH=coral
BUG=b:120407297
TEST=Discharge the battery to verify if the battery is cutoff.
Change-Id: Ia8ce02e9e6e9b1a0eafe872664fd246667a18b00
Signed-off-by: lu.zhang <lu.zhang@bitland.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/1408749
Reviewed-by: Scott Collyer <scollyer@chromium.org>
-rw-r--r-- | board/coral/battery.c | 20 | ||||
-rw-r--r-- | board/coral/board.h | 2 | ||||
-rw-r--r-- | common/charge_state_v2.c | 15 | ||||
-rw-r--r-- | include/battery.h | 10 | ||||
-rw-r--r-- | include/config.h | 2 | ||||
-rw-r--r-- | power/common.c | 12 |
6 files changed, 60 insertions, 1 deletions
diff --git a/board/coral/battery.c b/board/coral/battery.c index 76db4e86b5..6481a8cdc2 100644 --- a/board/coral/battery.c +++ b/board/coral/battery.c @@ -903,6 +903,26 @@ const struct battery_info *battery_get_info(void) return &board_get_batt_params()->batt_info; } +int battery_is_cutoff_required(void) +{ + /* + * this function is used to identify Coral SKU 70-71 units + * with EC RO FW older than v7292. For these units, + * want to prevent batteries from reaching < 1% SOC. + */ + uint32_t sku_id; + const char *version_ro; + char version_minor[5] = {0}; + + sku_id = system_get_sku_id(); + version_ro = system_get_version(SYSTEM_IMAGE_RO); + strncpy(version_minor, version_ro + 11, 4); + return (!strncmp(version_ro, "coral_v1.1.", 11) && + atoi(version_minor) < 7292 && + (70 == sku_id || 71 == sku_id)); + +} + int board_cut_off_battery(void) { int rv; diff --git a/board/coral/board.h b/board/coral/board.h index 62a118b84e..b6aeb6fe90 100644 --- a/board/coral/board.h +++ b/board/coral/board.h @@ -217,6 +217,8 @@ /* Depends on how fast the AP boots and typical ODRs */ #define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3) +#define CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF +#define CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF_REQUIRED #ifndef __ASSEMBLER__ diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 7ea1c79cf4..18ce4613b8 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -558,9 +558,24 @@ static void shutdown_on_critical_battery(void) if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) { /* Timeout waiting for charger to provide more power */ #if defined(CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF) +#ifdef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF_REQUIRED + /* + * Since can't cutoff battery if EC in hibernate mode + * prevent from hibernating if battery + * soc <= BATTERY_LEVEL_SHUTDOWN + */ + if (battery_is_cutoff_required()) { +#endif CPRINTS( "charge force battery cut-off due to critical level"); board_cut_off_battery(); +#ifdef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF_REQUIRED + } else { + CPRINTS( + "charge force EC hibernate due to critical battery"); + system_hibernate(0, 0); + } +#endif #elif defined(CONFIG_HIBERNATE) CPRINTS( "charge force EC hibernate due to critical battery"); diff --git a/include/battery.h b/include/battery.h index 0ccd29319d..03443c73bb 100644 --- a/include/battery.h +++ b/include/battery.h @@ -35,7 +35,7 @@ * Shut down main processor and/or hibernate EC when discharging and battery * level < this level. */ -#define BATTERY_LEVEL_SHUTDOWN 3 +#define BATTERY_LEVEL_SHUTDOWN 4 /* * Sometimes we have hardware to detect battery present, sometimes we have to @@ -353,6 +353,14 @@ void print_battery_debug(void); */ enum battery_disconnect_state battery_get_disconnect_state(void); +/** + * Check if need battery cutoff + * + * @return A value that if RO version is 10068.82 previous version + * and sku id is 70 and 71 + */ +int battery_is_cutoff_required(void); + #ifdef CONFIG_CMD_I2C_STRESS_TEST_BATTERY extern struct i2c_stress_test_dev battery_i2c_stress_test_dev; #endif diff --git a/include/config.h b/include/config.h index eb08f14ac5..a32f67f936 100644 --- a/include/config.h +++ b/include/config.h @@ -277,6 +277,8 @@ /* Perform a battery cut-off when we reach the battery critical level */ #undef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF +/* Make sure if need to perform a battery cutoff when battery critical level */ +#undef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF_REQUIRED /* * Support battery cut-off as host command and console command. diff --git a/power/common.c b/power/common.c index 467f41e9aa..3fbe58f3f9 100644 --- a/power/common.c +++ b/power/common.c @@ -225,6 +225,18 @@ static enum power_state power_common_state(enum power_state state) delay = CONFIG_HIBERNATE_BATT_SEC; #endif target_time = last_shutdown_time + delay * 1000000ull; +#ifdef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF_REQUIRED + /* + * Since can't cutoff battery if EC in hibernate mode + * prevent from hibernating if battery + * soc <= BATTERY_LEVEL_SHUTDOWN + * This action only affect 10068.82 previous version + * and sku id is 70 and 71 + */ + if (battery_is_cutoff_required() && + charge_get_percent() <= BATTERY_LEVEL_SHUTDOWN) + target_time = time_now + delay * 1000000ull; +#endif if (time_now > target_time) { /* * Time's up. Hibernate until wake pin |