summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2021-06-25 15:51:47 -0700
committerCommit Bot <commit-bot@chromium.org>2021-06-28 22:26:45 +0000
commit595d767e0900aa6d8836cc49893e87d607cf22bf (patch)
treeafc9c92c3c80855f625a1e66a0c622401344ed11 /board
parentf33ccc2310ac085b0306b7ba37c69a9835be6f19 (diff)
downloadchrome-ec-595d767e0900aa6d8836cc49893e87d607cf22bf.tar.gz
herobrine_npcx7: Enable battery fuel gauge
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:191803008 TEST=Built the herobrine_npcx7 image successfully. Change-Id: I84ff09e534b7b0513190fb94fa19e5210bfc27d4 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2987915 Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/herobrine_npcx7/battery.c91
-rw-r--r--board/herobrine_npcx7/board.h11
2 files changed, 68 insertions, 34 deletions
diff --git a/board/herobrine_npcx7/battery.c b/board/herobrine_npcx7/battery.c
index 47bacd3c31..2c22bc7170 100644
--- a/board/herobrine_npcx7/battery.c
+++ b/board/herobrine_npcx7/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 herobrine_npcx7 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/herobrine_npcx7/board.h b/board/herobrine_npcx7/board.h
index 0237c80d1f..b2539ba866 100644
--- a/board/herobrine_npcx7/board.h
+++ b/board/herobrine_npcx7/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);