From: Jonathan Cameron <jic23@kernel.org>
To: Rodrigo Alencar via B4 Relay
<devnull+rodrigo.alencar.analog.com@kernel.org>
Cc: rodrigo.alencar@analog.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org,
Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH v6 10/16] iio: frequency: ad9910: add basic parallel port support
Date: Fri, 3 Jul 2026 03:57:10 +0100 [thread overview]
Message-ID: <20260703035710.08af256a@jic23-huawei> (raw)
In-Reply-To: <20260618-ad9910-iio-driver-v6-10-79125ffbe430@analog.com>
On Thu, 18 Jun 2026 14:27:26 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:
> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
>
> Add parallel port support with amplitude, phase and frequency channels.
> Those will be buffered capable channels, but only basic control of offset
> and scale are implemented at this point. There are separate amplitude
> and phase control for polar destination, which will provide different scan
> types. Enabling and disabling of parallel mode will be implemented with
> buffer setup ops or with update_scan_mode() once IIO backend integration
> is in place.
>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Hi Rodrigo
Just a couple of comments on perhaps pushing the introduction of switch
statements on chan->address to the earlier patch to improve readability
of this one. + What looks to be a duplicated range check to me.
Jonathan
> ---
> drivers/iio/frequency/ad9910.c | 187 +++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 178 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/frequency/ad9910.c b/drivers/iio/frequency/ad9910.c
> index 95b01295e4a0..262702b62738 100644
> --- a/drivers/iio/frequency/ad9910.c
> +++ b/drivers/iio/frequency/ad9910.c
...
>
> static int ad9910_read_raw(struct iio_dev *indio_dev,
> @@ -640,11 +702,60 @@ static int ad9910_read_raw(struct iio_dev *indio_dev,
> return -EINVAL;
> }
> case IIO_CHAN_INFO_SCALE:
> - tmp64 = (u64)st->data.output_current_uA *
> - AD9910_NANO_MILLIAMP_PER_MICROAMP;
> - *val = 0;
> - *val2 = tmp64 >> 14;
> - return IIO_VAL_INT_PLUS_NANO;
> + switch (chan->address) {
> + case AD9910_CHAN_IDX_PHY:
> + tmp64 = (u64)st->data.output_current_uA *
> + AD9910_NANO_MILLIAMP_PER_MICROAMP;
Similar to below - I think I'd introduce a very minimal switch
in the earlier patch to reduce churn and make this patch
a tiny bit simpler.
> + *val = 0;
> + *val2 = tmp64 >> 14;
> + return IIO_VAL_INT_PLUS_NANO;
> + case AD9910_CHAN_IDX_PARALLEL_PHASE:
> + *val = 0;
> + *val2 = AD9910_PI_NANORAD >> 15;
> + return IIO_VAL_INT_PLUS_NANO;
> + case AD9910_CHAN_IDX_PARALLEL_FREQ:
> + tmp32 = FIELD_GET(AD9910_CFR2_FM_GAIN_MSK,
> + st->reg[AD9910_REG_CFR2].val32);
> + tmp64 = st->data.sysclk_freq_hz << tmp32;
> + tmp64 = ad9910_rational_scale(tmp64, NANO, BIT_ULL(32));
> + *val = div_s64_rem(tmp64, NANO, val2);
> + return IIO_VAL_INT_PLUS_NANO;
> + case AD9910_CHAN_IDX_PARALLEL_POLAR_AMP:
> + tmp64 = (u64)st->data.output_current_uA *
> + AD9910_NANO_MILLIAMP_PER_MICROAMP;
> + *val = 0;
> + *val2 = tmp64 >> 8;
> + return IIO_VAL_INT_PLUS_NANO;
> + case AD9910_CHAN_IDX_PARALLEL_POLAR_PHASE:
> + *val = 0;
> + *val2 = AD9910_PI_NANORAD >> 7;
> + return IIO_VAL_INT_PLUS_NANO;
> + default:
> + return -EINVAL;
> + }
> + case IIO_CHAN_INFO_OFFSET:
> + switch (chan->address) {
> + case AD9910_CHAN_IDX_PARALLEL_FREQ:
> + tmp64 = (u64)st->reg[AD9910_REG_FTW].val32 * MICRO;
> + tmp64 >>= FIELD_GET(AD9910_CFR2_FM_GAIN_MSK,
> + st->reg[AD9910_REG_CFR2].val32);
> + *val = div_s64_rem(tmp64, MICRO, val2);
> + return IIO_VAL_INT_PLUS_MICRO;
> + case AD9910_CHAN_IDX_PARALLEL_POLAR_AMP:
> + tmp32 = FIELD_GET(AD9910_ASF_SCALE_FACTOR_PP_LSB_MSK,
> + st->reg[AD9910_REG_ASF].val32);
> + *val = 0;
> + *val2 = MICRO * tmp32 >> 6;
> + return IIO_VAL_INT_PLUS_MICRO;
> + case AD9910_CHAN_IDX_PARALLEL_POLAR_PHASE:
> + tmp32 = FIELD_GET(AD9910_POW_PP_LSB_MSK,
> + st->reg[AD9910_REG_POW].val16);
> + *val = 0;
> + *val2 = MICRO * tmp32 >> 8;
> + return IIO_VAL_INT_PLUS_MICRO;
> + default:
> + return -EINVAL;
> + }
> default:
> return -EINVAL;
> }
> @@ -737,12 +848,63 @@ static int ad9910_write_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_SAMP_FREQ:
> return ad9910_set_sysclk_freq(st, val, true);
> case IIO_CHAN_INFO_SCALE:
> - if (val != 0 || val2 < 0)
> + switch (chan->address) {
> + case AD9910_CHAN_IDX_PHY:
Perhaps it's worth adding the switch in the earlier patch
(with just this and default) so that we get a nicer
diff here?
> + if (val != 0 || val2 < 0)
> + return -EINVAL;
> +
> + tmp32 = DIV_U64_ROUND_CLOSEST((u64)val2 << 14,
> + AD9910_NANO_MILLIAMP_PER_MICROAMP);
> + return ad9910_set_dac_current(st, tmp32, true);
> + case AD9910_CHAN_IDX_PARALLEL_FREQ:
> + if (val < 0 || val2 < 0)
> + return -EINVAL;
> +
> + tmp64 = ad9910_rational_scale((u64)val * NANO + val2, BIT_ULL(32),
> + (u64)st->data.sysclk_freq_hz * NANO);
> + tmp64 = roundup_pow_of_two(max(tmp64, 1ULL));
> + tmp32 = min_t(u32, ilog2(tmp64), FIELD_MAX(AD9910_CFR2_FM_GAIN_MSK));
> + tmp32 = FIELD_PREP(AD9910_CFR2_FM_GAIN_MSK, tmp32);
> + return ad9910_reg32_update(st, AD9910_REG_CFR2,
> + AD9910_CFR2_FM_GAIN_MSK,
> + tmp32, true);
> + default:
> + return -EINVAL;
> + }
> + case IIO_CHAN_INFO_OFFSET:
> + if (val < 0 || val2 < 0)
This is the check I mention below as being duplicated (val2 < 0 part)
> return -EINVAL;
>
> - tmp32 = DIV_U64_ROUND_CLOSEST((u64)val2 << 14,
> - AD9910_NANO_MILLIAMP_PER_MICROAMP);
> - return ad9910_set_dac_current(st, tmp32, true);
> + switch (chan->address) {
> + case AD9910_CHAN_IDX_PARALLEL_FREQ:
> + tmp64 = (u64)val * MICRO + val2;
> + tmp64 <<= FIELD_GET(AD9910_CFR2_FM_GAIN_MSK,
> + st->reg[AD9910_REG_CFR2].val32);
> + tmp64 = min_t(u64, DIV_U64_ROUND_CLOSEST(tmp64, MICRO),
> + U32_MAX);
> + return ad9910_reg32_write(st, AD9910_REG_FTW, tmp64, true);
> + case AD9910_CHAN_IDX_PARALLEL_POLAR_AMP:
> + if (val != 0 || val2 < 0)
Isn't val2 < 0 rejected already above?
> + return -EINVAL;
> + tmp32 = DIV_U64_ROUND_CLOSEST((u64)val2 << 6, MICRO);
> + tmp32 = min(tmp32, AD9910_ASF_PP_LSB_MAX);
> + tmp32 = FIELD_PREP(AD9910_ASF_SCALE_FACTOR_PP_LSB_MSK, tmp32);
> + return ad9910_reg32_update(st, AD9910_REG_ASF,
> + AD9910_ASF_SCALE_FACTOR_PP_LSB_MSK,
> + tmp32, true);
> + case AD9910_CHAN_IDX_PARALLEL_POLAR_PHASE:
> + if (val != 0 || val2 < 0)
> + return -EINVAL;
> +
> + tmp32 = DIV_U64_ROUND_CLOSEST((u64)val2 << 8, MICRO);
> + tmp32 = min(tmp32, AD9910_POW_PP_LSB_MAX);
> + tmp32 = FIELD_PREP(AD9910_POW_PP_LSB_MSK, tmp32);
> + return ad9910_reg16_update(st, AD9910_REG_POW,
> + AD9910_POW_PP_LSB_MSK,
> + tmp32, true);
> + default:
> + return -EINVAL;
> + }
> default:
> return -EINVAL;
> }
next prev parent reply other threads:[~2026-07-03 2:57 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 13:27 [PATCH v6 00/16] AD9910 Direct Digital Synthesizer Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:27 ` [PATCH v6 01/16] iio: ABI: add attributes for altcurrent channels Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-07-03 1:17 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 02/16] iio: ABI: scale and offset for frequency/phase channels Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:27 ` [PATCH v6 03/16] iio: ABI: add parent entry for iio channels Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-07-03 1:18 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 04/16] iio: add IIO_FREQUENCY channel type Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:27 ` [PATCH v6 05/16] iio: core: support 64-bit register through debugfs Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 14:45 ` Nuno Sá
2026-07-03 1:21 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 06/16] iio: core: create local __iio_chan_prefix_emit() for reuse Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 15:06 ` Nuno Sá
2026-06-18 16:14 ` Rodrigo Alencar
2026-06-18 18:14 ` Andy Shevchenko
2026-06-19 7:43 ` Rodrigo Alencar
2026-06-19 9:20 ` Nuno Sá
2026-06-19 9:19 ` Nuno Sá
2026-06-19 9:16 ` Nuno Sá
2026-07-03 1:08 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 07/16] iio: core: add hierarchical channel relationships Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:33 ` sashiko-bot
2026-07-03 1:33 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 08/16] dt-bindings: iio: frequency: add ad9910 Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:35 ` sashiko-bot
2026-06-30 14:02 ` Rob Herring
2026-07-03 1:13 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 09/16] iio: frequency: ad9910: initial driver implementation Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:37 ` sashiko-bot
2026-07-03 2:13 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 10/16] iio: frequency: ad9910: add basic parallel port support Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:41 ` sashiko-bot
2026-07-03 2:57 ` Jonathan Cameron [this message]
2026-06-18 13:27 ` [PATCH v6 11/16] iio: frequency: ad9910: add digital ramp generator support Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:42 ` sashiko-bot
2026-07-03 3:01 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 12/16] iio: frequency: ad9910: add RAM mode support Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:43 ` sashiko-bot
2026-07-03 3:05 ` Jonathan Cameron
2026-07-03 14:09 ` Nuno Sá
2026-07-04 16:50 ` David Lechner
2026-07-04 22:55 ` Jonathan Cameron
2026-07-06 9:47 ` Nuno Sá
2026-07-06 14:10 ` David Lechner
2026-07-07 10:53 ` Nuno Sá
2026-06-18 13:27 ` [PATCH v6 13/16] iio: frequency: ad9910: add output shift keying support Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-07-03 18:09 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 14/16] iio: frequency: ad9910: show channel priority in debugfs Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:45 ` sashiko-bot
2026-06-18 13:27 ` [PATCH v6 15/16] iio: ABI: add docs for ad9910 sysfs entries Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-06-18 13:44 ` sashiko-bot
2026-07-03 18:13 ` Jonathan Cameron
2026-06-18 13:27 ` [PATCH v6 16/16] docs: iio: add documentation for ad9910 driver Rodrigo Alencar
2026-06-18 13:27 ` Rodrigo Alencar via B4 Relay
2026-07-03 18:30 ` Jonathan Cameron
2026-07-06 14:23 ` Rodrigo Alencar
2026-07-06 15:51 ` 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=20260703035710.08af256a@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=devnull+rodrigo.alencar.analog.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=rodrigo.alencar@analog.com \
--cc=skhan@linuxfoundation.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 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.