public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Siddharth Menon <simeddon@gmail.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-staging@lists.linux.dev, gregkh@linuxfoundation.org,
	Michael.Hennerich@analog.com, lars@metafoo.de,
	marcelo.schmitt1@gmail.com
Subject: Re: [PATCH v5] iio: frequency: ad9832: Use FIELD_PREP macro to set bit fields
Date: Sat, 12 Apr 2025 11:33:40 +0100	[thread overview]
Message-ID: <20250412113340.6934a8e0@jic23-huawei> (raw)
In-Reply-To: <CAGd6pzP470VDxGoP4e_2hVXsKrJhnhbv-WgFzCq7tMX9RjOLwg@mail.gmail.com>

On Wed, 9 Apr 2025 01:25:52 +0530
Siddharth Menon <simeddon@gmail.com> wrote:

> On Sun, 30 Mar 2025 at 19:50, Jonathan Cameron <jic23@kernel.org> wrote:
> > > +     for (int i = 0; i < ARRAY_SIZE(regval_bytes); i++) {
> > > +             freq_cmd = (i % 2 == 0) ? AD9832_CMD_FRE8BITSW : AD9832_CMD_FRE16BITSW;
> > > +
> > > +             st->freq_data[i] = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, freq_cmd) |
> > > +                     FIELD_PREP(AD9832_ADD_MSK, addr - i) |
> > > +                     FIELD_PREP(AD9832_DAT_MSK, regval_bytes[i]));  
> > Looking at the data layout here, this seems like an interesting dance to fill two unrelated
> > u8 values - it's not a be16 at all.
> >
> > I'd be tempted to split the freq_data into u8s and then you will just have
> >                 st->freq_data[i][0] = FIELD_PREP(AD9832_CMD_MSK, freq_cmd) |
> >                                       FIELD_PREP(AD9832_ADD_SMK, addr - i);
> > //with masks adjusted appropriately.
> >                 st->freq_data[i][1] = regval_bytes[i];
> >  
> 
> Hello Jonathan,
> 
> I briefly went through the datasheet for the device.
> From what I understand, the device is expecting 16 bit write operations where:
> - First 4 bits: Operation type (frequency/phase)
> - Next 4 bits: Destination register address
> - Last 8 bits: Data
> so these fields would need to be combined into a single 16-bit value regardless.

Hmm. That is really a documentation thing rather than anything real.
If they had been documented it as a control value of 8 bits and a data value of 8
bits then it would naturally map to an array.

> 
> As I am unable to procure a testing unit at this time, I’m hesitant to make
> changes that could unintentionally break the existing driver.
Sure.  It is always a bit of a risk assessment for changes like this.
I'm less nervous about breaking staging drivers than others, but we should
still do our best to not do so.  Probably not worth spinning up some emulation
for this change!

> 
> Would it be acceptable to limit the scope of this patch to introducing
> bitfield macros and addressing the remaining feedback?
Sure.  We can perhaps revisit this suggestion in a future series.

Jonathan

> 
> Regards,
> Siddharth Menon
> 


  reply	other threads:[~2025-04-12 10:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-30 13:49 [PATCH v5] iio: frequency: ad9832: Use FIELD_PREP macro to set bit fields Siddharth Menon
2025-03-30 14:20 ` Jonathan Cameron
2025-04-08 19:55   ` Siddharth Menon
2025-04-12 10:33     ` Jonathan Cameron [this message]
2025-03-30 15:44 ` Marcelo Schmitt
2025-04-01 22:15   ` Siddharth Menon
2025-04-03 16:07     ` Marcelo Schmitt

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=20250412113340.6934a8e0@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=gregkh@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=marcelo.schmitt1@gmail.com \
    --cc=simeddon@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