[U-Boot,RESEND,v3,11/19] ti: common: board_detect: Allow DM I2C without CONFIG_DM_I2C_COMPAT

Message ID 1544190655-4405-12-git-send-email-jjhiblot@ti.com
State Awaiting Upstream
Delegated to: Heiko Schocher
Headers show
Series
  • DM_I2C_COMPAT removal for all ti platforms
Related show

Commit Message

Jean-Jacques Hiblot Dec. 7, 2018, 1:50 p.m.
From: Andreas Dannenberg <dannenberg@ti.com>

The EEPROM reading in the board detection code is done through legacy
I2C functions which on platforms using DM_I2C this functionality is
provided via the CONFIG_DM_I2C_COMPAT layer. To allow newer platforms
to use the board detection code without relying on CONFIG_DM_I2C_COMPAT
go ahead and add an I2C handling implementation that directly uses the
I2C DM functionality.

Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

Changes in v3: None
Changes in v2: None

 board/ti/common/board_detect.c | 54 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)

Comments

Tom Rini Dec. 7, 2018, 2:20 p.m. | #1
On Fri, Dec 07, 2018 at 02:50:47PM +0100, Jean-Jacques Hiblot wrote:

> From: Andreas Dannenberg <dannenberg@ti.com>
> 
> The EEPROM reading in the board detection code is done through legacy
> I2C functions which on platforms using DM_I2C this functionality is
> provided via the CONFIG_DM_I2C_COMPAT layer. To allow newer platforms
> to use the board detection code without relying on CONFIG_DM_I2C_COMPAT
> go ahead and add an I2C handling implementation that directly uses the
> I2C DM functionality.
> 
> Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Heiko Schocher Dec. 10, 2018, 5:19 a.m. | #2
Hello Jean-Jacques,

Am 07.12.2018 um 14:50 schrieb Jean-Jacques Hiblot:
> From: Andreas Dannenberg <dannenberg@ti.com>
> 
> The EEPROM reading in the board detection code is done through legacy
> I2C functions which on platforms using DM_I2C this functionality is
> provided via the CONFIG_DM_I2C_COMPAT layer. To allow newer platforms
> to use the board detection code without relying on CONFIG_DM_I2C_COMPAT
> go ahead and add an I2C handling implementation that directly uses the
> I2C DM functionality.
> 
> Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
> 
> Changes in v3: None
> Changes in v2: None
> 
>   board/ti/common/board_detect.c | 54 ++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 52 insertions(+), 2 deletions(-)

Thanks for resending!

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko Schocher

Patch

diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
index c475f10..085e732 100644
--- a/board/ti/common/board_detect.c
+++ b/board/ti/common/board_detect.c
@@ -50,6 +50,7 @@  int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen)
 }
 #endif
 
+#if !defined(CONFIG_DM_I2C) || defined(CONFIG_DM_I2C_COMPAT)
 /**
  * ti_i2c_eeprom_init - Initialize an i2c bus and probe for a device
  * @i2c_bus: i2c bus number to initialize
@@ -94,6 +95,7 @@  static int __maybe_unused ti_i2c_eeprom_read(int dev_addr, int offset,
 
 	return i2c_read(dev_addr, offset, alen, ep, epsize);
 }
+#endif
 
 /**
  * ti_eeprom_string_cleanup() - Handle eeprom programming errors
@@ -122,9 +124,57 @@  __weak void gpi2c_init(void)
 static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 					    u32 header, u32 size, uint8_t *ep)
 {
-	u32 byte, hdr_read;
+	u32 hdr_read;
 	int rc;
 
+#if defined(CONFIG_DM_I2C) && !defined(CONFIG_DM_I2C_COMPAT)
+	struct udevice *dev;
+	struct udevice *bus;
+
+	rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus);
+	if (rc)
+		return rc;
+	rc = i2c_get_chip(bus, dev_addr, 1, &dev);
+	if (rc)
+		return rc;
+
+	/*
+	 * Read the header first then only read the other contents.
+	 */
+	rc = i2c_set_chip_offset_len(dev, 2);
+	if (rc)
+		return rc;
+
+	rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
+	if (rc)
+		return rc;
+
+	/* Corrupted data??? */
+	if (hdr_read != header) {
+		rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
+		/*
+		 * read the eeprom header using i2c again, but use only a
+		 * 1 byte address (some legacy boards need this..)
+		 */
+		if (rc) {
+			rc =  i2c_set_chip_offset_len(dev, 1);
+			if (rc)
+				return rc;
+
+			rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
+		}
+		if (rc)
+			return rc;
+	}
+	if (hdr_read != header)
+		return -1;
+
+	rc = dm_i2c_read(dev, 0, ep, size);
+	if (rc)
+		return rc;
+#else
+	u32 byte;
+
 	gpi2c_init();
 	rc = ti_i2c_eeprom_init(bus_addr, dev_addr);
 	if (rc)
@@ -168,7 +218,7 @@  static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 	rc = i2c_read(dev_addr, 0x0, byte, ep, size);
 	if (rc)
 		return rc;
-
+#endif
 	return 0;
 }