Signed-off-by: Peter Delevoryas <pe...@pjd.dev> --- hw/nvram/eeprom_at24c.c | 15 +++++++++++++++ include/hw/nvram/eeprom_at24c.h | 2 ++ 2 files changed, 17 insertions(+)
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c index 0c27eae2b354..69565a420c28 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/bitops.h" #include "qemu/module.h" #include "hw/i2c/i2c.h" #include "hw/nvram/eeprom_at24c.h" @@ -138,6 +139,20 @@ void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size) i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort); } +void at24c_eeprom_write(I2CBus *bus, uint8_t address, uint16_t offset, + const uint8_t *buf, uint32_t len) +{ + int i; + + i2c_start_send(bus, address); + i2c_send(bus, extract16(offset, 8, 8)); + i2c_send(bus, extract16(offset, 0, 8)); + for (i = 0; i < len; i++) { + i2c_send(bus, buf[i]); + } + i2c_end_transfer(bus); +} + static void at24c_eeprom_realize(DeviceState *dev, Error **errp) { EEPROMState *ee = AT24C_EE(dev); diff --git a/include/hw/nvram/eeprom_at24c.h b/include/hw/nvram/eeprom_at24c.h index 9d9cf212757c..bbca73a07ad1 100644 --- a/include/hw/nvram/eeprom_at24c.h +++ b/include/hw/nvram/eeprom_at24c.h @@ -6,5 +6,7 @@ #include "hw/i2c/i2c.h" void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size); +void at24c_eeprom_write(I2CBus *bus, uint8_t address, uint16_t offset, + const uint8_t *buf, uint32_t len); #endif -- 2.39.0