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>
This commit is contained in:

committed by
Jonathan Cameron

parent
687d39d451
commit
380b107bbf
@@ -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;
|
||||
|
Reference in New Issue
Block a user