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