public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: rodrigo.alencar@analog.com
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Michael Auchter <michael.auchter@ni.com>,
	linux-hardening@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	David Lechner <dlechner@baylibre.com>,
	Andy Shevchenko <andy@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>
Subject: Re: [PATCH 11/22] iio: dac: ad5686: fix ref bit initialization for single-channel parts
Date: Wed, 22 Apr 2026 22:58:48 +0300	[thread overview]
Message-ID: <aekoeFYIUMMcKMtC@ashevche-desk.local> (raw)
In-Reply-To: <20260422-ad5313r-iio-support-v1-11-ed7dca001d1b@analog.com>

On Wed, Apr 22, 2026 at 03:45:45PM +0100, Rodrigo Alencar via B4 Relay wrote:

> For single-channel parts the control register is used to enable the
> internal voltage reference and perform powerdown control. The reference
> enable bit position was ignored when writing the register at the probe
> function. This patch adds a control_sync() function that properly consumes
> the mask definitions with FIELD_PREP(). As further cleanup, the created
> functions and definitions are also used in ad5686_write_dac_powerdown().
> Some local variables ended up being unused (so removed) and
> st->use_internal_vref is initialized earlier in probe.

...

> +static int ad5310_control_sync(struct ad5686_state *st)
> +{
> +	unsigned int pd_val = st->pwr_down_mask & st->pwr_down_mode;
> +
> +	return st->write(st, AD5686_CMD_CONTROL_REG, 0,
> +			 FIELD_PREP(AD5310_PD_MSK, pd_val) |
> +			 FIELD_PREP(AD5310_REF_BIT_MSK, !st->use_internal_vref));

I prefer to see explicit integers in use instead of implicit boolean promotions
in FIELD_*() that might lead to subtle mistakes.

st_use_internal_vref ? 0 : 1

In the code compiler will optimise this to the current state anyway.

> +}

...

>  	switch (st->chip_info->regmap_type) {
>  	case AD5310_REGMAP:
> -		shift = 9;
> -		ref_bit_msk = AD5310_REF_BIT_MSK;
> +		ret = ad5310_control_sync(st);
>  		break;
>  	case AD5683_REGMAP:
> -		shift = 13;
> -		ref_bit_msk = AD5683_REF_BIT_MSK;
> +		ret = ad5683_control_sync(st);
>  		break;
>  	case AD5686_REGMAP:
> -		shift = 0;
> -		ref_bit_msk = 0;
>  		/* AD5674R/AD5679R have 16 channels and 2 powerdown registers */
> -		if (chan->channel > 0x7)
> +		val = st->pwr_down_mask & st->pwr_down_mode;
> +		if (chan->channel > 0x7) {
>  			address = 0x8;
> +			val = upper_16_bits(val);
> +		} else {

Would be nice to see address to be assigned here explicitly if it's a constant.

> +			val = lower_16_bits(val);
> +		}
> +		ret = st->write(st, AD5686_CMD_POWERDOWN_DAC, address, val);
>  		break;
>  	default:
>  		return -EINVAL;
>  	}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-04-22 19:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 14:45 [PATCH 00/22] Extend device support for AD5686 driver Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 01/22] dt-bindings: iio: dac: ad5696: extend device support Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 02/22] dt-bindings: iio: dac: ad5696: add reset/ldac/gain gpio support Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 03/22] dt-bindings: iio: dac: ad5696: rework on power supplies Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 04/22] dt-bindings: iio: dac: ad5686: extend device support Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 05/22] dt-bindings: iio: dac: ad5686: add reset/ldac/gain gpio support Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 06/22] dt-bindings: iio: dac: ad5686: rework on power supplies Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 07/22] iio: dac: ad5686: refactor include headers Rodrigo Alencar via B4 Relay
2026-04-22 19:43   ` Andy Shevchenko
2026-04-22 14:45 ` [PATCH 08/22] iio: dac: ad5686: remove redundant register definition Rodrigo Alencar via B4 Relay
2026-04-22 19:47   ` Andy Shevchenko
2026-04-22 14:45 ` [PATCH 09/22] iio: dac: ad5686: drop enum id Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 10/22] iio: dac: ad5686: add of_match table to the spi driver Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 11/22] iio: dac: ad5686: fix ref bit initialization for single-channel parts Rodrigo Alencar via B4 Relay
2026-04-22 19:58   ` Andy Shevchenko [this message]
2026-04-22 14:45 ` [PATCH 12/22] iio: dac: ad5686: fix powerdown control Rodrigo Alencar via B4 Relay
2026-04-22 20:25   ` Andy Shevchenko
2026-04-22 14:45 ` [PATCH 13/22] iio: dac: ad5686: fix input raw value check Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 14/22] iio: dac: ad5686: add support for missing power supplies Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 15/22] iio: dac: ad5686: create bus ops struct Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 16/22] iio: dac: ad5686: extend device support with new parts Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 17/22] iio: dac: ad5686: update device list description Rodrigo Alencar via B4 Relay
2026-04-22 20:06   ` Andy Shevchenko
2026-04-22 20:07     ` Andy Shevchenko
2026-04-22 14:45 ` [PATCH 18/22] iio: dac: ad5686: consume optional reset signal Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 19/22] iio: dac: ad5686: add ldac gpio Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 20/22] iio: dac: ad5686: implement new sync() op for the spi bus Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 21/22] iio: dac: ad5686: add triggered buffer support Rodrigo Alencar via B4 Relay
2026-04-22 14:45 ` [PATCH 22/22] iio: dac: ad5686: add gain control support Rodrigo Alencar via B4 Relay
2026-04-22 20:28 ` [PATCH 00/22] Extend device support for AD5686 driver Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aekoeFYIUMMcKMtC@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gustavoars@kernel.org \
    --cc=jic23@kernel.org \
    --cc=kees@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.auchter@ni.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=rodrigo.alencar@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox