iio: __iio_update_buffers: Update mode before preenable/after postdisable
authorLars-Peter Clausen <lars@metafoo.de>
Thu, 30 Apr 2020 08:24:55 +0000 (11:24 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 16 May 2020 16:03:28 +0000 (17:03 +0100)
It is clear that we transition to INDIO_DIRECT_MODE when disabling the
buffer(s) and it is also clear that we transition from INDIO_DIRECT_MODE
when enabling the buffer(s). So leaving the currentmode field
INDIO_DIRECT_MODE until after the preenable() callback and updating it to
INDIO_DIRECT_MODE before the postdisable() callback doesn't add additional
value. On the other hand some drivers will need to perform different
actions depending on which mode the device is going to operate in/was
operating in.

Moving the update of currentmode before preenable() and after postdisable()
enables us to have drivers which perform mode dependent actions in those
callbacks.

Note, was originally not intended as such, but fixes an issue introduced
in the at91-sama5d2 adc driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Fixes: 065056cb0d0a ("iio: at91-sama5d2_adc: split at91_adc_current_chan_is_touch() helper")
Tested-by: Eugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-buffer.c

index eae39ea..ec4f531 100644 (file)
@@ -927,6 +927,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
        indio_dev->active_scan_mask = config->scan_mask;
        indio_dev->scan_timestamp = config->scan_timestamp;
        indio_dev->scan_bytes = config->scan_bytes;
+       indio_dev->currentmode = config->mode;
 
        iio_update_demux(indio_dev);
 
@@ -962,8 +963,6 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
                        goto err_disable_buffers;
        }
 
-       indio_dev->currentmode = config->mode;
-
        if (indio_dev->setup_ops->postenable) {
                ret = indio_dev->setup_ops->postenable(indio_dev);
                if (ret) {
@@ -980,10 +979,10 @@ err_disable_buffers:
                                             buffer_list)
                iio_buffer_disable(buffer, indio_dev);
 err_run_postdisable:
-       indio_dev->currentmode = INDIO_DIRECT_MODE;
        if (indio_dev->setup_ops->postdisable)
                indio_dev->setup_ops->postdisable(indio_dev);
 err_undo_config:
+       indio_dev->currentmode = INDIO_DIRECT_MODE;
        indio_dev->active_scan_mask = NULL;
 
        return ret;
@@ -1018,8 +1017,6 @@ static int iio_disable_buffers(struct iio_dev *indio_dev)
                        ret = ret2;
        }
 
-       indio_dev->currentmode = INDIO_DIRECT_MODE;
-
        if (indio_dev->setup_ops->postdisable) {
                ret2 = indio_dev->setup_ops->postdisable(indio_dev);
                if (ret2 && !ret)
@@ -1028,6 +1025,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev)
 
        iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask);
        indio_dev->active_scan_mask = NULL;
+       indio_dev->currentmode = INDIO_DIRECT_MODE;
 
        return ret;
 }