From: David Lechner <dlechner@baylibre.com>
To: rodrigo.alencar@analog.com, linux-kernel@vger.kernel.org,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Cc: Michael Hennerich <Michael.Hennerich@analog.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Jonathan Cameron <jic23@kernel.org>,
Andy Shevchenko <andy@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Subject: Re: [PATCH v2 4/6] iio: amplifiers: ad8366: add device tree support
Date: Sat, 31 Jan 2026 15:18:30 -0600 [thread overview]
Message-ID: <0e2c7eea-76d9-4e54-af08-0affcbbe0333@baylibre.com> (raw)
In-Reply-To: <20260126-iio-ad8366-update-v2-4-c9a4d31aeb01@analog.com>
On 1/26/26 7:51 AM, Rodrigo Alencar via B4 Relay wrote:
> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
>
> Add device-tree support by dropping the enum ID in favor of extended
> chip info table, containing:
> - gain_step, indicating with sign the start of the code range;
> - num_channels, to indicate the number IIO channels;
> - pack_code() function to describe how SPI buffer is populated;
>
> With this, switch cases on the device type were dropped:
> - probe() function adjusted accordingly;
> - Simplified read_raw() and write_raw() callbacks;
> - mutex_lock()/mutex_unlock() replaced for guard(mutex)() to allow
> moving to early returns;
>
...
> +static size_t simple_pack_code(struct ad8366_state *st)
This name is a bit generic. I would call it e.g. hmc792_pack_code()
so that it clearly belongs to this driver.
Or drop this function and make the logic elsewhere:
if (info->pack_code)
return info->pack_code(st);
st->data[0] = st->ch[0];
return 1;
Then the info struct definitions would be less verbose.
> +{
> + st->data[0] = st->ch[0];
> + return 1;
> +}
> +
...
> static int ad8366_probe(struct spi_device *spi)
> {
> struct device *dev = &spi->dev;
> @@ -264,35 +221,22 @@ static int ad8366_probe(struct spi_device *spi)
> return ret;
>
> st->spi = spi;
> - st->type = spi_get_device_id(spi)->driver_data;
> + st->info = spi_get_device_match_data(spi);
> + if (!st->info)
> + return dev_err_probe(dev, -EINVAL, "Invalid device info\n");
>
> - switch (st->type) {
> - case ID_AD8366:
> - indio_dev->channels = ad8366_channels;
> - indio_dev->num_channels = ARRAY_SIZE(ad8366_channels);
> - break;
> - case ID_ADA4961:
> - case ID_ADL5240:
> - case ID_HMC792:
> - case ID_HMC1119:
> - st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> - if (IS_ERR(st->reset_gpio))
> - return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
> - "Failed to get reset GPIO\n");
As a precursor cleanup, st->reset_gpio can be removed and turned into a
local variable. It isn't used anywhere else.
Also, this could use a comment to explain that previously the driver
specifically had the reset gpio for some chips that don't actually
have a reset pin. It could have been wired up to the power/enable pin
instead, so some users might be relying on this to turn the chip on
rather than reset it.
> + st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> + if (IS_ERR(st->reset_gpio))
> + return dev_err_probe(dev, PTR_ERR(st->reset_gpio),
> + "Failed to get reset GPIO\n");
>
> - indio_dev->channels = ada4961_channels;
> - indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
> - break;
> - default:
> - return dev_err_probe(dev, -EINVAL, "Invalid device ID\n");
> - }
> -
> - st->info = &ad8366_infos[st->type];
> indio_dev->name = spi_get_device_id(spi)->name;
> indio_dev->info = &ad8366_info;
> indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = ad8366_channels;
> + indio_dev->num_channels = st->info->num_channels;
>
> - ret = ad8366_write(indio_dev, 0, 0);
> + ret = ad8366_write_code(st);
> if (ret < 0)
> return dev_err_probe(dev, ret, "failed to write initial gain\n");
>
next prev parent reply other threads:[~2026-01-31 21:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-26 13:51 [PATCH v2 0/6] iio: amplifiers: ad8366: driver update and dt support Rodrigo Alencar via B4 Relay
2026-01-26 13:51 ` [PATCH v2 1/6] MAINTAINERS: Add missing maintainer entry for AD8366 driver Rodrigo Alencar via B4 Relay
2026-01-26 13:51 ` [PATCH v2 2/6] dt-bindings: iio: amplifiers: Add AD8366 support Rodrigo Alencar via B4 Relay
2026-01-26 20:11 ` Conor Dooley
2026-01-27 11:37 ` Rodrigo Alencar
2026-01-27 19:38 ` Conor Dooley
2026-01-28 9:39 ` Rodrigo Alencar
2026-01-28 14:43 ` Conor Dooley
2026-01-31 20:55 ` David Lechner
2026-01-26 13:51 ` [PATCH v2 3/6] iio: amplifiers: ad8366: refactor device resource management Rodrigo Alencar via B4 Relay
2026-01-27 21:12 ` Andy Shevchenko
2026-01-28 9:31 ` Rodrigo Alencar
2026-01-29 18:40 ` Jonathan Cameron
2026-01-26 13:51 ` [PATCH v2 4/6] iio: amplifiers: ad8366: add device tree support Rodrigo Alencar via B4 Relay
2026-01-27 21:21 ` Andy Shevchenko
2026-01-28 9:55 ` Rodrigo Alencar
2026-01-28 10:09 ` Andy Shevchenko
2026-01-28 10:23 ` Rodrigo Alencar
2026-01-28 12:39 ` Andy Shevchenko
2026-01-31 21:18 ` David Lechner [this message]
2026-01-26 13:51 ` [PATCH v2 5/6] iio: amplifiers: ad8366: consume enable gpio Rodrigo Alencar via B4 Relay
2026-01-31 21:19 ` David Lechner
2026-01-26 13:51 ` [PATCH v2 6/6] iio: amplifiers: ad8366: Update device support Rodrigo Alencar via B4 Relay
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=0e2c7eea-76d9-4e54-af08-0affcbbe0333@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=rodrigo.alencar@analog.com \
/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