1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2014 Google, Inc
4  */
5 
6 #ifndef __I2C_EEPROM
7 #define __I2C_EEPROM
8 
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 
12 struct udevice;
13 
14 struct 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);
18 	int (*size)(struct udevice *dev);
19 };
20 
21 struct i2c_eeprom {
22 	/* The EEPROM's page size in byte */
23 	unsigned long pagesize;
24 	/* The EEPROM's capacity in bytes */
25 	unsigned long size;
26 };
27 
28 #if CONFIG_IS_ENABLED(I2C_EEPROM)
29 /*
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  *
37  * Return: 0 on success, -ve on failure
38  */
39 int 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  *
49  * Return: 0 on success, -ve on failure
50  */
51 int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf,
52 		     int size);
53 
54 /*
55  * i2c_eeprom_size() - get size of I2C EEPROM chip
56  *
57  * @dev:	Chip to query
58  *
59  * Return: +ve size in bytes on success, -ve on failure
60  */
61 int i2c_eeprom_size(struct udevice *dev);
62 
63 #else /* !I2C_EEPROM */
64 
i2c_eeprom_read(struct udevice * dev,int offset,uint8_t * buf,int size)65 static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
66 				  int size)
67 {
68 	return -ENOSYS;
69 }
70 
i2c_eeprom_write(struct udevice * dev,int offset,const uint8_t * buf,int size)71 static inline int i2c_eeprom_write(struct udevice *dev, int offset,
72 				   const uint8_t *buf, int size)
73 {
74 	return -ENOSYS;
75 }
76 
i2c_eeprom_size(struct udevice * dev)77 static inline int i2c_eeprom_size(struct udevice *dev)
78 {
79 	return -ENOSYS;
80 }
81 
82 #endif /* I2C_EEPROM */
83 
84 #endif
85