From 1b6253ab991d272adf8c84b0a6063b4076253d61 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 25 Jan 2019 21:59:35 +0100 Subject: i2c_probe: Use a quick write transfer instead of writing a zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Sascha Hauer --- commands/i2c.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'commands') diff --git a/commands/i2c.c b/commands/i2c.c index 65ff7378ec..77d65e3fa3 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, ®, 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"); } -- cgit v1.2.3