summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-09-26 17:09:32 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-30 20:53:22 +0000
commit537990bdf332a4b086ca4204093133b8c4af93e9 (patch)
tree527516fe7d0f64e1160c283ed75de19f4b18b7c6
parent6ac2a834b5cbc5a7cf7b4d9a7eb8514d778f5d72 (diff)
downloadchrome-ec-537990bdf332a4b086ca4204093133b8c4af93e9.tar.gz
spring: Cut off battery when any cell hit 3.2V
If battery cells are unbalanced, a cell might hit 2.8V cut off before we cut off the battery. To avoid this, check cell voltages periodically and cut off the battery when any of the cells has voltage below 3.2V. BUG=chrome-os-partner:22807 TEST=TBD BRANCH=Spring Change-Id: I30241618da3bceb4cfbd130c16764611b83d28bd Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/170714 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/board.h1
-rw-r--r--common/battery_spring.c34
2 files changed, 28 insertions, 7 deletions
diff --git a/board/spring/board.h b/board/spring/board.h
index f82b0b8dc9..94f7287c55 100644
--- a/board/spring/board.h
+++ b/board/spring/board.h
@@ -34,6 +34,7 @@
/* Auto battery cut-off */
#define BATTERY_CUT_OFF_MAH 10
#define BATTERY_CUT_OFF_DELAY (15 * SECOND)
+#define BATTERY_CELL_CUT_OFF_MV 3200 /* 3.2V */
/* use STOP mode when we have nothing to do */
#define CONFIG_LOW_POWER_IDLE
diff --git a/common/battery_spring.c b/common/battery_spring.c
index 4bf0d5ab50..b1f248fae9 100644
--- a/common/battery_spring.c
+++ b/common/battery_spring.c
@@ -28,6 +28,10 @@
#define BATTERY_CUT_OFF_DELAY 0
#endif
+#ifndef BATTERY_CELL_CUT_OFF_MV
+#define BATTERY_CELL_CUT_OFF_MV 0
+#endif
+
static timestamp_t last_cutoff;
static int has_cutoff;
static int pending_cutoff;
@@ -58,23 +62,39 @@ int battery_is_cut_off(void)
get_time().val - last_cutoff.val < BATTERY_CUT_OFF_DELAY;
}
-int battery_check_cut_off(void)
+static int battery_want_cut_off(void)
{
int charge;
+ int i, v;
- if (!BATTERY_CUT_OFF_MAH)
- return 0;
if (battery_is_cut_off())
return 0;
if (chipset_in_state(CHIPSET_STATE_ON | CHIPSET_STATE_SUSPEND))
return 0;
- if (battery_remaining_capacity(&charge))
- return 0;
- if (charge > BATTERY_CUT_OFF_MAH)
- return 0;
if (board_get_ac())
return 0;
+ if (BATTERY_CUT_OFF_MAH)
+ if (!battery_remaining_capacity(&charge) &&
+ charge < BATTERY_CUT_OFF_MAH)
+ return 1;
+
+ if (BATTERY_CELL_CUT_OFF_MV) {
+ for (i = 0x3d; i <= 0x3f; ++i) {
+ if (sb_read(i, &v))
+ continue;
+ if (v < BATTERY_CELL_CUT_OFF_MV)
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int battery_check_cut_off(void)
+{
+ if (!battery_want_cut_off())
+ return 0;
ccprintf("[%T Cutting off battery]\n");
cflush();
battery_cut_off();