From: Alexandru Ardelean <aardelean@deviqon.com>
To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: jic23@kernel.org, pmeerw@pmeerw.net,
Alexandru Ardelean <aardelean@deviqon.com>
Subject: [PATCH 2/2] iio: temperature: tmp006: make sure the chip is powered up in probe
Date: Thu, 24 Jun 2021 11:19:24 +0300 [thread overview]
Message-ID: <20210624081924.15897-2-aardelean@deviqon.com> (raw)
In-Reply-To: <20210624081924.15897-1-aardelean@deviqon.com>
When the device is probed, there's no guarantee that the device is not in
power-down mode. This can happen if the driver is unregistered and
re-probed.
To make sure this doesn't happen, the value of the TMP006_CONFIG register
(which is read in the probe function and stored in the device's private
data) is being checked to see if the MOD bits have the correct value.
This is a fix for a somewhat-rare corner case. As it stands, this doesn't
look like a high priority to go into the Fixes route.
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
drivers/iio/temperature/tmp006.c | 33 +++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c
index db1ac6029c27..e4943a0bc9aa 100644
--- a/drivers/iio/temperature/tmp006.c
+++ b/drivers/iio/temperature/tmp006.c
@@ -193,15 +193,23 @@ static bool tmp006_check_identification(struct i2c_client *client)
return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC;
}
-static int tmp006_powerdown(struct tmp006_data *data)
+static int tmp006_power(struct device *dev, bool up)
{
+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct tmp006_data *data = iio_priv(indio_dev);
+
+ if (up)
+ data->config |= TMP006_CONFIG_MOD_MASK;
+ else
+ data->config &= ~TMP006_CONFIG_MOD_MASK;
+
return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
- data->config & ~TMP006_CONFIG_MOD_MASK);
+ data->config);
}
-static void tmp006_powerdown_cleanup(void *data)
+static void tmp006_powerdown_cleanup(void *dev)
{
- tmp006_powerdown(data);
+ tmp006_power(dev, false);
}
static int tmp006_probe(struct i2c_client *client,
@@ -239,7 +247,14 @@ static int tmp006_probe(struct i2c_client *client,
return ret;
data->config = ret;
- ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data);
+ if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) {
+ ret = tmp006_power(&client->dev, true);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup,
+ &client->dev);
if (ret < 0)
return ret;
@@ -249,16 +264,12 @@ static int tmp006_probe(struct i2c_client *client,
#ifdef CONFIG_PM_SLEEP
static int tmp006_suspend(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
- return tmp006_powerdown(iio_priv(indio_dev));
+ return tmp006_power(dev, false);
}
static int tmp006_resume(struct device *dev)
{
- struct tmp006_data *data = iio_priv(i2c_get_clientdata(
- to_i2c_client(dev)));
- return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG,
- data->config | TMP006_CONFIG_MOD_MASK);
+ return tmp006_power(dev, true);
}
#endif
--
2.31.1
next prev parent reply other threads:[~2021-06-24 8:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 8:19 [PATCH 1/2] iio: temperature: tmp006: convert probe to device-managed Alexandru Ardelean
2021-06-24 8:19 ` Alexandru Ardelean [this message]
2021-07-17 18:19 ` [PATCH 2/2] iio: temperature: tmp006: make sure the chip is powered up in probe Jonathan Cameron
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=20210624081924.15897-2-aardelean@deviqon.com \
--to=aardelean@deviqon.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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