summaryrefslogtreecommitdiff
path: root/board/waddledoo
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2020-07-06 12:31:33 -0700
committerCommit Bot <commit-bot@chromium.org>2020-08-27 04:21:04 +0000
commit018741aac031fcc7aeb9930f0c66a20f90eee88c (patch)
treec776cc31ff401ed62176789bfd50cf4923e2f085 /board/waddledoo
parent48f8461f39fee6375963c8b556deab3f283215d4 (diff)
downloadchrome-ec-018741aac031fcc7aeb9930f0c66a20f90eee88c.tar.gz
WADDLEDOO: Use common battery code
Use common battery fuel gauge code BRANCH=none BUG=b:152067066 TEST=make -j buildall Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: I25a97614e6ba5dc601812f59739bd9cb7ce572e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2283852 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/waddledoo')
-rw-r--r--board/waddledoo/battery.c146
-rw-r--r--board/waddledoo/board.h9
2 files changed, 65 insertions, 90 deletions
diff --git a/board/waddledoo/battery.c b/board/waddledoo/battery.c
index cb2e03063c..64af3b4302 100644
--- a/board/waddledoo/battery.c
+++ b/board/waddledoo/battery.c
@@ -2,99 +2,65 @@
* 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 "charge_state.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
-
-/* 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 all waddledoo 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[] = {
+ /* POW-TECH Battery Information */
+ [BATTERY_POWER_TECH] = {
+ .fuel_gauge = {
+ .manuf_name = "POW-TECH",
+ .ship_mode = {
+ .reg_addr = 0x0,
+ .reg_data = { 0x10, 0x10 },
+ },
+ .fet = {
+ .reg_addr = 0x00,
+ .reg_mask = 0x2000,
+ .disconnect_val = 0x2000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7700,
+ .voltage_min = 6000,
+ .precharge_current = 160, /* mA */
+ .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,
+ },
+
+ },
};
+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_POWER_TECH;
diff --git a/board/waddledoo/board.h b/board/waddledoo/board.h
index dcaa01af8a..189f9cb9dd 100644
--- a/board/waddledoo/board.h
+++ b/board/waddledoo/board.h
@@ -17,6 +17,9 @@
*/
#define CONFIG_SYSTEM_UNLOCKED
+/* Battery */
+#define CONFIG_BATTERY_FUEL_GAUGE
+
/* Charger */
#define CONFIG_CHARGER_RAA489000
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
@@ -165,6 +168,12 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
+/* List of possible batteries */
+enum battery_type {
+ BATTERY_POWER_TECH,
+ BATTERY_TYPE_COUNT,
+};
+
int board_is_sourcing_vbus(int port);
#endif /* !__ASSEMBLER__ */