Hello SH Kim,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/46290
to review the following change.
Change subject: device/i2c_bus: Add i2c_dev_writeb_at16() ......................................................................
device/i2c_bus: Add i2c_dev_writeb_at16()
i2c_dev_writeb_at16() sends a 16-bit offset to the I2C chip (for larger EEPROM parts), then write a byte.
Change-Id: Ic8ee87fd2175d7c2d4359ece425519aa25df9a16 Signed-off-by: Seunghwan Kim sh_.kim@samsung.corp-partner.google.com --- M src/device/i2c_bus.c M src/include/device/i2c_bus.h 2 files changed, 35 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/90/46290/1
diff --git a/src/device/i2c_bus.c b/src/device/i2c_bus.c index a65cdad..bbe1094 100644 --- a/src/device/i2c_bus.c +++ b/src/device/i2c_bus.c @@ -184,3 +184,32 @@ return -1; } } + +int i2c_dev_writeb_at16(struct device *const dev, + const uint16_t off, const uint8_t val) +{ + struct device *const busdev = i2c_busdev(dev); + if (!busdev) + return -1; + + if (busdev->ops->ops_i2c_bus) { + uint8_t buf[3]; + const struct i2c_msg msg = { + .flags = 0, + .slave = dev->path.i2c.device, + .buf = buf, + .len = sizeof(buf), + }; + + write_be16((uint16_t *)buf, off); + buf[2] = val; + + return busdev->ops->ops_i2c_bus->transfer(busdev, &msg, 1); + } else if (busdev->ops->ops_smbus_bus->write_byte) { + return busdev->ops->ops_smbus_bus->write_byte(dev, off, val); + } else { + printk(BIOS_ERR, "%s Missing ops_smbus_bus->write_byte", + dev_path(busdev)); + return -1; + } +} diff --git a/src/include/device/i2c_bus.h b/src/include/device/i2c_bus.h index b5e7710..6028e41 100644 --- a/src/include/device/i2c_bus.h +++ b/src/include/device/i2c_bus.h @@ -86,4 +86,10 @@ */ int i2c_dev_read_at16(struct device *, uint8_t *buf, size_t len, uint16_t off);
+/* + * Sends the 16-bit register offset `off` followed by the byte `val`. + * + * Returns 0 on success, negative `enum cb_err` value on error. + */ +int i2c_dev_writeb_at16(struct device *, uint16_t off, uint8_t val); #endif /* _DEVICE_I2C_BUS_H_ */
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/46290 )
Change subject: device/i2c_bus: Add i2c_dev_writeb_at16() ......................................................................
Patch Set 1:
(2 comments)
https://review.coreboot.org/c/coreboot/+/46290/1/src/device/i2c_bus.c File src/device/i2c_bus.c:
https://review.coreboot.org/c/coreboot/+/46290/1/src/device/i2c_bus.c@210 PS1, Line 210: } else { else is not generally useful after a break or return
https://review.coreboot.org/c/coreboot/+/46290/1/src/include/device/i2c_bus.... File src/include/device/i2c_bus.h:
https://review.coreboot.org/c/coreboot/+/46290/1/src/include/device/i2c_bus.... PS1, Line 94: int i2c_dev_writeb_at16(struct device *, uint16_t off, uint8_t val); function definition argument 'struct device *' should also have an identifier name