mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 00/10] iio: adc: ti-ads112c14: add filter support
@ 2026-09-10 21:12 David Lechner (TI)
  2026-09-10 21:13 ` [PATCH v3 01/10] iio: adc: ti-ads112c14: add DRDY interrupt support David Lechner (TI)
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: David Lechner (TI) @ 2026-09-10 21:12 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
  Cc: Chris Hall, Patrick Edwards, Kurt Borja, linux-iio, linux-kernel,
	David Lechner (TI)

I was hoping to avoid this, but until [0] lands, sashiko doesn't know
how to handle patch series with dependencies. So I have combined my
three outstanding ti-ads112c14 series into a single one. It's really
too much all at once, but this seems the best way to speed up the review
process at the moment.

[0]: https://github.com/sashiko-dev/sashiko/pull/389

So we now have:

* patches 1-3: "iio: adc: ti-ads112c14: continuous mode support", last
  reviewed as v5 [1] (identical to what was sent with [2] but review
  was done on the standalone series)
* patches 4-5: "iio: adc: ti-ads112c14: add burnout current support",
  last posted/reviewed as part of this bigger series [2].
* patches 6-10: "iio: adc: ti-ads112c14: add filter support", last
  posted as v2 [2]

Apart from the changes listed below, the patches are the same as in
those postings.

[1]: https://patch.msgid.link/20260831-iio-adc-ti-ads112c14-continuous-mode-v5-0-76f80a04b94f@baylibre.com
[2]: https://patch.msgid.link/20260904-iio-adc-ti-ads112c14-filter-support-v2-0-f86592360658@baylibre.com

The rest of this cover letter describes the filter support portion.

TI ADS112C14 has several features related to filtering that are all
interconnected. And to make things more interesting, not of the register
fields map directly to IIO attributes. So this is one of those cases
where we need to bend the rules a bit and just document it (we've
already discussed this a bit in the previous series for this driver and
came to this conclusion).

Here is the high-level overview:

We are adding sampling_frequency, oversampling_ratio, filter_type, and
a (new to IIO) settlingtime attribute.

Since register fields have different meanings depending on filter type
we have a quirky rule that if the filter type is sinc4 or sinc4+sinc1,
then you need to set the oversampling ratio first in order to see the
expected available values for the sampling frequency. For sinc4+sinc1+pf1
it is the other way around, you have to set sampling frequency first
in order to see the expected available oversampling ratios.

In other drivers, we've opted to store the requested values for dependant
attributes like this and pick the closest available one when actually
starting sampling. I opted not to do that here as there is not much
overlap between settings. And as we will see below, there are other
reasons for being picky about sampling frequency.

We also discussed in another series about a proposed settlingtime
attribute. The conclusion was that it should be the total settling time
delay (in seconds) before a chip takes the first sample (after any
settings have changed). In this chip there is a DELAY field in a
register that programs some extra delay in addition to an always present
fixed delay. So the way the attribute will work for this chip is that
the settlingtime_available attribute will list the range including a
minimum value. This happens to be the always present fixed delay. So the
difference between that and the current value of the settlingtime
attribute will be programed as the DELAY value. It also seems that the
fixed latency period includes the conversion time. We've just glossed
over that for now and not subtracted that from the settlingtime
 attribute.

Now, here is where things really get interesting/complicated. There are
even more settings that affect the settling time. We defined the
settling time as just a delay before the first sample. However, there
are a couple of things that trigger the "first" sample. On this chip,
the first sample only counts in continuous sampling mode. So only works
as described when using the DRDY trigger in this driver. When using
a generic trigger, e.g. a hrtimer trigger, single-shot sampling mode
is used, so every sample is a "first" sample and has the settling delay
added. This is mostly a non-issue other than it could throw people off
that they cannot set the hrtimer frequency close to the sampling
frequency attribute and actually get that sampling rate.

And there a few other idiosyncrasies we haven't accounted for. To keep
things simple, we've implemented settlingtime as tDELAY + tLATENCY
(datasheet values). But this actually include the conversion time as
well. Also, tLATENCY is longer if you are coming out of standby mode
(this doesn't matter at this point since we didn't implement power
management, but we wouldn't want to change it and break userspace
later).

Then there is also input chopping where the positive and negative input
channels are swapped in the mux in the ADC on each sample. In these
cases, every conversion requires the settling time because the mux is
switched after every conversion. And the actual first sample has
additional delay (presumably does two conversions). So the first sample
takes tGC_LATENCY = 2 × (tDELAY + tLATENCY) – 12 tMOD and every sample
after that takes tGC_DATA = tDELAY + tLATENCY – 12 tMOD. For this one,
I have valued simplicity over accuracy in the implementation, so it is
the same where settlingtime = tDELAY + tLATENCY and not worried about
the 12 tMOD difference. I think it makes sense to keep settlingtime
as a single tDELAY + tLATENCY in this case since the when the mux
changes after each sample, the next sample is now the first sample after
settings have changed.

This sort of breaks the definition of sampling frequency though since
in IIO, the 1 / sampling frequency is the time between each sample
being sent over the bus. I don't really want to change how sampling
frequency is implemented here though because the current values match
the datasheet which can be used to infer information like where the
notches in the filter are. The actual observed sampling rate will be
1 / tGC_DATA.

Having written all of this out now though, I'm tempted to go back and
change the settlingtime attribute implementation to be more accurate.
In any case, tDELAY will always be easy to infer because it is the
current value minus the minimum value (from the _available attribute).
Then when using input chopping one could get a reasonably accurate
sample period by taking 1 / sampling_frequency + settlingtime.

We will follow this up later with a documentation patch that explains
all of this too.

Signed-off-by: David Lechner (TI) <dlechner@baylibre.com>
---
Changes in v3:
- Patch 1 (DRDY interrupt): only require the "drdy" interrupt when it is
  actually listed in interrupt-names, falling back to polling mode
  otherwise instead of failing probe (the binding allows interrupt-names
  to list only "fault").
- Patch 3 (continuous mode): allocate and register the DRDY trigger
  before requesting the IRQ, so devres teardown disables the interrupt
  before freeing the trigger (avoids a possible use-after-free that
  sashiko flagged).
- Patch 6 (external clock): use FIELD_PREP() with named values for the
  CLK_SEL bit instead of regmap_set_bits(). Validate that the external
  clock's rate is non-zero.
- Patch 7 (filter support): fix div_u64_rem() pointer-sign warnings in
  the new ODR table code by using local u32 variables for the
  remainder. Use unsigned int instead of u32 for the new loop indices,
  declared locally in each loop.
- Patch 9 (settlingtime attribute): widen the intermediate delay
  calculation to u64 so a large requested settling time saturates
  instead of wrapping around. Rewrap the poll-timeout call.
- Patch 10 (settlingtime ABI): expand the commit message to explain why
  the total settling time isn't simply the difference between the first
  and subsequent sample times.
- Link to v2: https://patch.msgid.link/20260904-iio-adc-ti-ads112c14-filter-support-v2-0-f86592360658@baylibre.com

Changes in v2:
- Combined the continuous mode support and burnout current support
  series into this series (see above).
- Rebased on the current iio/testing.
- Bumped KernelVersion to 7.4 in the settlingtime ABI documentation so
  that it matches the rest of the new ABI in this series.
- Patches 1-3 (continuous mode): no changes since v5 [1].
   - FWIW, I didn't think sashiko's comments on the IRQ were realistic.
     This could never be used with a level interrupt. And we haven't
     typically tried to handle spurious interrupts in the past either.
     Everything it suggested could only happen with broken hardware or
     excessive noise (which I suppose counts as broken hardware).
- Patches 4-5 (burnout), changes since v2 [2]:
  - Pass an integer rather than a boolean to FIELD_PREP() for the global
    chop enable bit.
  - Drop the blank line after looking up the measurement.
  - Return the conversion error in preference to the error from turning
    the burnout current back off.
  - Use a local variable for the "burn-out-current-nanoamp" property
    name.
  - Compare against ADS112C14_DEVICE_CFG_BOCS_DISABLED explicitly
    instead of testing for non-zero.
  - Fix KernelVersion in the ABI docs.
- Patches 6-10 (filter support), changes since v1 [3]:
  - Move the driver code that was accidentally squashed into the
    "iio: ABI: add sinc4+sinc1+pf1 filter_type" patch back to the
    "iio: adc: ti-ads112c14: add filter support" patch where it belongs.
  - Fixed typos in the external clock patch commit message.
  - Added a note to the settlingtime ABI documentation that the settling
    time can apply to more than just the first conversion.
- Link to v1: https://patch.msgid.link/20260807-iio-adc-ti-ads112c14-filter-support-v1-0-4d3ba00caf18@baylibre.com

---
David Lechner (TI) (10):
      iio: adc: ti-ads112c14: add DRDY interrupt support
      iio: adc: ti-ads112c14: create data read helper functions
      iio: adc: ti-ads112c14: add continuous mode support
      iio: adc: ti-ads112c14: add burnout current support
      iio: ABI: add sysfs attribute for _burnoutraw
      iio: adc: ti-ads112c14: support external clock
      iio: adc: ti-ads112c14: add filter support
      iio: ABI: add sinc4+sinc1+pf1 filter_type
      iio: adc: ti-ads112c14: add settlingtime attribute
      iio: ABI: add settlingtime attributes

 Documentation/ABI/testing/sysfs-bus-iio     |   27 +
 Documentation/ABI/testing/sysfs-bus-iio-adc |    9 +
 drivers/iio/adc/ti-ads112c14.c              | 1298 +++++++++++++++++++++++++--
 3 files changed, 1275 insertions(+), 59 deletions(-)
---
base-commit: e7c1d459e542bc4a9c57f558e8ca1b14df7a7eef
change-id: 20260807-iio-adc-ti-ads112c14-filter-support-8a56850f590f

Best regards,
--  
David Lechner (TI) <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-09-13 20:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 21:12 [PATCH v3 00/10] iio: adc: ti-ads112c14: add filter support David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 01/10] iio: adc: ti-ads112c14: add DRDY interrupt support David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 02/10] iio: adc: ti-ads112c14: create data read helper functions David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 03/10] iio: adc: ti-ads112c14: add continuous mode support David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 04/10] iio: adc: ti-ads112c14: add burnout current support David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 05/10] iio: ABI: add sysfs attribute for _burnoutraw David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 06/10] iio: adc: ti-ads112c14: support external clock David Lechner (TI)
2026-09-11  8:38   ` Joshua Crofts
2026-09-11  9:16     ` Andy Shevchenko
2026-09-10 21:13 ` [PATCH v3 07/10] iio: adc: ti-ads112c14: add filter support David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 08/10] iio: ABI: add sinc4+sinc1+pf1 filter_type David Lechner (TI)
2026-09-10 21:13 ` [PATCH v3 09/10] iio: adc: ti-ads112c14: add settlingtime attribute David Lechner (TI)
2026-09-13 20:11   ` Jonathan Cameron
2026-09-10 21:13 ` [PATCH v3 10/10] iio: ABI: add settlingtime attributes David Lechner (TI)
2026-09-13 20:17 ` [PATCH v3 00/10] iio: adc: ti-ads112c14: add filter support Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®