i2c_eeprom.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2014 Google, Inc
  4. */
  5. #ifndef __I2C_EEPROM
  6. #define __I2C_EEPROM
  7. struct i2c_eeprom_ops {
  8. int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
  9. int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
  10. int size);
  11. int (*size)(struct udevice *dev);
  12. };
  13. struct i2c_eeprom {
  14. /* The EEPROM's page size in byte */
  15. unsigned long pagesize;
  16. /* The EEPROM's page width in bits (pagesize = 2^pagewidth) */
  17. unsigned pagewidth;
  18. /* The EEPROM's capacity in bytes */
  19. unsigned long size;
  20. };
  21. /*
  22. * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
  23. *
  24. * @dev: Chip to read from
  25. * @offset: Offset within chip to start reading
  26. * @buf: Place to put data
  27. * @size: Number of bytes to read
  28. *
  29. * @return 0 on success, -ve on failure
  30. */
  31. int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size);
  32. /*
  33. * i2c_eeprom_write() - write bytes to an I2C EEPROM chip
  34. *
  35. * @dev: Chip to write to
  36. * @offset: Offset within chip to start writing
  37. * @buf: Buffer containing data to write
  38. * @size: Number of bytes to write
  39. *
  40. * @return 0 on success, -ve on failure
  41. */
  42. int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size);
  43. /*
  44. * i2c_eeprom_size() - get size of I2C EEPROM chip
  45. *
  46. * @dev: Chip to query
  47. *
  48. * @return +ve size in bytes on success, -ve on failure
  49. */
  50. int i2c_eeprom_size(struct udevice *dev);
  51. #endif