From: Tomas Melin <tomas.melin@vaisala.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Nuno Sa <nuno.sa@analog.com>, Jonathan Cameron <jic23@kernel.org>,
David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>,
Alexandru Ardelean <alexandru.ardelean@analog.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: adc: ad9467: support write/read offset
Date: Tue, 2 Dec 2025 12:03:21 +0200 [thread overview]
Message-ID: <44a38485-ce29-45c8-8892-5000abb8d44e@vaisala.com> (raw)
In-Reply-To: <CAHp75VdaYR5S7MmVEMBH1e6g-0bQim_d7m48=X2ybpf3hBAfTA@mail.gmail.com>
Hi Andy,
On 01/12/2025 15:59, Andy Shevchenko wrote:
> On Mon, Dec 1, 2025 at 2:00 PM Tomas Melin <tomas.melin@vaisala.com> wrote:
>>
>> Support configuring output offset value. Among the devices
>> currently supported by this driver, this setting is specific to
>> ad9434.
>
> ...
>
>> +#define AD9434_CHAN(_chan, avai_mask, _si, _bits, _sign) \
>> +{ \
>> + .type = IIO_VOLTAGE, \
>> + .indexed = 1, \
>> + .channel = _chan, \
>> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
>> + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
>> + BIT(IIO_CHAN_INFO_OFFSET), \
>> + .info_mask_shared_by_type_available = avai_mask, \
>
> Okay, this macro uses parameterized avai_mask (which should be spelled
> correctly and probably in parentheses, but it's not the point) and
> it's being called only once. Why can't we just embed it for now?
Sure, I'm ok with embedding if that is preferred.
>
>
>> + .scan_index = _si, \
>> + .scan_type = { \
>> + .sign = _sign, \
>> + .realbits = _bits, \
>> + .storagebits = 16, \
>> + }, \
>> +}
>
> Also, looking at the existing macro below, I think you should have a
> common, parameterised macro and then 3 different on top of it for this
> case, and for the existing two.
>
> Does it make sense?
Keeping this and embedding the ad9434 declaration.
>
>> #define AD9467_CHAN(_chan, avai_mask, _si, _bits, _sign) \
>
> ...
>
>> static const struct iio_chan_spec ad9434_channels[] = {
>> - AD9467_CHAN(0, BIT(IIO_CHAN_INFO_SCALE), 0, 12, 's'),
>> + AD9434_CHAN(0, BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
>> + 0, 12, 's'),
>> };
>
> Also the first and third parameters are identical in all cases, can we
> for now just make them using a single parameter?
>
> ...
>
>> +static int ad9467_get_offset(struct ad9467_state *st, int *val)
>> +{
>> + *val = ad9467_spi_read(st, AN877_ADC_REG_OFFSET);
>> + if (*val < 0)
>> + return *val;
>
> The standard pattern is to avoid polluting the output in case of known
> errors. Hence
>
> int ret;
>
> ret = ad9467_spi_read(st, AN877_ADC_REG_OFFSET);
> if (ret < 0)
> return ret;
>
> *val = ret;
ok, will change to this format.
>
>> + return IIO_VAL_INT;
>> +}
>
>
> ...
>
>> + if (val < st->info->offset_range[0] || val > st->info->offset_range[2])
>> + return -EINVAL;
>
> Wondering if at some point we can switch to in_range(). And we perhaps
> need a new generic macro to supply start/end instead of start/size.
Atleast drop-in usage of in_range() does not seems feasible?
Thanks,
Tomas
>
next prev parent reply other threads:[~2025-12-02 10:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 11:59 [PATCH 0/2] iio: adc: ad9467: fixes for ad9434 Tomas Melin
2025-12-01 11:59 ` [PATCH 1/2] iio: adc: ad9467: fix ad9434 vref mask Tomas Melin
2025-12-01 13:49 ` Andy Shevchenko
2025-12-01 11:59 ` [PATCH 2/2] iio: adc: ad9467: support write/read offset Tomas Melin
2025-12-01 13:59 ` Andy Shevchenko
2025-12-02 10:03 ` Tomas Melin [this message]
2025-12-02 14:36 ` Andy Shevchenko
2025-12-01 17:40 ` David Lechner
2025-12-02 10:20 ` Tomas Melin
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=44a38485-ce29-45c8-8892-5000abb8d44e@vaisala.com \
--to=tomas.melin@vaisala.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=alexandru.ardelean@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@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
all inboxes | Powered by JetHome®