summaryrefslogtreecommitdiffstats
path: root/drivers/iio/imu/adis.c
diff options
context:
space:
mode:
authorNuno Sá <nuno.sa@analog.com>2020-01-07 13:17:04 +0200
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2020-01-12 11:34:12 +0000
commit380b107bbf9449ddea0637cefe65a6cbf7b6ca84 (patch)
treed1b5b4ae244e546eac2abf5955cde0f81f334e06 /drivers/iio/imu/adis.c
parent687d39d4512aa5f644450d0662f40aeeac1e84a7 (diff)
downloadlinux-380b107bbf9449ddea0637cefe65a6cbf7b6ca84.tar.gz
linux-380b107bbf9449ddea0637cefe65a6cbf7b6ca84.tar.bz2
linux-380b107bbf9449ddea0637cefe65a6cbf7b6ca84.zip
iio: adis: Introduce timeouts structure
The adis library only allows to define a `startup_delay` which for some devices is enough. However, other devices define different timeouts with significantly different timings which could lead to devices to not wait enough time or to wait a lot more than necessary (which is not efficient). This patch introduces a new timeout struct that must be passed into `adis_init()`. There are mainly, for now, three timeouts used. This is also an introductory patch with the goal of refactoring `adis_initial_startup()`. New driver's (eg: adis16480, adis16460) are replicating code for the device initial setup. With some changes (being this the first one) we can pass this to `adis_initial_startup()`. Signed-off-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/imu/adis.c')
-rw-r--r--drivers/iio/imu/adis.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
index 9ba4a7c8e7ad..8f0867495ef5 100644
--- a/drivers/iio/imu/adis.c
+++ b/drivers/iio/imu/adis.c
@@ -317,19 +317,25 @@ EXPORT_SYMBOL_GPL(__adis_check_status);
int __adis_reset(struct adis *adis)
{
int ret;
+ const struct adis_timeout *timeouts = adis->data->timeouts;
ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg,
ADIS_GLOB_CMD_SW_RESET);
- if (ret)
+ if (ret) {
dev_err(&adis->spi->dev, "Failed to reset device: %d\n", ret);
+ return ret;
+ }
- return ret;
+ msleep(timeouts->sw_reset_ms);
+
+ return 0;
}
EXPORT_SYMBOL_GPL(__adis_reset);
static int adis_self_test(struct adis *adis)
{
int ret;
+ const struct adis_timeout *timeouts = adis->data->timeouts;
ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg,
adis->data->self_test_mask);
@@ -339,7 +345,7 @@ static int adis_self_test(struct adis *adis)
return ret;
}
- msleep(adis->data->startup_delay);
+ msleep(timeouts->self_test_ms);
ret = __adis_check_status(adis);
@@ -368,7 +374,6 @@ int adis_initial_startup(struct adis *adis)
if (ret) {
dev_err(&adis->spi->dev, "Self-test failed, trying reset.\n");
__adis_reset(adis);
- msleep(adis->data->startup_delay);
ret = adis_self_test(adis);
if (ret) {
dev_err(&adis->spi->dev, "Second self-test failed, giving up.\n");
@@ -444,6 +449,11 @@ EXPORT_SYMBOL_GPL(adis_single_conversion);
int adis_init(struct adis *adis, struct iio_dev *indio_dev,
struct spi_device *spi, const struct adis_data *data)
{
+ if (!data || !data->timeouts) {
+ dev_err(&spi->dev, "No config data or timeouts not defined!\n");
+ return -EINVAL;
+ }
+
mutex_init(&adis->state_lock);
adis->spi = spi;
adis->data = data;