From 48eed0bebc403ebdccae7810fccc7a467da4125b Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Fri, 23 Jan 2015 13:52:58 -0800 Subject: [PATCH] bq27541: report battery present state The battery driver is not reporting battery present state, and as a result, is_present flag always remain NOT_SURE. Fix it. BRANCH=Ryu BUG=None TEST=On Ryu, 'chgstate' and see 'is_present = YES'. Change-Id: I84bedc390158797bf1e67e612d0bb3f526292dfa Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/242970 Reviewed-by: Alec Berg Commit-Queue: Vic Yang Tested-by: Vic Yang --- driver/battery/bq27541.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/driver/battery/bq27541.c b/driver/battery/bq27541.c index 11578037cc..516d3330e6 100644 --- a/driver/battery/bq27541.c +++ b/driver/battery/bq27541.c @@ -219,14 +219,16 @@ enum battery_present battery_is_present(void) void battery_get_params(struct batt_params *batt) { int v; + const uint32_t flags_to_check = BATT_FLAG_BAD_TEMPERATURE | + BATT_FLAG_BAD_STATE_OF_CHARGE | + BATT_FLAG_BAD_VOLTAGE | + BATT_FLAG_BAD_CURRENT; /* Reset flags */ batt->flags = 0; if (bq27541_read(REG_TEMPERATURE, &batt->temperature)) batt->flags |= BATT_FLAG_BAD_TEMPERATURE; - else - batt->flags |= BATT_FLAG_RESPONSIVE; /* Battery is responding */ if (bq27541_read8(REG_STATE_OF_CHARGE, &batt->state_of_charge)) batt->flags |= BATT_FLAG_BAD_STATE_OF_CHARGE; @@ -242,6 +244,14 @@ void battery_get_params(struct batt_params *batt) /* Default to not desiring voltage and current */ batt->desired_voltage = batt->desired_current = 0; + /* If any of those reads worked, the battery is responsive */ + if ((batt->flags & flags_to_check) != flags_to_check) { + batt->flags |= BATT_FLAG_RESPONSIVE; + batt->is_present = BP_YES; + } else { + batt->is_present = BP_NOT_SURE; + } + v = 0; if (battery_charging_allowed(&v)) { batt->flags |= BATT_FLAG_BAD_ANY;