[PATCH 2/2] i2c_probe: Use a quick write transfer instead of writing a zero

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This matches the method implemented in i2cdetect(8) when using its -q
option.

With this change an rx8130 RTC is detectable using i2c_probe. This
failed before because this chip acks the first byte (containing its
address and the R/̅W bit) but nacks the following 0 (representing the
target address to write nothing to) which makes i2c_write_reg() return
with an error and so the chip is not listed as available.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
---
 commands/i2c.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index 65ff7378ec14..77d65e3fa32b 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -24,19 +24,19 @@
 
 static void i2c_probe_range(struct i2c_adapter *adapter, int startaddr, int stopaddr)
 {
-	struct i2c_client client = {};
 	int addr;
-	int ret;
-	u8 reg;
-
-	client.adapter = adapter;
 
 	printf("probing i2c%d range 0x%02x-0x%02x: ", adapter->nr, startaddr, stopaddr);
 	for (addr = startaddr; addr <= stopaddr && !ctrlc(); addr++) {
-		client.addr = addr;
-		ret = i2c_write_reg(&client, 0x00, &reg, 0);
-		if (ret == 0)
+		struct i2c_msg msg = {
+			.addr = addr,
+			.buf = NULL,
+			.len = 0,
+		};
+		int ret = i2c_transfer(adapter, &msg, 1);
+		if (ret == 1)
 			printf("0x%02x ", addr);
+
 	}
 	printf("\n");
 }
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux