summaryrefslogtreecommitdiff
path: root/chip/stm32/spi.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-06-25 21:06:22 -0700
committerChromeBot <chrome-bot@google.com>2013-07-02 09:32:52 -0700
commit0ee2689ee9efc71df37e620b2ecef3c0ec635216 (patch)
tree200a7de48ae16230b2f406f216a9d2c1e09d54fa /chip/stm32/spi.c
parentc830c036dcf18b230de81b800ce9e9fd8b3dc19e (diff)
downloadchrome-ec-0ee2689ee9efc71df37e620b2ecef3c0ec635216.tar.gz
Add get-protocol-information command
This is necessary to support larger packet sizes for host protocol ver.3. The host previously didn't have any way to know how big a packet the EC could accept / respond with (except on LPC, where the size is determined by the I/O window). BUG=chrome-os-partner:20257 BRANCH=none TEST='ectool protoinfo' returns good info; on link, Protocol info: protocol versions: 2 3 max request: 256 bytes max response: 256 bytes flags: 0x00000000 and on pit, Protocol info: protocol versions: 2 3 max request: 544 bytes max response: 544 bytes flags: 0x00000001 Change-Id: Ic1e3831d9b4a96ffbf365c0d09b6023472de39a9 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/60703 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'chip/stm32/spi.c')
-rw-r--r--chip/stm32/spi.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/chip/stm32/spi.c b/chip/stm32/spi.c
index c2a6044da8..4f65820d9a 100644
--- a/chip/stm32/spi.c
+++ b/chip/stm32/spi.c
@@ -63,18 +63,15 @@ enum {
* for a 1MHz clock which is as slow as we would reasonably want it.
*/
SPI_CMD_RX_TIMEOUT_US = 8192,
-};
-/*
- * Our input and output buffers. These must be large enough for our largest
- * message, including protocol overhead.
- */
-static uint8_t out_msg[EC_HOST_PARAM_SIZE + SPI_MSG_PROTO_LEN];
-static uint8_t in_msg[EC_HOST_PARAM_SIZE + SPI_MSG_PROTO_LEN];
-static uint8_t active;
-static uint8_t enabled;
-static struct host_cmd_handler_args args;
-static struct host_packet spi_packet;
+ /*
+ * Max data size for request/response packet. This is big enough
+ * to handle a request/respose header, flash write offset/size, and
+ * 512 bytes of flash data.
+ */
+ SPI_MAX_REQUEST_SIZE = 0x220,
+ SPI_MAX_RESPONSE_SIZE = 0x220,
+};
/*
* The AP blindly clocks back bytes over the SPI interface looking for the
@@ -93,6 +90,17 @@ static const uint8_t out_preamble[4] = {
SPI_MSG_HEADER_BYTE2, /* This is the byte which matters */
};
+/*
+ * Our input and output buffers. These must be large enough for our largest
+ * message, including protocol overhead.
+ */
+static uint8_t out_msg[SPI_MAX_RESPONSE_SIZE + sizeof(out_preamble)];
+static uint8_t in_msg[SPI_MAX_REQUEST_SIZE];
+static uint8_t active;
+static uint8_t enabled;
+static struct host_cmd_handler_args args;
+static struct host_packet spi_packet;
+
/**
* Wait until we have received a certain number of bytes
*
@@ -228,7 +236,7 @@ static void setup_for_transaction(void)
}
/**
- * Called to indicate that a command has completed
+ * Called for V2 protocol to indicate that a command has completed
*
* Some commands can continue for a while. This function is called by
* host_command when it completes.
@@ -450,3 +458,24 @@ static void spi_chipset_shutdown(void)
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, spi_chipset_shutdown, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, spi_chipset_shutdown, HOOK_PRIO_DEFAULT);
+
+/**
+ * Get protocol information
+ */
+static int spi_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 << 2) | (1 << 3);
+ r->max_request_packet_size = SPI_MAX_REQUEST_SIZE;
+ r->max_response_packet_size = SPI_MAX_RESPONSE_SIZE;
+ r->flags = EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED;
+
+ args->response_size = sizeof(*r);
+
+ return EC_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO,
+ spi_get_protocol_info,
+ EC_VER_MASK(0));