i2c_eeprom.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 udevice;
  8. struct i2c_eeprom_ops {
  9. int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
  10. int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
  11. int size);
  12. int (*size)(struct udevice *dev);
  13. };
  14. struct i2c_eeprom {
  15. /* The EEPROM's page size in byte */
  16. unsigned long pagesize;
  17. /* The EEPROM's capacity in bytes */
  18. unsigned long size;
  19. };
  20. #if CONFIG_IS_ENABLED(I2C_EEPROM)
  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, const uint8_t *buf,
  43. int size);
  44. /*
  45. * i2c_eeprom_size() - get size of I2C EEPROM chip
  46. *
  47. * @dev: Chip to query
  48. *
  49. * Return: +ve size in bytes on success, -ve on failure
  50. */
  51. int i2c_eeprom_size(struct udevice *dev);
  52. #else /* !I2C_EEPROM */
  53. static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
  54. int size)
  55. {
  56. return -ENOSYS;
  57. }
  58. static inline int i2c_eeprom_write(struct udevice *dev, int offset,
  59. const uint8_t *buf, int size)
  60. {
  61. return -ENOSYS;
  62. }
  63. static inline int i2c_eeprom_size(struct udevice *dev)
  64. {
  65. return -ENOSYS;
  66. }
  67. #endif /* I2C_EEPROM */
  68. #endif