From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <nuno.sa@analog.com>, <jic23@kernel.org>,
Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v2 6/9] iio: imu: adis: Refactor adis_initial_startup
Date: Mon, 10 Feb 2020 15:26:03 +0200 [thread overview]
Message-ID: <20200210132606.9315-6-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20200210132606.9315-1-alexandru.ardelean@analog.com>
From: Nuno Sá <nuno.sa@analog.com>
All the ADIS devices perform, at the beginning, a self test to make sure
the device is in a sane state. Previously, the logic was that the self-test
was performed in adis_initial_startup() and if that failed a reset was done
and then a self-test was attempted again.
This change unifies the reset mechanism under the adis_initial_startup()
call. A HW reset will be done if GPIO is configured, or a SW reset
otherwise. This should make sure that the chip is in a sane state for
self-test. Once the reset is done, the self-test operation will be
performed. If anything goes wrong with self-test, the driver should just
bail/error-out (i.e. no second attempt). The chip would likely not be a in
a sane state state if the self-test fails after a reset.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/iio/imu/Kconfig | 1 +
drivers/iio/imu/adis.c | 29 ++++++++++++++++++++++-------
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index 60bb1029e759..63036cf473c7 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -85,6 +85,7 @@ endmenu
config IIO_ADIS_LIB
tristate
+ depends on GPIOLIB
help
A set of IO helper functions for the Analog Devices ADIS* device family.
diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
index f7845a90f376..0bd6e32cf577 100644
--- a/drivers/iio/imu/adis.c
+++ b/drivers/iio/imu/adis.c
@@ -7,6 +7,7 @@
*/
#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/kernel.h>
@@ -368,6 +369,10 @@ static int adis_self_test(struct adis *adis)
* __adis_initial_startup() - Device initial setup
* @adis: The adis device
*
+ * The function performs a HW reset via a reset pin that should be specified
+ * via GPIOLIB. If no pin is configured a SW reset will be performed.
+ * The RST pin for the ADIS devices should be configured as ACTIVE_LOW.
+ *
* Returns 0 if the device is operational, a negative error code otherwise.
*
* This function should be called early on in the device initialization sequence
@@ -375,18 +380,28 @@ static int adis_self_test(struct adis *adis)
*/
int __adis_initial_startup(struct adis *adis)
{
+ const struct adis_timeout *timeouts = adis->data->timeouts;
+ struct gpio_desc *gpio;
int ret;
- ret = adis_self_test(adis);
- if (ret) {
- dev_err(&adis->spi->dev, "Self-test failed, trying reset.\n");
- __adis_reset(adis);
- ret = adis_self_test(adis);
+ /* check if the device has rst pin low */
+ gpio = devm_gpiod_get_optional(&adis->spi->dev, "reset", GPIOD_ASIS);
+ if (IS_ERR(gpio))
+ return PTR_ERR(gpio);
+
+ if (gpio) {
+ gpiod_set_value_cansleep(gpio, 1);
+ msleep(10);
+ /* bring device out of reset */
+ gpiod_set_value_cansleep(gpio, 0);
+ msleep(timeouts->reset_ms);
+ } else {
+ ret = __adis_reset(adis);
if (ret)
- dev_err(&adis->spi->dev, "Second self-test failed, giving up.\n");
+ return ret;
}
- return ret;
+ return adis_self_test(adis);
}
EXPORT_SYMBOL_GPL(__adis_initial_startup);
--
2.20.1
next prev parent reply other threads:[~2020-02-10 13:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-10 13:25 [PATCH v2 1/9] iio: imu: adis16480: initialize adis_data statically Alexandru Ardelean
2020-02-10 13:25 ` [PATCH v2 2/9] iio: imu: adis16400: " Alexandru Ardelean
2020-02-14 14:29 ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 3/9] iio: gyro: adis16136: " Alexandru Ardelean
2020-02-14 14:30 ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 4/9] iio: imu: adis: add unlocked __adis_initial_startup() Alexandru Ardelean
2020-02-14 14:31 ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 5/9] iio: imu: adis: Add self_test_reg variable Alexandru Ardelean
2020-02-14 14:33 ` Jonathan Cameron
2020-02-10 13:26 ` Alexandru Ardelean [this message]
2020-02-14 14:39 ` [PATCH v2 6/9] iio: imu: adis: Refactor adis_initial_startup Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 7/9] iio: imu: adis: add support product ID check in adis_initial_startup Alexandru Ardelean
2020-02-14 14:41 ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 8/9] iio: adis16480: Make use of __adis_initial_startup Alexandru Ardelean
2020-02-14 14:44 ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 9/9] iio: adis16460: " Alexandru Ardelean
2020-02-14 14:45 ` Jonathan Cameron
2020-02-14 14:28 ` [PATCH v2 1/9] iio: imu: adis16480: initialize adis_data statically 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=20200210132606.9315-6-alexandru.ardelean@analog.com \
--to=alexandru.ardelean@analog.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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).