summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorphilipchen <philipchen@google.com>2016-11-05 17:08:15 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-12-14 06:03:14 -0800
commit4912f214aabf4c9ba231329df0d3583c5ddea9d6 (patch)
treed1c9f020ca8784242396ac000b393709f2fa3383 /common/charge_state_v2.c
parentc648430a6d3bd525becb523bf50703f16e147515 (diff)
downloadchrome-ec-4912f214aabf4c9ba231329df0d3583c5ddea9d6.tar.gz
i2c_passthru: fix virtual battery operation
In some cases, the virtual battery code creates transactions that violate SB spec. One example: If the host command is structured as two messages - a write to 0x03 (reg addr), followed by two bytes of write data, the first byte of the second message (write data) will be sent to virtual_battery_read(), as if it were a reg read request. Let's do the following change for virtual battery: 1. Parse the command more carefully with state machines. 2. Support write caching for some critical registers. 3. Cache more attributes (0x03 and 0x0f). BUG=chrome-os-partner:59239, chromium:659819 BRANCH=none TEST='power_supply_info' works on kevin Change-Id: Icdeb12b21f0dc3c329f29b206b7b9395ca4c9998 Reviewed-on: https://chromium-review.googlesource.com/407987 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c49
1 files changed, 1 insertions, 48 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 06ee6a7861..1ec4ca44ab 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -17,6 +17,7 @@
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
+#include "i2c.h"
#include "math_util.h"
#include "printf.h"
#include "sb_fw_update.h"
@@ -1002,54 +1003,6 @@ int charge_prevent_power_on(int power_button_pressed)
return prevent_power_on;
}
-#ifdef VIRTUAL_BATTERY_ADDR
-int virtual_battery_read(uint8_t batt_param, uint8_t *dest, int read_len)
-{
- int val;
-
- switch (batt_param) {
- case SB_SERIAL_NUMBER:
- val = strtoi(host_get_memmap(EC_MEMMAP_BATT_SERIAL), NULL, 16);
- memcpy(dest, &val, read_len);
- break;
- case SB_VOLTAGE:
- memcpy(dest, &curr.batt.voltage, read_len);
- break;
- case SB_RELATIVE_STATE_OF_CHARGE:
- memcpy(dest, &curr.batt.state_of_charge, read_len);
- break;
- case SB_TEMPERATURE:
- memcpy(dest, &curr.batt.temperature, read_len);
- break;
- case SB_CURRENT:
- memcpy(dest, &curr.batt.current, read_len);
- break;
- case SB_FULL_CHARGE_CAPACITY:
- memcpy(dest, &curr.batt.full_capacity, read_len);
- break;
- case SB_BATTERY_STATUS:
- memcpy(dest, &curr.batt.status, read_len);
- break;
- case SB_CYCLE_COUNT:
- memcpy(dest, (int *)host_get_memmap(EC_MEMMAP_BATT_CCNT),
- read_len);
- break;
- case SB_DESIGN_CAPACITY:
- memcpy(dest, (int *)host_get_memmap(EC_MEMMAP_BATT_DCAP),
- read_len);
- break;
- case SB_DESIGN_VOLTAGE:
- memcpy(dest, (int *)host_get_memmap(EC_MEMMAP_BATT_DVLT),
- read_len);
- break;
- default:
- return EC_ERROR_INVAL;
- }
- return EC_SUCCESS;
-
-}
-#endif
-
enum charge_state charge_get_state(void)
{
switch (curr.state) {