Skip to content

Commit a77f8a1

Browse files
committed
iio: adc: at91-sama5d2_adc: simplify the code in at91_adc_read_info_raw()
Simplify a bit the code in at91_adc_read_info_raw() by reducing the number of lines of code. Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
1 parent a59c50d commit a77f8a1

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,35 +1576,27 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
15761576
struct iio_chan_spec const *chan, int *val)
15771577
{
15781578
struct at91_adc_state *st = iio_priv(indio_dev);
1579+
int (*fn)(struct at91_adc_state *, int, u16 *) = NULL;
15791580
u16 tmp_val;
15801581
int ret;
15811582

15821583
/*
15831584
* Keep in mind that we cannot use software trigger or touchscreen
15841585
* if external trigger is enabled
15851586
*/
1586-
if (chan->type == IIO_POSITIONRELATIVE) {
1587-
ret = iio_device_claim_direct_mode(indio_dev);
1588-
if (ret)
1589-
return ret;
1590-
mutex_lock(&st->lock);
15911587

1592-
ret = at91_adc_read_position(st, chan->channel,
1593-
&tmp_val);
1594-
*val = tmp_val;
1595-
mutex_unlock(&st->lock);
1596-
iio_device_release_direct_mode(indio_dev);
1588+
if (chan->type == IIO_POSITIONRELATIVE)
1589+
fn = at91_adc_read_position;
1590+
if (chan->type == IIO_PRESSURE)
1591+
fn = at91_adc_read_pressure;
15971592

1598-
return at91_adc_adjust_val_osr(st, val);
1599-
}
1600-
if (chan->type == IIO_PRESSURE) {
1601-
ret = iio_device_claim_direct_mode(indio_dev);
1602-
if (ret)
1603-
return ret;
1604-
mutex_lock(&st->lock);
1593+
ret = iio_device_claim_direct_mode(indio_dev);
1594+
if (ret)
1595+
return ret;
1596+
mutex_lock(&st->lock);
16051597

1606-
ret = at91_adc_read_pressure(st, chan->channel,
1607-
&tmp_val);
1598+
if (fn) {
1599+
ret = fn(st, chan->channel, &tmp_val);
16081600
*val = tmp_val;
16091601
mutex_unlock(&st->lock);
16101602
iio_device_release_direct_mode(indio_dev);
@@ -1614,11 +1606,6 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
16141606

16151607
/* in this case we have a voltage channel */
16161608

1617-
ret = iio_device_claim_direct_mode(indio_dev);
1618-
if (ret)
1619-
return ret;
1620-
mutex_lock(&st->lock);
1621-
16221609
st->chan = chan;
16231610

16241611
at91_adc_cor(st, chan);

0 commit comments

Comments
 (0)