summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2020-12-17 14:22:45 -0800
committerCommit Bot <commit-bot@chromium.org>2020-12-18 02:07:45 +0000
commit8bc8a505f25f219cc1b072be87f26a61e58b6173 (patch)
treec5affa44976055a15ebc008da17e06fc44da71a1
parentdf3441b92b1a461df49d21724db46a6c7f4156a0 (diff)
downloadchrome-ec-8bc8a505f25f219cc1b072be87f26a61e58b6173.tar.gz
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 <waihong@google.com> Change-Id: I76bf50c7226c4ec9f633d4b7f6025dc9ab464b49 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2597801 Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--common/battery_fuel_gauge.c7
-rw-r--r--include/battery_fuel_gauge.h7
2 files changed, 13 insertions, 1 deletions
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)
diff --git a/include/battery_fuel_gauge.h b/include/battery_fuel_gauge.h
index 8b1b7106bd..36da40b274 100644
--- a/include/battery_fuel_gauge.h
+++ b/include/battery_fuel_gauge.h
@@ -71,6 +71,13 @@ int battery_bq4050_imbalance_mv(void);
#endif
/**
+ * Return the board-specific default battery type.
+ *
+ * @return a value of `enum battery_type`.
+ */
+__override_proto int board_get_default_battery_type(void);
+
+/**
* Return 1 if CFET is disabled, 0 if enabled. -1 if an error was encountered.
* If the CFET mask is not defined, it will return 0.
*/