Commit 065056cb authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

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: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: default avatarEugen Hristev <eugen.hristev@microchip.com>
Reviewed-by: default avatarLudovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent abb7e84d
...@@ -874,6 +874,15 @@ static bool at91_adc_buffer_check_use_irq(struct iio_dev *indio, ...@@ -874,6 +874,15 @@ static bool at91_adc_buffer_check_use_irq(struct iio_dev *indio,
return true; return true;
} }
static bool at91_adc_current_chan_is_touch(struct iio_dev *indio_dev)
{
struct at91_adc_state *st = iio_priv(indio_dev);
return !!bitmap_subset(indio_dev->active_scan_mask,
&st->touch_st.channels_bitmask,
AT91_SAMA5D2_MAX_CHAN_IDX + 1);
}
static int at91_adc_buffer_postenable(struct iio_dev *indio_dev) static int at91_adc_buffer_postenable(struct iio_dev *indio_dev)
{ {
int ret; int ret;
...@@ -881,12 +890,9 @@ static int at91_adc_buffer_postenable(struct iio_dev *indio_dev) ...@@ -881,12 +890,9 @@ static int at91_adc_buffer_postenable(struct iio_dev *indio_dev)
struct at91_adc_state *st = iio_priv(indio_dev); struct at91_adc_state *st = iio_priv(indio_dev);
/* check if we are enabling triggered buffer or the touchscreen */ /* check if we are enabling triggered buffer or the touchscreen */
if (bitmap_subset(indio_dev->active_scan_mask, if (at91_adc_current_chan_is_touch(indio_dev))
&st->touch_st.channels_bitmask,
AT91_SAMA5D2_MAX_CHAN_IDX + 1)) {
/* touchscreen enabling */
return at91_adc_configure_touch(st, true); return at91_adc_configure_touch(st, true);
}
/* if we are not in triggered mode, we cannot enable the buffer. */ /* if we are not in triggered mode, we cannot enable the buffer. */
if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
return -EINVAL; return -EINVAL;
...@@ -938,12 +944,9 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev) ...@@ -938,12 +944,9 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
u8 bit; u8 bit;
/* check if we are disabling triggered buffer or the touchscreen */ /* check if we are disabling triggered buffer or the touchscreen */
if (bitmap_subset(indio_dev->active_scan_mask, if (at91_adc_current_chan_is_touch(indio_dev))
&st->touch_st.channels_bitmask,
AT91_SAMA5D2_MAX_CHAN_IDX + 1)) {
/* touchscreen disable */
return at91_adc_configure_touch(st, false); return at91_adc_configure_touch(st, false);
}
/* if we are not in triggered mode, nothing to do here */ /* if we are not in triggered mode, nothing to do here */
if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
return -EINVAL; return -EINVAL;
...@@ -1937,14 +1940,10 @@ static __maybe_unused int at91_adc_resume(struct device *dev) ...@@ -1937,14 +1940,10 @@ static __maybe_unused int at91_adc_resume(struct device *dev)
return 0; return 0;
/* check if we are enabling triggered buffer or the touchscreen */ /* check if we are enabling triggered buffer or the touchscreen */
if (bitmap_subset(indio_dev->active_scan_mask, if (at91_adc_current_chan_is_touch(indio_dev))
&st->touch_st.channels_bitmask,
AT91_SAMA5D2_MAX_CHAN_IDX + 1)) {
/* touchscreen enabling */
return at91_adc_configure_touch(st, true); return at91_adc_configure_touch(st, true);
} else { else
return at91_adc_configure_trigger(st->trig, true); return at91_adc_configure_trigger(st->trig, true);
}
/* not needed but more explicit */ /* not needed but more explicit */
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment