blob: cba991e3574f7402639428c8af54d41ddb4c486d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass6ca4ba02014-12-10 08:55:54 -07002/*
3 * Copyright (c) 2014 Google, Inc
Simon Glass6ca4ba02014-12-10 08:55:54 -07004 */
5
6#ifndef __I2C_EEPROM
7#define __I2C_EEPROM
8
Max Krummenacher0e226eb2024-01-18 19:10:47 +01009#include <linux/errno.h>
10
Sean Andersond9e95022022-05-05 13:11:38 -040011struct udevice;
12
Simon Glass6ca4ba02014-12-10 08:55:54 -070013struct i2c_eeprom_ops {
14 int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
15 int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
16 int size);
Robert Beckett069ddc72019-10-28 18:29:06 +000017 int (*size)(struct udevice *dev);
Simon Glass6ca4ba02014-12-10 08:55:54 -070018};
19
20struct i2c_eeprom {
mario.six@gdsys.cc7559ac42016-06-22 15:14:16 +020021 /* The EEPROM's page size in byte */
22 unsigned long pagesize;
Robert Beckett069ddc72019-10-28 18:29:06 +000023 /* The EEPROM's capacity in bytes */
24 unsigned long size;
Simon Glass6ca4ba02014-12-10 08:55:54 -070025};
26
Sean Andersond9e95022022-05-05 13:11:38 -040027#if CONFIG_IS_ENABLED(I2C_EEPROM)
Jonas Karlman8427a242017-04-22 08:57:41 +000028/*
29 * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
30 *
31 * @dev: Chip to read from
32 * @offset: Offset within chip to start reading
33 * @buf: Place to put data
34 * @size: Number of bytes to read
35 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010036 * Return: 0 on success, -ve on failure
Jonas Karlman8427a242017-04-22 08:57:41 +000037 */
38int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size);
39
40/*
41 * i2c_eeprom_write() - write bytes to an I2C EEPROM chip
42 *
43 * @dev: Chip to write to
44 * @offset: Offset within chip to start writing
45 * @buf: Buffer containing data to write
46 * @size: Number of bytes to write
47 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010048 * Return: 0 on success, -ve on failure
Jonas Karlman8427a242017-04-22 08:57:41 +000049 */
Sean Anderson4a55f9d2022-05-05 13:11:37 -040050int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf,
51 int size);
Jonas Karlman8427a242017-04-22 08:57:41 +000052
Robert Beckett069ddc72019-10-28 18:29:06 +000053/*
54 * i2c_eeprom_size() - get size of I2C EEPROM chip
55 *
56 * @dev: Chip to query
57 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010058 * Return: +ve size in bytes on success, -ve on failure
Robert Beckett069ddc72019-10-28 18:29:06 +000059 */
60int i2c_eeprom_size(struct udevice *dev);
61
Sean Andersond9e95022022-05-05 13:11:38 -040062#else /* !I2C_EEPROM */
63
64static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
65 int size)
66{
67 return -ENOSYS;
68}
69
70static inline int i2c_eeprom_write(struct udevice *dev, int offset,
71 const uint8_t *buf, int size)
72{
73 return -ENOSYS;
74}
75
76static inline int i2c_eeprom_size(struct udevice *dev)
77{
78 return -ENOSYS;
79}
80
81#endif /* I2C_EEPROM */
82
Simon Glass6ca4ba02014-12-10 08:55:54 -070083#endif