Re: [PATCH v3 6/9] iio: adc: ti-ads1262: support excitation currents

From: Jonathan Cameron

Date: Sun Aug 16 2026 - 17:44:21 EST


On Fri, 07 Aug 2026 22:58:28 -0500
Kurt Borja <kuurtb@xxxxxxxxx> wrote:

> 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@xxxxxxxxx>
> ---
> drivers/iio/adc/ti-ads1262.c | 101 +++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 98 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads1262.c b/drivers/iio/adc/ti-ads1262.c
> index e2659941e1af..d5464b4f2bfb 100644
> --- a/drivers/iio/adc/ti-ads1262.c
> +++ b/drivers/iio/adc/ti-ads1262.c

> @@ -277,6 +282,25 @@ static const char * const ads1262_ref_sources_neg[] = {
> NULL
> };
>
> +static const u32 ads1262_idac_mags_nA[] = {
> + 0, 50000, 100000, 250000, 500000, 750000, 1000000, 1500000, 2000000,
Where we have long arrays like this a useful convention is to break them into a power
of 2 elements and provide a comment that says /* 0..7 */ etc
just to make it easier to count.

> + 2500000, 3000000
> +};
> +
> +static int ads1262_find_one(const int *array, size_t num_elements, int val)
> +{
> + int i;
> +
> + for (i = 0; i < num_elements; i++) {
> + if (val == array[i])
> + break;

Assuming this doesn't change later, an early return on match makes life simpler.
return i;

> + }

return -EINVAL;

> + if (i == num_elements)
> + return -EINVAL;
> +
> + return i;
> +}
> +