summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2021-06-29 14:46:22 -0700
committerCommit Bot <commit-bot@chromium.org>2021-07-13 22:13:54 +0000
commitbe675d26fab1efc625c1a9f04c136fd70dc97228 (patch)
treefa16283747f7c49fcb76fd09a054e03126391ea4
parent2ac1688423a1aa43706f126bfa616fa8de092bcf (diff)
downloadchrome-ec-be675d26fab1efc625c1a9f04c136fd70dc97228.tar.gz
trogdor: Enable battery fuel gauge
Do the same thing as CL:2987915, for Trogdor. Enable the battery fuel gauge and add the battery info as an example, such that the follower boards can just add the new battery info. I pick a battery from the Lazor board. As long as it is a 2-cell battery, it does not matter too much. BRANCH=None BUG=b:184071830 TEST=Built the trogdor image successfully and booted to AP. Change-Id: Ic861a46148d238ba1dc015cd7b907321b484deca Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2994752 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--board/trogdor/battery.c91
-rw-r--r--board/trogdor/board.h11
2 files changed, 68 insertions, 34 deletions
diff --git a/board/trogdor/battery.c b/board/trogdor/battery.c
index 0548a6e6d0..e95735eda7 100644
--- a/board/trogdor/battery.c
+++ b/board/trogdor/battery.c
@@ -5,41 +5,64 @@
* Battery pack vendor provided charging profile
*/
-#include "battery.h"
-#include "battery_smart.h"
+#include "battery_fuel_gauge.h"
+#include "common.h"
+#include "util.h"
-/* Shutdown mode parameter to write to manufacturer access register */
-#define SB_SHIP_MODE_REG SB_MANUFACTURER_ACCESS
-#define SB_SHUTDOWN_DATA 0x0010
+/*
+ * Battery info for all trogdor battery types. Note that the fields
+ * start_charging_min/max and charging_min/max are not used for the charger.
+ * The effective temperature limits are given by discharging_min/max_c.
+ *
+ * Fuel Gauge (FG) parameters which are used for determining if the battery
+ * is connected, the appropriate ship mode (battery cutoff) command, and the
+ * charge/discharge FETs status.
+ *
+ * Ship mode (battery cutoff) requires 2 writes to the appropriate smart battery
+ * register. For some batteries, the charge/discharge FET bits are set when
+ * charging/discharging is active, in other types, these bits set mean that
+ * charging/discharging is disabled. Therefore, in addition to the mask for
+ * these bits, a disconnect value must be specified. Note that for TI fuel
+ * gauge, the charge/discharge FET status is found in Operation Status (0x54),
+ * but a read of Manufacturer Access (0x00) will return the lower 16 bits of
+ * Operation status which contains the FET status bits.
+ *
+ * The assumption for battery types supported is that the charge/discharge FET
+ * status can be read with a sb_read() command and therefore, only the register
+ * address, mask, and disconnect value need to be provided.
+ */
-/* Battery info */
-static const struct battery_info info = {
- .voltage_max = 8800,
- .voltage_normal = 7700,
- .voltage_min = 6000,
- .precharge_current = 256, /* mA */
- .start_charging_min_c = 0,
- .start_charging_max_c = 50,
- .charging_min_c = 0,
- .charging_max_c = 60,
- .discharging_min_c = -20,
- .discharging_max_c = 75,
+const struct board_batt_params board_battery_info[] = {
+ /* AP16L5J */
+ [BATTERY_AP16L5J] = {
+ .fuel_gauge = {
+ .manuf_name = "PANASONIC",
+ .device_name = "AP16L5J",
+ .ship_mode = {
+ .reg_addr = 0x3A,
+ .reg_data = { 0xC574, 0xC574 },
+ },
+ .fet = {
+ .mfgacc_support = 0,
+ .reg_addr = 0x0,
+ .reg_mask = 0x4000,
+ .disconnect_val = 0x0,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800,
+ .voltage_normal = 7700, /* mV */
+ .voltage_min = 6000, /* mV */
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 50,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = -20,
+ .discharging_max_c = 75,
+ },
+ },
};
+BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
-const struct battery_info *battery_get_info(void)
-{
- return &info;
-}
-
-int board_cut_off_battery(void)
-{
- int rv;
-
- /* Ship mode command must be sent twice to take effect */
- rv = sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
-
- if (rv != EC_SUCCESS)
- return rv;
-
- return sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
-}
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_AP16L5J;
diff --git a/board/trogdor/board.h b/board/trogdor/board.h
index d4a1a00794..16bc508b2d 100644
--- a/board/trogdor/board.h
+++ b/board/trogdor/board.h
@@ -26,6 +26,11 @@
#define CONFIG_KEYBOARD_BOARD_CONFIG
#define CONFIG_PWM_KBLIGHT
+/* Battery */
+#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION"
+#define CONFIG_BATTERY_REVIVE_DISCONNECT
+#define CONFIG_BATTERY_FUEL_GAUGE
+
/* BC 1.2 Charger */
#define CONFIG_BC12_DETECT_PI3USB9201
@@ -92,6 +97,12 @@ enum pwm_channel {
PWM_CH_COUNT
};
+/* List of possible batteries */
+enum battery_type {
+ BATTERY_AP16L5J,
+ BATTERY_TYPE_COUNT,
+};
+
/* Reset all TCPCs. */
void board_reset_pd_mcu(void);
void board_set_tcpc_power_mode(int port, int mode);