Re: [PATCH v3 3/4] iio: dac: ad3530r: parameterize DAC resolution
From: Andy Shevchenko
Date: Mon Aug 17 2026 - 07:17:31 EST
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