Re: [PATCH v5 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs

From: Jonathan Cameron

Date: Sat Jul 04 2026 - 19:44:20 EST


On Thu, 2 Jul 2026 18:45:27 -0300
Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx> wrote:

> Support for LTC2378-20 and similar analog-to-digital converters.
>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
Just a couple of trivial additional comments as you are spinning
again anyway.

> diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c
> new file mode 100644
> index 000000000000..b5cf2e974dac
> --- /dev/null
> +++ b/drivers/iio/adc/ltc2378.c
> @@ -0,0 +1,404 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Analog Devices LTC2378 ADC series driver
> + *
> + * Copyright (C) 2026 Analog Devices Inc.
> + * Author: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
> + */
> +
> +#include <linux/bitops.h>
> +#include <linux/bits.h>
> +#include <linux/cleanup.h>
> +#include <linux/delay.h>
> +#include <linux/err.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/mod_devicetable.h>

Drop this one. Uwe just had a series merged that moved
the relevant include path into spi/spi.h
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/include/linux/spi/spi.h?id=ecca1d63c1eadbbb38ceab82de0f7adfbc2b465d

I'll probably rebase the iio tree on rc2 or merge that in
to resolve any conflicts.

> +#include <linux/module.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/spi/spi.h>
> +#include <linux/types.h>
> +#include <linux/units.h>
> +
> +#include <linux/iio/iio.h>
> +#include <linux/iio/types.h>

We had some discussion about this recently and IIRC concluded that types.h will
always be included by iio.h so maybe just iio.h is enough.
I don't care strongly either way though.

> +
> +static int ltc2378_channel_single_read(const struct iio_chan_spec *chan,
> + struct ltc2378_state *st, int *val)
> +{
> + const struct iio_scan_type *scan_type = &chan->scan_type;
> + u32 sample;
> + int ret;
> +
> + ret = ltc2378_convert_and_acquire(st);
> + if (ret)
> + return ret;
> +
> + if (chan->scan_type.endianness == IIO_BE) {
> + if (chan->scan_type.realbits > 16)
> + sample = be32_to_cpu(st->scan.data.sample_buf32_be);
> + else
> + sample = be16_to_cpu(st->scan.data.sample_buf16_be);
> + } else {

Trivial but can we have a /* IIO_CPU */ for this else.
I briefly wondered why for little endian we didn't need to use lexx_to_cpu()
before registering this is for offload where the spi controller is dealing
with it (and hence IIO_CPU for the endian)


> + if (chan->scan_type.realbits > 16)
> + sample = st->scan.data.sample_buf32;
> + else
> + sample = st->scan.data.sample_buf16;
> + }
> +
> + sample >>= chan->scan_type.shift;
> +
> + if (scan_type->format == IIO_SCAN_FORMAT_SIGNED_INT)
> + *val = sign_extend32(sample, scan_type->realbits - 1);
> + else
> + *val = sample;
> +
> + return 0;
> +}