The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v10 0/2] iio: adc: Add support for LTC2378 and similar ADCs
@ 2026-08-13 23:04 Marcelo Schmitt
  2026-08-13 23:05 ` [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18 Marcelo Schmitt
  0 siblings, 1 reply; 6+ messages in thread
From: Marcelo Schmitt @ 2026-08-13 23:04 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: jic23, nuno.sa, Michael.Hennerich, dlechner, andy,
	marcelo.schmitt1

Improvementes to LTC2378 device driver according to v9 review.

Rebased on top of
54355e3b189c ("iio: adc: ltc2378: Enable triggered buffer data capture")
Will require rebasing testing and togreg branches.

Previous submissions:
  v9: https://lore.kernel.org/linux-iio/cover.1785186980.git.marcelo.schmitt@analog.com/
  v8: https://lore.kernel.org/linux-iio/cover.1784835663.git.marcelo.schmitt@analog.com/
  v7: https://lore.kernel.org/linux-iio/cover.1784235595.git.marcelo.schmitt@analog.com/
  v6: https://lore.kernel.org/linux-iio/cover.1783629101.git.marcelo.schmitt@analog.com/
  v5: https://lore.kernel.org/linux-iio/cover.1783028033.git.marcelo.schmitt@analog.com/
  v4: https://lore.kernel.org/linux-iio/cover.1782397418.git.marcelo.schmitt@analog.com/
  v3: https://lore.kernel.org/linux-iio/cover.1781661028.git.marcelo.schmitt@analog.com/
  v2: https://lore.kernel.org/linux-iio/cover.1779976379.git.marcelo.schmitt@analog.com/
  v1: https://lore.kernel.org/linux-iio/cover.1779117444.git.marcelo.schmitt1@gmail.com/

Change log v9 -> v10:
[DT]
No changes in device tree doc.
[IIO]
- Added {} to make local variable at top of code block scope.
- if-else code neat.
- Mention the possibility of having same index for diff channels (e.g. voltageX-voltageX)
  in ABI doc.

With best regards,
Marcelo


Marcelo Schmitt (2):
  iio: adc: ltc2378: Add support for LTC2338-18
  iio: ABI: Encourage differential voltage ABI usage

 Documentation/ABI/testing/sysfs-bus-iio | 11 ++++---
 drivers/iio/adc/ltc2378.c               | 44 +++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 6 deletions(-)


base-commit: 54355e3b189c7015d4575ae04a3bc7b803975bd1
-- 
2.53.0


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

* [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18
  2026-08-13 23:04 [PATCH v10 0/2] iio: adc: Add support for LTC2378 and similar ADCs Marcelo Schmitt
@ 2026-08-13 23:05 ` Marcelo Schmitt
  2026-08-17  7:28   ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Marcelo Schmitt @ 2026-08-13 23:05 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: jic23, nuno.sa, Michael.Hennerich, dlechner, andy,
	marcelo.schmitt1

LTC2338-18 is similar to LTC2378-18, differentiating from the already
supported part mainly on the embedment of an internal voltage reference and
addition of a resistor divider network connected to the input signal path.
Extend the device driver, handling the internal reference and input signal
attenuation, enabling it to also support LTC2338-18.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
Change log v9 -> v10:
- Added {} to make local variable at top of code block scope.
- if-else code neat.

 drivers/iio/adc/ltc2378.c | 44 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c
index 146eaadbeb6c..74ac6b8cb7c4 100644
--- a/drivers/iio/adc/ltc2378.c
+++ b/drivers/iio/adc/ltc2378.c
@@ -107,6 +107,8 @@
 
 struct ltc2378_chip_info {
 	const char *name;
+	unsigned int internal_ref_uV;
+	struct u32_fract internal_div;
 	struct iio_chan_spec chan[2]; /* 1 physical chan + 1 timestamp chan */
 	struct iio_chan_spec offload_chan;
 	unsigned int max_sample_rate_Hz;
@@ -145,6 +147,16 @@ struct ltc2378_state {
 	} scan __aligned(IIO_DMA_MINALIGN);
 };
 
