[U-Boot,RESEND,v3,02/19] dm: i2c: Make i2c_get_chip_for_busnum() fail if the chip is not detected

Message ID 1544190655-4405-3-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.
i2c_get_chip_for_busnum() really should check the presence of the chip on
the bus. Most of the users of this function assume that this is done.

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

---

Changes in v3:
- removed commit introducing dm_i2c_probe_device(). Instead probe the
  presence of the chip on the I2C bus in i2c_get_chip_for_busnum().

Changes in v2: None

 drivers/i2c/i2c-uclass.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Heiko Schocher Dec. 10, 2018, 5:02 a.m. | #1
Hello Jean-Jacques,

Am 07.12.2018 um 14:50 schrieb Jean-Jacques Hiblot:
> i2c_get_chip_for_busnum() really should check the presence of the chip on
> the bus. Most of the users of this function assume that this is done.
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> 
> ---
> 
> Changes in v3:
> - removed commit introducing dm_i2c_probe_device(). Instead probe the
>    presence of the chip on the I2C bus in i2c_get_chip_for_busnum().
> 
> Changes in v2: None
> 
>   drivers/i2c/i2c-uclass.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)

Thanks for resending!

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

bye,
Heiko Schocher

Patch

diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index c5a3c4e..975318e 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -347,6 +347,17 @@  int i2c_get_chip_for_busnum(int busnum, int chip_addr, uint offset_len,
 		debug("Cannot find I2C bus %d\n", busnum);
 		return ret;
 	}
+
+	/* detect the presence of the chip on the bus */
+	ret = i2c_probe_chip(bus, chip_addr, 0);
+	debug("%s: bus='%s', address %02x, ret=%d\n", __func__, bus->name,
+	      chip_addr, ret);
+	if (ret) {
+		debug("Cannot detect I2C chip %02x on bus %d\n", chip_addr,
+		      busnum);
+		return ret;
+	}
+
 	ret = i2c_get_chip(bus, chip_addr, offset_len, devp);
 	if (ret) {
 		debug("Cannot find I2C chip %02x on bus %d\n", chip_addr,