summaryrefslogtreecommitdiff
path: root/common/i2c_controller.c
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2021-06-02 11:57:59 +0200
committerCommit Bot <commit-bot@chromium.org>2021-06-08 08:08:44 +0000
commita4dc0476c7b0955fbc8d0885a5d442bc41504db4 (patch)
tree4e7f65dab82c621dde80489e9cfc81d67ac0da63 /common/i2c_controller.c
parentd5e9773ea42c8ea3c2666b031abef85f3d43b162 (diff)
downloadchrome-ec-a4dc0476c7b0955fbc8d0885a5d442bc41504db4.tar.gz
zephyr: Fix I2C_PASSTHRU host command
ZephyrEC uses different I2C port numbers than CrosEC does, so convert the received remote port via I2C_PASSTHRU command into a proper one. The conversion is done based on a new property remote-port, which tells what port number is used by external components like kernel. The change fixes an issue with unexpected entering OTG mode by the charger. BUG=b:188885798 BRANCH=none TEST=Flash Lazor and make sure that no "charge problem" prints are displayed. Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: Id00265a3abf286ca59cbecb38ff7933d75e0d361 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2933296 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'common/i2c_controller.c')
-rw-r--r--common/i2c_controller.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/common/i2c_controller.c b/common/i2c_controller.c
index 035cf8d8ca..e2fa3ec28f 100644
--- a/common/i2c_controller.c
+++ b/common/i2c_controller.c
@@ -1159,8 +1159,32 @@ static int check_i2c_params(const struct host_cmd_handler_args *args)
return EC_RES_SUCCESS;
}
+#ifdef I2C_PORT_VIRTUAL_BATTERY
+static inline int is_i2c_port_virtual_battery(int port)
+{
+#ifdef CONFIG_ZEPHYR
+ /* For Zephyr compare the actual device, which will be used in
+ * i2c_transfer function.
+ */
+ return (i2c_get_device_for_port(port) ==
+ i2c_get_device_for_port(I2C_PORT_VIRTUAL_BATTERY));
+#else
+ return (port == I2C_PORT_VIRTUAL_BATTERY);
+#endif
+}
+#endif /* I2C_PORT_VIRTUAL_BATTERY */
+
static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args)
{
+#ifdef CONFIG_ZEPHYR
+ /* For Zephyr, convert the received remote port number to a port number
+ * used in EC.
+ */
+ ((struct ec_params_i2c_passthru *)(args->params))->port =
+ i2c_get_port_from_remote_port(
+ ((struct ec_params_i2c_passthru *)(args->params))
+ ->port);
+#endif
const struct ec_params_i2c_passthru *params = args->params;
const struct ec_params_i2c_passthru_msg *msg;
struct ec_response_i2c_passthru *resp = args->response;
@@ -1220,9 +1244,8 @@ 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(CONFIG_ZEPHYR) || defined(I2C_PORT_VIRTUAL_BATTERY))
- if (params->port == I2C_PORT_VIRTUAL_BATTERY &&
+#if defined(VIRTUAL_BATTERY_ADDR_FLAGS) && defined(I2C_PORT_VIRTUAL_BATTERY)
+ if (is_i2c_port_virtual_battery(params->port) &&
addr_flags == VIRTUAL_BATTERY_ADDR_FLAGS) {
if (virtual_battery_handler(resp, in_len, &rv,
xferflags, read_len,
@@ -1318,6 +1341,15 @@ static void i2c_passthru_protect_tcpc_ports(void)
static enum ec_status
i2c_command_passthru_protect(struct host_cmd_handler_args *args)
{
+#ifdef CONFIG_ZEPHYR
+ /* For Zephyr, convert the received remote port number to a port number
+ * used in EC.
+ */
+ ((struct ec_params_i2c_passthru_protect *)(args->params))
+ ->port = i2c_get_port_from_remote_port(
+ ((struct ec_params_i2c_passthru_protect *)(args->params))
+ ->port);
+#endif
const struct ec_params_i2c_passthru_protect *params = args->params;
struct ec_response_i2c_passthru_protect *resp = args->response;