Commit 37ada026 authored by Fabrice Gasnier's avatar Fabrice Gasnier Committed by Jonathan Cameron

iio: adc: stm32-dfsdm: claim direct mode for raw read and settings

Claim direct mode to ensure no buffer mode is in use for:
- single conversion
- sample rate setting (must be set when filter isn't enabled).
- oversampling ratio (must be set when filter isn't enabled).
Signed-off-by: default avatarFabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 11646e81
...@@ -1039,16 +1039,23 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, ...@@ -1039,16 +1039,23 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_OVERSAMPLING_RATIO: case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;
ret = stm32_dfsdm_set_osrs(fl, 0, val); ret = stm32_dfsdm_set_osrs(fl, 0, val);
if (!ret) if (!ret)
adc->oversamp = val; adc->oversamp = val;
iio_device_release_direct_mode(indio_dev);
return ret; return ret;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
if (!val) if (!val)
return -EINVAL; return -EINVAL;
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;
switch (ch->src) { switch (ch->src) {
case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL:
spi_freq = adc->dfsdm->spi_master_freq; spi_freq = adc->dfsdm->spi_master_freq;
...@@ -1070,9 +1077,11 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, ...@@ -1070,9 +1077,11 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
if (ret < 0) { if (ret < 0) {
dev_err(&indio_dev->dev, dev_err(&indio_dev->dev,
"Not able to find parameter that match!\n"); "Not able to find parameter that match!\n");
iio_device_release_direct_mode(indio_dev);
return ret; return ret;
} }
adc->sample_freq = val; adc->sample_freq = val;
iio_device_release_direct_mode(indio_dev);
return 0; return 0;
} }
...@@ -1089,11 +1098,15 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, ...@@ -1089,11 +1098,15 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;
ret = iio_hw_consumer_enable(adc->hwc); ret = iio_hw_consumer_enable(adc->hwc);
if (ret < 0) { if (ret < 0) {
dev_err(&indio_dev->dev, dev_err(&indio_dev->dev,
"%s: IIO enable failed (channel %d)\n", "%s: IIO enable failed (channel %d)\n",
__func__, chan->channel); __func__, chan->channel);
iio_device_release_direct_mode(indio_dev);
return ret; return ret;
} }
ret = stm32_dfsdm_single_conv(indio_dev, chan, val); ret = stm32_dfsdm_single_conv(indio_dev, chan, val);
...@@ -1102,8 +1115,10 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, ...@@ -1102,8 +1115,10 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev,
dev_err(&indio_dev->dev, dev_err(&indio_dev->dev,
"%s: Conversion failed (channel %d)\n", "%s: Conversion failed (channel %d)\n",
__func__, chan->channel); __func__, chan->channel);
iio_device_release_direct_mode(indio_dev);
return ret; return ret;
} }
iio_device_release_direct_mode(indio_dev);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO: case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
......
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