diff options
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/i2c_bus.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/device/i2c_bus.c b/src/device/i2c_bus.c index 30bb80ca98..93634d223b 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,39 @@ int i2c_dev_writeb_at(struct device *const dev, return -1; } } + +int i2c_dev_read_at16(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; + } +} |