summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2021-01-05 15:15:20 -0800
committerCommit Bot <commit-bot@chromium.org>2021-01-06 21:57:07 +0000
commitcbdd34446ef0faf89ea5348701a14f77e0e1b947 (patch)
tree710090ed07afada8c54141d8612450c779b9b294
parent5cbdb885f06ce87d7674c7edc3a7e33f3ba91b51 (diff)
downloadchrome-ec-cbdd34446ef0faf89ea5348701a14f77e0e1b947.tar.gz
coil: remove virtual_battery
This code uses coil terms we're removing, but we don't use it in platform/cr50. Remove the code instead of replacing the terms. BUG=b:175244613 TEST=make buildall -j Change-Id: I4b562b52817493afc123346280c845913be7694b Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2613141 Reviewed-by: Namyoon Woo <namyoon@chromium.org>
-rw-r--r--common/build.mk1
-rw-r--r--common/i2c_master.c10
-rw-r--r--common/virtual_battery.c294
-rw-r--r--include/virtual_battery.h49
4 files changed, 0 insertions, 354 deletions
diff --git a/common/build.mk b/common/build.mk
index 343c8e58ef..3b62c67c6b 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -84,7 +84,6 @@ common-$(CONFIG_HOSTCMD_RTC)+=rtc.o
common-$(CONFIG_I2C_DEBUG)+=i2c_trace.o
common-$(CONFIG_I2C_MASTER)+=i2c_master.o
common-$(CONFIG_I2C_SLAVE)+=i2c_slave.o
-common-$(CONFIG_I2C_VIRTUAL_BATTERY)+=virtual_battery.o
common-$(CONFIG_INDUCTIVE_CHARGING)+=inductive_charging.o
common-$(CONFIG_KEYBOARD_PROTOCOL_8042)+=keyboard_8042.o \
keyboard_8042_sharedlib.o
diff --git a/common/i2c_master.c b/common/i2c_master.c
index be371e52ed..db26aaf0ee 100644
--- a/common/i2c_master.c
+++ b/common/i2c_master.c
@@ -17,7 +17,6 @@
#include "task.h"
#include "util.h"
#include "watchdog.h"
-#include "virtual_battery.h"
/* Delay for bitbanging i2c corresponds roughly to 100kHz. */
#define I2C_BITBANG_DELAY_US 5
@@ -1010,15 +1009,6 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
if (resp->num_msgs == params->num_msgs - 1)
xferflags |= I2C_XFER_STOP;
-#if defined(VIRTUAL_BATTERY_ADDR_FLAGS) && defined(I2C_PORT_VIRTUAL_BATTERY)
- if (params->port == I2C_PORT_VIRTUAL_BATTERY &&
- addr_flags == VIRTUAL_BATTERY_ADDR_FLAGS) {
- if (virtual_battery_handler(resp, in_len, &rv,
- xferflags, read_len,
- write_len, out))
- break;
- }
-#endif
/* Transfer next message */
PTHRUPRINTS("xfer port=%x addr=0x%x rlen=%d flags=0x%x",
params->port, addr_flags,
diff --git a/common/virtual_battery.c b/common/virtual_battery.c
deleted file mode 100644
index 7fdd92de1a..0000000000
--- a/common/virtual_battery.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/* Copyright 2016 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.
- */
-
-/* Virtual battery cross-platform code for Chrome EC */
-
-#include "battery.h"
-#include "charge_state.h"
-#include "i2c.h"
-#include "system.h"
-#include "util.h"
-#include "virtual_battery.h"
-
-/* Console output macros */
-#define CPUTS(outstr) cputs(CC_I2C, outstr)
-#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
-
-#define BATT_MODE_UNINITIALIZED -1
-
-/*
- * The state machine used to parse smart battery command
- * to support virtual battery.
- */
-enum batt_cmd_parse_state {
- IDLE = 0, /* initial state */
- START = 1, /* received the register address (command code) */
- WRITE_VB, /* writing data bytes to the slave */
- READ_VB, /* reading data bytes to the slave */
-};
-
-static enum batt_cmd_parse_state sb_cmd_state;
-static uint8_t cache_hit;
-static const uint8_t *batt_cmd_head;
-static int acc_write_len;
-
-int virtual_battery_handler(struct ec_response_i2c_passthru *resp,
- int in_len, int *err_code, int xferflags,
- int read_len, int write_len,
- const uint8_t *out)
-{
-
-#if defined(CONFIG_BATTERY_PRESENT_GPIO) || \
- defined(CONFIG_BATTERY_PRESENT_CUSTOM)
- /*
- * If the battery isn't present, return a NAK (which we
- * would have gotten anyways had we attempted to talk to
- * the battery.)
- */
- if (battery_is_present() != BP_YES) {
- resp->i2c_status = EC_I2C_STATUS_NAK;
- return EC_ERROR_INVAL;
- }
-#endif
- switch (sb_cmd_state) {
- case IDLE:
- /*
- * A legal battery command must start
- * with a i2c write for reg index.
- */
- if (write_len == 0) {
- resp->i2c_status = EC_I2C_STATUS_NAK;
- return EC_ERROR_INVAL;
- }
- /* Record the head of battery command. */
- batt_cmd_head = out;
- sb_cmd_state = START;
- *err_code = 0;
- break;
- case START:
- if (write_len > 0) {
- sb_cmd_state = WRITE_VB;
- *err_code = 0;
- } else {
- sb_cmd_state = READ_VB;
- *err_code = virtual_battery_operation(batt_cmd_head,
- NULL, 0, 0);
- /*
- * If the reg is not handled by virtual battery, we
- * do not support it.
- */
- if (*err_code)
- return EC_ERROR_INVAL;
- cache_hit = 1;
- }
- break;
- case WRITE_VB:
- if (write_len == 0) {
- resp->i2c_status = EC_I2C_STATUS_NAK;
- reset_parse_state();
- return EC_ERROR_INVAL;
- }
- *err_code = 0;
- break;
- case READ_VB:
- if (read_len == 0) {
- resp->i2c_status = EC_I2C_STATUS_NAK;
- reset_parse_state();
- return EC_ERROR_INVAL;
- }
- /*
- * Do not send the command to battery
- * if the reg is cached.
- */
- if (cache_hit)
- *err_code = 0;
- break;
- default:
- reset_parse_state();
- return EC_ERROR_INVAL;
- }
-
- acc_write_len += write_len;
-
- /* the last message */
- if (xferflags & I2C_XFER_STOP) {
- switch (sb_cmd_state) {
- /* write to virtual battery */
- case START:
- case WRITE_VB:
- virtual_battery_operation(batt_cmd_head,
- NULL,
- 0,
- acc_write_len);
- break;
- /* read from virtual battery */
- case READ_VB:
- if (cache_hit) {
- read_len += in_len;
- memset(&resp->data[0], 0, read_len);
- virtual_battery_operation(batt_cmd_head,
- &resp->data[0],
- read_len,
- 0);
- }
- break;
- default:
- reset_parse_state();
- return EC_ERROR_INVAL;
-
- }
- /* Reset the state in the end of messages */
- reset_parse_state();
- }
- return EC_RES_SUCCESS;
-}
-
-void reset_parse_state(void)
-{
- sb_cmd_state = IDLE;
- cache_hit = 0;
- acc_write_len = 0;
-}
-
-/*
- * Copy memmap string data from offset to dest, up to size len, in the format
- * expected by SBS (first byte of dest contains strlen).
- */
-void copy_memmap_string(uint8_t *dest, int offset, int len)
-{
- uint8_t *memmap_str;
- uint8_t memmap_strlen;
-
- if (len == 0)
- return;
- memmap_str = host_get_memmap(offset);
- /* memmap_str might not be NULL terminated */
- memmap_strlen = *(memmap_str + EC_MEMMAP_TEXT_MAX - 1) == '\0' ?
- strlen(memmap_str) : EC_MEMMAP_TEXT_MAX;
- dest[0] = memmap_strlen;
- memcpy(dest + 1, memmap_str, MIN(memmap_strlen, len - 1));
-}
-
-int virtual_battery_operation(const uint8_t *batt_cmd_head,
- uint8_t *dest,
- int read_len,
- int write_len)
-{
- int val;
- /*
- * We cache battery operational mode locally for both read and write
- * commands. If MODE_CAPACITY bit is set, battery capacity will be
- * reported in 10mW/10mWh, instead of the default unit, mA/mAh.
- * Note that we don't update the cached capacity: We do a real-time
- * conversion and return the converted values.
- */
- static int batt_mode_cache = BATT_MODE_UNINITIALIZED;
- const struct batt_params *curr_batt;
- /*
- * Don't allow host reads into arbitrary memory space, most params
- * are two bytes.
- */
- int bounded_read_len = MIN(read_len, 2);
-
- curr_batt = charger_current_battery_params();
- switch (*batt_cmd_head) {
- case SB_BATTERY_MODE:
- if (write_len == 3) {
- batt_mode_cache = batt_cmd_head[1] |
- (batt_cmd_head[2] << 8);
- } else if (read_len > 0) {
- if (batt_mode_cache == BATT_MODE_UNINITIALIZED)
- /*
- * Read the battery operational mode from
- * the battery to initialize batt_mode_cache.
- * This may cause an i2c transaction.
- */
- if (battery_get_mode(&batt_mode_cache) ==
- EC_ERROR_UNIMPLEMENTED)
- /*
- * Register not supported, choose
- * typical SB defaults.
- */
- batt_mode_cache =
- MODE_INTERNAL_CHARGE_CONTROLLER |
- MODE_ALARM |
- MODE_CHARGER;
-
- memcpy(dest, &batt_mode_cache, bounded_read_len);
- }
- break;
- case SB_SERIAL_NUMBER:
- val = strtoi(host_get_memmap(EC_MEMMAP_BATT_SERIAL), NULL, 16);
- memcpy(dest, &val, bounded_read_len);
- break;
- case SB_VOLTAGE:
- memcpy(dest, &(curr_batt->voltage), bounded_read_len);
- break;
- case SB_RELATIVE_STATE_OF_CHARGE:
- memcpy(dest, &(curr_batt->state_of_charge), bounded_read_len);
- break;
- case SB_TEMPERATURE:
- memcpy(dest, &(curr_batt->temperature), bounded_read_len);
- break;
- case SB_CURRENT:
- memcpy(dest, &(curr_batt->current), bounded_read_len);
- break;
- case SB_FULL_CHARGE_CAPACITY:
- val = curr_batt->full_capacity;
- if (batt_mode_cache & MODE_CAPACITY)
- val = val * curr_batt->voltage / 10000;
- memcpy(dest, &val, bounded_read_len);
- break;
- case SB_BATTERY_STATUS:
- memcpy(dest, &(curr_batt->status), bounded_read_len);
- break;
- case SB_CYCLE_COUNT:
- memcpy(dest, (int *)host_get_memmap(EC_MEMMAP_BATT_CCNT),
- bounded_read_len);
- break;
- case SB_DESIGN_CAPACITY:
- val = *(int *)host_get_memmap(EC_MEMMAP_BATT_DCAP);
- if (batt_mode_cache & MODE_CAPACITY)
- val = val * curr_batt->voltage / 10000;
- memcpy(dest, &val, bounded_read_len);
- break;
- case SB_DESIGN_VOLTAGE:
- memcpy(dest, (int *)host_get_memmap(EC_MEMMAP_BATT_DVLT),
- bounded_read_len);
- break;
- case SB_REMAINING_CAPACITY:
- val = curr_batt->remaining_capacity;
- if (batt_mode_cache & MODE_CAPACITY)
- val = val * curr_batt->voltage / 10000;
- memcpy(dest, &val, bounded_read_len);
- break;
- case SB_MANUFACTURER_NAME:
- copy_memmap_string(dest, EC_MEMMAP_BATT_MFGR, read_len);
- break;
- case SB_DEVICE_NAME:
- copy_memmap_string(dest, EC_MEMMAP_BATT_MODEL, read_len);
- break;
- case SB_AVERAGE_TIME_TO_FULL:
- /* This may cause an i2c transaction */
- if (battery_time_to_full(&val))
- return EC_ERROR_INVAL;
- memcpy(dest, &val, bounded_read_len);
- break;
- case SB_AVERAGE_TIME_TO_EMPTY:
- /* This may cause an i2c transaction */
- if (battery_time_to_empty(&val))
- return EC_ERROR_INVAL;
- memcpy(dest, &val, bounded_read_len);
- break;
- case SB_MANUFACTURER_ACCESS:
- /* No manuf. access reg access allowed over VB interface */
- return EC_ERROR_INVAL;
- default:
- CPRINTS("Unhandled VB reg %x", *batt_cmd_head);
- return EC_ERROR_INVAL;
- }
- return EC_SUCCESS;
-}
-
diff --git a/include/virtual_battery.h b/include/virtual_battery.h
deleted file mode 100644
index 4e7ca31d05..0000000000
--- a/include/virtual_battery.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Copyright 2016 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.
- */
-
-#ifndef __CROS_EC_VIRTUAL_BATTERY_H
-#define __CROS_EC_VIRTUAL_BATTERY_H
-
-#if defined(CONFIG_I2C_VIRTUAL_BATTERY) && defined(CONFIG_BATTERY_SMART)
-#define VIRTUAL_BATTERY_ADDR_FLAGS BATTERY_ADDR_FLAGS
-#endif
-
-/**
- * Read/write value of battery parameter from charge state.
- *
- * @param batt_cmd_head The beginning of the smart battery command
- * @param dest Destination buffer for data
- * @param read_len Number of bytes to read to the buffer
- * @param write_len Number of bytes to write
- * @return EC_SUCCESS if successful, non-zero if error.
- *
- */
-int virtual_battery_operation(const uint8_t *batt_cmd_head,
- uint8_t *dest,
- int read_len,
- int write_len);
-
-/**
- * Parse a command for virtual battery function.
- *
- * @param resp Pointer to the data structure to store the i2c messages
- * @param in_len Accumulative number of bytes read
- * @param err_code Pointer to the return value of i2c_xfer() or
- * virtual_battery_operation()
- * @param xferflags Flags
- * @param read_len Number of bytes to read
- * @param write_len Number of bytes to write
- * @param out Data to send
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int virtual_battery_handler(struct ec_response_i2c_passthru *resp,
- int in_len, int *err_code, int xferflags,
- int read_len, int write_len,
- const uint8_t *out);
-
-/* Reset the state machine and static variables. */
-void reset_parse_state(void);
-
-#endif /* __CROS_EC_VIRTUAL_BATTERY_H */