public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Eddie James <eajames@linux.ibm.com>
To: linux-i2c@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	jic23@kernel.org, lars@metafoo.de, wsa@kernel.org,
	milton@us.ibm.com, peda@axentia.se,
	Eddie James <eajames@linux.ibm.com>
Subject: [RFC 2/2] iio: humidity: si7020: Use core transfer callback to sleep after reset
Date: Wed, 18 May 2022 15:41:19 -0500	[thread overview]
Message-ID: <20220518204119.38943-3-eajames@linux.ibm.com> (raw)
In-Reply-To: <20220518204119.38943-1-eajames@linux.ibm.com>

While the SI7020 is starting up after power on or reset, any I2C commands
on the bus can potentially upset the startup sequence. Therefore, the host
needs to wait for the startup sequence to finish before issuing further
i2c commands. This is impractical in cases where the SI7020 is on a shared
bus or behind a mux, which may switch channels at any time (potentially
generating I2C traffic). To resolve this, use the new transfer callback
on the adapter to sleep the required interval.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/iio/humidity/si7020.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
index ab6537f136ba..f19e88818bd6 100644
--- a/drivers/iio/humidity/si7020.c
+++ b/drivers/iio/humidity/si7020.c
@@ -103,6 +103,13 @@ static const struct iio_info si7020_info = {
 	.read_raw = si7020_read_raw,
 };
 
+static void si7020_xfer_callback(void *data, int xfer_rc)
+{
+	/* Wait the maximum power-up time after software reset. */
+	if (!xfer_rc)
+		msleep(15);
+}
+
 static int si7020_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -115,12 +122,13 @@ static int si7020_probe(struct i2c_client *client,
 				     I2C_FUNC_SMBUS_READ_WORD_DATA))
 		return -EOPNOTSUPP;
 
+	i2c_lock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER);
+	i2c_adapter_xfer_callback(client->adapter, si7020_xfer_callback, NULL);
 	/* Reset device, loads default settings. */
 	ret = i2c_smbus_write_byte(client, SI7020CMD_RESET);
+	i2c_unlock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER);
 	if (ret < 0)
 		return ret;
-	/* Wait the maximum power-up time after software reset. */
-	msleep(15);
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
 	if (!indio_dev)
-- 
2.27.0


      parent reply	other threads:[~2022-05-18 20:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 20:41 [RFC 0/2] i2c: core and si7020: Add adapter transfer callback Eddie James
2022-05-18 20:41 ` [RFC 1/2] i2c: core: " Eddie James
2022-05-20 11:42   ` Peter Rosin
2022-05-18 20:41 ` Eddie James [this message]

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=20220518204119.38943-3-eajames@linux.ibm.com \
    --to=eajames@linux.ibm.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=milton@us.ibm.com \
    --cc=peda@axentia.se \
    --cc=wsa@kernel.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