summaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/charge_state_v2.h11
-rw-r--r--include/virtual_battery.h49
2 files changed, 49 insertions, 11 deletions
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index e5855c2fe1..70ca47f6d3 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -73,16 +73,5 @@ enum ec_status charger_profile_override_set_param(uint32_t param,
*/
int charge_set_input_current_limit(int ma, int mv);
-
-/**
- * Get value of battery parameter from charge state.
- *
- * @param batt_param battery parameter
- * @param dest Destination buffer for data
- * @param read_len Number of bytes to write to buffer
- * @return EC_SUCCESS if successful, non-zero if error.
- *
- */
-int virtual_battery_read(uint8_t batt_param, uint8_t *dest, int read_len);
#endif /* __CROS_EC_CHARGE_STATE_V2_H */
diff --git a/include/virtual_battery.h b/include/virtual_battery.h
new file mode 100644
index 0000000000..c686a76172
--- /dev/null
+++ b/include/virtual_battery.h
@@ -0,0 +1,49 @@
+/* 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 BATTERY_ADDR
+#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 */