From: Baruch Siach Date: Sun, 7 Apr 2019 09:38:49 +0000 (+0300) Subject: misc: i2c_eeprom: add eeprom write support X-Git-Tag: v2019.07-rc1~29^2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=84c80c63d53bc8a7779b1e7e7084ee3b2d20e768;p=oweals%2Fu-boot.git misc: i2c_eeprom: add eeprom write support Write up to page size in each i2c transfer. Signed-off-by: Baruch Siach Reviewed-by: Heiko Schocher --- diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c index ce2cad44d8..f25d054007 100644 --- a/drivers/misc/i2c_eeprom.c +++ b/drivers/misc/i2c_eeprom.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,24 @@ 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; + struct i2c_eeprom *priv = dev_get_priv(dev); + int ret; + + while (size > 0) { + int write_size = min_t(int, size, priv->pagesize); + + ret = dm_i2c_write(dev, offset, buf, write_size); + if (ret) + return ret; + + offset += write_size; + buf += write_size; + size -= write_size; + + udelay(10000); + } + + return 0; } static const struct i2c_eeprom_ops i2c_eeprom_std_ops = {