diff options
author | Nuno Sa <nuno.sa@analog.com> | 2024-06-18 15:32:04 +0200 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2024-06-25 22:04:49 +0200 |
commit | d80d4a3ce3aa3b0d8ac6966cb15f79d0c4a542e2 (patch) | |
tree | 1374a7e7bd1346635c6ffd36d89c9931a2048f91 /drivers/iio | |
parent | dt-bindings: iio: st-sensors: add LIS2DS12 accelerometer (diff) | |
download | linux-d80d4a3ce3aa3b0d8ac6966cb15f79d0c4a542e2.tar.xz linux-d80d4a3ce3aa3b0d8ac6966cb15f79d0c4a542e2.zip |
iio: imu: adis_buffer: split trigger handling
Split trigger handling for devices that have paging and need to
select the correct page to get the data. Although this actually
introduces more LOC, it makes the code and the locking clear. It will
also make the following move to the cleanup magic cleaner.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240618-dev-iio-adis-cleanup-v1-1-bd93ce7845c7@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/imu/adis_buffer.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c index 871b78b225e2..5bde698cce18 100644 --- a/drivers/iio/imu/adis_buffer.c +++ b/drivers/iio/imu/adis_buffer.c @@ -126,32 +126,41 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, } EXPORT_SYMBOL_NS_GPL(adis_update_scan_mode, IIO_ADISLIB); -static irqreturn_t adis_trigger_handler(int irq, void *p) +static int adis_paging_trigger_handler(struct adis *adis) { - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis *adis = iio_device_get_drvdata(indio_dev); int ret; - if (adis->data->has_paging) { - mutex_lock(&adis->state_lock); - if (adis->current_page != 0) { - adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); - adis->tx[1] = 0; - ret = spi_write(adis->spi, adis->tx, 2); - if (ret) { - dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret); - mutex_unlock(&adis->state_lock); - goto irq_done; - } - - adis->current_page = 0; + mutex_lock(&adis->state_lock); + if (adis->current_page != 0) { + adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); + adis->tx[1] = 0; + ret = spi_write(adis->spi, adis->tx, 2); + if (ret) { + dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret); + mutex_unlock(&adis->state_lock); + return ret; } + + adis->current_page = 0; } ret = spi_sync(adis->spi, &adis->msg); + mutex_unlock(&adis->state_lock); + + return ret; +} + +static irqreturn_t adis_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct adis *adis = iio_device_get_drvdata(indio_dev); + int ret; + if (adis->data->has_paging) - mutex_unlock(&adis->state_lock); + ret = adis_paging_trigger_handler(adis); + else + ret = spi_sync(adis->spi, &adis->msg); if (ret) { dev_err(&adis->spi->dev, "Failed to read data: %d", ret); goto irq_done; |