Re: [PATCH v3] iio: frequency: ad9832: Use FIELD_PREP macro to set bit fields
From: Marcelo Schmitt
Date: Sat Mar 29 2025 - 09:41:11 EST
Hi Siddharth,
On 03/25, Siddharth Menon wrote:
> On Sat, 22 Mar 2025 at 18:50, Marcelo Schmitt
> <marcelo.schmitt1@xxxxxxxxx> wrote:
> >
> > On 03/19, Siddharth Menon wrote:
> > > Refactor code to use the FIELD_PREP macro for setting bit fields
> > > instead of manual bit manipulation.
> >
...
> I shall send in another patch addressing this.
My understanding of Jonathan's reply to this patch is that it would actually be
ok to do all MASK/FIELD_PREP/FIELD_GET cleanup in a single patch.
>
> > > - st->data = cpu_to_be16((AD9832_CMD_SYNCSELSRC << CMD_SHIFT) |
> > > + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SYNCSELSRC) |
> > > st->ctrl_ss);
> > Not sure about this assignment with mix of FIELD_PREP and non-FIELD_PREP value.
> > Maybe have
> > FIELD_PREP(AD9832_DAT_MSK, st->ctrl_ss)); ?
>
> From what I understood, I don't think that would work out. AD9832_SELSRC
> = BIT(12) but AD9832_DAT_MSK only covers bits 7 through 0 GENMASK(7, 0).
> It could exceed the maximum value allowed by the mask.
Ah yes, that's correct. I didn't look very carefully at the assignment
surroundings when replying. Sure, it would use the BIT(12) mask. So, something like
FIELD_PREP(AD9832_SELSRC, st->ctrl_ss)
>
> Thanks,
> Siddharth Menon
Regards,
Marcelo