blob: 32dcb03497309681f44f0c1e8aa740a2d15a35db [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass20142012014-12-10 08:55:54 -07002/*
3 * Copyright (c) 2014 Google, Inc
Simon Glass20142012014-12-10 08:55:54 -07004 */
5
6#ifndef __I2C_EEPROM
7#define __I2C_EEPROM
8
Sean Anderson42f477f2022-05-05 13:11:38 -04009struct udevice;
10
Simon Glass20142012014-12-10 08:55:54 -070011struct i2c_eeprom_ops {
12 int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
13 int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
14 int size);
Robert Beckett033e18b2019-10-28 18:29:06 +000015 int (*size)(struct udevice *dev);
Simon Glass20142012014-12-10 08:55:54 -070016};
17
18struct i2c_eeprom {
mario.six@gdsys.ccd7e28912016-06-22 15:14:16 +020019 /* The EEPROM's page size in byte */
20 unsigned long pagesize;
Robert Beckett033e18b2019-10-28 18:29:06 +000021 /* The EEPROM's capacity in bytes */
22 unsigned long size;
Simon Glass20142012014-12-10 08:55:54 -070023};
24
Sean Anderson42f477f2022-05-05 13:11:38 -040025#if CONFIG_IS_ENABLED(I2C_EEPROM)
Jonas Karlman8880efb2017-04-22 08:57:41 +000026/*
27 * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
28 *
29 * @dev: Chip to read from
30 * @offset: Offset within chip to start reading
31 * @buf: Place to put data
32 * @size: Number of bytes to read
33 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010034 * Return: 0 on success, -ve on failure
Jonas Karlman8880efb2017-04-22 08:57:41 +000035 */
36int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size);
37
38/*
39 * i2c_eeprom_write() - write bytes to an I2C EEPROM chip
40 *
41 * @dev: Chip to write to
42 * @offset: Offset within chip to start writing
43 * @buf: Buffer containing data to write
44 * @size: Number of bytes to write
45 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010046 * Return: 0 on success, -ve on failure
Jonas Karlman8880efb2017-04-22 08:57:41 +000047 */
Sean Andersondda3b382022-05-05 13:11:37 -040048int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf,
49 int size);
Jonas Karlman8880efb2017-04-22 08:57:41 +000050
Robert Beckett033e18b2019-10-28 18:29:06 +000051/*
52 * i2c_eeprom_size() - get size of I2C EEPROM chip
53 *
54 * @dev: Chip to query
55 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010056 * Return: +ve size in bytes on success, -ve on failure
Robert Beckett033e18b2019-10-28 18:29:06 +000057 */
58int i2c_eeprom_size(struct udevice *dev);
59
Sean Anderson42f477f2022-05-05 13:11:38 -040060#else /* !I2C_EEPROM */
61
62static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
63 int size)
64{
65 return -ENOSYS;
66}
67
68static inline int i2c_eeprom_write(struct udevice *dev, int offset,
69 const uint8_t *buf, int size)
70{
71 return -ENOSYS;
72}
73
74static inline int i2c_eeprom_size(struct udevice *dev)
75{
76 return -ENOSYS;
77}
78
79#endif /* I2C_EEPROM */
80
Simon Glass20142012014-12-10 08:55:54 -070081#endif