Linux IIO development
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Angelo Dureghello <adureghello@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, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: dac: ad3552r-hs: add debugfs reg access
Date: Wed, 19 Mar 2025 09:10:26 -0500	[thread overview]
Message-ID: <a6246dea-738b-48fc-80fc-6676967157eb@baylibre.com> (raw)
In-Reply-To: <20250319-wip-bl-ad3552r-fixes-v2-1-2656bdd6778e@baylibre.com>

On 3/19/25 8:30 AM, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@baylibre.com>
> 
> Add debugfs register access.
> 

Forgot to pick up Nuno's review tag or explain why not.

> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> ---
> Changes in v2:
> - set reg size setup as inline.
> - Link to v1: https://lore.kernel.org/r/20250319-wip-bl-ad3552r-fixes-v1-1-cf10d6fae52a@baylibre.com
> ---
>  drivers/iio/dac/ad3552r-hs.c | 26 ++++++++++++++++++++++++++
>  drivers/iio/dac/ad3552r.h    |  2 ++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/drivers/iio/dac/ad3552r-hs.c b/drivers/iio/dac/ad3552r-hs.c
> index cd8dabb60c5548780f0fce5d1b68c494cd71321d..fdea9984547ae338a51c4671024133be82ed854f 100644
> --- a/drivers/iio/dac/ad3552r-hs.c
> +++ b/drivers/iio/dac/ad3552r-hs.c
> @@ -7,6 +7,7 @@
>   */
>  
>  #include <linux/bitfield.h>
> +#include <linux/debugfs.h>

Is this header actually needed?

>  #include <linux/delay.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/iio/backend.h>
> @@ -464,6 +465,30 @@ static int ad3552r_hs_setup_custom_gain(struct ad3552r_hs_state *st,
>  				      gain, 1);
>  }
>  
> +static int ad3552r_hs_reg_access(struct iio_dev *indio_dev, unsigned int reg,
> +				 unsigned int writeval, unsigned int *readval)
> +{
> +	struct ad3552r_hs_state *st = iio_priv(indio_dev);
> +	int size_xfer, max_reg_addr;
> +
> +	max_reg_addr = (st->model_data->num_hw_channels == 2) ?
> +			AD3552R_REG_ADDR_MAX : AD3551R_REG_ADDR_MAX;

Might as well add max reg to the model_data struct and read it directly instead
of inferring it from other info.

> +
> +	if (reg > max_reg_addr)
> +		return -EINVAL;
> +
> +	/*
> +	 * There is no 3 or 4 bytes r/w len possible in HDL, so keeping 2
> +	 * also for the 24bit area.
> +	 */
> +	size_xfer = (reg > AD3552R_SECONDARY_REGION_START) ? 2 : 1;

If we are reading both bytes of a 16-bit register at the same time, we should
only allow reading the lower of the two addresses, otherwise reading the high
register address could return 1 byte from one register and 1 byte from another
register.

And if we can't read the 24-bit and 32-bit registers all at once, I think we
should read them as 8-bit instead of 16-bit because the 24-bit registers are
not 16-bit aligned.

Or to keep it consistent, just allow accessing everything as 8-bit registers.

> +
> +	if (readval)
> +		return ad3552r_hs_reg_read(st, reg, readval, size_xfer);
> +
> +	return st->data->bus_reg_write(st->back, reg, writeval, size_xfer);
> +}


      reply	other threads:[~2025-03-19 14:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 13:30 [PATCH v2] iio: dac: ad3552r-hs: add debugfs reg access Angelo Dureghello
2025-03-19 14:10 ` David Lechner [this message]

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=a6246dea-738b-48fc-80fc-6676967157eb@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=adureghello@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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