Skip to content

Commit 5cb1a54

Browse files
larsclausenjic23
authored andcommitted
iio: __iio_update_buffers: Update mode before preenable/after postdisable
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 <[email protected]> Signed-off-by: Alexandru Ardelean <[email protected]> Fixes: 065056c ("iio: at91-sama5d2_adc: split at91_adc_current_chan_is_touch() helper") Tested-by: Eugen Hristev <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 3adb82e commit 5cb1a54

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/iio/industrialio-buffer.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
927927
indio_dev->active_scan_mask = config->scan_mask;
928928
indio_dev->scan_timestamp = config->scan_timestamp;
929929
indio_dev->scan_bytes = config->scan_bytes;
930+
indio_dev->currentmode = config->mode;
930931

931932
iio_update_demux(indio_dev);
932933

@@ -962,8 +963,6 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
962963
goto err_disable_buffers;
963964
}
964965

965-
indio_dev->currentmode = config->mode;
966-
967966
if (indio_dev->setup_ops->postenable) {
968967
ret = indio_dev->setup_ops->postenable(indio_dev);
969968
if (ret) {
@@ -980,10 +979,10 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,
980979
buffer_list)
981980
iio_buffer_disable(buffer, indio_dev);
982981
err_run_postdisable:
983-
indio_dev->currentmode = INDIO_DIRECT_MODE;
984982
if (indio_dev->setup_ops->postdisable)
985983
indio_dev->setup_ops->postdisable(indio_dev);
986984
err_undo_config:
985+
indio_dev->currentmode = INDIO_DIRECT_MODE;
987986
indio_dev->active_scan_mask = NULL;
988987

989988
return ret;
@@ -1018,8 +1017,6 @@ static int iio_disable_buffers(struct iio_dev *indio_dev)
10181017
ret = ret2;
10191018
}
10201019

1021-
indio_dev->currentmode = INDIO_DIRECT_MODE;
1022-
10231020
if (indio_dev->setup_ops->postdisable) {
10241021
ret2 = indio_dev->setup_ops->postdisable(indio_dev);
10251022
if (ret2 && !ret)
@@ -1028,6 +1025,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev)
10281025

10291026
iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask);
10301027
indio_dev->active_scan_mask = NULL;
1028+
indio_dev->currentmode = INDIO_DIRECT_MODE;
10311029

10321030
return ret;
10331031
}

0 commit comments

Comments
 (0)