summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2012-07-23 12:23:48 -0700
committerGerrit <chrome-bot@google.com>2012-07-24 11:26:57 -0700
commit2de38e81a230950922d4926baf401e88b10538a3 (patch)
treebdbaa37e1de90a9a8ae773b5543bb217fcbdbf17
parent3120c479ec3e797bd1fdb4023e4f23f58a3794b1 (diff)
downloadchrome-ec-2de38e81a230950922d4926baf401e88b10538a3.tar.gz
Revert "Revert "i2c: Support command version numbers""
This reverts commit 3bb4c6acf4ff327f956ee5e1b6deefcd84dc8fbb Change-Id: I690baa9bcc0229502c103fc31314170bbc825f65 Reviewed-on: https://gerrit.chromium.org/gerrit/28189 Commit-Ready: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r--chip/stm32/i2c.c59
-rw-r--r--include/ec_commands.h12
-rw-r--r--include/host_command.h1
3 files changed, 57 insertions, 15 deletions
diff --git a/chip/stm32/i2c.c b/chip/stm32/i2c.c
index 31c5174c55..7e7bafefc6 100644
--- a/chip/stm32/i2c.c
+++ b/chip/stm32/i2c.c
@@ -41,8 +41,8 @@
static uint16_t i2c_sr1[NUM_PORTS];
static struct mutex i2c_mutex;
-/* buffer for host commands (including error code and checksum) */
-static uint8_t host_buffer[EC_HOST_PARAM_SIZE + 2];
+/* buffer for host commands (including version, error code and checksum) */
+static uint8_t host_buffer[EC_HOST_PARAM_SIZE + 4];
static struct host_cmd_handler_args host_cmd_args;
/* current position in host buffer for reception */
@@ -127,10 +127,14 @@ static void i2c_send_response(struct host_cmd_handler_args *args)
const uint8_t *data = args->response;
int size = args->response_size;
uint8_t *out = host_buffer;
- int sum, i;
+ int sum = 0, i;
*out++ = args->result;
- for (i = 0, sum = 0; i < size; i++, data++, out++) {
+ if (!args->i2c_old_response) {
+ *out++ = size;
+ sum = args->result + size;
+ }
+ for (i = 0; i < size; i++, data++, out++) {
if (data != out)
*out = *data;
sum += *data;
@@ -144,18 +148,43 @@ static void i2c_send_response(struct host_cmd_handler_args *args)
/* Process the command in the i2c host buffer */
static void i2c_process_command(void)
{
+ struct host_cmd_handler_args *args = &host_cmd_args;
+ char *buff = host_buffer;
+
+ args->command = *buff;
+ args->result = EC_RES_SUCCESS;
+ if (args->command >= EC_CMD_VERSION0) {
+ int csum, i;
+
+ /* Read version and data size */
+ args->version = args->command - EC_CMD_VERSION0;
+ args->command = buff[1];
+ args->params_size = buff[2];
+
+ /* Verify checksum */
+ for (csum = i = 0; i < args->params_size + 3; i++)
+ csum += buff[i];
+ if ((uint8_t)csum != buff[i])
+ args->result = EC_RES_INVALID_CHECKSUM;
+
+ buff += 3;
+ args->i2c_old_response = 0;
+ } else {
+ /* Old style command */
+ args->version = 0;
+ args->params_size = EC_HOST_PARAM_SIZE; /* unknown */
+ buff++;
+ args->i2c_old_response = 1;
+ }
+
/* we have an available command : execute it */
- host_cmd_args.command = host_buffer[0];
- host_cmd_args.result = EC_RES_SUCCESS;
- host_cmd_args.send_response = i2c_send_response;
- host_cmd_args.version = 0;
- host_cmd_args.params = host_buffer + 1;
- host_cmd_args.params_size = EC_HOST_PARAM_SIZE;
- /* skip room for error code */
- host_cmd_args.response = host_buffer + 1;
- host_cmd_args.response_max = EC_HOST_PARAM_SIZE;
- host_cmd_args.response_size = 0;
- host_command_received(&host_cmd_args);
+ args->send_response = i2c_send_response;
+ args->params = buff;
+ /* skip room for error code, arglen */
+ args->response = host_buffer + 2;
+ args->response_max = EC_HOST_PARAM_SIZE;
+ args->response_size = 0;
+ host_command_received(args);
}
static void i2c_event_handler(int port)
diff --git a/include/ec_commands.h b/include/ec_commands.h
index d53c267af6..d6337a20ae 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -942,6 +942,18 @@ struct ec_params_reboot_ec {
*/
#define EC_CMD_REBOOT 0xd1 /* Think "die" */
+/*
+ * This header byte on a command indicate version 0. Any header byte less
+ * than this means that we are talking to an old EC which doesn't support
+ * versioning. In that case, we assume version 0.
+ *
+ * Header bytes greater than this indicate a later version. For example,
+ * EC_CMD_VERSION0 + 1 means we are using version 1.
+ *
+ * The old EC interface must not use commands 0dc or higher.
+ */
+#define EC_CMD_VERSION0 0xdc
+
#endif /* !__ACPI__ */
#endif /* __CROS_EC_COMMANDS_H */
diff --git a/include/host_command.h b/include/host_command.h
index a88761a6e2..135f493737 100644
--- a/include/host_command.h
+++ b/include/host_command.h
@@ -22,6 +22,7 @@ struct host_cmd_handler_args {
uint8_t command; /* Command (e.g., EC_CMD_FLASH_GET_INFO) */
uint8_t version; /* Version of command (0-31) */
uint8_t params_size; /* Size of input parameters in bytes */
+ uint8_t i2c_old_response; /* (for I2C) send an old-style response */
const uint8_t *params; /* Input parameters */
/*
* Pointer to output response data buffer. On input to the handler,