summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorLouis Yung-Chieh Lo <yjlou@chromium.org>2014-04-24 13:34:59 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-25 03:41:58 +0000
commit3ac560d41bf8c225725cdf03c2b4f4d723739d0f (patch)
tree687b9335e739ffd62ffe910742bd8a87e987537a /common
parentb0409436adcf68cda3bf70a2964b9fdee599189a (diff)
downloadchrome-ec-3ac560d41bf8c225725cdf03c2b4f4d723739d0f.tar.gz
battery: don't talk to battery after cut-off
Add a shortcut in smart battery driver and i2c passthru. Once the battery cut-off order is submitted (in the factory line), the EC will no longer talk to battery. BUG=chrome-os-partner:28248 BRANCH=tot,nyan TEST=See below > remove AC, cutoff: expect system is off. > cutoff, then remove AC: expect system is off. > cutoff, wait for 1 min, then remove AC: expect system is off. Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org> Change-Id: Ied963c19d17d581ce99e4543469cf2fa165f0439 Reviewed-on: https://chromium-review.googlesource.com/196657 Tested-by: Yung-chieh Lo <yjlou@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Yung-chieh Lo <yjlou@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/battery.c37
-rw-r--r--common/charge_state_v2.c9
-rw-r--r--common/i2c.c9
3 files changed, 51 insertions, 4 deletions
diff --git a/common/battery.c b/common/battery.c
index 19ad2e49b8..b6e79bb383 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -9,12 +9,18 @@
#include "charge_state.h"
#include "common.h"
#include "console.h"
+#include "extpower.h"
#include "gpio.h"
+#include "hooks.h"
#include "host_command.h"
#include "timer.h"
#include "util.h"
#include "watchdog.h"
+#ifdef CONFIG_BATTERY_CUT_OFF
+static int is_cut_off;
+#endif
+
#ifdef CONFIG_BATTERY_PRESENT_GPIO
#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
#error "Don't define both CONFIG_BATTERY_PRESENT_CUSTOM and" \
@@ -252,19 +258,44 @@ DECLARE_CONSOLE_COMMAND(battery, command_battery,
#ifdef CONFIG_BATTERY_CUT_OFF
-int battery_command_cut_off(struct host_cmd_handler_args *args)
+int battery_is_cut_off(void)
+{
+ return is_cut_off;
+}
+
+static void clean_cut_off(void)
+{
+ if (extpower_is_present())
+ is_cut_off = 0;
+}
+DECLARE_HOOK(HOOK_AC_CHANGE, clean_cut_off, HOOK_PRIO_DEFAULT);
+
+static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
- return board_cut_off_battery();
+ int rv = board_cut_off_battery();
+ if (!rv)
+ is_cut_off = 1;
+
+ return rv;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));
static int command_cutoff(int argc, char **argv)
{
- return board_cut_off_battery();
+ int rv = board_cut_off_battery();
+ if (!rv)
+ is_cut_off = 1;
+
+ return rv;
}
DECLARE_CONSOLE_COMMAND(cutoff, command_cutoff,
"",
"Cut off the battery output",
NULL);
+#else
+int battery_is_cut_off(void)
+{
+ return 0; /* Always return NOT cut off */
+}
#endif /* CONFIG_BATTERY_CUT_OFF */
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 36addbe332..a5a621da8b 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -620,12 +620,19 @@ wait_for_it:
/* Charger only accpets request when AC is on. */
if (curr.ac) {
/*
+ * Some batteries would wake up after cut-off if we keep
+ * charging it. Thus, we only charge when AC is on and
+ * battery is not cut off yet.
+ */
+ if (battery_is_cut_off())
+ charge_request(0, 0);
+ /*
* As a safety feature, some chargers will stop
* charging if we don't communicate with it frequently
* enough. In manual mode, we'll just tell it what it
* knows.
*/
- if (manual_mode) {
+ else if (manual_mode) {
charge_request(curr.chg.voltage,
curr.chg.current);
} else {
diff --git a/common/i2c.c b/common/i2c.c
index f5ce577aa2..8667bff1cf 100644
--- a/common/i2c.c
+++ b/common/i2c.c
@@ -5,6 +5,7 @@
/* I2C cross-platform code for Chrome EC */
+#include "battery.h"
#include "clock.h"
#include "console.h"
#include "host_command.h"
@@ -492,6 +493,14 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args)
return EC_RES_ACCESS_DENIED;
#endif
+#ifdef CONFIG_BATTERY_CUT_OFF
+ /*
+ * Some batteries would wake up after cut-off if we talk to it.
+ */
+ if (battery_is_cut_off())
+ return EC_RES_ACCESS_DENIED;
+#endif
+
ret = check_i2c_params(args);
if (ret)
return ret;