summaryrefslogtreecommitdiff
path: root/board/magolor/battery.c
diff options
context:
space:
mode:
authorBen Chen <ben.chen2@quanta.corp-partner.google.com>2020-08-21 18:42:15 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-04 03:00:18 +0000
commit854e4ca0471a123a9cb50fe26219bc91aa1c98a8 (patch)
treed12c1379e475cc252a958def4f361817bf42b464 /board/magolor/battery.c
parenta0695f17ca648883717bebfd1afeaaaf29d78e9d (diff)
downloadchrome-ec-854e4ca0471a123a9cb50fe26219bc91aa1c98a8.tar.gz
magolor: Support new battery AP18C8K/AP18C4K
Add new battery config : AP18C8k/AP18C4K. BUG=b:166237036, b:166237839, b:166736661 BRANCH=master TEST=Check found battery info in console and cutoff work. Change-Id: Ib352f13701c5feac5dae03fe1c82340c3828bab3 Signed-off-by: Ben Chen <ben.chen2@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2379354 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/magolor/battery.c')
-rw-r--r--board/magolor/battery.c179
1 files changed, 89 insertions, 90 deletions
diff --git a/board/magolor/battery.c b/board/magolor/battery.c
index cb2e03063c..e7572946b2 100644
--- a/board/magolor/battery.c
+++ b/board/magolor/battery.c
@@ -2,99 +2,98 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * Battery pack information
+ * Battery pack vendor provided charging profile
*/
-
#include "battery.h"
-#include "battery_smart.h"
+#include "battery_fuel_gauge.h"
#include "common.h"
-#include "ec_commands.h"
-#include "extpower.h"
-
-/* Shutdown mode parameter to write to manufacturer access register */
-#define SB_SHUTDOWN_DATA 0x0010
+#include "gpio.h"
+#include "util.h"
-/* Battery info */
-static const struct battery_info info = {
- .voltage_max = 8880,
- .voltage_normal = 7700,
- .voltage_min = 6000,
- .precharge_current = 160,
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 45,
- .discharging_min_c = -20,
- .discharging_max_c = 60,
+/*
+ * Battery info for magolor 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 AP18C8K Battery Information */
+ [BATTERY_LGC_AP18C8K] = {
+ .fuel_gauge = {
+ .manuf_name = "LGC KT0030G020",
+ .device_name = "AP18C8K",
+ .ship_mode = {
+ .reg_addr = 0x3A,
+ .reg_data = { 0xC574, 0xC574 },
+ },
+ .fet = {
+ .reg_addr = 0x43,
+ .reg_mask = 0x0001,
+ .disconnect_val = 0x0,
+ .cfet_mask = 0x0002,
+ .cfet_off_val = 0x0000,
+ },
+ },
+ .batt_info = {
+ .voltage_max = 13050,
+ .voltage_normal = 11250,
+ .voltage_min = 9000,
+ .precharge_current = 256,
+ .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,
+ },
+ },
+ /* Murata AP18C4K Battery Information */
+ [BATTERY_MURATA_AP18C4K] = {
+ .fuel_gauge = {
+ .manuf_name = "Murata KT00304012",
+ .device_name = "AP18C4K",
+ .ship_mode = {
+ .reg_addr = 0x3A,
+ .reg_data = { 0xC574, 0xC574 },
+ },
+ .fet = {
+ .reg_addr = 0x0,
+ .reg_mask = 0x2000,
+ .disconnect_val = 0x2000,
+ .cfet_mask = 0x4000,
+ .cfet_off_val = 0x4000,
+ },
+ },
+ .batt_info = {
+ .voltage_max = 13200,
+ .voltage_normal = 11400,
+ .voltage_min = 9000,
+ .precharge_current = 256,
+ .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_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
- if (rv != EC_SUCCESS)
- return EC_RES_ERROR;
-
- rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
- return rv ? EC_RES_ERROR : EC_RES_SUCCESS;
-}
-
-enum battery_disconnect_state battery_get_disconnect_state(void)
-{
- uint8_t data[6];
- int rv;
-
- /*
- * Take note if we find that the battery isn't in disconnect state,
- * and always return NOT_DISCONNECTED without probing the battery.
- * This assumes the battery will not go to disconnect state during
- * runtime.
- */
- static int not_disconnected;
-
- if (not_disconnected)
- return BATTERY_NOT_DISCONNECTED;
-
- /* Check if battery discharge FET is disabled. */
- rv = sb_read_mfgacc(PARAM_OPERATION_STATUS,
- SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
- if (rv)
- return BATTERY_DISCONNECT_ERROR;
- if (~data[3] & (BATTERY_DISCHARGING_DISABLED)) {
- not_disconnected = 1;
- return BATTERY_NOT_DISCONNECTED;
- }
-
- /*
- * Battery discharge FET is disabled. Verify that we didn't enter this
- * state due to a safety fault.
- */
- rv = sb_read_mfgacc(PARAM_SAFETY_STATUS,
- SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
- if (rv || data[2] || data[3] || data[4] || data[5])
- return BATTERY_DISCONNECT_ERROR;
-
- /* No safety fault, battery is disconnected */
- return BATTERY_DISCONNECTED;
-}
-
-int battery_is_charge_fet_disabled(void)
-{
- uint8_t data[6];
- int rv;
-
- /* Check if battery charge FET is disabled. */
- rv = sb_read_mfgacc(PARAM_OPERATION_STATUS,
- SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
- if (rv)
- return -1;
-
- return !!(~data[3] & (BATTERY_CHARGING_DISABLED));
-} \ No newline at end of file
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_LGC_AP18C8K;