Linux IIO development
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: ad7124: Micro-optimize channel disabling
Date: Mon, 20 Jan 2025 15:52:20 +0000	[thread overview]
Message-ID: <dfb5c6311896c040593bafc390d72b5a0ef307d5.camel@gmail.com> (raw)
In-Reply-To: <20250120140708.1093655-2-u.kleine-koenig@baylibre.com>

On Mon, 2025-01-20 at 15:07 +0100, Uwe Kleine-König wrote:
> The key objective in ad7124_disable_one() is clearing the
> AD7124_CHANNEL_EN_MSK bit in the channel register. However there is no
> advantage to keep the other bits in that register because when the
> channel is used next time, all fields are rewritten anyhow. So instead
> of using ad7124_spi_write_mask() (which is a register read plus a
> register write) use a simple register write clearing the complete
> register.
> 
> Also do the same in the .disable_all() callback by using the
> .disable_one() callback there.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

> Hello,
> 
> in (implicit) v1 I only adapted ad7124_disable_one() which resulted in
> the very legitimate question why this wasn't done for .disable_all(). I
> haven't checked because I wrongly assumed that .disable_all() used
> .disable_one(). This v2 now makes the latter true and so .disable_all()
> now also benefits from the micro optimisation.
> 
> Best regards
> Uwe
> 
>  drivers/iio/adc/ad7124.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 6ae27cdd3250..2fdeb3247952 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -540,6 +540,14 @@ static int ad7124_append_status(struct ad_sigma_delta
> *sd, bool append)
>  	return 0;
>  }
>  
> +static int ad7124_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
> +{
> +	struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
> +
> +	/* The relevant thing here is that AD7124_CHANNEL_EN_MSK is cleared.
> */
> +	return ad_sd_write_reg(&st->sd, AD7124_CHANNEL(chan), 2, 0);
> +}
> +
>  static int ad7124_disable_all(struct ad_sigma_delta *sd)
>  {
>  	struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
> @@ -547,7 +555,7 @@ static int ad7124_disable_all(struct ad_sigma_delta *sd)
>  	int i;
>  
>  	for (i = 0; i < st->num_channels; i++) {
> -		ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i),
> AD7124_CHANNEL_EN_MSK, 0, 2);
> +		ret = ad7124_disable_one(sd, i);
>  		if (ret < 0)
>  			return ret;
>  	}
> @@ -555,13 +563,6 @@ static int ad7124_disable_all(struct ad_sigma_delta *sd)
>  	return 0;
>  }
>  
> -static int ad7124_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
> -{
> -	struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
> -
> -	return ad7124_spi_write_mask(st, AD7124_CHANNEL(chan),
> AD7124_CHANNEL_EN_MSK, 0, 2);
> -}
> -
>  static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
>  	.set_channel = ad7124_set_channel,
>  	.append_status = ad7124_append_status,
> 
> base-commit: b323d8e7bc03d27dec646bfdccb7d1a92411f189


  reply	other threads:[~2025-01-20 15:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 14:07 [PATCH v2] iio: adc: ad7124: Micro-optimize channel disabling Uwe Kleine-König
2025-01-20 15:52 ` Nuno Sá [this message]
2025-01-25 12:29   ` Jonathan Cameron

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=dfb5c6311896c040593bafc390d72b5a0ef307d5.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.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