Devicetree
 help / color / mirror / Atom feed
From: Kurt Borja <kuurtb@gmail.com>
To: Kurt Borja <kuurtb@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>,
	 Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	David Lechner <dlechner@baylibre.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Jonathan Cameron" <jic23@kernel.org>
Subject: [PATCH v2 4/7] iio: adc: ti-ads1262: Add excitation current support
Date: Sun, 28 Jun 2026 00:36:05 -0500	[thread overview]
Message-ID: <20260628-ads126x-v2-4-4b1b231325ba@gmail.com> (raw)
In-Reply-To: <20260628-ads126x-v2-0-4b1b231325ba@gmail.com>

Support the two IDAC excitation current sources. Each channel can route
its IDAC1/IDAC2 outputs to a pin via the "excitation-channels" property
and select a magnitude via "excitation-current-nanoamp".

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
 drivers/iio/adc/ti-ads1262.c | 78 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ti-ads1262.c b/drivers/iio/adc/ti-ads1262.c
index ece97a0c2b1304ad..8921eaae537f6b0a 100644
--- a/drivers/iio/adc/ti-ads1262.c
+++ b/drivers/iio/adc/ti-ads1262.c
@@ -193,6 +193,22 @@ enum {
 	ADS1262_INPMUX_LAST
 };
 
+enum {
+	ADS1262_IDACMUX_AIN0,
+	ADS1262_IDACMUX_AIN1,
+	ADS1262_IDACMUX_AIN2,
+	ADS1262_IDACMUX_AIN3,
+	ADS1262_IDACMUX_AIN4,
+	ADS1262_IDACMUX_AIN5,
+	ADS1262_IDACMUX_AIN6,
+	ADS1262_IDACMUX_AIN7,
+	ADS1262_IDACMUX_AIN8,
+	ADS1262_IDACMUX_AIN9,
+	ADS1262_IDACMUX_AINCOM,
+	ADS1262_IDACMUX_NO_CONN,
+	ADS1262_IDACMUX_LAST
+};
+
 enum {
 	ADS1262_REFMUX_INTERNAL,
 	ADS1262_REFMUX_AIN0_AIN1,
@@ -213,6 +229,8 @@ struct ads1262_channel {
 	u8 gain;
 	u8 data_rate;
 	u8 reference[3];
+	u8 idac_mux[2];
+	u8 idac_mag[2];
 	u8 pga_bypass:1;
 	u8 ref_reversal:1;
 	u8 input_chop:1;
@@ -450,7 +468,7 @@ static int ads1262_dev_read_by_cmd(struct ads1262 *st, u8 cmd, __be32 *val)
 static int ads1262_channel_enable(struct ads1262 *st,
 				  struct ads1262_channel *chan)
 {
-	u8 mode0, mode1, mode2, inpmux, refmux;
+	u8 mode0, mode1, mode2, inpmux, idacmux, idacmag, refmux;
 	int ret;
 
 	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
@@ -464,6 +482,10 @@ static int ads1262_channel_enable(struct ads1262 *st,
 		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
 	inpmux = FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]) |
 		 FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]);
+	idacmux = FIELD_PREP(ADS1262_IDACMUX_MUX1_MASK, chan->idac_mux[0]) |
+		  FIELD_PREP(ADS1262_IDACMUX_MUX2_MASK, chan->idac_mux[1]);
+	idacmag = FIELD_PREP(ADS1262_IDACMAG_MAG1_MASK, chan->idac_mag[0]) |
+		  FIELD_PREP(ADS1262_IDACMAG_MAG2_MASK, chan->idac_mag[1]);
 	refmux = FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]) |
 		 FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]);
 	mutex_unlock(&st->chan_lock);
