summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt_Wang <Matt_Wang@compal.corp-partner.google.com>2019-03-26 20:49:33 +0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2019-03-29 20:39:09 +0000
commit11f95cf0c8237cb82c79975c610c9299d989ca1d (patch)
tree2b0ca4f1d606c4bedeaba98b184f8bbf3818a518
parenta7ed75d1b31fb9758421a830f5356d4da713a8b0 (diff)
downloadchrome-ec-11f95cf0c8237cb82c79975c610c9299d989ca1d.tar.gz
chgstv2: Disable battery communication after cutoff
Simplo battery(Gauge IC: Renesas) will cancel cutoff mode if there is communication after receiving cutoff command. This patch will disable battery communication after EC issues cutoff command. Add battery_set_cut_off_state function to set battery_cutoff_state. Add battery_cutoff to call board_cut_off_battery function. BUG=b/129030695 BRANCH=strago TEST=Verify w/ Simplo battery on Kefka. 1. Let battery discharge to 5% then enter cutoff mode. 2. Check there is no communication w/ battery in EC console and battery enter cutoff mode successfully. Change-Id: Id37d74cf970e4a6acfe273de41ba761cbaf2c317 Signed-off-by: Matt_Wang <Matt_Wang@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1544636 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Raymond Chou <raymond_chou@compal.corp-partner.google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com>
-rw-r--r--common/battery.c56
-rw-r--r--common/charge_state_v2.c2
-rw-r--r--include/battery.h13
-rw-r--r--power/common.c2
4 files changed, 41 insertions, 32 deletions
diff --git a/common/battery.c b/common/battery.c
index 408ae92c46..23eb23f6e7 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -26,6 +26,10 @@
#define CONFIG_BATTERY_CUTOFF_DELAY_US (1 * SECOND)
#endif
+/*
+ * Battery cutoff state from EC's perspective. It doesn't necessarily mean
+ * the battery is in cutoff state (yet).
+ */
static enum battery_cutoff_states battery_cutoff_state =
BATTERY_CUTOFF_STATE_NORMAL;
@@ -272,29 +276,42 @@ DECLARE_CONSOLE_COMMAND(battery, command_battery,
NULL);
#ifdef CONFIG_BATTERY_CUT_OFF
+/*
+ * Returning true (should) block further communication with the battery.
+ */
int battery_is_cut_off(void)
{
return (battery_cutoff_state == BATTERY_CUTOFF_STATE_CUT_OFF);
}
-static void pending_cutoff_deferred(void)
+static void battery_set_cut_off_state(enum battery_cutoff_states state)
+{
+ battery_cutoff_state = state;
+}
+
+int battery_cutoff(void)
{
int rv;
rv = board_cut_off_battery();
-
- if (rv == EC_SUCCESS)
- CPRINTF("[%T Battery cut off succeeded.]\n");
+ if (rv)
+ CPRINTS("Battery cut off failed (%d)", rv);
else
- CPRINTF("[%T Battery cut off failed!]\n");
+ battery_set_cut_off_state(BATTERY_CUTOFF_STATE_CUT_OFF);
+ return rv;
+}
+
+static void pending_cutoff_deferred(void)
+{
+ battery_cutoff();
}
DECLARE_DEFERRED(pending_cutoff_deferred);
static void clear_pending_cutoff(void)
{
if (extpower_is_present()) {
- battery_cutoff_state = BATTERY_CUTOFF_STATE_NORMAL;
- hook_call_deferred(pending_cutoff_deferred, -1);
+ battery_set_cut_off_state(BATTERY_CUTOFF_STATE_NORMAL);
+ hook_call_deferred(&pending_cutoff_deferred, -1);
}
}
DECLARE_HOOK(HOOK_AC_CHANGE, clear_pending_cutoff, HOOK_PRIO_DEFAULT);
@@ -302,26 +319,17 @@ DECLARE_HOOK(HOOK_AC_CHANGE, clear_pending_cutoff, HOOK_PRIO_DEFAULT);
static int battery_command_cutoff(struct host_cmd_handler_args *args)
{
const struct ec_params_battery_cutoff *p;
- int rv;
if (args->version == 1) {
p = args->params;
if (p->flags & EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN) {
- battery_cutoff_state = BATTERY_CUTOFF_STATE_PENDING;
+ battery_set_cut_off_state(BATTERY_CUTOFF_STATE_PENDING);
CPRINTS("Battery cut off at-shutdown is scheduled");
return EC_RES_SUCCESS;
}
}
- rv = board_cut_off_battery();
- if (!rv) {
- CPRINTS("Battery cut off is successful.");
- battery_cutoff_state = BATTERY_CUTOFF_STATE_CUT_OFF;
- } else {
- CPRINTS("Battery cut off has failed.");
- }
-
- return rv;
+ return battery_cutoff();
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cutoff,
EC_VER_MASK(0) | EC_VER_MASK(1));
@@ -339,24 +347,16 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, check_pending_cutoff, HOOK_PRIO_LAST);
static int command_cutoff(int argc, char **argv)
{
- int rv;
-
if (argc > 1) {
if (!strcasecmp(argv[1], "at-shutdown")) {
- battery_cutoff_state = BATTERY_CUTOFF_STATE_PENDING;
+ battery_set_cut_off_state(BATTERY_CUTOFF_STATE_PENDING);
return EC_SUCCESS;
} else {
return EC_ERROR_INVAL;
}
}
- rv = board_cut_off_battery();
- if (!rv) {
- ccprintf("[%T Battery cut off]\n");
- battery_cutoff_state = BATTERY_CUTOFF_STATE_CUT_OFF;
- }
-
- return rv;
+ return battery_cutoff();
}
DECLARE_CONSOLE_COMMAND(cutoff, command_cutoff,
"[at-shutdown]",
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index de696a3622..3c09ca3f69 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -535,7 +535,7 @@ static int shutdown_on_critical_battery(void)
break;
case CRITICAL_SHUTDOWN_CUTOFF:
CPRINTS("Cutoff due to critical battery");
- board_cut_off_battery();
+ battery_cutoff();
break;
case CRITICAL_SHUTDOWN_IGNORE:
default:
diff --git a/include/battery.h b/include/battery.h
index dcf05592a6..00df41914e 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -283,9 +283,10 @@ int battery_device_chemistry(char *dest, int size);
int battery_manufacturer_date(int *year, int *month, int *day);
/**
- * Call board-specific cut-off function.
+ * Execute board-specific battery cutoff
*
- * @return EC_RES_INVALID_COMMAND if the battery doesn't support.
+ * @return EC_RES_INVALID_COMMAND if the battery doesn't support or EC_SUCCESS
+ * if cutoff is successfully requested.
*/
int board_cut_off_battery(void);
@@ -295,6 +296,14 @@ int board_cut_off_battery(void);
int battery_is_cut_off(void);
/**
+ * Request battery cutoff
+ *
+ * @return non-zero if cutoff fails or EC_SUCCESS if cutoff is successfully
+ * requested.
+ */
+int battery_cutoff(void);
+
+/**
* Read battery vendor parameter.
*
* Vendor parameter handlers are implemented in a board-specific battery.c
diff --git a/power/common.c b/power/common.c
index 28547292a6..318367a876 100644
--- a/power/common.c
+++ b/power/common.c
@@ -190,7 +190,7 @@ static enum power_state power_common_state(enum power_state state)
#ifdef CONFIG_BATTERY_CUT_OFF
case CRITICAL_SHUTDOWN_CUTOFF:
CPRINTS("Cutoff due to G3 idle");
- board_cut_off_battery();
+ battery_cutoff();
break;
#endif
case CRITICAL_SHUTDOWN_IGNORE: