From: Eddie James <eajames@linux.ibm.com>
To: linux-i2c@vger.kernel.org
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
wsa@kernel.org, peda@axentia.se, jic23@kernel.org,
lars@metafoo.de, eajames@linux.ibm.com, miltonm@us.ibm.com,
joel@jms.id.au
Subject: [PATCH 2/2] iio: si7020: Lock root adapter to wait for reset
Date: Thu, 26 May 2022 15:53:34 -0500 [thread overview]
Message-ID: <20220526205334.64114-3-eajames@linux.ibm.com> (raw)
In-Reply-To: <20220526205334.64114-1-eajames@linux.ibm.com>
Use the new mux root operations to lock the root adapter while waiting for
the reset to complete. I2C commands issued after the SI7020 is starting up
or after reset can potentially upset the startup sequence. Therefore, the
host needs to wait for the startup sequence to finish before issuing
further I2C commands.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
drivers/iio/humidity/si7020.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
index ab6537f136ba..76ca7863f35b 100644
--- a/drivers/iio/humidity/si7020.c
+++ b/drivers/iio/humidity/si7020.c
@@ -106,6 +106,7 @@ static const struct iio_info si7020_info = {
static int si7020_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct i2c_adapter *root;
struct iio_dev *indio_dev;
struct i2c_client **data;
int ret;
@@ -115,13 +116,24 @@ static int si7020_probe(struct i2c_client *client,
I2C_FUNC_SMBUS_READ_WORD_DATA))
return -EOPNOTSUPP;
+ root = i2c_lock_select_bus(client->adapter);
+ if (IS_ERR(root))
+ return PTR_ERR(root);
+
/* Reset device, loads default settings. */
- ret = i2c_smbus_write_byte(client, SI7020CMD_RESET);
- if (ret < 0)
+ ret = __i2c_smbus_xfer(root, client->addr, client->flags,
+ I2C_SMBUS_WRITE, SI7020CMD_RESET,
+ I2C_SMBUS_BYTE, NULL);
+ if (ret < 0) {
+ i2c_unlock_deselect_bus(client->adapter);
return ret;
+ }
+
/* Wait the maximum power-up time after software reset. */
msleep(15);
+ i2c_unlock_deselect_bus(client->adapter);
+
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
--
2.27.0
prev parent reply other threads:[~2022-05-26 20:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-26 20:53 [PATCH 0/2] i2c: core: Add mux root adapter operations Eddie James
2022-05-26 20:53 ` [PATCH 1/2] " Eddie James
2022-05-27 16:50 ` kernel test robot
2022-06-03 8:01 ` Joel Stanley
2022-09-06 20:10 ` Eddie James
2022-05-26 20:53 ` 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=20220526205334.64114-3-eajames@linux.ibm.com \
--to=eajames@linux.ibm.com \
--cc=jic23@kernel.org \
--cc=joel@jms.id.au \
--cc=lars@metafoo.de \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miltonm@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;
as well as URLs for NNTP newsgroup(s).