From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: Gabriel Shahrouzi <gshahrouzi@gmail.com>
Cc: gregkh@linuxfoundation.org, jic23@kernel.org, lars@metafoo.de,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-staging@lists.linux.dev, Michael.Hennerich@analog.com,
skhan@linuxfoundation.org,
kernelmentees@lists.linuxfoundation.org, stable@vger.kernel.org
Subject: Re: [PATCH] iio: ad5933: Correct settling cycles encoding per datasheet
Date: Sat, 19 Apr 2025 21:48:34 -0300 [thread overview]
Message-ID: <aAREYg1uAc8NSVKY@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <CAKUZ0zJoV6pLEFh6mEjz5awousn4o8Mq2D9AL8CfvqqW620X4A@mail.gmail.com>
...
> > > @@ -411,14 +417,15 @@ static ssize_t ad5933_store(struct device *dev,
> > > ret = ad5933_cmd(st, 0);
> > > break;
> > > case AD5933_OUT_SETTLING_CYCLES:
> > > - val = clamp(val, (u16)0, (u16)0x7FF);
> > > + val = clamp(val, (u16)0, (u16)AD5933_MAX_SETTLING_CYCLES);
> > > st->settling_cycles = val;
> > >
> > > - /* 2x, 4x handling, see datasheet */
> > > + /* Encode value for register: D10..D0 */
> > > + /* Datasheet Table 13: If cycles > 1022 -> val/4, set bits D10=1, D9=1 */
> > > if (val > 1022)
> > > - val = (val >> 2) | (3 << 9);
> > > - else if (val > 511)
> > > - val = (val >> 1) | BIT(9);
> > > + val = (val >> 2) | AD5933_SETTLE_MUL_4X;
> > then this would become something like
> >
> > reg_data &= ~AD5933_SETTLE_MUL_MSK;
> > reg_data |= FIELD_PREP(AD5933_SETTLE_MUL_MSK, AD5933_SETTLE_MUL_4X);
> > reg_data &= ~AD5933_SETTLING_TIME_CYCLES_MSK;
> > reg_data |= FIELD_PREP(AD5933_SETTLING_TIME_CYCLES_MSK, val >> 2);
> I currently have:
> val >>= 2;
> val |= FIELD_PREP(AD5933_SETTLING_MULTIPLIER_MASK,
> AD5933_SETTLING_MULTIPLIER_VAL_X4);
> which assumes val only has bits within a certain range which I believe
> is the case here but not completely sure. Would it be better to clear
> the bits regardless and then apply said operations?
Nah, since val is being clamped to max settling time value, I think this is good.
> > ...
> >
> > Though, I guess it would then be preferable to use masks and bitfield macros for
> > all other places where we handle register data in ad5933 driver. Probably
> > something for a different patch (if worth it).
> I separated the original fix from the refactoring so the patches stay
> modular. I can apply the use of masks and bitfield macros for other
> register data. Should the refactoring be all in one patch or spread
> across multiple?
I believe all mask/bitfield refactoring can be done in one patch.
next prev parent reply other threads:[~2025-04-20 0:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 14:22 Gabriel Shahrouzi
2025-04-18 15:37 ` Jonathan Cameron
2025-04-18 18:11 ` Gabriel Shahrouzi
2025-04-19 15:42 ` Marcelo Schmitt
2025-04-20 0:25 ` Gabriel Shahrouzi
2025-04-20 0:48 ` Marcelo Schmitt [this message]
2025-04-20 1:12 ` Gabriel Shahrouzi
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=aAREYg1uAc8NSVKY@debian-BULLSEYE-live-builder-AMD64 \
--to=marcelo.schmitt1@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=gregkh@linuxfoundation.org \
--cc=gshahrouzi@gmail.com \
--cc=jic23@kernel.org \
--cc=kernelmentees@lists.linuxfoundation.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=skhan@linuxfoundation.org \
--cc=stable@vger.kernel.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 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®