blob: b96254ae79f5bb7cc071e005efd41934f92e5d56 [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
9struct i2c_eeprom_ops {
10 int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
11 int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
12 int size);
Robert Beckett069ddc72019-10-28 18:29:06 +000013 int (*size)(struct udevice *dev);
Simon Glass6ca4ba02014-12-10 08:55:54 -070014};
15
16struct i2c_eeprom {
mario.six@gdsys.cc7559ac42016-06-22 15:14:16 +020017 /* The EEPROM's page size in byte */
18 unsigned long pagesize;
19 /* The EEPROM's page width in bits (pagesize = 2^pagewidth) */
20 unsigned pagewidth;
Robert Beckett069ddc72019-10-28 18:29:06 +000021 /* The EEPROM's capacity in bytes */
22 unsigned long size;
Simon Glass6ca4ba02014-12-10 08:55:54 -070023};
24
Jonas Karlman8427a242017-04-22 08:57:41 +000025/*
26 * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
27 *
28 * @dev: Chip to read from
29 * @offset: Offset within chip to start reading
30 * @buf: Place to put data
31 * @size: Number of bytes to read
32 *
33 * @return 0 on success, -ve on failure
34 */
35int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size);
36
37/*
38 * i2c_eeprom_write() - write bytes to an I2C EEPROM chip
39 *
40 * @dev: Chip to write to
41 * @offset: Offset within chip to start writing
42 * @buf: Buffer containing data to write
43 * @size: Number of bytes to write
44 *
45 * @return 0 on success, -ve on failure
46 */
47int i2c_eeprom_write(struct udevice *dev, int offset, uint8_t *buf, int size);
48
Robert Beckett069ddc72019-10-28 18:29:06 +000049/*
50 * i2c_eeprom_size() - get size of I2C EEPROM chip
51 *
52 * @dev: Chip to query
53 *
54 * @return +ve size in bytes on success, -ve on failure
55 */
56int i2c_eeprom_size(struct udevice *dev);
57
Simon Glass6ca4ba02014-12-10 08:55:54 -070058#endif