From 49cc3902b06b10c03bb139fda864ca9b591f958a Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Fri, 6 Jun 2014 09:18:45 -0700 Subject: samus: allow charging of dead battery requesting nil On samus battery, when the battery is dead it reports 0 for desired voltage, current, and state of charge. In this case we should allow charging. Added a CONFIG option for this that should be removed as soon as the battery side is fixed. With this CL, when a dead samus battery is used and a charger is connected, we attempt to charge it. BUG=chrome-os-partner:29465 BRANCH=none TEST=test on a samus with a dead battery. w/o this CL, the battery never charges because the charging not allowed flag is set. With this CL, the battery charges. Change-Id: Ic61f27a27237166d33cb9ea5f024d3ef6360ce82 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/202603 Reviewed-by: Bill Richardson --- board/samus/board.h | 2 ++ common/charge_state_v2.c | 15 +++++++++++++++ driver/battery/smart.c | 13 +++++++++++++ include/config.h | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/board/samus/board.h b/board/samus/board.h index 36e83f68c7..b914964e78 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -29,6 +29,8 @@ /* Note: not CONFIG_BACKLIGHT_LID. It's handled specially for Samus. */ #define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BL_EN #define CONFIG_BATTERY_SAMUS +/* TODO(crosbug.com/p/29467): remove this workaround when possible. */ +#define CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD #define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_BATTERY_SMART #define CONFIG_CHARGER diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 4a58aae54f..87ad28561b 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -570,6 +570,21 @@ void charger_task(void) goto wait_for_it; } else { /* The battery is responding. Yay. Try to use it. */ +#ifdef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD + /* + * TODO (crosbug.com/p/29467): remove this workaround + * for dead battery that requests no voltage/current + */ + if (curr.requested_voltage == 0 && + curr.requested_current == 0 && + curr.batt.state_of_charge == 0) { + /* Battery is dead, give precharge current */ + curr.requested_voltage = + batt_info->voltage_max; + curr.requested_current = + batt_info->precharge_current; + } else +#endif if (curr.state == ST_PRECHARGE || battery_seems_to_be_dead) { CPRINTS("battery woke up"); diff --git a/driver/battery/smart.c b/driver/battery/smart.c index 52e61a8699..6dcedfd81f 100644 --- a/driver/battery/smart.c +++ b/driver/battery/smart.c @@ -300,9 +300,22 @@ void battery_get_params(struct batt_params *batt) if (!(batt_new.flags & (BATT_FLAG_BAD_DESIRED_VOLTAGE | BATT_FLAG_BAD_DESIRED_CURRENT | BATT_FLAG_BAD_STATE_OF_CHARGE)) && +#ifdef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD + /* + * TODO (crosbug.com/p/29467): remove this workaround + * for dead battery that requests no voltage/current + */ + ((batt_new.desired_voltage && + batt_new.desired_current && + batt_new.state_of_charge < BATTERY_LEVEL_FULL) || + (batt_new.desired_voltage == 0 && + batt_new.desired_current == 0 && + batt_new.state_of_charge == 0))) +#else batt_new.desired_voltage && batt_new.desired_current && batt_new.state_of_charge < BATTERY_LEVEL_FULL) +#endif batt_new.flags |= BATT_FLAG_WANT_CHARGE; else /* Force both to zero */ diff --git a/include/config.h b/include/config.h index 86b43d2509..464ad50953 100644 --- a/include/config.h +++ b/include/config.h @@ -143,6 +143,13 @@ */ #undef CONFIG_BATTERY_VENDOR_PARAM +/* + * TODO(crosbug.com/p/29467): allows charging of a dead battery that + * requests nil for current and voltage. Remove this workaround when + * possible. + */ +#undef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD + /*****************************************************************************/ /* -- cgit v1.2.1