From 8bc8a505f25f219cc1b072be87f26a61e58b6173 Mon Sep 17 00:00:00 2001 From: Wai-Hong Tam Date: Thu, 17 Dec 2020 14:22:45 -0800 Subject: battery_fuel_gauge: Make the default battery type customizable Currently the default battery type is a constant. There is a need that a board can support both 2S and 3S batteries, according to its SKU ID. For example, a SKU which uses 2S battery will use a 2-to-1 switching capacitor to regulate the output voltage. A SKU which uses 3S battery will use a 3-to-1 switching capacitor. If the battery is not attached, the default battery is selected to configure the charger. A wrong battery configuration may be selected. For example, the charger may output a 2S voltage but the switching capacitor uses the 3-to-1 ratio. This change enables the board to customize the default battery type. It helps fixing the above issue. BRANCH=Trogdor BUG=b:175625362 TEST=Build the Lazor image and use it on the board with 3S battery but the battery is not attached. Signed-off-by: Wai-Hong Tam Change-Id: I76bf50c7226c4ec9f633d4b7f6025dc9ab464b49 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2597801 Reviewed-by: Diana Z --- common/battery_fuel_gauge.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'common/battery_fuel_gauge.c') diff --git a/common/battery_fuel_gauge.c b/common/battery_fuel_gauge.c index 444144dfeb..4a989a0db4 100644 --- a/common/battery_fuel_gauge.c +++ b/common/battery_fuel_gauge.c @@ -64,6 +64,11 @@ static int get_battery_type(void) return battery_type; } +__overridable int board_get_default_battery_type(void) +{ + return DEFAULT_BATTERY_TYPE; +} + /* * Initialize the battery type for the board. * @@ -82,7 +87,7 @@ static inline const struct board_batt_params *get_batt_params(void) int type = get_battery_type(); return &board_battery_info[type == BATTERY_TYPE_COUNT ? - DEFAULT_BATTERY_TYPE : type]; + board_get_default_battery_type() : type]; } const struct battery_info *battery_get_info(void) -- cgit v1.2.1