@@ -493,6 +515,18 @@ static int ads1262_channel_enable(struct ads1262 *st,
 	if (ret)
 		return ret;
 
+	ret = regmap_update_bits(st->regmap, ADS1262_IDACMUX_REG,
+				 ADS1262_IDACMUX_MUX1_MASK |
+				 ADS1262_IDACMUX_MUX2_MASK, idacmux);
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(st->regmap, ADS1262_IDACMAG_REG,
+				 ADS1262_IDACMAG_MAG1_MASK |
+				 ADS1262_IDACMAG_MAG2_MASK, idacmag);
+	if (ret)
+		return ret;
+
 	return regmap_update_bits(st->regmap, ADS1262_REFMUX_REG,
 				  ADS1262_REFMUX_RMUXN_MASK |
 				  ADS1262_REFMUX_RMUXP_MASK, refmux);
@@ -1040,13 +1074,19 @@ static int ads1262_parse_channel_node(struct ads1262 *st,
 				      struct fwnode_handle *node)
 {
 	struct device *dev = &st->spi->dev;
+	static const u32 idac_nA[] = {
+		0, 50000, 100000, 250000, 500000, 750000,
+		1000000, 1500000, 2000000, 2500000, 3000000
+	};
 	const char *ref_sources[3] = {};
-	u32 pins[2];
+	u32 pins[2], mags[2];
 	int ret;
 
 	/* Write non-zero default configuration values */
 	chan->filter = ADS1262_FILTER_FIR;
 	chan->data_rate = ADS1262_DR_20_SPS;
+	chan->idac_mux[0] = ADS1262_IDACMUX_NO_CONN;
+	chan->idac_mux[1] = ADS1262_IDACMUX_NO_CONN;
 
 	ret = fwnode_property_read_u32_array(node, "diff-channels", pins, ARRAY_SIZE(pins));
 	if (ret)
@@ -1086,6 +1126,40 @@ static int ads1262_parse_channel_node(struct ads1262 *st,
 		}
 	}
 
+	if (fwnode_property_present(node, "excitation-channels")) {
+		ret = fwnode_property_read_u32_array(node, "excitation-channels",
+						     pins, ARRAY_SIZE(pins));
+		if (ret)
+			return dev_err_probe(dev, ret, "%s: Failed to read excitation-channels\n",
+					     fwnode_get_name(node));
+		if (pins[0] >= ADS1262_IDACMUX_LAST || pins[1] >= ADS1262_IDACMUX_LAST)
+			return dev_err_probe(dev, -EINVAL, "%s: excitation-channels not in range\n",
+					     fwnode_get_name(node));
+		chan->idac_mux[0] = pins[0];
+		chan->idac_mux[1] = pins[1];
+
+		ret = fwnode_property_read_u32_array(node, "excitation-current-nanoamp",
+						     mags, ARRAY_SIZE(mags));
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "%s: Failed to read excitation-current-nanoamp\n",
+					     fwnode_get_name(node));
+
+		ret = ads1262_find_one(idac_nA, mags[0]);
+		if (ret < 0)
+			return dev_err_probe(dev, ret,
+					     "%s: Invalid excitation-current-nanoamp\n",
+					     fwnode_get_name(node));
+		chan->idac_mag[0] = ret;
+
+		ret = ads1262_find_one(idac_nA, mags[1]);
+		if (ret < 0)
+			return dev_err_probe(dev, ret,
+					     "%s: Invalid excitation-current-nanoamp\n",
+					     fwnode_get_name(node));
+		chan->idac_mag[1] = ret;
+	}
+
 	if (fwnode_property_present(node, "ti,pga-bypass"))
 		chan->pga_bypass = 1;
 

-- 
2.54.0


  parent reply	other threads:[~2026-06-28  5:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-28  5:36 [PATCH v2 0/7] iio: adc: Add TI ADS126X ADC family support Kurt Borja
2026-06-28  5:36 ` [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family Kurt Borja
2026-06-28 15:45   ` David Lechner
2026-06-28 19:12     ` Kurt Borja
2026-06-28  5:36 ` [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver Kurt Borja
2026-06-28 17:15   ` David Lechner
2026-06-28 20:00     ` Kurt Borja
2026-06-28  5:36 ` [PATCH v2 3/7] iio: adc: ti-ads1262: Add channel filter support Kurt Borja
2026-06-28  5:36 ` Kurt Borja [this message]
2026-06-28  5:36 ` [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support Kurt Borja
2026-06-28  5:36 ` [PATCH v2 6/7] iio: adc: ti-ads1262: Add buffer and trigger support Kurt Borja
2026-06-28  5:36 ` [PATCH v2 7/7] iio: adc: Add ti-ads1263-adc2 driver Kurt Borja
2026-06-28 17:22   ` David Lechner
2026-06-28 20:08     ` Kurt Borja

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=20260628-ads126x-v2-4-4b1b231325ba@gmail.com \
    --to=kuurtb@gmail.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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