From: Marcelo Schmitt <marcelo.schmitt@analog.com>
To: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, <nuno.sa@analog.com>,
<Michael.Hennerich@analog.com>, <dlechner@baylibre.com>,
<andy@kernel.org>, <robh@kernel.org>, <krzk+dt@kernel.org>,
<conor+dt@kernel.org>, <julianbraha@gmail.com>,
<marcelo.schmitt1@gmail.com>
Subject: [PATCH v9 5/6] iio: adc: ltc2378: Add support for LTC2338-18
Date: Mon, 27 Jul 2026 18:31:58 -0300 [thread overview]
Message-ID: <39f2ff86cf736ff97286d6451fcc45fdba6732f9.1785186980.git.marcelo.schmitt@analog.com> (raw)
In-Reply-To: <cover.1785186980.git.marcelo.schmitt@analog.com>
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>
---
New patch mainly extracted from the base driver patch with the addition of input
attenuation handling for LTC2338-18.
drivers/iio/adc/ltc2378.c | 44 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c
index 146eaadbeb6c..689fa5419faf 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) },
@@ -383,7 +395,10 @@ static int ltc2378_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
}
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:
@@ -641,6 +656,28 @@ 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;
+ return 0;
+ }
+
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "failed to read refin regulator\n");
+
+ st->ref_uV = ret * 2;
+
+ return 0;
+}
+
static int ltc2378_ref_setup(struct device *dev, struct ltc2378_state *st)
{
int ret;
@@ -676,7 +713,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 +790,7 @@ static int ltc2378_probe(struct spi_device *spi)
}
static const struct of_device_id ltc2378_of_match[] = {
+ { .compatible = "adi,ltc2338-18", .data = <c2338_18_chip_info },
{ .compatible = "adi,ltc2364-16", .data = <c2364_16_chip_info },
{ .compatible = "adi,ltc2364-18", .data = <c2364_18_chip_info },
{ .compatible = "adi,ltc2367-16", .data = <c2367_16_chip_info },
@@ -774,6 +815,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)<c2338_18_chip_info },
{ .name = "ltc2364-16", .driver_data = (kernel_ulong_t)<c2364_16_chip_info },
{ .name = "ltc2364-18", .driver_data = (kernel_ulong_t)<c2364_18_chip_info },
{ .name = "ltc2367-16", .driver_data = (kernel_ulong_t)<c2367_16_chip_info },
--
2.53.0
next prev parent reply other threads:[~2026-07-27 21:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 21:30 [PATCH v9 0/6] iio: adc: Add support for LTC2378 and similar ADCs Marcelo Schmitt
2026-07-27 21:30 ` [PATCH v9 1/6] dt-bindings: iio: adc: Add ltc2378 Marcelo Schmitt
2026-07-27 21:30 ` [PATCH v9 2/6] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs Marcelo Schmitt
2026-07-27 21:31 ` [PATCH v9 3/6] iio: adc: ltc2378: Enable high-speed data capture Marcelo Schmitt
2026-07-27 21:31 ` [PATCH v9 4/6] iio: adc: ltc2378: Enable triggered buffer " Marcelo Schmitt
2026-07-27 21:31 ` Marcelo Schmitt [this message]
2026-08-10 7:37 ` [PATCH v9 5/6] iio: adc: ltc2378: Add support for LTC2338-18 Andy Shevchenko
2026-08-11 2:45 ` Marcelo Schmitt
2026-08-11 8:56 ` Andy Shevchenko
2026-08-12 4:03 ` Jonathan Cameron
2026-07-27 21:32 ` [PATCH v9 6/6] iio: ABI: Encourage differential voltage ABI usage Marcelo Schmitt
2026-08-12 4:01 ` Jonathan Cameron
2026-08-12 18:25 ` Marcelo Schmitt
2026-08-15 1:39 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39f2ff86cf736ff97286d6451fcc45fdba6732f9.1785186980.git.marcelo.schmitt@analog.com \
--to=marcelo.schmitt@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=julianbraha@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®