summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2019-11-02 10:22:30 -0600
committerCommit Bot <commit-bot@chromium.org>2019-11-09 04:57:54 +0000
commitbd2b21346ceb7bdd736efcd83f444c1d7f84ee7d (patch)
tree69d5ebaaa0291c17eed1c795065f54f46397f117
parentb127de71fac86406c275a6ad6d5a7bbcf5d11111 (diff)
downloadchrome-ec-bd2b21346ceb7bdd736efcd83f444c1d7f84ee7d.tar.gz
volteer: add initial battery support
Add ODM specified 62 Wh battery. BUG=b:143477210 BRANCH=none TEST=make buildall Change-Id: I7c3292bbd23405781207366981c2af03b6d4624a Signed-off-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1896648
-rw-r--r--baseboard/volteer/baseboard.c6
-rw-r--r--baseboard/volteer/baseboard.h7
-rw-r--r--baseboard/volteer/battery_presence.c70
-rw-r--r--baseboard/volteer/build.mk1
-rw-r--r--board/volteer/battery.c68
-rw-r--r--board/volteer/board.h5
-rw-r--r--board/volteer/build.mk1
-rw-r--r--board/volteer/gpio.inc3
8 files changed, 155 insertions, 6 deletions
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c
index 5c780d74b2..d79268c36a 100644
--- a/baseboard/volteer/baseboard.c
+++ b/baseboard/volteer/baseboard.c
@@ -5,7 +5,6 @@
/* Volteer family-specific configuration */
#include "adc_chip.h"
-#include "battery.h"
#include "charge_state.h"
#include "gpio.h"
#include "i2c.h"
@@ -154,11 +153,6 @@ enum charge_state charge_get_state(void)
return PWR_STATE_UNCHANGE;
}
-enum battery_present battery_is_present(void)
-{
- return BP_NOT_SURE;
-}
-
int charge_get_percent(void)
{
return 0;
diff --git a/baseboard/volteer/baseboard.h b/baseboard/volteer/baseboard.h
index c60b75a5a3..a7736f4063 100644
--- a/baseboard/volteer/baseboard.h
+++ b/baseboard/volteer/baseboard.h
@@ -66,6 +66,10 @@
/* Common charger defines */
/* Common battery defines */
+#define CONFIG_BATTERY_SMART
+#define CONFIG_BATTERY_FUEL_GAUGE
+/* TODO: b/143809318 enable cut off */
+/* #define CONFIG_BATTERY_CUT_OFF */
/* USB Type C and USB PD defines */
@@ -79,6 +83,9 @@
#define I2C_PORT_USB_1_MIX NPCX_I2C_PORT3_0
#define I2C_PORT_POWER NPCX_I2C_PORT5_0
#define I2C_PORT_EEPROM NPCX_I2C_PORT7_0
+
+#define I2C_PORT_BATTERY I2C_PORT_POWER
+
#define I2C_ADDR_EEPROM_FLAGS 0x50
#define CONFIG_I2C_MASTER
diff --git a/baseboard/volteer/battery_presence.c b/baseboard/volteer/battery_presence.c
new file mode 100644
index 0000000000..0d6590011f
--- /dev/null
+++ b/baseboard/volteer/battery_presence.c
@@ -0,0 +1,70 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Common battery presence checking for Volteer family.
+ * Each board should implement board_battery_info[] to define the specific
+ * battery packs supported.
+ */
+#include <stdbool.h>
+
+#include "battery.h"
+#include "battery_smart.h"
+#include "gpio.h"
+
+static enum battery_present batt_pres_prev = BP_NOT_SURE;
+
+enum battery_present battery_hw_present(void)
+{
+ /* The GPIO is low when the battery is physically present */
+ return gpio_get_level(GPIO_EC_BATT_PRES_ODL) ? BP_NO : BP_YES;
+}
+
+static bool battery_init(void)
+{
+ int batt_status;
+
+ return battery_status(&batt_status) ? 0 :
+ !!(batt_status & STATUS_INITIALIZED);
+}
+
+/*
+ * Physical detection of battery.
+ */
+static enum battery_present battery_check_present_status(void)
+{
+ enum battery_present batt_pres;
+
+ /* Get the physical hardware status */
+ batt_pres = battery_hw_present();
+
+ /*
+ * If the battery is not physically connected, then no need to perform
+ * any more checks.
+ */
+ if (batt_pres != BP_YES)
+ return batt_pres;
+
+ /*
+ * If the battery is present now and was present last time we checked,
+ * return early.
+ */
+ if (batt_pres == batt_pres_prev)
+ return batt_pres;
+
+ /*
+ * Ensure that battery is:
+ * 1. Not in cutoff
+ * 2. Initialized
+ */
+ if (battery_is_cut_off() || !battery_init())
+ batt_pres = BP_NO;
+
+ return batt_pres;
+}
+
+enum battery_present battery_is_present(void)
+{
+ batt_pres_prev = battery_check_present_status();
+ return batt_pres_prev;
+}
diff --git a/baseboard/volteer/build.mk b/baseboard/volteer/build.mk
index bb7e57ad6a..296bc15520 100644
--- a/baseboard/volteer/build.mk
+++ b/baseboard/volteer/build.mk
@@ -8,3 +8,4 @@
baseboard-y=baseboard.o
baseboard-y+=led.o
+baseboard-y+=battery_presence.o
diff --git a/board/volteer/battery.c b/board/volteer/battery.c
new file mode 100644
index 0000000000..a74afdd763
--- /dev/null
+++ b/board/volteer/battery.c
@@ -0,0 +1,68 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Battery pack vendor provided charging profile
+ */
+
+#include "battery_fuel_gauge.h"
+#include "common.h"
+#include "util.h"
+
+/*
+ * Battery info for all Volteer 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.
+ */
+const struct board_batt_params board_battery_info[] = {
+ /* LGC\011 L17L3PB0 Battery Information */
+ /*
+ * Battery info provided by ODM on b/143477210, comment #11
+ */
+ [BATTERY_LGC011] = {
+ .fuel_gauge = {
+ .manuf_name = "LGC",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x10, 0x10 },
+ },
+ .fet = {
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = TARGET_WITH_MARGIN(13050, 5),
+ .voltage_normal = 11400, /* mV */
+ .voltage_min = 9000, /* mV */
+ .precharge_current = 500, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 50,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
+
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_LGC011;
diff --git a/board/volteer/board.h b/board/volteer/board.h
index 990dd82194..0d645c99c3 100644
--- a/board/volteer/board.h
+++ b/board/volteer/board.h
@@ -71,6 +71,11 @@
#include "gpio_signal.h"
#include "registers.h"
+enum battery_type {
+ BATTERY_LGC011,
+ BATTERY_TYPE_COUNT,
+};
+
/* TODO: b/143375057 - Remove this code after power on. */
void c10_gate_change(enum gpio_signal signal);
diff --git a/board/volteer/build.mk b/board/volteer/build.mk
index 9ebde9ae1b..681f1b1fe0 100644
--- a/board/volteer/build.mk
+++ b/board/volteer/build.mk
@@ -28,4 +28,5 @@ ENV_VARS := VOLTEER_POWER_SEQUENCE
board-y=board.o
+board-y+=battery.o
board-$(VOLTEER_POWER_SEQUENCE)+=power_sequence.o
diff --git a/board/volteer/gpio.inc b/board/volteer/gpio.inc
index c459a8d589..5ce78773b6 100644
--- a/board/volteer/gpio.inc
+++ b/board/volteer/gpio.inc
@@ -102,6 +102,9 @@ GPIO(EC_I2C5_POWER_SDA, PIN(3, 6), GPIO_INPUT)
GPIO(EC_I2C7_EEPROM_SCL, PIN(B, 3), GPIO_INPUT)
GPIO(EC_I2C7_EEPROM_SDA, PIN(B, 2), GPIO_INPUT)
+/* Battery signals */
+GPIO(EC_BATT_PRES_ODL, PIN(E, 1), GPIO_INPUT)
+
/* Alternate functions GPIO definitions */
ALTERNATE(PIN_MASK(B, BIT(5) | BIT(4)), 0, MODULE_I2C, (GPIO_INPUT | GPIO_SEL_1P8V)) /* I2C0 */
ALTERNATE(PIN_MASK(9, BIT(0) | BIT(2) | BIT(1)), 0, MODULE_I2C, 0) /* I2C1 SCL / I2C2 */