summaryrefslogtreecommitdiff
path: root/include/usb_i2c.h
diff options
context:
space:
mode:
authorChun-Ta Lin <itspeter@google.com>2017-05-18 14:44:55 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-06-05 07:55:32 -0700
commitd5c08763e12cff3207696ec53232cf6eb3303096 (patch)
treecfa7abd458a477260d2621066bd5af9fed24d2b4 /include/usb_i2c.h
parentce65199e5ed75bf8ab4cc3a4f9abae85f63f1a02 (diff)
downloadchrome-ec-d5c08763e12cff3207696ec53232cf6eb3303096.tar.gz
usb_i2c: extend the protocol to support larger payload
The default USB packet has a maximum size of 64 bytes, however, we need to support some USB over I2C write transaction that exceed this default. To support so with protocol backwards-compatible in mind, we enable a config option CONFIG_USB_I2C_MAX_WRITE_COUNT that will enlarge the USB RX queue. BRANCH=none BUG=b:35587174 TEST=Complete presubmit test. TEST=Manually update elan trackpad firmware with interrupt disabled. Change-Id: Ia8983b036b7297f7ca673459ae34b7e5ecd2ee01 Reviewed-on: https://chromium-review.googlesource.com/513642 Commit-Ready: Chun-ta Lin <itspeter@chromium.org> Tested-by: Chun-ta Lin <itspeter@chromium.org> Reviewed-by: Chun-ta Lin <itspeter@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'include/usb_i2c.h')
-rw-r--r--include/usb_i2c.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/include/usb_i2c.h b/include/usb_i2c.h
index a1fe5f10db..335550b66e 100644
--- a/include/usb_i2c.h
+++ b/include/usb_i2c.h
@@ -23,12 +23,13 @@
*
* slave address: 1 byte, i2c 7-bit bus address
*
- * write count: 1 byte, zero based count of bytes to write
+ * write count: 1 byte, zero based count of bytes to write. If write
+ * count exceed 60 bytes, following packets are expected
+ * to continue the payload without header.
*
* read count: 1 byte, zero based count of bytes to read
*
- * data: write payload up to 60 bytes of data to write,
- * length must match write count
+ * data: payload of data to write.
*
* Response:
* +-------------+---+---+-----------------------+
@@ -41,7 +42,7 @@
* 0x0002: Busy, try again
* This can happen if someone else has acquired the shared memory
* buffer that the I2C driver uses as /dev/null
- * 0x0003: Write count invalid (> 60 bytes, or mismatch with payload)
+ * 0x0003: Write count invalid (mismatch with merged payload)
* 0x0004: Read count invalid (> 60 bytes)
* 0x0005: The port specified is invalid.
* 0x8000: Unknown error mask
@@ -63,10 +64,11 @@ enum usb_i2c_error {
};
-#define USB_I2C_MAX_WRITE_COUNT 60
#define USB_I2C_MAX_READ_COUNT 60
+#define USB_I2C_CONFIG_BUFFER_SIZE \
+ ((CONFIG_USB_I2C_MAX_WRITE_COUNT+4) > USB_MAX_PACKET_SIZE ? \
+ (CONFIG_USB_I2C_MAX_WRITE_COUNT+4) : USB_MAX_PACKET_SIZE)
-BUILD_ASSERT(USB_MAX_PACKET_SIZE == (1 + 1 + 1 + 1 + USB_I2C_MAX_WRITE_COUNT));
BUILD_ASSERT(USB_MAX_PACKET_SIZE == (2 + 1 + 1 + USB_I2C_MAX_READ_COUNT));
/*
@@ -105,7 +107,8 @@ extern struct consumer_ops const usb_i2c_consumer_ops;
INTERFACE_NAME, \
ENDPOINT) \
static uint16_t \
- CONCAT2(NAME, _buffer_)[USB_MAX_PACKET_SIZE/2]; \
+ CONCAT2(NAME, _buffer_) \
+ [USB_I2C_CONFIG_BUFFER_SIZE / 2]; \
static void CONCAT2(NAME, _deferred_)(void); \
DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); \
static struct queue const CONCAT2(NAME, _to_usb_); \
@@ -134,7 +137,7 @@ extern struct consumer_ops const usb_i2c_consumer_ops;
QUEUE_DIRECT(USB_MAX_PACKET_SIZE, uint8_t, \
null_producer, CONCAT2(NAME, _usb_).consumer); \
static struct queue const CONCAT3(usb_to_, NAME, _) = \
- QUEUE_DIRECT(USB_MAX_PACKET_SIZE, uint8_t, \
+ QUEUE_DIRECT(CONFIG_USB_I2C_MAX_WRITE_COUNT+4, uint8_t, \
CONCAT2(NAME, _usb_).producer, NAME.consumer); \
static void CONCAT2(NAME, _deferred_)(void) \
{ usb_i2c_deferred(&NAME); }