[dwi2c PATCH v1] dwi2c add offsets to reads

cduffinx cooperx.duffin at intel.com
Thu Nov 5 22:26:27 CET 2020


modify the designware_i2c_xfer function to use 1 byte per
address, it was set to 0 before which makes it think its
reading a register type. Added offset of where it is
supposed to read from. Before it was always reading from
offset 0 despite specifying the offset in the higher level
function.

Signed-off-by: Cooper Duffin <cooperx.duffin at intel.com>
Signed-off-by: cduffinx <cooperx.duffin at intel.com>
---

 drivers/i2c/designware_i2c.c | 5 +++--
 drivers/i2c/i2c-uclass.c     | 1 +
 include/i2c.h                | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/designware_i2c.c b/drivers/i2c/designware_i2c.c
index 0b5e70af59..46f5d1e56c 100644
--- a/drivers/i2c/designware_i2c.c
+++ b/drivers/i2c/designware_i2c.c
@@ -658,8 +658,9 @@ static int designware_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
 	for (; nmsgs > 0; nmsgs--, msg++) {
 		debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
 		if (msg->flags & I2C_M_RD) {
-			ret = __dw_i2c_read(i2c->regs, msg->addr, 0, 0,
-					    msg->buf, msg->len);
+			ret = __dw_i2c_read(i2c->regs, msg->addr,
+					    msg->offset, 1, msg->buf,
+					    msg->len);
 		} else {
 			ret = __dw_i2c_write(i2c->regs, msg->addr, 0, 0,
 					     msg->buf, msg->len);
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 2aa3efe8aa..455d56c3b8 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -147,6 +147,7 @@ int dm_i2c_read(struct udevice *dev, uint offset, uint8_t *buffer, int len)
 		ptr->flags |= I2C_M_RD;
 		ptr->len = len;
 		ptr->buf = buffer;
+		ptr->offset = offset;
 		ptr++;
 	}
 	msg_count = ptr - msg;
diff --git a/include/i2c.h b/include/i2c.h
index 0faf8542e2..f997c2537e 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -141,6 +141,7 @@ struct i2c_msg {
 	uint addr;
 	uint flags;
 	uint len;
+	uint offset;
 	u8 *buf;
 };
 
-- 
2.25.1



More information about the U-Boot mailing list