Re: [PATCH v3] iio: frequency: ad9832: Use FIELD_PREP macro to set bit fields
From: Siddharth Menon
Date: Tue Mar 25 2025 - 08:06:40 EST
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.
>
> The word 'refactor' by itself isn't very appealing.
> Instead, maybe promote how the patch improves code readability saying something
> like 'Use bitfield macros to clearly specify AD9832 SPI command fields and to
> make register write code more readable.' Use that exact text if you want.
>
Thanks for the feedback, I will update the commit message.
> I think AD9832_PHASE and RES_MASK could also be declared as a mask, but maybe
> that change can be made on a separate patch.
I shall send in another patch addressing this.
> > - 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.
Thanks,
Siddharth Menon