From ff48c55fa23433a4beb5e057cab01ebfd60bbcea Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Dec 2020 17:04:52 -0700 Subject: Add information for battery charging Copy this over from the EC code base so that volteer can build the charger task BUG=b:175248556 TEST=build and boot on volteer (no actual test) Cq-Depend: chromium:2600228 Change-Id: I42de66fc6023762eb6e0eb84d5b6e93bd41ca7d7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/zephyr-chrome/+/2599493 Reviewed-by: Keith Short Commit-Queue: Simon Glass Tested-by: Simon Glass Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2630164 Tested-by: Jack Rosenthal Reviewed-by: Simon Glass Commit-Queue: Jack Rosenthal --- zephyr/projects/volteer/CMakeLists.txt | 1 + zephyr/projects/volteer/include/i2c_map.h | 1 + zephyr/projects/volteer/prj.conf | 1 + zephyr/projects/volteer/src/battery.c | 78 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 zephyr/projects/volteer/src/battery.c diff --git a/zephyr/projects/volteer/CMakeLists.txt b/zephyr/projects/volteer/CMakeLists.txt index fd5ed88bfe..20928eaea9 100644 --- a/zephyr/projects/volteer/CMakeLists.txt +++ b/zephyr/projects/volteer/CMakeLists.txt @@ -21,5 +21,6 @@ project(volteer) # Include board specific header files zephyr_include_directories(include) +target_sources(app PRIVATE "src/battery.c") target_sources(app PRIVATE "src/battery_presence.c") target_sources(app PRIVATE "src/pwrok_signals.c") diff --git a/zephyr/projects/volteer/include/i2c_map.h b/zephyr/projects/volteer/include/i2c_map.h index 70a73fbb8c..4a0b131a70 100644 --- a/zephyr/projects/volteer/include/i2c_map.h +++ b/zephyr/projects/volteer/include/i2c_map.h @@ -23,5 +23,6 @@ #define I2C_ADDR_EEPROM_FLAGS 0x50 #define I2C_PORT_BATTERY I2C_PORT_POWER +#define I2C_PORT_CHARGER I2C_PORT_EEPROM #endif /* __ZEPHYR_CHROME_I2C_MAP_H */ diff --git a/zephyr/projects/volteer/prj.conf b/zephyr/projects/volteer/prj.conf index 9055bd0da7..acfa0bdaad 100644 --- a/zephyr/projects/volteer/prj.conf +++ b/zephyr/projects/volteer/prj.conf @@ -20,6 +20,7 @@ CONFIG_PLATFORM_EC_CBI=y # Battery CONFIG_PLATFORM_EC_BATTERY=y CONFIG_PLATFORM_EC_BATTERY_SMART=y +CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y # Power Sequencing CONFIG_PLATFORM_EC_POWERSEQ=y diff --git a/zephyr/projects/volteer/src/battery.c b/zephyr/projects/volteer/src/battery.c new file mode 100644 index 0000000000..d2530979fa --- /dev/null +++ b/zephyr/projects/volteer/src/battery.c @@ -0,0 +1,78 @@ +/* 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 "common.h" +#include "battery_fuel_gauge.h" +#include "charger.h" +#include "util.h" +#include "../driver/charger/isl9241.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(13200, 5), + .voltage_normal = 11550, /* mV */ + .voltage_min = 9000, /* mV */ + .precharge_current = 256, /* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 75, + }, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); + +const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_LGC011; + +const struct charger_config_t chg_chips[] = { + { + .i2c_port = I2C_PORT_CHARGER, + .i2c_addr_flags = ISL9241_ADDR_FLAGS, + .drv = &isl9241_drv, + }, +}; -- cgit v1.2.1