Skip to content

Commit 065056c

Browse files
commodojic23
authored andcommitted
iio: at91-sama5d2_adc: split at91_adc_current_chan_is_touch() helper
This change moves the logic to check if the current channel is the touchscreen channel to a separate helper. This reduces some code duplication, but the main intent is to re-use this in the next patches. Signed-off-by: Alexandru Ardelean <[email protected]> Reviewed-by: Eugen Hristev <[email protected]> Reviewed-by: Ludovic Desroches <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent abb7e84 commit 065056c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -874,19 +874,25 @@ static bool at91_adc_buffer_check_use_irq(struct iio_dev *indio,
874874
return true;
875875
}
876876

877+
static bool at91_adc_current_chan_is_touch(struct iio_dev *indio_dev)
878+
{
879+
struct at91_adc_state *st = iio_priv(indio_dev);
880+
881+
return !!bitmap_subset(indio_dev->active_scan_mask,
882+
&st->touch_st.channels_bitmask,
883+
AT91_SAMA5D2_MAX_CHAN_IDX + 1);
884+
}
885+
877886
static int at91_adc_buffer_postenable(struct iio_dev *indio_dev)
878887
{
879888
int ret;
880889
u8 bit;
881890
struct at91_adc_state *st = iio_priv(indio_dev);
882891

883892
/* check if we are enabling triggered buffer or the touchscreen */
884-
if (bitmap_subset(indio_dev->active_scan_mask,
885-
&st->touch_st.channels_bitmask,
886-
AT91_SAMA5D2_MAX_CHAN_IDX + 1)) {
887-
/* touchscreen enabling */
893+
if (at91_adc_current_chan_is_touch(indio_dev))
888894
return at91_adc_configure_touch(st, true);
889-
}
895+
890896
/* if we are not in triggered mode, we cannot enable the buffer. */
891897
if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
892898
return -EINVAL;
@@ -938,12 +944,9 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
938944
u8 bit;
939945

940946
/* check if we are disabling triggered buffer or the touchscreen */
941-
if (bitmap_subset(indio_dev->active_scan_mask,
942-
&st->touch_st.channels_bitmask,
943-
AT91_SAMA5D2_MAX_CHAN_IDX + 1)) {
944-
/* touchscreen disable */
947+
if (at91_adc_current_chan_is_touch(indio_dev))
945948
return at91_adc_configure_touch(st, false);
946-
}
949+
947950
/* if we are not in triggered mode, nothing to do here */
948951
if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
949952
return -EINVAL;
@@ -1937,14 +1940,10 @@ static __maybe_unused int at91_adc_resume(struct device *dev)
19371940
return 0;
19381941

19391942
/* check if we are enabling triggered buffer or the touchscreen */
1940-
if (bitmap_subset(indio_dev->active_scan_mask,
1941-
&st->touch_st.channels_bitmask,
1942-
AT91_SAMA5D2_MAX_CHAN_IDX + 1)) {
1943-
/* touchscreen enabling */
1943+
if (at91_adc_current_chan_is_touch(indio_dev))
19441944
return at91_adc_configure_touch(st, true);
1945-
} else {
1945+
else
19461946
return at91_adc_configure_trigger(st->trig, true);
1947-
}
19481947

19491948
/* not needed but more explicit */
19501949
return 0;

0 commit comments

Comments
 (0)