diff mbox series

[v4,09/16] misc: i2c_eeprom: Add fallbacks

Message ID 20220505171146.557773-10-sean.anderson@seco.com
State Accepted
Commit 42f477f0ab2b179e6760f1f272b2611618082301
Delegated to: Tom Rini
Headers show
Series Add support for NVMEM API | expand

Commit Message

Sean Anderson May 5, 2022, 5:11 p.m. UTC
Add some fallback functions for when i2c_eeprom is disabled. This allows
code to reference i2c_eeprom_* functions without needing to check
whether support has been compiled in.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

Changes in v4:
- New

 include/i2c_eeprom.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/include/i2c_eeprom.h b/include/i2c_eeprom.h
index 90fdb25232..32dcb03497 100644
--- a/include/i2c_eeprom.h
+++ b/include/i2c_eeprom.h
@@ -6,6 +6,8 @@ 
 #ifndef __I2C_EEPROM
 #define __I2C_EEPROM
 
+struct udevice;
+
 struct i2c_eeprom_ops {
 	int (*read)(struct udevice *dev, int offset, uint8_t *buf, int size);
 	int (*write)(struct udevice *dev, int offset, const uint8_t *buf,
@@ -20,6 +22,7 @@  struct i2c_eeprom {
 	unsigned long size;
 };
 
+#if CONFIG_IS_ENABLED(I2C_EEPROM)
 /*
  * i2c_eeprom_read() - read bytes from an I2C EEPROM chip
  *
@@ -54,4 +57,25 @@  int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf,
  */
 int i2c_eeprom_size(struct udevice *dev);
 
+#else /* !I2C_EEPROM */
+
+static inline int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
+				  int size)
+{
+	return -ENOSYS;
+}
+
+static inline int i2c_eeprom_write(struct udevice *dev, int offset,
+				   const uint8_t *buf, int size)
+{
+	return -ENOSYS;
+}
+
+static inline int i2c_eeprom_size(struct udevice *dev)
+{
+	return -ENOSYS;
+}
+
+#endif /* I2C_EEPROM */
+
 #endif