blob: 1fe32d2dd687aa9f3b4f6add7bcbcfbe749f77c5 [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>
Tom Rini135ec302024-05-01 19:30:24 -060010#include <linux/types.h>
Max Krummenacher0e226eb2024-01-18 19:10:47 +010011
Sean Andersond9e95022022-05-05 13:11:38 -040012struct udevice;
13
Simon Glass6ca4ba02014-12-10 08:55:54 -070014struct i2c_eeprom_ops {
15 int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
16 int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
17 int size);
Robert Beckett069ddc72019-10-28 18:29:06 +000018 int (*size)(struct udevice *dev);
Simon Glass6ca4ba02014-12-10 08:55:54 -070019};
20
21struct i2c_eeprom {
mario.six@gdsys.cc7559ac42016-06-22 15:14:16 +020022 /* The EEPROM's page size in byte */
23 unsigned long pagesize;
Robert Beckett069ddc72019-10-28 18:29:06 +000024 /* The EEPROM's capacity in bytes */
25 unsigned long size;
Simon Glass6ca4ba02014-12-10 08:55:54 -070026};
27
Sean Andersond9e95022022-05-05 13:11:38 -040028#if CONFIG_IS_ENABLED(I2C_EEPROM)
Jonas Karlman8427a242017-04-22 08:57:41 +000029/*
30 * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
31 *
32 * @dev: Chip to read from
33 * @offset: Offset within chip to start reading
34 * @buf: Place to put data
35 * @size: Number of bytes to read
36 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010037 * Return: 0 on success, -ve on failure
Jonas Karlman8427a242017-04-22 08:57:41 +000038 */
39int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size);
40
41/*
42 * i2c_eeprom_write() - write bytes to an I2C EEPROM chip
43 *
44 * @dev: Chip to write to
45 * @offset: Offset within chip to start writing
46 * @buf: Buffer containing data to write
47 * @size: Number of bytes to write
48 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010049 * Return: 0 on success, -ve on failure
Jonas Karlman8427a242017-04-22 08:57:41 +000050 */
Sean Anderson4a55f9d2022-05-05 13:11:37 -040051int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf,
52 int size);
Jonas Karlman8427a242017-04-22 08:57:41 +000053
Robert Beckett069ddc72019-10-28 18:29:06 +000054/*
55 * i2c_eeprom_size() - get size of I2C EEPROM chip
56 *
57 * @dev: Chip to query
58 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010059 * Return: +ve size in bytes on success, -ve on failure
Robert Beckett069ddc72019-10-28 18:29:06 +000060 */
61int i2c_eeprom_size(struct udevice *dev);
62
Sean Andersond9e95022022-05-05 13:11:38 -040063#else /* !I2C_EEPROM */
64
65static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
66 int size)
67{
68 return -ENOSYS;
69}
70
71static inline int i2c_eeprom_write(struct udevice *dev, int offset,
72 const uint8_t *buf, int size)
73{
74 return -ENOSYS;
75}
76
77static inline int i2c_eeprom_size(struct udevice *dev)
78{
79 return -ENOSYS;
80}
81
82#endif /* I2C_EEPROM */
83
Simon Glass6ca4ba02014-12-10 08:55:54 -070084#endif