summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2017-02-08 18:09:27 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-02-14 23:54:53 -0800
commit61a5649e302915c617f4f70a1b3211805f363ed8 (patch)
tree6752655b84379e0de094048f7a9aa1017d0edfa4
parentaeeeafb1929d38f4ae6575688832d7dee1794cf5 (diff)
downloadchrome-ec-61a5649e302915c617f4f70a1b3211805f363ed8.tar.gz
eve: Add support for LISHEN battery
There are two batteries being evaludated for Eve and there needs to be a batteery_info struct for each one for situations where the gas gauge can't be read and the charge state machine uses these parameters. BUG=chrome-os-partner:62711 BRANCH=none TEST=Verifed that battery_type is read correctly for both LG and LISHEN battery units. On Lishen unit Drain battery completely, then reconnect type C charger. Verified that battery is now charging. Prior to this CL, the LISHEN bat would not charge because the internal overcurrent protection mode would not tolerate the 256 mA precharge current that's specified for the LG battery. Tested that both Lishen and LG recovered after forcing a battery disconnect. Change-Id: I201eaf61ad03d3dc0d199ab441b07c371bceddde Signed-off-by: Scott <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/440514 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/eve/battery.c101
1 files changed, 97 insertions, 4 deletions
diff --git a/board/eve/battery.c b/board/eve/battery.c
index 84d13244bc..fad21c2249 100644
--- a/board/eve/battery.c
+++ b/board/eve/battery.c
@@ -13,16 +13,41 @@
#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
+#include "hooks.h"
#include "util.h"
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
+enum battery_type {
+ BATTERY_LG,
+ BATTERY_LISHEN,
+ BATTERY_TYPE_COUNT,
+};
+
+struct board_batt_params {
+ const char *manuf_name;
+ const struct battery_info *batt_info;
+};
+
+/*
+ * Set LISHEN as default since the LG precharge current level could cause the
+ * LISHEN battery to not accept charge when it's recovering from a fully
+ * discharged state.
+ */
+#define DEFAULT_BATTERY_TYPE BATTERY_LISHEN
static enum battery_present batt_pres_prev = BP_NOT_SURE;
+static enum battery_type board_battery_type = BATTERY_TYPE_COUNT;
-/* Battery info for proto */
-static const struct battery_info info = {
- .voltage_max = 8800, /* mV */
+/*
+ * Battery info for LG A50. Note that the fields start_charging_min/max and
+ * charging_min/max are not used for the Eve charger. The effective temperature
+ * limits are given by discharging_min/max_c.
+ */
+static const struct battery_info batt_info_lg = {
+ .voltage_max = 8800, /* mV */
.voltage_normal = 7700,
.voltage_min = 6100, /* Add 100mV for charger accuracy */
.precharge_current = 256, /* mA */
@@ -34,9 +59,77 @@ static const struct battery_info info = {
.discharging_max_c = 60,
};
+/*
+ * Battery info for LISHEN. Note that the fields start_charging_min/max and
+ * charging_min/max are not used for the Eve charger. The effective temperature
+ * limits are given by discharging_min/max_c.
+ */
+static const struct battery_info batt_info_lishen = {
+ .voltage_max = 8750, /* mV */
+ .voltage_normal = 7700,
+ .voltage_min = 6100, /* Add 100mV for charger accuracy */
+ .precharge_current = 88, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 46,
+ .charging_min_c = 10,
+ .charging_max_c = 50,
+ .discharging_min_c = 10,
+ .discharging_max_c = 50,
+};
+
+static const struct board_batt_params info[] = {
+ [BATTERY_LG] = {
+ .manuf_name = "LG A50",
+ .batt_info = &batt_info_lg,
+ },
+
+ [BATTERY_LISHEN] = {
+ .manuf_name = "Lishen A50",
+ .batt_info = &batt_info_lishen,
+ },
+
+};
+BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_TYPE_COUNT);
+
+/* Get type of the battery connected on the board */
+static int board_get_battery_type(void)
+{
+ char name[3];
+ int i;
+
+ if (!battery_manufacturer_name(name, sizeof(name))) {
+ for (i = 0; i < BATTERY_TYPE_COUNT; i++) {
+ if (!strncasecmp(name, info[i].manuf_name,
+ ARRAY_SIZE(name)-1)) {
+ board_battery_type = i;
+ break;
+ }
+ }
+ }
+
+ return board_battery_type;
+}
+
+/*
+ * Initialize the battery type for the board.
+ *
+ * Very first battery info is called by the charger driver to initialize
+ * the charger parameters hence initialize the battery type for the board
+ * as soon as the I2C is initialized.
+ */
+static void board_init_battery_type(void)
+{
+ if (board_get_battery_type() != BATTERY_TYPE_COUNT)
+ CPRINTS("found batt: %s", info[board_battery_type].manuf_name);
+ else
+ CPRINTS("battery not found");
+}
+DECLARE_HOOK(HOOK_INIT, board_init_battery_type, HOOK_PRIO_INIT_I2C + 1);
+
const struct battery_info *battery_get_info(void)
{
- return &info;
+ return info[board_battery_type == BATTERY_TYPE_COUNT ?
+ DEFAULT_BATTERY_TYPE : board_battery_type].batt_info;
}
int board_cut_off_battery(void)