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

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.