[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c2d746c73f7450dd10c0a0b229b3672e44fe583a.camel@gmail.com>
Date: Wed, 26 Jun 2024 10:59:05 +0200
From: Nuno Sá <noname.nuno@...il.com>
To: Olivier Moysan <olivier.moysan@...s.st.com>,
fabrice.gasnier@...s.st.com, Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>, Maxime Coquelin
<mcoquelin.stm32@...il.com>, Alexandre Torgue <alexandre.torgue@...s.st.com>
Cc: Nuno Sa <nuno.sa@...log.com>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-stm32@...md-mailman.stormreply.com,
linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v2 8/8] iio: adc: stm32-dfsdm: add scaling support to
dfsdm
Hi Olivier,
One thing that I just noticed...
On Tue, 2024-06-25 at 17:07 +0200, Olivier Moysan wrote:
> Add scaling support to STM32 DFSDM.
>
> When used in an analog context, a DFSDM filter typically converts the data
> from a sigma delta modulator. The IIO device associated to the DFSDM
> filter provides these data as raw data.
> The IIO device can provide scaling information (voltage and offset) to
> allow conversion of raw data into physical values.
>
> With the new binding based on IIO backend framework, the sigma delta
> modulators are defined as backends providing scaling information.
>
> The scaling is not supported with legacy binding.
>
> Signed-off-by: Olivier Moysan <olivier.moysan@...s.st.com>
> Acked-by: Nuno Sa <nuno.sa@...log.com>
> ---
>
...
> +
> + case IIO_CHAN_INFO_SCALE:
> + /*
> + * Scale is expressed in mV.
> + * When fast mode is disabled, actual resolution may be lower
> + * than 2^n, where n = realbits - 1.
> + * This leads to underestimating the input voltage.
> + * To compensate this deviation, the voltage reference can be
> + * corrected with a factor = realbits resolution / actual max
> + */
> + if (adc->backend[idx]) {
> + iio_backend_read_raw(adc->backend[idx], chan, val,
> val2, mask);
Eve if it does not matter for your usecase, you should still do error handling
as iio_backend_read_raw() can return an error.
> + *val = div_u64((u64)*val * (u64)BIT(DFSDM_DATA_RES -
> 1), max);
> + *val2 = chan->scan_type.realbits;
> + if (chan->differential)
> + *val *= 2;
> + }
> + return IIO_VAL_FRACTIONAL_LOG2;
> +
> + case IIO_CHAN_INFO_OFFSET:
> + /*
> + * DFSDM output data are in the range [-2^n, 2^n],
> + * with n = realbits - 1.
> + * - Differential modulator:
> + * Offset correspond to SD modulator offset.
> + * - Single ended modulator:
> + * Input is in [0V, Vref] range,
> + * where 0V corresponds to -2^n, and Vref to 2^n.
> + * Add 2^n to offset. (i.e. middle of input range)
> + * offset = offset(sd) * vref / res(sd) * max / vref.
> + */
> + if (adc->backend[idx]) {
> + iio_backend_read_raw(adc->backend[idx], chan, val,
> val2, mask);
Same...
- Nuno Sá
Powered by blists - more mailing lists