Re: [PATCH 3/4] docs: iio: new docs for ad4052 driver

From: Jorge Marques
Date: Fri Mar 14 2025 - 14:13:35 EST


On Mon, Mar 10, 2025 at 07:54:16PM +0000, Jonathan Cameron wrote:
> On Sun, 9 Mar 2025 21:49:24 +0100
> Jorge Marques <gastmaier@xxxxxxxxx> wrote:
>
> > > > +.. list-table:: Driver attributes
> > > > + :header-rows: 1
> > > > +
> > > > + * - Attribute
> > > > + - Description
> > > > + * - ``in_voltage0_raw``
> > > > + - Raw ADC voltage value
> > > > + * - ``in_voltage0_oversampling_ratio``
> > > > + - Enable the device's burst averaging mode to over sample using
> > > > + the internal sample rate.
> > > > + * - ``in_voltage0_oversampling_ratio_available``
> > > > + - List of available oversampling values. Value 0 disable the burst
> > > > + averaging mode.
> > > > + * - ``sample_rate``
> > > > + - Device internal sample rate used in the burst averaging mode.
> > > > + * - ``sample_rate_available``
> > > > + - List of available sample rates.
> > >
> > > Why not using the standard sampling_frequency[_available] attributes?
> > Because sampling_frequency is the sampling frequency for the pwm trigger
> > during buffer readings.
> > sample_rate is the internal device clock used during monitor and burst
> > averaging modes.
>
> For an ABI that is very vague and the two use cases seem to be logically
> quite different.
>
> Seems that for each trigger we have an oversampling ratio controlled number
> of samples at this rate. It is unusual to be able to control oversampling
> rate separately from the trigger clock, hence the lack of ABI. If
> we add something new for this it should something relating to oversampling.
> oversampling_frequency perhaps.
>
> For monitor mode, it is tied to the sampling frequency for most devices.
> But there are exceptions. E.g. the max1363. Trick is to make it an event
> ABI property and hence under events/ rather than in the root directory.
>
> In this case you'll have to store two values and write the appropriate
> one into the register to suit a given operating mode.
>

If doing buffer captures with oversampling enabled, both sampling
frequencies have an impact:

e.g.,
oversampling: 4
sample_rate: 2MHz
PWM sampling frequency: 500KHz

PWM trigger out (CNV) | | | | |
ADC conversion ++++ ++++ ++++ ++++ ++++
ADC data ready (GP) * * * * *

For monitor mode, it will constantly be doing conversion to check for
threshold crossings, at the defined sample_rate.

I like the idea of having the device's sample_rate as
conversion_frequency.

> >
> > > > +
> > > > +Threshold events
> > > > +================
> > > > +
> > > > +The ADC supports a monitoring mode to raise threshold events.
> > > > +The driver supports a single interrupt for both rising and falling
> > > > +readings.
> > > > +
> > > > +During monitor mode, the device is busy since other transactions
> > > > +require to put the device in configuration mode first.
> > >
> > > This isn't so clear to me. Is this saying that events do not work
> > > while doing a buffered read? Do you need to do need to read the
> > > in_voltage0_raw input to trigger an event?
> > >
> > No, the device monitor mode and trigger mode autonomously samples using the
> > internal clock set with the sample rate property.
> > I rephrased that to:
> >
> > The feature is enabled/disabled by setting ``thresh_either_en``.
> > During monitor mode, the device continuously operate in autonomous mode until
> > put back in configuration mode, due to this, the device returns busy until the
> > feature is disabled.
> >
> > The reasoning is that during configuration mode no ADC
> > conversion is done, including if the previous mode was autonomous.
> > If instead of return busy the driver hided this and resumed monitor mode
> > after the access, a hidden (to the user) monitoring down-time would and
> > thresholds crossings could be lost, undermining the feature.
>
> hmm. This is a trade off between usability and precise matching of expectations.
> From your description does monitor mode only trigger if the threshold is
> crossed or is it a level comparison? If it's level I'd consider the
> option of brief disabling. Unlikely to be a problem interrupting things
> in vast majority of usecases. Documentation can then express this issue.
>

The gpio asserts when the threshold is crossed, and desserts when it is
back in bounds.
The interrupt controller should be configured to detecting rising
edges, to not call multiple irq_handlers for the same crossing.
If the interrupt controller is set to trigger on level,
multiple irq handler calls will occur before being able to access
the device register to disable the GPIO.

Jorge