From c4731c7ad61e1d4f022bfae14345956b07af47bd Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Tue, 7 Apr 2020 22:28:50 +0300 Subject: drivers: i2c_eeprom: add proper write implementation Add writing to I2CR EEPROM using repeated addressing and performing length separate write transactions of one byte each. Relates-to: ELB-1402 Signed-off-by: Igor Opaniuk --- drivers/misc/i2c_eeprom.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c index 9a77c6e164..6f4968b9ef 100644 --- a/drivers/misc/i2c_eeprom.c +++ b/drivers/misc/i2c_eeprom.c @@ -39,7 +39,31 @@ static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf, static int i2c_eeprom_std_write(struct udevice *dev, int offset, const uint8_t *buf, int size) { - return -ENODEV; + uint8_t *buf_p = (uint8_t *) buf; + struct dm_i2c_chip *i2c_chip; + int ret; + + i2c_chip = dev_get_parent_platdata(dev); + if (!i2c_chip) + return -ENOSYS; + + /* + * Repeated addressing - perform separate + * write transactions of one byte each + */ + while (size-- > 0) { + i2c_chip->flags |= DM_I2C_CHIP_WR_ADDRESS; + + ret = dm_i2c_write(dev, offset++, buf_p++, 1); + if (ret) + return ret; + +#if !defined(CONFIG_SYS_I2C_FRAM) + udelay(11000); +#endif + } + + return ret; } static const struct i2c_eeprom_ops i2c_eeprom_std_ops = { -- cgit v1.2.3