From 3a3834ab345b640af1a611566910d06e5faefb5d Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Wed, 26 Oct 2016 14:22:21 -0700 Subject: [PATCH] kevin / gru: Add custom charge profile - Stop charging when thermal limits are violated. - Don't start charging if battery percent is above 95% (but continue to charge if we're already charging). - Don't allow battery voltage to get too close (10mA) to BD9995X VBAT setting. If battery voltage exceeds VBAT then back boosting may occur. BUG=chrome-os-partner:56255 BRANCH=gru TEST=Manual on kevin, insert charger with battery at 97%, verify battery doesn't charge and reported current is 0. Discharge down to 95% and insert charger, verify battery charges. Charge to 100%, verify battery stops requesting current. Change-Id: Icc5641e88bfad7d9d8ad4b6840338541fe7ba9a8 Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/403483 Reviewed-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/415494 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Shawn N --- board/kevin/battery.c | 31 ++++++++++++++++++++----------- board/kevin/board.h | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/board/kevin/battery.c b/board/kevin/battery.c index 68150f6ce0..c1b2e09c67 100644 --- a/board/kevin/battery.c +++ b/board/kevin/battery.c @@ -18,7 +18,7 @@ #ifdef BOARD_KEVIN static const struct battery_info info = { - .voltage_max = 8700, + .voltage_max = 8688, /* 8700mA, round down for chg reg */ .voltage_normal = 7600, .voltage_min = 6000, .precharge_current = 200, @@ -31,7 +31,7 @@ static const struct battery_info info = { }; #elif defined(BOARD_GRU) static const struct battery_info info = { - .voltage_max = 8700, + .voltage_max = 8688, /* 8700mA, round down for chg reg */ .voltage_normal = 7600, .voltage_min = 5800, .precharge_current = 256, @@ -116,19 +116,28 @@ enum battery_disconnect_state battery_get_disconnect_state(void) int charger_profile_override(struct charge_state_data *curr) { - const struct battery_info *batt_info; + static int prev_state = ST_IDLE; + const struct battery_info *batt_info = battery_get_info(); + /* battery temp in 0.1 deg C */ int bat_temp_c = curr->batt.temperature - 2731; - batt_info = battery_get_info(); - /* Don't charge if outside of allowable temperature range */ - if (bat_temp_c >= batt_info->charging_max_c * 10 || - bat_temp_c < batt_info->charging_min_c * 10) { - curr->requested_current = 0; - curr->requested_voltage = 0; - curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE; - curr->state = ST_IDLE; + if (curr->state == ST_CHARGE) { + /* Don't charge if outside of allowable temperature range */ + if (bat_temp_c >= batt_info->charging_max_c * 10 || + bat_temp_c < batt_info->charging_min_c * 10 || + /* Don't start charging if battery is nearly full */ + (prev_state != ST_CHARGE && + curr->batt.state_of_charge > 95) || + /* Don't charge if battery voltage is approaching max */ + curr->batt.voltage > batt_info->voltage_max - 10) { + curr->requested_current = curr->requested_voltage = 0; + curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE; + curr->state = ST_IDLE; + } } + + prev_state = curr->state; return 0; } diff --git a/board/kevin/board.h b/board/kevin/board.h index 5fb35ea8f5..fa7cca42a1 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -66,6 +66,7 @@ #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2 #define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 2 #define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000 +#define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_USB_CHARGER #define CONFIG_USB_MUX_VIRTUAL