summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-10-04 13:49:26 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-05 17:11:37 -0700
commit5f70312a264986f5853dfde457d39af47ba1c87d (patch)
tree1af1140c13af3b5a1eb120040d38c37c7d4246ad
parentcab4ccf3f9217692ee092b92871876643b2351de (diff)
downloadchrome-ec-5f70312a264986f5853dfde457d39af47ba1c87d.tar.gz
i2c: Move I2C_MAX_HOST_PACKET_SIZE to i2c.h
This patch moves I2C_MAX_HOST_PACKET_SIZE to include/i2c.h. It's currently used only by i2c-stm32*.c but should be commonly available for other chips. It also moves i2c_get_protocol_info to common/i2c.c for the same reason. BUG=none BRANCH=none TEST=make runtest Change-Id: I28d8bca0167bb7b2ce99574601a6efb62fc20eca Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/393328 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/stm32/i2c-stm32f0.c29
-rw-r--r--common/i2c.c20
-rw-r--r--include/i2c.h15
3 files changed, 35 insertions, 29 deletions
diff --git a/chip/stm32/i2c-stm32f0.c b/chip/stm32/i2c-stm32f0.c
index 8710d73be5..d33941d5b5 100644
--- a/chip/stm32/i2c-stm32f0.c
+++ b/chip/stm32/i2c-stm32f0.c
@@ -27,12 +27,6 @@
/* Transmit timeout in microseconds */
#define I2C_TX_TIMEOUT_MASTER (10 * MSEC)
-/*
- * Max data size for a version 3 request/response packet. This is
- * big enough for EC_CMD_GET_VERSION plus header info.
- */
-#define I2C_MAX_HOST_PACKET_SIZE 128
-
#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
#if (I2C_PORT_EC == STM32_I2C1_PORT)
#define IRQ_SLAVE STM32_IRQ_I2C1
@@ -612,26 +606,3 @@ static void i2c_init(void)
}
DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C);
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
-/**
- * Get protocol information
- */
-static 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
-
diff --git a/common/i2c.c b/common/i2c.c
index fc6e657a18..af2aa61133 100644
--- a/common/i2c.c
+++ b/common/i2c.c
@@ -1030,3 +1030,23 @@ 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/include/i2c.h b/include/i2c.h
index ddd3dd3c7f..3af738201b 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -9,11 +9,18 @@
#define __CROS_EC_I2C_H
#include "common.h"
+#include "host_command.h"
/* Flags for slave address field, in addition to the 8-bit address */
#define I2C_FLAG_BIG_ENDIAN 0x100 /* 16 byte values are MSB-first */
/*
+ * Max data size for a version 3 request/response packet. This is
+ * big enough for EC_CMD_GET_VERSION plus header info.
+ */
+#define I2C_MAX_HOST_PACKET_SIZE 128
+
+/*
* Supported I2C CLK frequencies.
* TODO(crbug.com/549286): Use this enum in i2c_port_t.
*/
@@ -286,4 +293,12 @@ int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
*/
int i2c_port_to_controller(int port);
+/**
+ * Command handler to get host command protocol information
+ *
+ * @param args: host command handler arguments
+ * @return EC_SUCCESS
+ */
+int i2c_get_protocol_info(struct host_cmd_handler_args *args);
+
#endif /* __CROS_EC_I2C_H */