summaryrefslogtreecommitdiff
path: root/common/usb_i2c.c
diff options
context:
space:
mode:
authorChun-Ta Lin <itspeter@google.com>2017-11-28 15:16:22 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-12-07 05:09:28 -0800
commitab238235f8f45cb1ba3e26893199c01f4792a8ff (patch)
tree9f89b9428d868a80c5d9c0a5fb9ead38941f7b71 /common/usb_i2c.c
parent1956a98ad4988305777bbb633fb007cb5f86b89f (diff)
downloadchrome-ec-ab238235f8f45cb1ba3e26893199c01f4792a8ff.tar.gz
i2c: support large reading in i2c_xfer()
There might be more than one place that will use very similar codes in CL:542716 (usb_i2c.c). To avoid unnecessary duplication of code, we fold the logic into i2c_xfer(). With config enabled (illustrated in this CL), i2c_xfer() will support large reading. An early prototype of potential usage is demostrated in CL:781300. BRANCH=none TEST=For CONFIG_I2C_XFER_LARGE_READ: With proprietary software on slave: ./touchpad_updater -d TEST=For usb_i2c regression: ./touchpad_updater still works (where the reading is less than 255) TEST=For generic EC regression test: On poppy EC (With CONFIG_I2C_XFER_LARGE_READ defined) (1) Prevent override of update /usr/share/vboot/bin/set_gbb_flags.sh 0xa39 (2) flashrom -p ec -w ec_binary_contains_this_CL.bin (3) ectool reboot_ec cold (4) "ectool version" verified that both RO/RW/Build info is local. (5) Test with a type-C DP dongle on DELL 2408WFP. (6) Plug-in type-C charger and external display still works. (7) Confirmed that battery is charging. (7) "ectool battery" reads same data (for fixed field) as before. (8) "ectool usbpdpower", confirmed charger info displayed as before. (9) "ectool usbpd 0", confirmed content exactly as before. (10) For Gyro. Verify under Arc++ Using App: com.gamma.bubblelevel, works the same as before. (11) For Accelerometers. Verify under Arc++ Using App: com.innoventions.sensorkinetics, small movement's charts looks as expected. TEST=For generic EC regression test: On Caroline EC (Without CONFIG_I2C_XFER_LARGE_READ defined). Details in CL:810332 BUG=b:63993891 Change-Id: I654868945fa535e784800177d54eb2d9803f5249 Signed-off-by: Chun-Ta Lin <itspeter@google.com> Reviewed-on: https://chromium-review.googlesource.com/788479 Commit-Ready: Chun-ta Lin <itspeter@chromium.org> Tested-by: Chun-ta Lin <itspeter@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/usb_i2c.c')
-rw-r--r--common/usb_i2c.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/common/usb_i2c.c b/common/usb_i2c.c
index de8314f8fa..5fa04e0ba1 100644
--- a/common/usb_i2c.c
+++ b/common/usb_i2c.c
@@ -84,12 +84,8 @@ void usb_i2c_execute(struct usb_i2c_config const *config)
uint8_t slave_addr = (config->buffer[0] >> 7) & 0xfe;
int write_count = (config->buffer[1] >> 0) & 0xff;
int read_count = (config->buffer[1] >> 8) & 0xff;
- uint8_t *payload = (uint8_t *)(config->buffer + 2);
- int xfer_flag = I2C_XFER_START;
int offset = 0; /* Offset for extended reading header. */
- int rv = 0;
- int complete_bytes = 0;
- int bytes_to_read, port;
+ int port;
config->buffer[0] = 0;
config->buffer[1] = 0;
@@ -120,28 +116,12 @@ void usb_i2c_execute(struct usb_i2c_config const *config)
* EC_CMD_I2C_PASSTHRU, which can protect ports and ranges.
*/
port = i2c_ports[portindex].port;
- /*
- * Because The I2C_XFER_SINGLE might limit the reading to be
- * less than 255 bytes (For example, register design of
- * STM32_I2C_CR2 in i2c-stm32f0.c), we hold the STOP bits for
- * reading request larger than 255 bytes.
- */
- do {
- bytes_to_read = read_count - complete_bytes;
- if (bytes_to_read > MAX_BYTES_IN_ONE_READING)
- bytes_to_read = MAX_BYTES_IN_ONE_READING;
- else
- xfer_flag |= I2C_XFER_STOP;
- rv = i2c_xfer(
- port, slave_addr,
- complete_bytes ? NULL : payload + offset,
- complete_bytes ? 0 : write_count,
- payload + complete_bytes,
- bytes_to_read, xfer_flag);
- complete_bytes += bytes_to_read;
- xfer_flag = 0;
- } while (complete_bytes < read_count && !rv);
- config->buffer[0] = usb_i2c_map_error(rv);
+ config->buffer[0] = usb_i2c_map_error(
+ i2c_xfer(port, slave_addr,
+ (uint8_t *)(config->buffer + 2) + offset,
+ write_count,
+ (uint8_t *)(config->buffer + 2),
+ read_count, I2C_XFER_SINGLE));
}
usb_i2c_write_packet(config, read_count + 4);
}