From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] i2c_probe: Use a quick write transfer instead of writing a zero
Date: Fri, 25 Jan 2019 21:59:35 +0100 [thread overview]
Message-ID: <20190125205935.15135-2-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20190125205935.15135-1-u.kleine-koenig@pengutronix.de>
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@pengutronix.de>
---
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, ®, 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-01-25 20:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 20:59 [PATCH 1/2] i2c_probe: limit slave addresses to [0x04, 0x77] Uwe Kleine-König
2019-01-25 20:59 ` Uwe Kleine-König [this message]
2019-01-28 9:01 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190125205935.15135-2-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox