Re: [PATCH v4 7/8] iio: adc: ti-ads1015: replace custom shift macros with FIELD_PREP/GET
From: Andy Shevchenko
Date: Thu Aug 27 2026 - 15:34:39 EST
On Thu, Aug 27, 2026 at 10:50:59PM +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.
...
> + cfg = FIELD_PREP(ADS1015_CFG_MUX_MASK, chan) | FIELD_PREP(ADS1015_CFG_PGA_MASK, pga) |
> + FIELD_PREP(ADS1015_CFG_DR_MASK, dr);
Indentation is broken.
...
> + cfg |= FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK,
> + data->thresh_data[chan].comp_queue) |
> + FIELD_PREP(ADS1015_CFG_COMP_MODE_MASK,
> + data->comp_mode);
Same issue here.
...
> static int ads1015_disable_event_config(struct ads1015_data *data,
> const struct iio_chan_spec *chan, int comp_mode)
> {
struct regmap *map = data->regmap;
> + unsigned int val = FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK, ADS1015_CFG_COMP_DISABLE);
Split the assignment.
> int ret;
...
> - ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG,
> - ADS1015_CFG_COMP_QUE_MASK,
> - ADS1015_CFG_COMP_DISABLE <<
> - ADS1015_CFG_COMP_QUE_SHIFT);
> + ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, ADS1015_CFG_COMP_QUE_MASK, val);
> if (ret)
> return ret;
val = FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK, ADS1015_CFG_COMP_DISABLE);
ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_COMP_QUE_MASK, val);
--
With Best Regards,
Andy Shevchenko