summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-05-09 19:59:19 +0000
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2019-05-09 20:10:59 +0000
commitf575f8de1bcea5cfac23d05f151246b427ce40fc (patch)
treeaa5e9e8ef75feaa412236b14c05dca5435e625b1
parent1ceacc4f0ed52b224a222485db7cf6edd97e8fac (diff)
downloadchrome-ec-f575f8de1bcea5cfac23d05f151246b427ce40fc.tar.gz
Revert "chgstv2: Disable battery communication after cutoff"
This reverts commit 11f95cf0c8237cb82c79975c610c9299d989ca1d. Reason for revert: we're not going to use this feature. Original change's description: > 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> Bug: b/129030695 Change-Id: Ieb7913719f67aae999ecbef63f27c9dad9e453e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1603166 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-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, 32 insertions, 41 deletions
diff --git a/common/battery.c b/common/battery.c
index 23eb23f6e7..408ae92c46 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -26,10 +26,6 @@
#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;
@@ -276,42 +272,29 @@ 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 battery_set_cut_off_state(enum battery_cutoff_states state)
-{
- battery_cutoff_state = state;
-}
-
-int battery_cutoff(void)
+static void pending_cutoff_deferred(void)
{
int rv;
rv = board_cut_off_battery();
- if (rv)
- CPRINTS("Battery cut off failed (%d)", rv);
- else
- battery_set_cut_off_state(BATTERY_CUTOFF_STATE_CUT_OFF);
- return rv;
-}
-static void pending_cutoff_deferred(void)
-{
- battery_cutoff();
+ if (rv == EC_SUCCESS)
+ CPRINTF("[%T Battery cut off succeeded.]\n");
+ else
+ CPRINTF("[%T Battery cut off failed!]\n");
}
DECLARE_DEFERRED(pending_cutoff_deferred);
static void clear_pending_cutoff(void)
{
if (extpower_is_present()) {
- battery_set_cut_off_state(BATTERY_CUTOFF_STATE_NORMAL);
- hook_call_deferred(&pending_cutoff_deferred, -1);
+ battery_cutoff_state = BATTERY_CUTOFF_STATE_NORMAL;
+ hook_call_deferred(pending_cutoff_deferred, -1);
}
}
DECLARE_HOOK(HOOK_AC_CHANGE, clear_pending_cutoff, HOOK_PRIO_DEFAULT);
@@ -319,17 +302,26 @@ 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_set_cut_off_state(BATTERY_CUTOFF_STATE_PENDING);
+ battery_cutoff_state = BATTERY_CUTOFF_STATE_PENDING;
CPRINTS("Battery cut off at-shutdown is scheduled");
return EC_RES_SUCCESS;
}
}
- return battery_cutoff();
+ 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;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cutoff,
EC_VER_MASK(0) | EC_VER_MASK(1));
@@ -347,16 +339,24 @@ 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_set_cut_off_state(BATTERY_CUTOFF_STATE_PENDING);
+ battery_cutoff_state = BATTERY_CUTOFF_STATE_PENDING;
return EC_SUCCESS;
} else {
return EC_ERROR_INVAL;
}
}
- return battery_cutoff();
+ rv = board_cut_off_battery();
+ if (!rv) {
+ ccprintf("[%T Battery cut off]\n");
+ battery_cutoff_state = BATTERY_CUTOFF_STATE_CUT_OFF;
+ }
+
+ return rv;
}
DECLARE_CONSOLE_COMMAND(cutoff, command_cutoff,
"[at-shutdown]",
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 3c09ca3f69..de696a3622 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");
- battery_cutoff();
+ board_cut_off_battery();
break;
case CRITICAL_SHUTDOWN_IGNORE:
default:
diff --git a/include/battery.h b/include/battery.h
index 00df41914e..dcf05592a6 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -283,10 +283,9 @@ int battery_device_chemistry(char *dest, int size);
int battery_manufacturer_date(int *year, int *month, int *day);
/**
- * Execute board-specific battery cutoff
+ * Call board-specific cut-off function.
*
- * @return EC_RES_INVALID_COMMAND if the battery doesn't support or EC_SUCCESS
- * if cutoff is successfully requested.
+ * @return EC_RES_INVALID_COMMAND if the battery doesn't support.
*/
int board_cut_off_battery(void);
@@ -296,14 +295,6 @@ 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 318367a876..28547292a6 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");
- battery_cutoff();
+ board_cut_off_battery();
break;
#endif
case CRITICAL_SHUTDOWN_IGNORE: