summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei-Ning Huang <wnhuang@google.com>2017-04-21 23:32:53 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-04-26 13:37:04 -0700
commit59bd55c41e02eab2ac01cd3adbdda1950f7fb09e (patch)
treed580917ddd736d45812f7e5b54a31ffb2b60f08e
parentee28ccb0ca0a76ff3c097471ba7732facf404663 (diff)
downloadchrome-ec-59bd55c41e02eab2ac01cd3adbdda1950f7fb09e.tar.gz
i2c: separate slave and master code
Split i2c.c code in two (i2c_slave.c and i2c_master.c). i2c_slave.c is used when EC has no i2c device connected (i2c master code not needed) but EC is connected to AP via i2c. BRANCH=none BUG=b:37584134 TEST=1. Compile rose board with CONFIG_I2C and CONFIG_CMD_HOSTCMD. Then make sure EC_CMD_GET_PROTOCOL_INFO works. 2. On Kevin and Elm, cherry-pick to firmware branch respectively, build and flash ec, i2c function works. Change-Id: I1f95ad277713c5e30913e0a010ca03dfd9ec248c Signed-off-by: Wei-Ning Huang <wnhuang@google.com> Reviewed-on: https://chromium-review.googlesource.com/484999 Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org> Tested-by: Wei-Ning Huang <wnhuang@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--common/build.mk3
-rw-r--r--common/i2c_master.c (renamed from common/i2c.c)20
-rw-r--r--common/i2c_slave.c28
3 files changed, 30 insertions, 21 deletions
diff --git a/common/build.mk b/common/build.mk
index 630e9f9eaa..47b8f8add6 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -56,7 +56,8 @@ common-$(CONFIG_FMAP)+=fmap.o
common-$(CONFIG_GESTURE_SW_DETECTION)+=gesture.o
common-$(CONFIG_HOSTCMD_EVENTS)+=host_event_commands.o
common-$(CONFIG_HOSTCMD_PD)+=host_command_master.o
-common-$(CONFIG_I2C_MASTER)+=i2c.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 \
diff --git a/common/i2c.c b/common/i2c_master.c
index 8255484b3c..1dc1a09b64 100644
--- a/common/i2c.c
+++ b/common/i2c_master.c
@@ -1019,23 +1019,3 @@ DECLARE_CONSOLE_COMMAND(i2ctest, command_i2ctest,
"i2ctest count|udelay|dev",
"I2C stress test");
#endif /* CONFIG_CMD_I2C_STRESS_TEST */
-
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
-int i2c_get_protocol_info(struct host_cmd_handler_args *args)
-{
- struct ec_response_get_protocol_info *r = args->response;
-
- memset(r, 0, sizeof(*r));
- r->protocol_versions = (1 << 3);
- r->max_request_packet_size = I2C_MAX_HOST_PACKET_SIZE;
- r->max_response_packet_size = I2C_MAX_HOST_PACKET_SIZE;
- r->flags = 0;
-
- args->response_size = sizeof(*r);
-
- return EC_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO,
- i2c_get_protocol_info,
- EC_VER_MASK(0));
-#endif /* CONFIG_HOSTCMD_I2C_SLAVE_ADDR */
diff --git a/common/i2c_slave.c b/common/i2c_slave.c
new file mode 100644
index 0000000000..3dbb7d1036
--- /dev/null
+++ b/common/i2c_slave.c
@@ -0,0 +1,28 @@
+/* Copyright 2017 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.
+ */
+
+/* I2C slave cross-platform code for Chrome EC */
+
+#include "host_command.h"
+#include "i2c.h"
+#include "util.h"
+
+int i2c_get_protocol_info(struct host_cmd_handler_args *args)
+{
+ struct ec_response_get_protocol_info *r = args->response;
+
+ memset(r, 0, sizeof(*r));
+ r->protocol_versions = (1 << 3);
+ r->max_request_packet_size = I2C_MAX_HOST_PACKET_SIZE;
+ r->max_response_packet_size = I2C_MAX_HOST_PACKET_SIZE;
+ r->flags = 0;
+
+ args->response_size = sizeof(*r);
+
+ return EC_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO,
+ i2c_get_protocol_info,
+ EC_VER_MASK(0));