Re: [PATCH v4 3/4] iio: adc: ltc2378: Enable high-speed data capture
From: Andy Shevchenko
Date: Mon Jun 29 2026 - 01:49:26 EST
On Thu, Jun 25, 2026 at 11:35:40AM -0300, Marcelo Schmitt wrote:
> Make use of SPI transfer offloading to speed up data capture, enabling data
> acquisition at faster sample rates (up to 2 MSPS).
...
> +#include <linux/math.h>
> +#include <linux/math64.h>
The latter is superior, drop math.h
...
> struct ltc2378_chip_info {
> const char *name;
> unsigned int internal_ref_uv;
> struct iio_chan_spec chan;
> + struct iio_chan_spec offload_chan;
> + unsigned int max_sample_rate_hz;
Perhaps _Hz for the consistency. I dunno in this case, because it's quite
widespread (in small letters).
> + unsigned int tconv_ns;
> };
...
> + *val = st->cnv_Hz;
Ah, you already use that, so please do in the above.
...
> + if (freq_Hz < 1 || freq_Hz > st->info->max_sample_rate_hz)
Can we use in_range()?
> + return -ERANGE;
...
> + do {
> + cnv_wf.duty_length_ns = target;
> + ret = pwm_round_waveform_might_sleep(st->cnv_trigger, &cnv_wf);
> + if (ret)
> + return ret;
> + target += 10; /* Increment by PWM duty cycle period */
> + } while (count++ < 100 && cnv_wf.duty_length_ns < LTC2378_TCNV_HIGH_NS);
Seems count is not used directly, can be `while (--count ...)` as usual pattern.
> + /* Double check the minimum CNV high time is met */
> + if (cnv_wf.duty_length_ns < LTC2378_TCNV_HIGH_NS)
> + return -EIO;
Hmm... How is this IO issue?
> + /*
> + * Configure SPI offload PWM trigger.
> + * The trigger should fire after tBUSYLH + tCONV + tDSDOBUSYL.
> + * Minimum time needed: TBUSYLH (13ns) + TCONV (part-specific) + TDSDOBUSYL (5ns)
> + *
> + * Use the same period as CNV PWM to avoid timing issues.
> + * Convert back from period to frequency for the SPI offload API.
> + */
> + offload_period_ns = cnv_wf.period_length_ns;
> + config->periodic.frequency_hz = DIV_ROUND_UP(HZ_PER_GHZ, offload_period_ns);
> + min_read_offset = LTC2378_TBUSYLH_NS + st->info->tconv_ns + LTC2378_TDSDOBUSYL_NS;
> + offload_offset_ns = min_read_offset;
> + count = 0;
> + do {
> + config->periodic.offset_ns = offload_offset_ns;
> + ret = spi_offload_trigger_validate(st->offload_trigger, config);
> + if (ret)
> + return ret;
> + offload_offset_ns += 10;
> + } while (count++ < 100 && config->periodic.offset_ns < min_read_offset);
Same comment against count.
--
With Best Regards,
Andy Shevchenko