From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: Tomas Borquez <tomasborquez13@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"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>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
linux-staging@lists.linux.dev
Subject: Re: [PATCH 4/5] staging: iio: ad9832: convert to iio channels and ext_info attrs
Date: Thu, 18 Dec 2025 12:04:37 -0300 [thread overview]
Message-ID: <aUQYBdiYVy3sn0Nx@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <20251215190806.11003-5-tomasborquez13@gmail.com>
Hi Tomas,
The updates look mostly good to me. A few comments inline.
On 12/15, Tomas Borquez wrote:
> Convert ad9832 from custom sysfs attributes to standard channel interface
> using a single IIO_ALTCURRENT channel with ext_info attributes, as this
> device is a current source DAC with one output, as well as removing the
> dds.h header.
>
> Changes:
> - Add single iio_chan_spec with ext_info for frequency0/1 and phase0-3
> - Phase attributes accept radians directly, driver converts internally
> - Frequency attributes accept Hz (unchanged)
> - Cache frequency and phase values in driver state for readback
> - Remove dependency on dds.h macros
I'm not sure, was the dds stuff being used before this patch? Maybe dds.h
removal would be better as another separate clean up patch.
> - Rename symbol attributes to frequency_symbol and phase_symbol
It's nice to have a change log between patch versions. Though, it's usually
provided as part of extra patch info, not commit message.
>
> The pincontrol_en attribute is kept temporarily with a TODO noting it
> should become a DT property during staging graduation.
>
> NOTE: This changes the ABI from out_altvoltage0_* to out_altcurrent0_*
> with different attribute organization.
>
> Signed-off-by: Tomas Borquez <tomasborquez13@gmail.com>
> ---
The change log is usually provided here, below the '---'.
> drivers/staging/iio/frequency/ad9832.c | 279 +++++++++++++++++++------
> 1 file changed, 215 insertions(+), 64 deletions(-)
This patch fails to apply? I've tried getting it applied on top of current
IIO testing branch with b4 shazam, git am <individual patches>, and
git apply <patch4 on top of applied patch3>, but patch 4 fails to apply either way.
Couldn't figure out how to fix that.
>
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index 8d04f1b44f..454a317732 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
...
> +static const u32 ad9832_phase_addr[] = {
> + AD9832_PHASE0H, AD9832_PHASE1H, AD9832_PHASE2H, AD9832_PHASE3H
> +};
> +
> +static ssize_t ad9832_write_phase(struct iio_dev *indio_dev,
> + uintptr_t private,
> + struct iio_chan_spec const *chan,
> + const char *buf, size_t len)
> {
> + struct ad9832_state *st = iio_priv(indio_dev);
> u8 phase_bytes[2];
> u16 phase_cmd;
> + u32 phase_urad, phase;
> + int val, val2, ret;
>
> - if (phase >= BIT(AD9832_PHASE_BITS))
> + if (private >= ARRAY_SIZE(ad9832_phase_addr))
> return -EINVAL;
>
> + ret = iio_str_to_fixpoint(buf, 100000, &val, &val2);
Maybe I'm missing something but, why 100000 here? Should it be MICRO instead?
> + if (ret)
> + return ret;
> +
> + if (val < 0 || val2 < 0)
> + return -EINVAL;
> +
> + phase_urad = val * 1000000 + val2;
We can use macros to make it easier to read values that are related to metric units.
phase_urad = val * MICRO + val2;
then
#include <linux/units.h>
...
> +static ssize_t ad9832_read_phase(struct iio_dev *indio_dev,
> + uintptr_t private,
> + struct iio_chan_spec const *chan,
> + char *buf)
> +{
> + struct ad9832_state *st = iio_priv(indio_dev);
> + u32 phase_urad;
> +
> + if (private >= ARRAY_SIZE(ad9832_phase_addr))
> + return -EINVAL;
> +
> + guard(mutex)(&st->lock);
> + phase_urad = ((u64)st->phase[private] * AD9832_2PI_URAD) >> AD9832_PHASE_BITS;
> +
> + return sysfs_emit(buf, "%u.%06u\n", phase_urad / 1000000, phase_urad % 1000000);
return sysfs_emit(buf, "%u.%06u\n", phase_urad / MICRO, phase_urad % MICRO);
?
> }
>
...
> @@ -234,49 +322,110 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
> st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SLEEPRESCLR) |
> st->ctrl_src);
> ret = spi_sync(st->spi, &st->msg);
> + if (ret)
> + return ret;
> +
> + st->output_en = val;
> + break;
> + case AD9832_PINCTRL_EN:
> + if (val != 1 && val != 0)
> + return -EINVAL;
> +
> + st->ctrl_ss &= ~AD9832_SELSRC;
> + st->ctrl_ss |= FIELD_PREP(AD9832_SELSRC, val ? 0 : 1);
this would then be only
st->ctrl_ss |= FIELD_PREP(AD9832_SELSRC, val);
so we keep consistency with previous FIELD_PREP() in ad9832_store().
> +
> + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SYNCSELSRC) |
> + st->ctrl_ss);
> + ret = spi_sync(st->spi, &st->msg);
> + if (ret)
> + return ret;
> +
> + st->pinctrl_en = val;
> break;
> default:
> return -ENODEV;
> }
>
> - return ret ? ret : len;
> + return len;
> }
>
...
> +#define AD9832_CHAN_FREQ(_name, _channel) { \
> + .name = _name, \
> + .write = ad9832_write_frequency, \
> + .read = ad9832_read_frequency, \
> + .private = _channel, \
Since the DAC has only one output channel, doesn't it look somewhat misleading
to call private data _channel?
Based on data sheet naming, I'd call it _select. Maybe _fselect _psel?
> + .shared = IIO_SEPARATE, \
> +}
> +
> +#define AD9832_CHAN_PHASE(_name, _channel) { \
> + .name = _name, \
> + .write = ad9832_write_phase, \
> + .read = ad9832_read_phase, \
> + .private = _channel, \
same here
> + .shared = IIO_SEPARATE, \
> +}
> +
Best regards,
Marcelo
next prev parent reply other threads:[~2025-12-18 15:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 19:08 [PATCH 0/5] staging: ad9832: driver cleanup Tomas Borquez
2025-12-15 19:08 ` [PATCH 1/5] staging: iio: ad9832: clean up whitespace Tomas Borquez
2025-12-18 14:27 ` Marcelo Schmitt
2025-12-21 19:17 ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 2/5] staging: iio: ad9832: convert to guard(mutex) Tomas Borquez
2025-12-18 14:34 ` Marcelo Schmitt
2025-12-18 15:16 ` Tomas Borquez
2025-12-21 19:22 ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 3/5] staging: iio: ad9832: cleanup dev_err_probe() Tomas Borquez
2025-12-18 14:38 ` Marcelo Schmitt
2025-12-21 19:25 ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 4/5] staging: iio: ad9832: convert to iio channels and ext_info attrs Tomas Borquez
2025-12-18 15:04 ` Marcelo Schmitt [this message]
2025-12-18 15:46 ` Tomas Borquez
2025-12-21 19:36 ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 5/5] staging: iio: ad9832: add sysfs documentation Tomas Borquez
2025-12-18 15:10 ` Marcelo Schmitt
2025-12-21 19:43 ` 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=aUQYBdiYVy3sn0Nx@debian-BULLSEYE-live-builder-AMD64 \
--to=marcelo.schmitt1@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=nuno.sa@analog.com \
--cc=tomasborquez13@gmail.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