From: "Kurt Borja" <kuurtb@gmail.com>
To: "David Lechner" <dlechner@baylibre.com>,
"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>,
"Linus Walleij" <linusw@kernel.org>,
"Bartosz Golaszewski" <brgl@kernel.org>
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, linux-gpio@vger.kernel.org
Subject: Re: [PATCH v3 4/9] iio: adc: ti-ads1262: support per-channel reference and gain
Date: Sun, 09 Aug 2026 03:28:01 -0500 [thread overview]
Message-ID: <DKK9RQR8LIQ5.2SWUEDKZTT98P@gmail.com> (raw)
In-Reply-To: <ff566148-b3fb-49fc-9e87-6c5a317e1a2f@baylibre.com>
On Sat Aug 8, 2026 at 1:39 PM -05, David Lechner wrote:
> On 8/7/26 10:58 PM, Kurt Borja wrote:
>> Allow each channel to select its voltage reference through the
>> "reference-sources" firmware property. Then, use the reference voltage
>> to calculate available scales.
>
> It looks like this is also implementing PGA gain at the same time, but
> isn't mentioned in ght commit messsage. I would also expect something
> here about how we should handle PGA bypass (even if it just says default
> works always and we can consdier controlling it later).
I forgot about the PGA bypass stuff. I do believe it should belong in
devicetree because it changes the voltage range of the analog inputs.
See datasheet section 10.3 and 7.3.
>
>>
>> The ADS1262 allows single-ended supply configurations or bipolar supply
>> configurations. In single ended configurations both the analog and
>> digital rails share the same ground, i.e. AVSS = DGND = 0 V. In bipolar
>> supply configurations, AVSS can go below ground, e.g. AVSS = -2.5 V.
>>
>> If AVSS is below ground, the ADC can achieve true bipolar measurements
>> and the external references can also have voltage levels below ground.
>> This is currently an issue because the regulator subsystem doesn't
>> support negative voltages.
>>
>> The ad4170-4 driver faces this problem too and the same workaround is
>> used in this case: assume every regulator reports magnitudes (absolute
>> values). If the chip has a bipolar supply configuration, then assume
>> positive references are above ground (>= 0 V) and negative references
>> are below ground (<= 0 V). This is not a hardware constraint, but it is
>> the most common wiring.
>>
>> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
>> ---
>> drivers/iio/adc/ti-ads1262.c | 417 +++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 406 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ti-ads1262.c b/drivers/iio/adc/ti-ads1262.c
>> index b3b7b1249102..360ce01a5871 100644
>> --- a/drivers/iio/adc/ti-ads1262.c
>> +++ b/drivers/iio/adc/ti-ads1262.c
[...]
>> @@ -688,6 +818,91 @@ static const struct regmap_bus ads1262_regmap_bus = {
>> .max_raw_write = ADS1262_MAX_REGMAP_WRITE,
>> };
>>
>> +static void ads1262_calculate_scales(int (*scales)[2], size_t num_scales,
>> + u32 full_scale, u64 mult,
>> + u32 resolution)
>> +{
>> + unsigned int i;
>> + s64 val;
>> +
>> + for (i = 0; i < num_scales; i++) {
>
> This could use a comment explaining the relasionship of the index in the
> array to the PGA multipier.
>
>> + val = mul_u64_u64_shr(full_scale, mult, resolution - 1 + i);
>> + iio_val_s64_decompose(val, &scales[i][0], &scales[i][1]);
>> + }
>> +}
>> +
>> +static int ads1262_populate_scales_resistance(struct ads1262 *st,
>> + const struct iio_chan_spec *spec)
>> +{
>> + struct ads1262_channel *chan = &st->channels[spec->scan_index];
>> + u32 full_scale;
>> +
>> + if (WARN_ON(!ads1262_ref_is_external(chan->ref_p, chan->ref_n)))
>> + return -EINVAL;
>
> WARN_ON() is a bit strong for something that is coming from the devicetree.
> I would just fail the parse() function with an appropriate error message
> so that we don't have to check here.
Actually, an IIO_RESISTANCE channel without external reference is just a
bug and would read past the end of buffer below, which is the only
reason I verify it one last time. We should never actually hit this
warning. I'll add a comment explaining that.
>
>> +
>> + full_scale = st->rref_ohms[chan->ref_p - 1][chan->ref_n - 1];
>> +
>> + chan->num_scales = ARRAY_SIZE(chan->scales);
>> +
>> + ads1262_calculate_scales(chan->scales, chan->num_scales, full_scale,
>> + PICO, ADS1262_ADC1_RESOLUTION);
>> +
>> + return 0;
>> +}
--
Thanks,
~ Kurt
next prev parent reply other threads:[~2026-08-09 8:28 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 3:58 [PATCH v3 0/9] iio: adc: Add TI ADS126X ADC family support Kurt Borja
2026-08-08 3:58 ` [PATCH v3 1/9] dt-bindings: iio: adc: support the TI ADS126x ADC family Kurt Borja
2026-08-08 4:08 ` sashiko-bot
2026-08-08 18:38 ` David Lechner
2026-08-09 8:26 ` Kurt Borja
2026-08-08 3:58 ` [PATCH v3 2/9] iio: adc: add the ti-ads1262 driver Kurt Borja
2026-08-08 4:11 ` sashiko-bot
2026-08-08 18:39 ` David Lechner
2026-08-09 8:26 ` Kurt Borja
2026-08-08 22:28 ` Uwe Kleine-König
2026-08-09 16:24 ` Kurt Borja
2026-08-08 3:58 ` [PATCH v3 3/9] iio: adc: ti-ads1262: support per-channel sampling frequency Kurt Borja
2026-08-08 4:11 ` sashiko-bot
2026-08-08 18:39 ` David Lechner
2026-08-09 8:27 ` Kurt Borja
2026-08-08 3:58 ` [PATCH v3 4/9] iio: adc: ti-ads1262: support per-channel reference and gain Kurt Borja
2026-08-08 18:39 ` David Lechner
2026-08-09 8:28 ` Kurt Borja [this message]
2026-08-08 3:58 ` [PATCH v3 5/9] iio: adc: ti-ads1262: support input chopping Kurt Borja
2026-08-08 18:39 ` David Lechner
2026-08-08 3:58 ` [PATCH v3 6/9] iio: adc: ti-ads1262: support excitation currents Kurt Borja
2026-08-08 4:13 ` sashiko-bot
2026-08-08 18:39 ` David Lechner
2026-08-08 3:58 ` [PATCH v3 7/9] iio: adc: ti-ads1262: support triggered buffer sampling Kurt Borja
2026-08-08 4:09 ` sashiko-bot
2026-08-08 18:39 ` David Lechner
2026-08-09 8:28 ` Kurt Borja
2026-08-08 3:58 ` [PATCH v3 8/9] iio: adc: ti-ads1262: support REFOUT and VBIAS regulators Kurt Borja
2026-08-08 4:11 ` sashiko-bot
2026-08-08 18:40 ` David Lechner
2026-08-09 8:28 ` Kurt Borja
2026-08-08 3:58 ` [PATCH v3 9/9] iio: adc: ti-ads1262: support common mode supplies Kurt Borja
2026-08-08 18:40 ` David Lechner
2026-08-09 8:29 ` Kurt Borja
2026-08-08 18:37 ` [PATCH v3 0/9] iio: adc: Add TI ADS126X ADC family support David Lechner
2026-08-09 8:29 ` 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=DKK9RQR8LIQ5.2SWUEDKZTT98P@gmail.com \
--to=kuurtb@gmail.com \
--cc=andy@kernel.org \
--cc=brgl@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=linusw@kernel.org \
--cc=linux-gpio@vger.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