devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Antoniu Miclaus <antoniu.miclaus@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] iio: amplifiers: adl8113: add driver support
Date: Sat, 6 Dec 2025 19:03:32 +0000	[thread overview]
Message-ID: <20251206190332.53874d41@jic23-huawei> (raw)
In-Reply-To: <20251205144058.1918-3-antoniu.miclaus@analog.com>

On Fri, 5 Dec 2025 16:40:41 +0200
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:

> Add support for adl8113 10MHz to 12GHz Low Noise Amplifier with
> 10MHz to 14GHz bypass switches.
> 
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> ---
Hi Antoniu,

> no changes in v6.
Given I assume you just missed Andy's prior review I'll take
a look at this version with assumption both sets of comments will be
sorted for v7.

A few things inline.

> diff --git a/drivers/iio/amplifiers/adl8113.c b/drivers/iio/amplifiers/adl8113.c
> new file mode 100644
> index 000000000000..eed5fe69280b
> --- /dev/null
> +++ b/drivers/iio/amplifiers/adl8113.c

> +struct adl8113_gain_config {
> +	enum adl8113_signal_path path;
> +	int gain_db;
> +	int va;
> +	int vb;

What are va and vb for?  Currently seem unused because you derive
them from path at use point.

> +};



> +
> +static const struct iio_info adl8113_info = {
> +	.read_raw = adl8113_read_raw,
> +	.write_raw = adl8113_write_raw,
> +};
> +
> +static int adl8113_init_gain_configs(struct device *dev, struct adl8113_state *st)
> +{
> +	int external_a_gain, external_b_gain, i = 0, j;

Preference for not hiding initializations in a list where only one is initialized.

	int external_a_gain, external_b_gain, j;
	int i = 0;

makes it easier to spot.

> +
> +	/*
> +	 * Allocate for all 4 possible paths:
> +	 * - Internal amp and bypass (always present)
> +	 * - External bypass A and B (optional, or INT_MIN for testing)
> +	 */
> +	st->gain_configs = devm_kcalloc(dev, 4,
> +					sizeof(*st->gain_configs), GFP_KERNEL);

Slightly odd wrap. I'd move the sizeof() up a line.

> +	if (!st->gain_configs)
> +		return -ENOMEM;
> +
> +	/* Always include internal amplifier (14dB) */
> +	st->gain_configs[i].path = ADL8113_INTERNAL_AMP;
> +	st->gain_configs[i].gain_db = 14;

Could do this as something like:

	st->gain_configs[i++] = (struct adl8113_gain_config) {
		.path = ADL8113_INTERNAL_AMP,
		.gain_db = 14,
	};

	st->gain_configs[i++] = (struct adl8113_gain_config) {
		.path = ADL8113_INTERNAL_BYPASS,
		.gain_db = -2,
	};

etc.

> +	i++;
> +
> +	/* Always include internal bypass (-2dB insertion loss) */
> +	st->gain_configs[i].path = ADL8113_INTERNAL_BYPASS;
> +	st->gain_configs[i].gain_db = -2;
> +	i++;
> +
> +	/* Add external bypass A if configured */
> +	if (!device_property_read_u32(dev, "adi,external-bypass-a-gain-db",
> +				      &external_a_gain)) {
> +		st->gain_configs[i].path = ADL8113_EXTERNAL_A;
> +		st->gain_configs[i].gain_db = external_a_gain;
> +		i++;
> +	}
> +
> +	/* Add external bypass B if configured */
> +	if (!device_property_read_u32(dev, "adi,external-bypass-b-gain-db",
> +				      &external_b_gain)) {
> +		st->gain_configs[i].path = ADL8113_EXTERNAL_B;
> +		st->gain_configs[i].gain_db = external_b_gain;
> +		i++;
> +	}
> +
> +	/*
> +	 * If there's a free external bypass path, add one with INT_MIN gain
> +	 * to represent "nothing connected" for testing purposes

I don't follow this one.  What sort of testing purpose?  Something we want
in a real system?

> +	 */
> +	if (!device_property_present(dev, "adi,external-bypass-a-gain-db")) {
> +		st->gain_configs[i].path = ADL8113_EXTERNAL_A;
> +		st->gain_configs[i].gain_db = INT_MIN;
> +		i++;
> +	} else if (!device_property_present(dev, "adi,external-bypass-b-gain-db")) {
> +		st->gain_configs[i].path = ADL8113_EXTERNAL_B;
> +		st->gain_configs[i].gain_db = INT_MIN;
> +		i++;
> +	}
> +
> +	st->num_gain_configs = i;
> +
> +	/* Check for duplicate gain values */
> +	for (i = 0; i < st->num_gain_configs - 1; i++) {
> +		for (j = i + 1; j < st->num_gain_configs; j++) {
> +			if (st->gain_configs[i].gain_db == st->gain_configs[j].gain_db)
> +				return dev_err_probe(dev, -EINVAL,
> +						     "Duplicate gain values not allowed: %d dB\n",
> +						     st->gain_configs[i].gain_db);

What happens if we just don't bother enforcing this? I assume the second of the duplicates
can't be selected?  Do we care beyond it being silly?

> +		}
> +	}
> +
> +	return 0;
> +}

  parent reply	other threads:[~2025-12-06 19:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 14:40 [PATCH v6 0/2] iio: amplifiers: add support for ADL8113 Low Noise Amplifier Antoniu Miclaus
2025-12-05 14:40 ` [PATCH v6 1/2] dt-bindings: iio: amplifiers: add adl8113 Antoniu Miclaus
2025-12-06 18:50   ` Jonathan Cameron
2025-12-09 20:51   ` Rob Herring (Arm)
2025-12-05 14:40 ` [PATCH v6 2/2] iio: amplifiers: adl8113: add driver support Antoniu Miclaus
2025-12-05 15:10   ` Andy Shevchenko
2025-12-06 19:03   ` Jonathan Cameron [this message]
2025-12-06 20:48     ` Andy Shevchenko
2025-12-07 12:52       ` Jonathan Cameron
2025-12-12 10:41     ` Miclaus, Antoniu
2025-12-13 16:26       ` 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=20251206190332.53874d41@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --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;
as well as URLs for NNTP newsgroup(s).