diff mbox series

[U-Boot,v1] eeprom: Add device model based I2C support to eeprom command

Message ID 20181121224043.23524-1-lukma@denx.de
State Accepted
Commit 0c07a9b4078d7a414674e5548c428994df1842bf
Delegated to: Tom Rini
Headers show
Series [U-Boot,v1] eeprom: Add device model based I2C support to eeprom command | expand

Commit Message

Lukasz Majewski Nov. 21, 2018, 10:40 p.m. UTC
After this change the 'eeprom' command can be used with DM aware boards.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---

 cmd/eeprom.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Tom Rini Dec. 3, 2018, 10:49 p.m. UTC | #1
On Wed, Nov 21, 2018 at 11:40:43PM +0100, Lukasz Majewski wrote:

> After this change the 'eeprom' command can be used with DM aware boards.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/cmd/eeprom.c b/cmd/eeprom.c
index 4052cf494a..e88cb131a1 100644
--- a/cmd/eeprom.c
+++ b/cmd/eeprom.c
@@ -137,6 +137,23 @@  static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 		spi_write(addr, alen, buffer, len);
 #else	/* I2C */
 
+#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS)
+	struct udevice *dev;
+
+	ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS, addr[0],
+				      alen - 1, &dev);
+	if (ret) {
+		printf("%s: Cannot find udev for a bus %d\n", __func__,
+		       CONFIG_SYS_I2C_EEPROM_BUS);
+		return CMD_RET_FAILURE;
+	}
+
+	if (read)
+		ret = dm_i2c_read(dev, offset, buffer, len);
+	else
+		ret = dm_i2c_write(dev, offset, buffer, len);
+
+#else /* Non DM I2C support - will be removed */
 #if defined(CONFIG_SYS_I2C_EEPROM_BUS)
 	i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
 #endif
@@ -145,10 +162,11 @@  static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 		ret = i2c_read(addr[0], offset, alen - 1, buffer, len);
 	else
 		ret = i2c_write(addr[0], offset, alen - 1, buffer, len);
-
-	if (ret)
-		ret = 1;
 #endif
+#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */
+	if (ret)
+		ret = CMD_RET_FAILURE;
+
 	return ret;
 }