[coreboot-gerrit] Change in coreboot[master]: device/i2c_bus: Add i2c_dev_readb_at_word()

Nico Huber (Code Review) gerrit at coreboot.org
Mon Nov 5 18:35:53 CET 2018


Nico Huber has uploaded this change for review. ( https://review.coreboot.org/29478


Change subject: device/i2c_bus: Add i2c_dev_readb_at_word()
......................................................................

device/i2c_bus: Add i2c_dev_readb_at_word()

Does the same as i2c_dev_readb_at() but sends a 2-byte offset to the I2C
chip (for larger EEPROM parts).

Change-Id: I7516f3e5d9aca362c2b340aa5627d91510c09412
Signed-off-by: Nico Huber <nico.huber at secunet.com>
---
M src/device/i2c_bus.c
M src/include/device/i2c_bus.h
2 files changed, 47 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/78/29478/1

diff --git a/src/device/i2c_bus.c b/src/device/i2c_bus.c
index 30bb80c..8d8e61a 100644
--- a/src/device/i2c_bus.c
+++ b/src/device/i2c_bus.c
@@ -16,6 +16,7 @@
 #include <console/console.h>
 #include <device/smbus.h>
 #include <device/i2c_bus.h>
+#include <commonlib/endian.h>
 
 struct bus *i2c_link(struct device *const dev)
 {
@@ -159,3 +160,40 @@
 		return -1;
 	}
 }
+
+int i2c_dev_readb_at_word(struct device *const dev,
+			  uint8_t *const buf, const size_t len, uint16_t off)
+{
+	struct device *const busdev = i2c_busdev(dev);
+	if (!busdev)
+		return -1;
+
+	if (busdev->ops->ops_i2c_bus) {
+		const struct i2c_msg msg[] = {
+			{
+				.flags	= 0,
+				.slave	= dev->path.i2c.device,
+				.buf	= (uint8_t *)&off,
+				.len	= sizeof(off),
+			},
+			{
+				.flags	= I2C_M_RD,
+				.slave	= dev->path.i2c.device,
+				.buf	= buf,
+				.len	= len,
+			},
+		};
+
+		write_be16(&off, off);
+		const int ret = busdev->ops->ops_i2c_bus->
+			transfer(busdev, msg, ARRAY_SIZE(msg));
+		if (ret)
+			return ret;
+		else
+			return len;
+	} else {
+		printk(BIOS_ERR, "%s Missing ops_i2c_bus->transfer",
+		       dev_path(busdev));
+		return -1;
+	}
+}
diff --git a/src/include/device/i2c_bus.h b/src/include/device/i2c_bus.h
index 6aa4f9b..27e261f 100644
--- a/src/include/device/i2c_bus.h
+++ b/src/include/device/i2c_bus.h
@@ -89,4 +89,13 @@
  */
 int i2c_dev_writeb_at(struct device *, uint8_t off, uint8_t val);
 
+/*
+ * Sends the 2-byte register offset `off` and reads `len` bytes into `buf`.
+ *
+ * Returns the number of bytes read on success, negative `enum cb_err`
+ * value on error.
+ */
+int i2c_dev_readb_at_word(struct device *,
+			  uint8_t *buf, size_t len, uint16_t off);
+
 #endif	/* _DEVICE_I2C_BUS_H_ */

-- 
To view, visit https://review.coreboot.org/29478
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7516f3e5d9aca362c2b340aa5627d91510c09412
Gerrit-Change-Number: 29478
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h at gmx.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20181105/65d92d69/attachment-0001.html>


More information about the coreboot-gerrit mailing list