From 5ffb6887c27d86215c5ffa603131ff9b1f0929ae Mon Sep 17 00:00:00 2001 From: Jitao Shi Date: Mon, 1 Feb 2016 17:33:49 +0800 Subject: device/i2c: Add i2c_read_bytes() API Add multi-bytes read support. BRANCH=none BUG=none TEST=saw edid log and dev screen Change-Id: I106be98e751e2a3b998ccaedb28f71f3c6e18994 Signed-off-by: Patrick Georgi Original-Commit-Id: 94ee0b834947e8d971943aa24e61a9353c7b7306 Original-Change-Id: Iac5fe497da92b7d09383e0d6a04d98709aea5b20 Original-Signed-off-by: Jitao Shi Original-Reviewed-on: https://chromium-review.googlesource.com/325211 Original-Commit-Ready: Yidi Lin Original-Tested-by: Yidi Lin Original-Reviewed-by: Julius Werner Reviewed-on: https://review.coreboot.org/13978 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- src/include/device/i2c.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/include/device/i2c.h b/src/include/device/i2c.h index 78817bb300..8e59ba7c21 100644 --- a/src/include/device/i2c.h +++ b/src/include/device/i2c.h @@ -87,6 +87,28 @@ static inline int i2c_write_raw(unsigned bus, uint8_t chip, uint8_t *data, return i2c_transfer(bus, &seg, 1); } +/** + * Read multi-bytes with two segments in one frame + * + * [start][slave addr][w][register addr][start][slave addr][r][data...][stop] + */ +static inline int i2c_read_bytes(unsigned bus, uint8_t chip, uint8_t reg, + uint8_t *data, int len) +{ + struct i2c_seg seg[2]; + + seg[0].read = 0; + seg[0].chip = chip; + seg[0].buf = ® + seg[0].len = 1; + seg[1].read = 1; + seg[1].chip = chip; + seg[1].buf = data; + seg[1].len = len; + + return i2c_transfer(bus, seg, ARRAY_SIZE(seg)); +} + /** * Read a byte with two segments in one frame * -- cgit v1.2.3