Commit 8880efbd1ffd54bcddb427229ff925151a054257

Authored by Jonas Karlman
Committed by Simon Glass
1 parent 26e2e404b7

i2c_eeprom: add read and write functions

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 50 additions and 6 deletions Side-by-side Diff

drivers/misc/i2c_eeprom.c
... ... @@ -10,21 +10,41 @@
10 10 #include <i2c.h>
11 11 #include <i2c_eeprom.h>
12 12  
13   -static int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
14   - int size)
  13 +int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size)
15 14 {
  15 + const struct i2c_eeprom_ops *ops = device_get_ops(dev);
  16 +
  17 + if (!ops->read)
  18 + return -ENOSYS;
  19 +
  20 + return ops->read(dev, offset, buf, size);
  21 +}
  22 +
  23 +int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size)
  24 +{
  25 + const struct i2c_eeprom_ops *ops = device_get_ops(dev);
  26 +
  27 + if (!ops->write)
  28 + return -ENOSYS;
  29 +
  30 + return ops->write(dev, offset, buf, size);
  31 +}
  32 +
  33 +static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf,
  34 + int size)
  35 +{
16 36 return dm_i2c_read(dev, offset, buf, size);
17 37 }
18 38  
19   -static int i2c_eeprom_write(struct udevice *dev, int offset,
20   - const uint8_t *buf, int size)
  39 +static int i2c_eeprom_std_write(struct udevice *dev, int offset,
  40 + const uint8_t *buf, int size)
21 41 {
22 42 return -ENODEV;
23 43 }
24 44  
25 45 struct i2c_eeprom_ops i2c_eeprom_std_ops = {
26   - .read = i2c_eeprom_read,
27   - .write = i2c_eeprom_write,
  46 + .read = i2c_eeprom_std_read,
  47 + .write = i2c_eeprom_std_write,
28 48 };
29 49  
30 50 static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)
include/i2c_eeprom.h
... ... @@ -20,5 +20,29 @@
20 20 unsigned pagewidth;
21 21 };
22 22  
  23 +/*
  24 + * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
  25 + *
  26 + * @dev: Chip to read from
  27 + * @offset: Offset within chip to start reading
  28 + * @buf: Place to put data
  29 + * @size: Number of bytes to read
  30 + *
  31 + * @return 0 on success, -ve on failure
  32 + */
  33 +int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size);
  34 +
  35 +/*
  36 + * i2c_eeprom_write() - write bytes to an I2C EEPROM chip
  37 + *
  38 + * @dev: Chip to write to
  39 + * @offset: Offset within chip to start writing
  40 + * @buf: Buffer containing data to write
  41 + * @size: Number of bytes to write
  42 + *
  43 + * @return 0 on success, -ve on failure
  44 + */
  45 +int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size);
  46 +
23 47 #endif