Re: [PATCH v3 7/8] iio: adc: ti-ads1015: replace custom shift macros with FIELD_PREP/GET

From: Andy Shevchenko

Date: Thu Aug 13 2026 - 05:12:40 EST


On Wed, Aug 12, 2026 at 10:14:32PM +0530, Archit Anant wrote:
> The driver currently uses custom _SHIFT macros and manual bitwise
> operations to read and write to the configuration register.
>
> Modernize the bitwise logic by replacing all manual shifts with the
> standard FIELD_PREP() and FIELD_GET() macros from <linux/bitfield.h>.
> This improves readability and prevents potential bitwise errors.
>
> Remove the now-unused _SHIFT macros from the top of the file.

...

> dr = data->channel_data[chan].data_rate;
> mask = ADS1015_CFG_MUX_MASK | ADS1015_CFG_PGA_MASK |
> ADS1015_CFG_DR_MASK;
> - cfg = chan << ADS1015_CFG_MUX_SHIFT | pga << ADS1015_CFG_PGA_SHIFT |
> - dr << ADS1015_CFG_DR_SHIFT;
> + cfg = FIELD_PREP(ADS1015_CFG_MUX_MASK, chan) | FIELD_PREP(ADS1015_CFG_PGA_MASK, pga) |
> + FIELD_PREP(ADS1015_CFG_DR_MASK, dr);

Wrong indentation. Please, make sure in the lines you touched the indentation
is also correct.

...

> unsigned int cfg_comp =
> - ADS1015_CFG_COMP_DISABLE << ADS1015_CFG_COMP_QUE_SHIFT |
> - 1 << ADS1015_CFG_COMP_LAT_SHIFT;
> + FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK,
> + ADS1015_CFG_COMP_DISABLE) |
> + FIELD_PREP(ADS1015_CFG_COMP_LAT_MASK, 1);

It might be better to keep a longer line.

unsigned int cfg_comp =
FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK, ADS1015_CFG_COMP_DISABLE) |
FIELD_PREP(ADS1015_CFG_COMP_LAT_MASK, 1);

--
With Best Regards,
Andy Shevchenko