All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Olivier Moysan <olivier.moysan@foss.st.com>,
	fabrice.gasnier@foss.st.com,  Nuno Sa <nuno.sa@analog.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/8] iio: add read scale and offset services to iio backend framework
Date: Fri, 05 Jul 2024 12:18:16 +0200	[thread overview]
Message-ID: <e1de64478918e495ccdcbcb5ad5bae0e48d45808.camel@gmail.com> (raw)
In-Reply-To: <20240704155338.2387858-2-olivier.moysan@foss.st.com>

On Thu, 2024-07-04 at 17:53 +0200, Olivier Moysan wrote:
> Add iio_backend_read_scale() and iio_backend_read_offset() services
> to read channel scale and offset from an IIO backbend device.
> 
> Also add a read_raw callback which replicates the read_raw callback of
> the IIO framework, and is intended to request miscellaneous channel
> attributes from the backend device.
> Both scale and offset helpers use this callback.
> 
> Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> ---
>  drivers/iio/industrialio-backend.c | 34 ++++++++++++++++++++++++++++++
>  include/linux/iio/backend.h        |  9 +++++++-
>  2 files changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-
> backend.c
> index efe05be284b6..4e0ff6e6e9d4 100644
> --- a/drivers/iio/industrialio-backend.c
> +++ b/drivers/iio/industrialio-backend.c
> @@ -357,6 +357,40 @@ int devm_iio_backend_request_buffer(struct device *dev,
>  }
>  EXPORT_SYMBOL_NS_GPL(devm_iio_backend_request_buffer, IIO_BACKEND);
>  
> +/**
> + * iio_backend_read_scale - Request channel scale from the IIO backend.
> + * @back:	Backend device
> + * @chan:	IIO channel reference
> + * @scale:	returned scale value
> + *
> + * RETURNS:
> + * 0 on success, negative error number on failure.
> + */
> +int iio_backend_read_scale(struct iio_backend *back,
> +			   struct iio_chan_spec const *chan, int *scale)
> +{
> +	return iio_backend_op_call(back, read_raw, chan, scale, NULL,
> +				   IIO_CHAN_INFO_SCALE);
> +}
> +EXPORT_SYMBOL_NS_GPL(iio_backend_read_scale, IIO_BACKEND);
> +
> +/**
> + * iio_backend_read_offset - Request channel offset from the IIO backend.
> + * @back:	Backend device
> + * @chan:	IIO channel reference
> + * @offset:	returned offset value
> + *
> + * RETURNS:
> + * 0 on success, negative error number on failure.
> + */
> +int iio_backend_read_offset(struct iio_backend *back,
> +			    struct iio_chan_spec const *chan, int *offset)
> +{
> +	return iio_backend_op_call(back, read_raw, chan, offset, NULL,
> +				   IIO_CHAN_INFO_OFFSET);
> +}
> +EXPORT_SYMBOL_NS_GPL(iio_backend_read_offset, IIO_BACKEND);
> +

Hi Olivier,

Not exactly what I had in mind :). My thinking was to have:

int iio_backend_read_raw(struct iio_backend *back,
			 struct iio_chan_spec const *chan, int *val, int *val2,
                         long mask)
{
	return iio_backend_op_call(back, read_raw, chan, val, val2, mask);
}
EXPORT_SYMBOL_NS_GPL(iio_backend_read_raw, IIO_BACKEND);

Then, on backend.h

static inline int iio_backend_read_scale(struct iio_backend *back, struct
iio_chan_spec const *chan, int *val, int val2)
{
	return iio_backend_read_raw(..., IIO_CHAN_INFO_SCALE);
}

Advantage is that we only need to export one symbol from the framework. But the most
important piece I don't really agree in the patch is assuming NULL for val2 (even
more in scale where often we use both vals). So I think it already makes sense to
expose the API with two int's even if you don't need them for your usecase.

- Nuno Sá



  reply	other threads:[~2024-07-05 10:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04 15:53 [PATCH v4 0/8] iio: adc: dfsdm: add scaling support Olivier Moysan
2024-07-04 15:53 ` [PATCH v4 1/8] iio: add read scale and offset services to iio backend framework Olivier Moysan
2024-07-05 10:18   ` Nuno Sá [this message]
2024-07-04 15:53 ` [PATCH v4 2/8] iio: add enable and disable " Olivier Moysan
2024-07-04 15:53 ` [PATCH v4 3/8] iio: add child nodes support in " Olivier Moysan
2024-07-04 15:53 ` [PATCH v4 4/8] dt-bindings: iio: dfsdm: move to " Olivier Moysan
2024-07-08 17:08   ` Rob Herring
2024-07-04 15:53 ` [PATCH v4 5/8] dt-bindings: iio: add backend support to sd modulator Olivier Moysan
2024-07-04 16:36   ` Conor Dooley
2024-07-04 15:53 ` [PATCH v4 6/8] iio: adc: stm32-dfsdm: adopt generic channels bindings Olivier Moysan
2024-07-07 15:18   ` Jonathan Cameron
2024-07-04 15:53 ` [PATCH v4 7/8] iio: add iio backend support to sd modulator Olivier Moysan
2024-07-04 15:53 ` [PATCH v4 8/8] iio: adc: stm32-dfsdm: add scaling support to dfsdm Olivier Moysan
2024-07-07 15:21   ` 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=e1de64478918e495ccdcbcb5ad5bae0e48d45808.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=olivier.moysan@foss.st.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.