From 5323adb2f6349fa605387e30d22ffcb887957f6d Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Tue, 25 May 2021 18:09:34 -0700 Subject: chgstv2: Move battery validate code to battery.c This patch moves the code validating battery parameters to battery.c. There is no functionality change. BUG=None BRANCH=None TEST=buildall Change-Id: I1706c4b504565b52964391077894665b4e5d1a86 Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3007375 Reviewed-by: Vincent Palatin --- common/battery.c | 23 +++++++++++++++++++++++ common/charge_state_v2.c | 20 +------------------- include/battery.h | 2 ++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/common/battery.c b/common/battery.c index ecb1152df1..4670b436b0 100644 --- a/common/battery.c +++ b/common/battery.c @@ -781,3 +781,26 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP, reduce_input_voltage_when_full, DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT); #endif + +void battery_validate_params(struct batt_params *batt) +{ + /* + * TODO(crosbug.com/p/27527). Sometimes the battery thinks its + * temperature is 6280C, which seems a bit high. Let's ignore + * anything above the boiling point of tungsten until this bug + * is fixed. If the battery is really that warm, we probably + * have more urgent problems. + */ + if (batt->temperature > CELSIUS_TO_DECI_KELVIN(5660)) { + CPRINTS("ignoring ridiculous batt.temp of %dC", + DECI_KELVIN_TO_CELSIUS(batt->temperature)); + batt->flags |= BATT_FLAG_BAD_TEMPERATURE; + } + + /* If the battery thinks it's above 100%, don't believe it */ + if (batt->state_of_charge > 100) { + CPRINTS("ignoring ridiculous batt.soc of %d%%", + batt->state_of_charge); + batt->flags |= BATT_FLAG_BAD_STATE_OF_CHARGE; + } +} diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index b169bb16f9..cc7dd9094d 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1966,25 +1966,7 @@ void charger_task(void *u) hook_notify(HOOK_BATTERY_SOC_CHANGE); } - /* - * TODO(crosbug.com/p/27527). Sometimes the battery thinks its - * temperature is 6280C, which seems a bit high. Let's ignore - * anything above the boiling point of tungsten until this bug - * is fixed. If the battery is really that warm, we probably - * have more urgent problems. - */ - if (curr.batt.temperature > CELSIUS_TO_DECI_KELVIN(5660)) { - CPRINTS("ignoring ridiculous batt.temp of %dC", - DECI_KELVIN_TO_CELSIUS(curr.batt.temperature)); - curr.batt.flags |= BATT_FLAG_BAD_TEMPERATURE; - } - - /* If the battery thinks it's above 100%, don't believe it */ - if (curr.batt.state_of_charge > 100) { - CPRINTS("ignoring ridiculous batt.soc of %d%%", - curr.batt.state_of_charge); - curr.batt.flags |= BATT_FLAG_BAD_STATE_OF_CHARGE; - } + battery_validate_params(&curr.batt); notify_host_of_over_current(&curr.batt); diff --git a/include/battery.h b/include/battery.h index 49525e59cf..2de5835807 100644 --- a/include/battery.h +++ b/include/battery.h @@ -474,4 +474,6 @@ void battery_compensate_params(struct batt_params *batt); */ __override_proto void board_battery_compensate_params(struct batt_params *batt); +void battery_validate_params(struct batt_params *batt); + #endif /* __CROS_EC_BATTERY_H */ -- cgit v1.2.1