devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-doc@vger.kernel.org>, <linux-spi@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <michael.hennerich@analog.com>,
	<nuno.sa@analog.com>, <eblanc@baylibre.com>,
	<dlechner@baylibre.com>, <andy@kernel.org>, <robh@kernel.org>,
	<krzk+dt@kernel.org>, <conor+dt@kernel.org>, <corbet@lwn.net>,
	<marcelo.schmitt1@gmail.com>
Subject: Re: [PATCH v3 8/8] iio: adc: ad4030: Add support for ADAQ4216 and ADAQ4224
Date: Sun, 28 Sep 2025 11:26:28 +0100	[thread overview]
Message-ID: <20250928112628.7a1357ab@jic23-huawei> (raw)
In-Reply-To: <4be3b7a31146836b35cc88005f2314cff9f3db97.1758916484.git.marcelo.schmitt@analog.com>

On Fri, 26 Sep 2025 17:41:04 -0300
Marcelo Schmitt <marcelo.schmitt@analog.com> wrote:

> ADAQ4216 and ADAQ4224 are similar to AD4030, but feature a PGA circuitry
> that scales the analog input signal prior to it reaching the ADC. The PGA
> is controlled through a pair of pins (A0 and A1) whose state define the
> gain that is applied to the input signal.
> 
> Add support for ADAQ4216 and ADAQ4224. Provide a list of PGA options
> through the IIO device channel scale available interface and enable control
> of the PGA through the channel scale interface.
> 
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>

One trivial comment + a suggestion that we might want to consider pushing
the pin strap pga support to a future patch so we can not stall the driver
on that being resolved.  Note that would mean splitting the DT patch as well.

Anyhow, no rush on that given we have lots of time in this kernel cycle.

Jonathan

> @@ -996,6 +1116,17 @@ static int ad4030_write_raw(struct iio_dev *indio_dev,
>  	return ret;
>  }

> @@ -1307,6 +1439,50 @@ static int ad4030_spi_offload_setup(struct iio_dev *indio_dev,
>  							   IIO_BUFFER_DIRECTION_IN);
>  }
>  
> +static int ad4030_setup_pga(struct device *dev, struct iio_dev *indio_dev,
> +			    struct ad4030_state *st)
> +{
> +	unsigned int i;
> +	int pga_gain_dB;
> +	int ret;
> +
> +	ret = device_property_read_u32(dev, "adi,pga-gain-db", &pga_gain_dB);

I'm not sure the pga question will resolve quickly so perhaps we initially only
support the pins connected to gpios and add the pin strapped support later?

It's early in this cycle, so we can delay that decision for a few weeks and
see where we are then on that DT question.

> +	if (ret == -EINVAL) {
> +		/* Setup GPIOs for PGA control */
> +		st->pga_gpios = devm_gpiod_get_array(dev, "pga", GPIOD_OUT_LOW);
> +		if (IS_ERR(st->pga_gpios))
> +			return dev_err_probe(dev, PTR_ERR(st->pga_gpios),
> +					     "Failed to get PGA gpios.\n");
> +
> +		if (st->pga_gpios->ndescs != ADAQ4616_PGA_PINS)
> +			return dev_err_probe(dev, -EINVAL,
> +					     "Expected 2 GPIOs for PGA control.\n");
> +
> +		st->scale_avail_size = ARRAY_SIZE(adaq4216_hw_gains_db);
> +		st->pga_index = 0;
> +		return 0;
> +	} else if (ret != 0) {

if (ret) is fairly commonly used for error checking when non 0 is what we want.

> +		return dev_err_probe(dev, ret, "Failed to get PGA value.\n");
> +	}
> +
> +	/* Set ADC driver to handle pin-strapped PGA pins setup */
> +	for (i = 0; i < ARRAY_SIZE(adaq4216_hw_gains_db); i++) {
> +		if (pga_gain_dB != adaq4216_hw_gains_db[i])
> +			continue;
> +
> +		st->pga_index = i;
> +		break;
> +	}
> +	if (i == ARRAY_SIZE(adaq4216_hw_gains_db))
> +		return dev_err_probe(dev, -EINVAL, "Invalid PGA gain: %d.\n",
> +				     pga_gain_dB);
> +
> +	st->scale_avail_size = 1;
> +	st->pga_gpios = NULL;
> +
> +	return 0;
> +}


      reply	other threads:[~2025-09-28 10:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26 20:37 [PATCH v3 0/8] Add SPI offload support to AD4030 Marcelo Schmitt
2025-09-26 20:38 ` [PATCH v3 1/8] dt-bindings: iio: adc: adi,ad4030: Reference spi-peripheral-props Marcelo Schmitt
2025-09-26 20:38 ` [PATCH v3 2/8] Docs: iio: ad4030: Add double PWM SPI offload doc Marcelo Schmitt
2025-09-26 20:39 ` [PATCH v3 3/8] dt-bindings: iio: adc: adi,ad4030: Add PWM Marcelo Schmitt
2025-09-26 20:39 ` [PATCH v3 4/8] iio: adc: ad4030: Reduce register access transfer speed Marcelo Schmitt
2025-09-28  9:53   ` Jonathan Cameron
2025-09-28 14:17     ` Marcelo Schmitt
2025-09-26 20:40 ` [PATCH v3 5/8] iio: adc: ad4030: Use BIT macro to improve code readability Marcelo Schmitt
2025-09-26 20:40 ` [PATCH v3 6/8] iio: adc: ad4030: Add SPI offload support Marcelo Schmitt
2025-09-27 12:59   ` kernel test robot
2025-09-28 10:02     ` Jonathan Cameron
2025-09-28 10:08   ` Jonathan Cameron
2025-09-26 20:40 ` [PATCH v3 7/8] dt-bindings: iio: adc: adi,ad4030: Add ADAQ4216 and ADAQ4224 Marcelo Schmitt
2025-09-26 22:10   ` Rob Herring (Arm)
2025-09-28 10:19   ` Jonathan Cameron
2025-09-29 14:31     ` Rob Herring
2025-09-29 16:16       ` David Lechner
2025-09-30 14:47         ` Marcelo Schmitt
2025-09-30 17:02           ` Marcelo Schmitt
2025-09-30 18:26         ` Rob Herring
2025-10-01 11:55           ` David Lechner
2025-09-26 20:41 ` [PATCH v3 8/8] iio: adc: ad4030: Add support for " Marcelo Schmitt
2025-09-28 10:26   ` Jonathan Cameron [this message]

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=20250928112628.7a1357ab@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eblanc@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=marcelo.schmitt@analog.com \
    --cc=michael.hennerich@analog.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;
as well as URLs for NNTP newsgroup(s).