Re: [PATCH v6] iio: frequency: ad9832: Use FIELD_PREP macro to set bit fields

From: Marcelo Schmitt
Date: Sun Apr 13 2025 - 14:08:33 EST


Hi Siddharth,

Your patch looks good to me and I keep the review tag offered on the other email.
One small thing I noticed right before closing the driver. See comments below.

On 04/13, Siddharth Menon wrote:
> Use bitfield and bitmask macros to clearly specify AD9832 SPI
> command fields to make register write code more readable.
>
> Suggested-by: Marcelo Schmitt <marcelo.schmitt1@xxxxxxxxx>
> Signed-off-by: Siddharth Menon <simeddon@xxxxxxxxx>
> ---
...
> +
> + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SYNCSELSRC) |
> st->ctrl_ss);
I think st->ctrl_ss alignment with the preceding parenthesis could also have
been adjusted since the patch is updating the very same assignment.
st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SYNCSELSRC) |
st->ctrl_ss);
There are some other places where similar change could be done but these are
probably not a reason for a v7.

> ret = spi_sync(st->spi, &st->msg);
> break;
...
> - st->data = cpu_to_be16((AD9832_CMD_FPSELECT << CMD_SHIFT) |
> + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_FPSELECT) |
> st->ctrl_fp);
This one would have become
st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_FPSELECT) |
st->ctrl_fp);

> ret = spi_sync(st->spi, &st->msg);
> break;
...
> - st->data = cpu_to_be16((AD9832_CMD_FPSELECT << CMD_SHIFT) |
> + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_FPSELECT) |
> st->ctrl_fp);
Same here
> ret = spi_sync(st->spi, &st->msg);
> break;
...
>
> - st->data = cpu_to_be16((AD9832_CMD_SLEEPRESCLR << CMD_SHIFT) |
> + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SLEEPRESCLR) |
> st->ctrl_src);
ditto

> ret = spi_sync(st->spi, &st->msg);
> break;
> @@ -396,7 +400,7 @@ static int ad9832_probe(struct spi_device *spi)
> spi_message_add_tail(&st->phase_xfer[1], &st->phase_msg);
>
> st->ctrl_src = AD9832_SLEEP | AD9832_RESET | AD9832_CLR;
> - st->data = cpu_to_be16((AD9832_CMD_SLEEPRESCLR << CMD_SHIFT) |
> + st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SLEEPRESCLR) |
> st->ctrl_src);
ditto

Regards,
Marcelo