Skip to content

Commit b929117

Browse files
committed
iio: adc: at91-sama5d2_adc: add locking parameter to at91_adc_read_info_raw()
Add a parameter to at91_adc_read_info_raw() to specify if st->lock mutex need to be acquired. This prepares for the addition of temperature sensor code which will re-use at91_adc_read_info_raw() function to read 2 voltages for determining the real temperature. Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
1 parent b2fcb71 commit b929117

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,8 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private)
15831583
}
15841584

15851585
static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
1586-
struct iio_chan_spec const *chan, int *val)
1586+
struct iio_chan_spec const *chan, int *val,
1587+
bool lock)
15871588
{
15881589
struct at91_adc_state *st = iio_priv(indio_dev);
15891590
int (*fn)(struct at91_adc_state *, int, u16 *) = NULL;
@@ -1603,13 +1604,15 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
16031604
ret = iio_device_claim_direct_mode(indio_dev);
16041605
if (ret)
16051606
return ret;
1606-
mutex_lock(&st->lock);
1607+
if (lock)
1608+
mutex_lock(&st->lock);
16071609

16081610
if (fn) {
16091611
ret = fn(st, chan->channel, &tmp_val);
16101612
*val = tmp_val;
16111613
ret = at91_adc_adjust_val_osr(st, val);
1612-
mutex_unlock(&st->lock);
1614+
if (lock)
1615+
mutex_unlock(&st->lock);
16131616
iio_device_release_direct_mode(indio_dev);
16141617

16151618
return ret;
@@ -1645,7 +1648,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
16451648
/* Needed to ACK the DRDY interruption */
16461649
at91_adc_readl(st, LCDR);
16471650

1648-
mutex_unlock(&st->lock);
1651+
if (lock)
1652+
mutex_unlock(&st->lock);
16491653

16501654
iio_device_release_direct_mode(indio_dev);
16511655
return ret;
@@ -1659,7 +1663,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev,
16591663

16601664
switch (mask) {
16611665
case IIO_CHAN_INFO_RAW:
1662-
return at91_adc_read_info_raw(indio_dev, chan, val);
1666+
return at91_adc_read_info_raw(indio_dev, chan, val, true);
1667+
16631668
case IIO_CHAN_INFO_SCALE:
16641669
*val = st->vref_uv / 1000;
16651670
if (chan->differential)

0 commit comments

Comments
 (0)