From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt@analog.com>,
devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v1 5/5] iio: adc: Add support for ADA4355 and similar ADCs
Date: Wed, 18 Nov 2026 13:27:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-221011@kernel.org> (raw)
In-Reply-To: <2f5e83aa17aea08bbff69ca6ef7d32b11368f518.1795003864.git.marcelo.schmitt@analog.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] iio: adc: ada4355: backend channel 0 left disabled after
calibration
- [High] iio: adc: ada4355: 1000x scale error in ada4355_fill_scale_tb()
- [Medium] iio: adc: ada4355: negative sampling freq wraps in
ada4355_write_raw()
- [Medium] iio: adc: ada4355: missing cleanup on error in
ada4355_calibrate()
- [Medium] iio: adc: ada4355: power supply regulators not enabled in
ada4355_probe()
- [Low] iio: adc: ada4355: inconsistent st->lock usage in read and
debugfs paths
--
commit 3d8753d370ebe3f8cd0cc6198719fc1f9fb5fb1d
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>
iio: adc: Add support for ADA4355 and similar ADCs
This commit adds an IIO ADC driver for the Analog Devices ADA4355 and
ADA4356 current-input ADCs, using SPI for configuration and an IIO backend
for LVDS data capture.
> diff --git a/drivers/iio/adc/ada4355.c b/drivers/iio/adc/ada4355.c
> new file mode 100644
> index 0000000000000..7f9f58a143856
> --- /dev/null
> +++ b/drivers/iio/adc/ada4355.c
[ ... ]
> +/* ADC differential input span, ±1 V with the 1 V internal reference. */
> +#define ADA4355_ADC_SPAN_mV 2000
> +/* ADC differential input with no input current flowing. */
> +#define ADA4355_ADC_BIAS_mV 825
> +
> +#define ADA4355_NUM_GSEL_GPIOS 2
> +
> +enum ada4355_tz_options {
> + ADA4355_TZ0,
> + ADA4355_TZ1,
> + ADA4355_TZ2,
> +};
> +
> +static const unsigned int ada4355_tz_options_ohms[] = {
> + [ADA4355_TZ1] = 2000, /* -80 to +800 uA input range */
> + [ADA4355_TZ2] = 20000, /* -8.0 to +80 uA input range */
> + [ADA4355_TZ0] = 200000, /* -0.8 to +8.0 uA input range */
> +};
[ ... ]
> +static int ada4355_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg,
> + unsigned int writeval, unsigned int *readval)
> +{
> + struct ada4355_state *st = iio_priv(indio_dev);
> +
> + if (readval)
> + return regmap_read(st->regmap, reg, readval);
> +
> + return regmap_write(st->regmap, reg, writeval);
> +}
> +
> +/*
> + * The ADC output code decreases as the input current increases so the scale to
> + * milliamps is sign reversed.
> + */
> +static void ada4355_fill_scale_tb(struct ada4355_state *st,
> + struct ada4355_chip_info const *chip_info)
> +{
> + u64 numerator, denominator;
> + u32 rem;
> +
> + st->scale_tb_size = chip_info->gain_options_size;
> + for (unsigned int i = 0; i < st->scale_tb_size; i++) {
> + numerator = (u64)ADA4355_ADC_SPAN_mV * NANO * MILLI;
> + denominator = BIT_ULL(st->chan->scan_type.realbits) * chip_info->gain_options[i];
> + numerator = div64_u64(numerator, denominator);
> + st->scale_tb[i][0] = div_u64_rem(numerator, NANO, &rem);
> + st->scale_tb[i][1] = -(int)rem;
> + }
> +}
[Severity: High]
Does multiplying ADA4355_ADC_SPAN_mV by MILLI here make st->scale_tb[][]
1000 times too large?
ADA4355_ADC_SPAN_mV is already in millivolts (2000 mV) and
chip_info->gain_options[i] is in Ohms, so dividing ADA4355_ADC_SPAN_mV by
gain_options[i] directly gives the full-scale current in milliamps. The
extra MILLI factor reports microamps per LSB instead of milliamps per LSB
(for example, -0.061035156 mA/LSB instead of -0.000061035 mA/LSB at 2000
Ohms).
> +
> +static int ada4355_get_scale(struct ada4355_state *st, int *val, int *val2)
> +{
> + *val = st->scale_tb[st->scale_idx][0];
> + *val2 = st->scale_tb[st->scale_idx][1];
> +
> + return IIO_VAL_INT_PLUS_NANO;
> +}
> +
> +static int ada4355_set_scale(struct ada4355_state *st, int val, int val2)
> +{
> + unsigned long gsel;
> + int ret;
> +
> + guard(mutex)(&st->lock);
[Severity: Low]
Should ada4355_get_scale() and ada4355_debugfs_reg_access() also take
st->lock?
ada4355_set_scale() and ada4355_update_clock() both run under
IIO_DEV_ACQUIRE_DIRECT_MODE() in ada4355_write_raw() and take st->lock,
whereas ada4355_get_scale() reads st->scale_idx twice without st->lock and
ada4355_debugfs_reg_access() accesses st->regmap without serializing
against the multi-register reset and calibration sequences in
ada4355_update_clock().
[ ... ]
> +static int ada4355_calibrate_prepare(struct ada4355_state *st)
> +{
[ ... ]
> + return iio_backend_chan_enable(st->back, 0);
> +}
> +
> +static int ada4355_calibrate_stop(struct ada4355_state *st)
> +{
> + int ret;
> +
> + ret = iio_backend_calibration_source_set(st->back,
> + IIO_BACKEND_CALIB_SOURCE_NONE,
> + 0);
> + if (ret)
> + return ret;
> +
> + ret = iio_backend_chan_disable(st->back, 0);
> + if (ret)
> + return ret;
> +
> + return ada4355_testmode_set(st, ADA4355_TEST_MODE_OFF);
> +}
[Severity: High]
Does disabling backend channel 0 in ada4355_calibrate_stop() leave the
channel disabled during buffered captures?
Nothing else in the driver calls iio_backend_chan_enable(st->back, 0):
ada4355_iio_info does not implement update_scan_mode and no buffer setup
ops are registered. Once ada4355_calibrate_stop() disables channel 0 (or
if the backend does not set IIO_BACKEND_CAP_CALIBRATION and skips
ada4355_calibrate() altogether), backend channel 0 stays disabled when
userspace starts a buffered capture.
[ ... ]
> +static int ada4355_calibrate(struct ada4355_state *st)
> +{
> + unsigned int lane;
> + int ret;
> +
> + /* all points invalid */
> + bitmap_fill(st->calib_map, st->calib_map_size);
> +
> + ret = ada4355_calibrate_prepare(st);
> + if (ret)
> + return ret;
> +
> + /*
> + * The frame signal has to be aligned first: the pattern match block
> + * only reports meaningful per-lane errors once the word boundary is
> + * known.
> + */
> + ret = ada4355_calibrate_lane(st, IIO_BACKEND_CALIB_SOURCE_FRAME,
> + ADA4355_FRAME_LANE,
> + ADA4355_MAX_DATA_LANES * ADA4355_MAX_TEST_POINTS);
> + if (ret)
> + return ret;
> +
> + for (lane = 0; lane < ADA4355_MAX_DATA_LANES; lane++) {\
> + ret = ada4355_calibrate_lane(st,
> + IIO_BACKEND_CALIB_SOURCE_DATA_LANE,
> + lane,
> + lane * ADA4355_MAX_TEST_POINTS);
> + if (ret)
> + return ret;
> + }
> +
> + return ada4355_calibrate_stop(st);
> +}
[Severity: Medium]
If ada4355_calibrate_lane() fails during a runtime clock update in
ada4355_update_clock(), does returning early here leave the ADC in
ADA4355_TEST_MODE_USER and the backend calibration source enabled?
[ ... ]
> +static int ada4355_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + struct ada4355_state *st = iio_priv(indio_dev);
> + long r_clk;
> +
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
> + return -EBUSY;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + r_clk = clk_round_rate(st->clk, val);
> + if (!in_range(r_clk, 1, ADA4355_MAX_SAMP_RATE_SPS))
> + return -ERANGE;
> +
> + return ada4355_update_clock(st, r_clk);
[Severity: Medium]
Can a negative or zero val in ada4355_write_raw() reprogram the clock
instead of returning an error?
clk_round_rate() takes an unsigned long rate, so a negative val sign-extends
to a large unsigned value and rounds down to the clock provider's maximum
rate (and 0 rounds up to its minimum rate). If that rounded rate falls
within [1, ADA4355_MAX_SAMP_RATE_SPS], ada4355_update_clock() applies it.
[ ... ]
> + st->clk = devm_clk_get_enabled(dev, NULL);
> + if (IS_ERR(st->clk))
> + return PTR_ERR(st->clk);
> +
> + indio_dev->name = chip_info->name;
> + indio_dev->channels = &ada4355_channel;
> + indio_dev->num_channels = 1;
> + indio_dev->info = &ada4355_iio_info;
> + st->chan = &ada4355_channel;
> +
> + ret = ada4355_setup(st, chip_info);
[Severity: Medium]
Should ada4355_probe() enable the vcc-supply, vea-supply, and ved-supply
regulators before accessing the device in ada4355_setup()?
The DT binding in Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
requires vcc-supply and lists vea-supply and ved-supply as optional
supplies, but the driver never requests or enables them, leaving the chip
unpowered on boards where those regulators are not always-on.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795003864.git.marcelo.schmitt@analog.com?part=5
next prev parent reply other threads:[~2026-11-18 13:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 13:02 [PATCH v1 0/5] Add support for ADA4355 Marcelo Schmitt
2026-11-18 13:03 ` [PATCH v1 1/5] iio: backend: Add calibration source interface Marcelo Schmitt
2026-11-19 2:57 ` Jonathan Cameron
2026-11-19 20:33 ` Marcelo Schmitt
2026-11-18 13:03 ` [PATCH v1 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE Marcelo Schmitt
2026-11-18 17:38 ` Conor Dooley
2026-11-18 13:03 ` [PATCH v1 3/5] iio: adc: adi-axi-adc: Support AXI ADA4355 IP core Marcelo Schmitt
2026-11-18 13:04 ` [PATCH v1 4/5] dt-bindings: iio: adc: Add ADA4355 Marcelo Schmitt
2026-11-18 17:39 ` Conor Dooley
2026-11-19 2:59 ` Jonathan Cameron
2026-11-19 14:53 ` Marcelo Schmitt
2026-11-18 13:04 ` [PATCH v1 5/5] iio: adc: Add support for ADA4355 and similar ADCs Marcelo Schmitt
2026-11-18 13:27 ` sashiko-bot [this message]
2026-11-19 3:16 ` 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=sashiko-outbox-221011@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=marcelo.schmitt@analog.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.