Re: [PATCH v3 3/4] iio: dac: ad3530r: parameterize DAC resolution

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-devicetree,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 Mon, Aug 17, 2026 at 02:37:13PM +0800, Kim Seer Paller wrote:
> In preparation for adding the AD5710R/AD5711R, which support selectable
> 12-/16-bit resolution, add a per-chip resolution field and use it in the
> raw read/write and scale paths instead of assuming 16 bits. Drop
> AD3530R_REG_VAL_MASK and AD3530R_DAC_MAX_VAL, which hardcoded the 16-bit
> width and are now unused.

...

>  	case IIO_CHAN_INFO_RAW:
> -		if (val < 0 || val > AD3530R_DAC_MAX_VAL)
> +		if (val < 0 || val > (1 << st->chip_info->resolution) - 1)

		if (val < 0 || val > (BIT(st->chip_info->resolution) - 1))

OR

		if (val < 0 || val > GENMASK(st->chip_info->resolution - 1, 0))

One (GENMASK) works for 32, another (BIT) for 0. While it's tempting to use
BIT() for readability, the 0 is unlikely is correct, but 32 might be.

>  			return -EINVAL;

-- 
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.