+static const struct ltc2378_chip_info ltc2338_18_chip_info = {
+	.name = "ltc2338-18",
+	.internal_ref_uV = 2048000,
+	.internal_div = { .numerator = 5, .denominator = 2 },
+	.chan = { LTC2378_DIFF_CHANNEL(18), IIO_CHAN_SOFT_TIMESTAMP(1) },
+	.offload_chan = LTC2378_OFFLOAD_DIFF_CHANNEL(18),
+	.max_sample_rate_Hz = 1 * HZ_PER_MHZ,
+	.tconv_ns = 527,
+};
+
 static const struct ltc2378_chip_info ltc2364_16_chip_info = {
 	.name = "ltc2364-16",
 	.chan = { LTC2378_PSEUDO_DIFF_CHANNEL(16), IIO_CHAN_SOFT_TIMESTAMP(1) },
@@ -382,8 +394,11 @@ static int ltc2378_read_raw(struct iio_dev *indio_dev,
 
 		return IIO_VAL_INT;
 	}
-	case IIO_CHAN_INFO_SCALE:
+	case IIO_CHAN_INFO_SCALE: {
+		struct u32_fract fract = st->info->internal_div;
 		*val = st->ref_uV / MILLI;
+		if (fract.numerator && fract.denominator)
+			*val = mult_frac(*val, fract.numerator, fract.denominator);
 		/*
 		 * For all LTC2378-like devices, the amount of bits that express
 		 * voltage magnitude depend on the polarity / output code format:
@@ -396,6 +411,7 @@ static int ltc2378_read_raw(struct iio_dev *indio_dev,
 			*val2 = chan->scan_type.realbits;
 
 		return IIO_VAL_FRACTIONAL_LOG2;
+	}
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		*val = st->cnv_Hz;
 		return IIO_VAL_INT;
@@ -641,6 +657,25 @@ static const struct spi_offload_config ltc2378_offload_config = {
 			    SPI_OFFLOAD_CAP_RX_STREAM_DMA,
 };
 
+static int ltc2378_refin_setup(struct device *dev, struct ltc2378_state *st)
+{
+	int ret;
+
+	/*
+	 * The internal reference buffer amplifies both the internal reference
+	 * and REFIN by a factor of 2.
+	 */
+	ret = devm_regulator_get_enable_read_voltage(dev, "refin");
+	if (ret == -ENODEV) /* refin is optional */
+		st->ref_uV = st->info->internal_ref_uV * 2;
+	else if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to read refin regulator\n");
+	else
+		st->ref_uV = ret * 2;
+
+	return 0;
+}
+
 static int ltc2378_ref_setup(struct device *dev, struct ltc2378_state *st)
 {
 	int ret;
@@ -676,7 +711,10 @@ static int ltc2378_probe(struct spi_device *spi)
 	if (!st->info)
 		return -EINVAL;
 
-	ret = ltc2378_ref_setup(dev, st);
+	if (st->info->internal_ref_uV)
+		ret = ltc2378_refin_setup(dev, st);
+	else
+		ret = ltc2378_ref_setup(dev, st);
 	if (ret)
 		return ret;
 
@@ -750,6 +788,7 @@ static int ltc2378_probe(struct spi_device *spi)
 }
 
 static const struct of_device_id ltc2378_of_match[] = {
+	{ .compatible = "adi,ltc2338-18", .data = &ltc2338_18_chip_info },
 	{ .compatible = "adi,ltc2364-16", .data = &ltc2364_16_chip_info },
 	{ .compatible = "adi,ltc2364-18", .data = &ltc2364_18_chip_info },
 	{ .compatible = "adi,ltc2367-16", .data = &ltc2367_16_chip_info },
@@ -774,6 +813,7 @@ static const struct of_device_id ltc2378_of_match[] = {
 MODULE_DEVICE_TABLE(of, ltc2378_of_match);
 
 static const struct spi_device_id ltc2378_spi_id[] = {
+	{ .name = "ltc2338-18", .driver_data = (kernel_ulong_t)&ltc2338_18_chip_info },
 	{ .name = "ltc2364-16", .driver_data = (kernel_ulong_t)&ltc2364_16_chip_info },
 	{ .name = "ltc2364-18", .driver_data = (kernel_ulong_t)&ltc2364_18_chip_info },
 	{ .name = "ltc2367-16", .driver_data = (kernel_ulong_t)&ltc2367_16_chip_info },
-- 
2.53.0


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

* Re: [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18
  2026-08-13 23:05 ` [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18 Marcelo Schmitt
@ 2026-08-17  7:28   ` Andy Shevchenko
  2026-08-22  2:20     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-17  7:28 UTC (permalink / raw)
  To: Marcelo Schmitt
  Cc: linux-iio, linux-kernel, jic23, nuno.sa, Michael.Hennerich,
	dlechner, andy, marcelo.schmitt1

On Thu, Aug 13, 2026 at 08:05:07PM -0300, Marcelo Schmitt wrote:
> LTC2338-18 is similar to LTC2378-18, differentiating from the already
> supported part mainly on the embedment of an internal voltage reference and
> addition of a resistor divider network connected to the input signal path.
> Extend the device driver, handling the internal reference and input signal
> attenuation, enabling it to also support LTC2338-18.

LGTM now,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

...

> -	case IIO_CHAN_INFO_SCALE:
> +	case IIO_CHAN_INFO_SCALE: {
> +		struct u32_fract fract = st->info->internal_div;

+ blank line

>  		*val = st->ref_uV / MILLI;
> +		if (fract.numerator && fract.denominator)
> +			*val = mult_frac(*val, fract.numerator, fract.denominator);

He-he, I have a local patch to add mult_fract() macro for this kind of cases :-)
Perhaps need to submit it at some point...

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18
  2026-08-17  7:28   ` Andy Shevchenko
@ 2026-08-22  2:20     ` Jonathan Cameron
  2026-08-24  8:21       ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2026-08-22  2:20 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Marcelo Schmitt, linux-iio, linux-kernel, nuno.sa,
	Michael.Hennerich, dlechner, andy, marcelo.schmitt1

On Mon, 17 Aug 2026 10:28:21 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Thu, Aug 13, 2026 at 08:05:07PM -0300, Marcelo Schmitt wrote:
> > LTC2338-18 is similar to LTC2378-18, differentiating from the already
> > supported part mainly on the embedment of an internal voltage reference and
> > addition of a resistor divider network connected to the input signal path.
> > Extend the device driver, handling the internal reference and input signal
> > attenuation, enabling it to also support LTC2338-18.  
> 
> LGTM now,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Ah. I applied the earlier version fixing up at least comments it seems.
(Not that I've completely forgotten doing so!)

Can you please check if there is anything different we can handle
as a follow on patch?

Thanks,

Jonathan

> 
> ...
> 
> > -	case IIO_CHAN_INFO_SCALE:
> > +	case IIO_CHAN_INFO_SCALE: {
> > +		struct u32_fract fract = st->info->internal_div;  
> 
> + blank line
> 
> >  		*val = st->ref_uV / MILLI;
> > +		if (fract.numerator && fract.denominator)
> > +			*val = mult_frac(*val, fract.numerator, fract.denominator);  
> 
> He-he, I have a local patch to add mult_fract() macro for this kind of cases :-)
> Perhaps need to submit it at some point...
> 


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

* Re: [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18
  2026-08-22  2:20     ` Jonathan Cameron
@ 2026-08-24  8:21       ` Andy Shevchenko
  2026-08-24 12:30         ` Marcelo Schmitt
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-08-24  8:21 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Marcelo Schmitt, linux-iio, linux-kernel, nuno.sa,
	Michael.Hennerich, dlechner, andy, marcelo.schmitt1

On Sat, Aug 22, 2026 at 03:20:14AM +0100, Jonathan Cameron wrote:
> On Mon, 17 Aug 2026 10:28:21 +0300
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Thu, Aug 13, 2026 at 08:05:07PM -0300, Marcelo Schmitt wrote:
> > > LTC2338-18 is similar to LTC2378-18, differentiating from the already
> > > supported part mainly on the embedment of an internal voltage reference and
> > > addition of a resistor divider network connected to the input signal path.
> > > Extend the device driver, handling the internal reference and input signal
> > > attenuation, enabling it to also support LTC2338-18.  
> > 
> > LGTM now,
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Ah. I applied the earlier version fixing up at least comments it seems.
> (Not that I've completely forgotten doing so!)
> 
> Can you please check if there is anything different we can handle
> as a follow on patch?

Hmm... Are you asking me doing this? I would delegate this to Marcelo.
If we forget something, I don't think it would be a big deal. I just have
almost no time for this.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18
  2026-08-24  8:21       ` Andy Shevchenko
@ 2026-08-24 12:30         ` Marcelo Schmitt
  0 siblings, 0 replies; 6+ messages in thread
From: Marcelo Schmitt @ 2026-08-24 12:30 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Marcelo Schmitt, linux-iio, linux-kernel,
	nuno.sa, Michael.Hennerich, dlechner, andy

On 08/24, Andy Shevchenko wrote:
> On Sat, Aug 22, 2026 at 03:20:14AM +0100, Jonathan Cameron wrote:
> > On Mon, 17 Aug 2026 10:28:21 +0300
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > On Thu, Aug 13, 2026 at 08:05:07PM -0300, Marcelo Schmitt wrote:
> > > > LTC2338-18 is similar to LTC2378-18, differentiating from the already
> > > > supported part mainly on the embedment of an internal voltage reference and
> > > > addition of a resistor divider network connected to the input signal path.
> > > > Extend the device driver, handling the internal reference and input signal
> > > > attenuation, enabling it to also support LTC2338-18.  
> > > 
> > > LGTM now,
> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> > Ah. I applied the earlier version fixing up at least comments it seems.
> > (Not that I've completely forgotten doing so!)
> > 
> > Can you please check if there is anything different we can handle
> > as a follow on patch?
> 
I'll wait a week or so until the release cycle rush ends to send a follow on patch.

> Hmm... Are you asking me doing this? I would delegate this to Marcelo.
> If we forget something, I don't think it would be a big deal. I just have
> almost no time for this.
> 
Agree, the difference from the applied version to v10 is just condestyle/readability.
No functional change or bug fix of any sort being made.

With Best Regards,
Marcelo

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

end of thread, other threads:[~2026-08-24 12:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-13 23:04 [PATCH v10 0/2] iio: adc: Add support for LTC2378 and similar ADCs Marcelo Schmitt
2026-08-13 23:05 ` [PATCH v10 1/2] iio: adc: ltc2378: Add support for LTC2338-18 Marcelo Schmitt
2026-08-17  7:28   ` Andy Shevchenko
2026-08-22  2:20     ` Jonathan Cameron
2026-08-24  8:21       ` Andy Shevchenko
2026-08-24 12:30         ` Marcelo Schmitt

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