Re: [PATCH v5 02/10] iio: dac: mcp47feb02: Fix gain field initialization for active channels
From: Jonathan Cameron
Date: Sun Sep 13 2026 - 17:44:54 EST
On Wed, 9 Sep 2026 17:18:45 +0300
Ariana Lazar <ariana.lazar@xxxxxxxxxxxxx> wrote:
> As per MCP47FXBX48 Datasheet, in the format of the Gain Control and System
> Status Register each DAC channel has one bit to control its gain,
> starting at bit 8, while bits 0-7 contain status or unimplemented bits.
>
> The previous formula didn't initialize correctly all channels, being
> replaced by the already defined macro used in write operations where needed
> in the rest of the driver implementation. DAC_GAIN_MASK(i) extracts the
> gain control bit for each active channel correctly ine one step.
>
> Signed-off-by: Ariana Lazar <ariana.lazar@xxxxxxxxxxxxx>
> ---
> drivers/iio/dac/mcp47feb02.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iio/dac/mcp47feb02.c b/drivers/iio/dac/mcp47feb02.c
> index 7502959d98eab27941d58b6b961e6e3dee4222e6..bf78618ac2c896b94e494a1ce76ef5b3e520f482 100644
> --- a/drivers/iio/dac/mcp47feb02.c
> +++ b/drivers/iio/dac/mcp47feb02.c
> @@ -1017,7 +1017,6 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)
> if (ret)
> return ret;
>
> - gain_ch = gain_ch & MCP47FEB02_GAIN_BITS_MASK;
> for_each_set_bit(i, &data->active_channels_mask, data->phys_channels) {
> struct device *dev = regmap_get_device(data->regmap);
> unsigned int pd_tmp, dac_val;
> @@ -1028,7 +1027,7 @@ static int mcp47feb02_init_ctrl_regs(struct mcp47feb02_data *data)
> data->chdata[i].dac_data = dac_val;
>
> data->chdata[i].ref_mode = (vref_ch >> (2 * i)) & MCP47FEB02_DAC_CTRL_MASK;
> - data->chdata[i].use_2x_gain = (gain_ch >> i) & MCP47FEB02_GAIN_BIT_MASK;
> + data->chdata[i].use_2x_gain = (gain_ch & DAC_GAIN_MASK(i)) ? 1 : 0;
It's not a performance path (field_get() is a bit heavyweight!) so
data->chdata[i].use_2x_gain = field_get(DAC_GAIN_MASK(i), gain_ch);
is perhaps a little more readable.
I don't mind that much either way.
Jonathan
>
> /*
> * Inform the user that the current voltage reference read from the volatile
>