Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __I2C_EEPROM |
| 7 | #define __I2C_EEPROM |
| 8 | |
Sean Anderson | d9e9502 | 2022-05-05 13:11:38 -0400 | [diff] [blame] | 9 | struct udevice; |
| 10 | |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 11 | struct i2c_eeprom_ops { |
| 12 | int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size); |
| 13 | int (*write)(struct udevice *dev, int offset, const uint8_t *buf, |
| 14 | int size); |
Robert Beckett | 069ddc7 | 2019-10-28 18:29:06 +0000 | [diff] [blame] | 15 | int (*size)(struct udevice *dev); |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | struct i2c_eeprom { |
mario.six@gdsys.cc | 7559ac4 | 2016-06-22 15:14:16 +0200 | [diff] [blame] | 19 | /* The EEPROM's page size in byte */ |
| 20 | unsigned long pagesize; |
Robert Beckett | 069ddc7 | 2019-10-28 18:29:06 +0000 | [diff] [blame] | 21 | /* The EEPROM's capacity in bytes */ |
| 22 | unsigned long size; |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Sean Anderson | d9e9502 | 2022-05-05 13:11:38 -0400 | [diff] [blame] | 25 | #if CONFIG_IS_ENABLED(I2C_EEPROM) |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 26 | /* |
| 27 | * i2c_eeprom_read() - read bytes from an I2C EEPROM chip |
| 28 | * |
| 29 | * @dev: Chip to read from |
| 30 | * @offset: Offset within chip to start reading |
| 31 | * @buf: Place to put data |
| 32 | * @size: Number of bytes to read |
| 33 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 34 | * Return: 0 on success, -ve on failure |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 35 | */ |
| 36 | int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size); |
| 37 | |
| 38 | /* |
| 39 | * i2c_eeprom_write() - write bytes to an I2C EEPROM chip |
| 40 | * |
| 41 | * @dev: Chip to write to |
| 42 | * @offset: Offset within chip to start writing |
| 43 | * @buf: Buffer containing data to write |
| 44 | * @size: Number of bytes to write |
| 45 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 46 | * Return: 0 on success, -ve on failure |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 47 | */ |
Sean Anderson | 4a55f9d | 2022-05-05 13:11:37 -0400 | [diff] [blame] | 48 | int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf, |
| 49 | int size); |
Jonas Karlman | 8427a24 | 2017-04-22 08:57:41 +0000 | [diff] [blame] | 50 | |
Robert Beckett | 069ddc7 | 2019-10-28 18:29:06 +0000 | [diff] [blame] | 51 | /* |
| 52 | * i2c_eeprom_size() - get size of I2C EEPROM chip |
| 53 | * |
| 54 | * @dev: Chip to query |
| 55 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 56 | * Return: +ve size in bytes on success, -ve on failure |
Robert Beckett | 069ddc7 | 2019-10-28 18:29:06 +0000 | [diff] [blame] | 57 | */ |
| 58 | int i2c_eeprom_size(struct udevice *dev); |
| 59 | |
Sean Anderson | d9e9502 | 2022-05-05 13:11:38 -0400 | [diff] [blame] | 60 | #else /* !I2C_EEPROM */ |
| 61 | |
| 62 | static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, |
| 63 | int size) |
| 64 | { |
| 65 | return -ENOSYS; |
| 66 | } |
| 67 | |
| 68 | static inline int i2c_eeprom_write(struct udevice *dev, int offset, |
| 69 | const uint8_t *buf, int size) |
| 70 | { |
| 71 | return -ENOSYS; |
| 72 | } |
| 73 | |
| 74 | static inline int i2c_eeprom_size(struct udevice *dev) |
| 75 | { |
| 76 | return -ENOSYS; |
| 77 | } |
| 78 | |
| 79 | #endif /* I2C_EEPROM */ |
| 80 | |
Simon Glass | 6ca4ba0 | 2014-12-10 08:55:54 -0700 | [diff] [blame] | 81 | #endif |