From 889d00b06f05d94ab944afd2c396f324deaacc46 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Mon, 21 Oct 2013 12:39:46 -0700 Subject: spring: do not start up the AP with a battery cell in undervoltage Check all cell voltages before starting up the main processor, if one is below our software cut-off threshold (3.2V), it cancels the boot. Signed-off-by: Vincent Palatin BRANCH=spring BUG=chrome-os-partner:22807 TEST=on Spring, with two good battery (one somewhat charged, the other discharged) successfully starts the machine plugged on Spring charger. With a self cut-off battery, see the EC preventing the CPU start-up and the system staying stable and charging the battery, then retry an successfully boot. Change-Id: I91ac9f4c584d2192bfb57ba200d613a83d5f5d9b Reviewed-on: https://chromium-review.googlesource.com/173912 Reviewed-by: Puneet Kumar Commit-Queue: Vincent Palatin Tested-by: Vincent Palatin --- common/battery_spring.c | 27 ++++++++++++++++++--------- common/pmu_tps65090_charger.c | 2 ++ include/battery_pack.h | 7 +++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/common/battery_spring.c b/common/battery_spring.c index 351745a1a5..8a8e81f3d3 100644 --- a/common/battery_spring.c +++ b/common/battery_spring.c @@ -62,10 +62,25 @@ int battery_is_cut_off(void) get_time().val - last_cutoff.val < BATTERY_CUT_OFF_DELAY; } +int battery_cell_in_undervoltage(void) +{ + int i, v; + + 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; +} + static int battery_want_cut_off(void) { int charge; - int i, v; if (battery_is_cut_off()) return 0; @@ -77,14 +92,8 @@ static int battery_want_cut_off(void) 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; - } - } + if (battery_cell_in_undervoltage()) + return 1; return 0; } diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index 4d24c5bef3..c7de9d515e 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -429,6 +429,8 @@ int charge_keep_power_off(void) if (!ret && !(blk_opstatus & (1 << (1 + 8)))) return 1; #endif + if (battery_cell_in_undervoltage()) + return 1; if (BATTERY_AP_OFF_LEVEL == 0) return 0; diff --git a/include/battery_pack.h b/include/battery_pack.h index 5e0593a75a..eeff368b99 100644 --- a/include/battery_pack.h +++ b/include/battery_pack.h @@ -65,4 +65,11 @@ int battery_check_cut_off(void); */ int battery_is_cut_off(void); +/** + * Check if one of the battery cell voltage is below our cut-off threshold. + * + * @return 1 if one cell is in undervoltage. + */ +int battery_cell_in_undervoltage(void); + #endif -- cgit v1.2.1