Re: [PATCH v2 8/8] iio: adc: stm32-dfsdm: claim direct mode for raw read and settings

From: Jonathan Cameron
Date: Sun Mar 24 2019 - 13:12:51 EST


On Thu, 21 Mar 2019 17:47:29 +0100
Fabrice Gasnier <fabrice.gasnier@xxxxxx> wrote:

> 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: Fabrice Gasnier <fabrice.gasnier@xxxxxx>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
> drivers/iio/adc/stm32-dfsdm-adc.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c
> index 51688eb..ca42946 100644
> --- a/drivers/iio/adc/stm32-dfsdm-adc.c
> +++ b/drivers/iio/adc/stm32-dfsdm-adc.c
> @@ -1039,16 +1039,23 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
>
> switch (mask) {
> 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);
> if (!ret)
> adc->oversamp = val;
> -
> + iio_device_release_direct_mode(indio_dev);
> return ret;
>
> case IIO_CHAN_INFO_SAMP_FREQ:
> if (!val)
> return -EINVAL;
>
> + ret = iio_device_claim_direct_mode(indio_dev);
> + if (ret)
> + return ret;
> +
> switch (ch->src) {
> case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL:
> spi_freq = adc->dfsdm->spi_master_freq;
> @@ -1070,9 +1077,11 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
> if (ret < 0) {
> dev_err(&indio_dev->dev,
> "Not able to find parameter that match!\n");
> + iio_device_release_direct_mode(indio_dev);
> return ret;
> }
> adc->sample_freq = val;
> + iio_device_release_direct_mode(indio_dev);
>
> return 0;
> }
> @@ -1089,11 +1098,15 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> + ret = iio_device_claim_direct_mode(indio_dev);
> + if (ret)
> + return ret;
> ret = iio_hw_consumer_enable(adc->hwc);
> if (ret < 0) {
> dev_err(&indio_dev->dev,
> "%s: IIO enable failed (channel %d)\n",
> __func__, chan->channel);
> + iio_device_release_direct_mode(indio_dev);
> return ret;
> }
> ret = stm32_dfsdm_single_conv(indio_dev, chan, val);
> @@ -1102,8 +1115,10 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev,
> dev_err(&indio_dev->dev,
> "%s: Conversion failed (channel %d)\n",
> __func__, chan->channel);
> + iio_device_release_direct_mode(indio_dev);
> return ret;
> }
> + iio_device_release_direct_mode(indio_dev);
> return IIO_VAL_INT;
>
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO: