devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Peter Rosin <peda@axentia.se>, linux-kernel@vger.kernel.org
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 2/8] iio: inkern: add helpers to query available values from channels
Date: Sun, 30 Oct 2016 13:21:04 +0000	[thread overview]
Message-ID: <c7848c84-960b-506f-f2e2-4aadfc5246f9@kernel.org> (raw)
In-Reply-To: <1477262381-7800-3-git-send-email-peda@axentia.se>

On 23/10/16 23:39, Peter Rosin wrote:
> Specifically a helper for reading the available maximum raw value of a
> channel and a helper for forwarding read_avail requests for raw values
> from one iio driver to an iio channel that is consumed.
> 
> These rather specific helpers are in turn built with generic helpers
> making it easy to build more helpers for available values as needed.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>
Looks good to me.  Just what I was after.

Jonathan
> ---
>  drivers/iio/inkern.c         | 97 ++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/iio/consumer.h | 29 +++++++++++++
>  include/linux/iio/iio.h      | 17 ++++++++
>  3 files changed, 143 insertions(+)
> 
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index c4757e6367e7..74808f8a187a 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -703,6 +703,103 @@ int iio_read_channel_scale(struct iio_channel *chan, int *val, int *val2)
>  }
>  EXPORT_SYMBOL_GPL(iio_read_channel_scale);
>  
> +static int iio_channel_read_avail(struct iio_channel *chan,
> +				  const int **vals, int *type, int *length,
> +				  enum iio_chan_info_enum info)
> +{
> +	if (!iio_channel_has_available(chan->channel, info))
> +		return -EINVAL;
> +
> +	return chan->indio_dev->info->read_avail(chan->indio_dev, chan->channel,
> +						 vals, type, length, info);
> +}
> +
> +int iio_read_avail_channel_raw(struct iio_channel *chan,
> +			       const int **vals, int *type, int *length)
> +{
> +	int ret;
> +
> +	mutex_lock(&chan->indio_dev->info_exist_lock);
> +	if (!chan->indio_dev->info) {
> +		ret = -ENODEV;
> +		goto err_unlock;
> +	}
> +
> +	ret = iio_channel_read_avail(chan,
> +				     vals, type, length, IIO_CHAN_INFO_RAW);
> +err_unlock:
> +	mutex_unlock(&chan->indio_dev->info_exist_lock);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw);
> +
> +static int iio_channel_read_max(struct iio_channel *chan,
> +				int *val, int *val2, int *type,
> +				enum iio_chan_info_enum info)
> +{
> +	int unused;
> +	const int *vals;
> +	int length;
> +	int ret;
> +
> +	if (!val2)
> +		val2 = &unused;
> +
> +	ret = iio_channel_read_avail(chan, &vals, type, &length, info);
> +	switch (ret) {
> +	case IIO_AVAIL_RANGE:
> +		switch (*type) {
> +		case IIO_VAL_INT:
> +			*val = vals[2];
> +			break;
> +		default:
> +			*val = vals[4];
> +			*val2 = vals[5];
> +		}
> +		return 0;
> +
> +	case IIO_AVAIL_LIST:
> +		if (length <= 0)
> +			return -EINVAL;
> +		switch (*type) {
> +		case IIO_VAL_INT:
> +			*val = vals[--length];
> +			while (length) {
> +				if (vals[--length] > *val)
> +					*val = vals[length];
> +			}
> +			break;
> +		default:
> +			/* FIXME: learn about max for other iio values */
> +			return -EINVAL;
> +		}
> +		return 0;
> +
> +	default:
> +		return ret;
> +	}
> +}
> +
> +int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
> +{
> +	int ret;
> +	int type;
> +
> +	mutex_lock(&chan->indio_dev->info_exist_lock);
> +	if (!chan->indio_dev->info) {
> +		ret = -ENODEV;
> +		goto err_unlock;
> +	}
> +
> +	ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
> +err_unlock:
> +	mutex_unlock(&chan->indio_dev->info_exist_lock);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);
> +
>  int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
>  {
>  	int ret = 0;
> diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
> index 9edccfba1ffb..baab5e45734f 100644
> --- a/include/linux/iio/consumer.h
> +++ b/include/linux/iio/consumer.h
> @@ -226,6 +226,35 @@ int iio_read_channel_processed(struct iio_channel *chan, int *val);
>  int iio_write_channel_raw(struct iio_channel *chan, int val);
>  
>  /**
> + * iio_read_max_channel_raw() - read maximum available raw value from a given
> + *				channel
> + * @chan:		The channel being queried.
> + * @val:		Value read back.
> + *
> + * Note raw reads from iio channels are in adc counts and hence
> + * scale will need to be applied if standard units are required.
> + */
> +int iio_read_max_channel_raw(struct iio_channel *chan, int *val);
> +
> +/**
> + * iio_read_avail_channel_raw() - read available raw values from a given channel
> + * @chan:		The channel being queried.
> + * @vals:		Available values read back.
> + * @type:		Type of available values in vals.
> + * @length:		Number of entries in vals.
> + *
> + * Returns an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST.
> + *
> + * For ranges, three vals are always returned; min, step and max.
> + * For lists, all the possible values are enumerated.
> + *
> + * Note raw available values from iio channels are in adc counts and
> + * hence scale will need to be applied if standard units are required.
> + */
> +int iio_read_avail_channel_raw(struct iio_channel *chan,
> +			       const int **vals, int *type, int *length);
> +
> +/**
>   * iio_get_channel_type() - get the type of a channel
>   * @channel:		The channel being queried.
>   * @type:		The type of the channel.
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 45b781084a4b..e565701d13ce 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -315,6 +315,23 @@ static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
>  		(chan->info_mask_shared_by_all & BIT(type));
>  }
>  
> +/**
> + * iio_channel_has_available() - Checks if a channel has an available attribute
> + * @chan: The channel to be queried
> + * @type: Type of the available attribute to be checked
> + *
> + * Returns true if the channels supports reporting available values for the
> + * given attribute type, false otherwise.
> + */
> +static inline bool iio_channel_has_available(const struct iio_chan_spec *chan,
> +					     enum iio_chan_info_enum type)
> +{
> +	return (chan->info_mask_separate_available & BIT(type)) |
> +		(chan->info_mask_shared_by_type_available & BIT(type)) |
> +		(chan->info_mask_shared_by_dir_available & BIT(type)) |
> +		(chan->info_mask_shared_by_all_available & BIT(type));
> +}
> +
>  #define IIO_CHAN_SOFT_TIMESTAMP(_si) {					\
>  	.type = IIO_TIMESTAMP,						\
>  	.channel = -1,							\
> 

  reply	other threads:[~2016-10-30 13:21 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-23 22:39 [PATCH v3 0/8] IIO wrapper drivers, dpot-dac and envelope-detector Peter Rosin
2016-10-23 22:39 ` [PATCH v3 5/8] dt-bindings: iio: document dpot-dac bindings Peter Rosin
     [not found]   ` <1477262381-7800-6-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-10-30 13:28     ` Jonathan Cameron
2016-10-30 20:41     ` Rob Herring
     [not found] ` <1477262381-7800-1-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-10-23 22:39   ` [PATCH v3 1/8] iio:core: add a callback to allow drivers to provide _available attributes Peter Rosin
     [not found]     ` <1477262381-7800-2-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-10-30 13:11       ` Jonathan Cameron
2016-11-07 11:37     ` Daniel Baluta
     [not found]       ` <CAEnQRZDgF-x6rNiS1Uv9Evdt1sVfUu9pMF98Z4=r-vKP52C1kA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-07 11:57         ` Peter Rosin
     [not found]           ` <62f150ba-abc0-8e45-1355-8a61354ee3e1-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-11-07 12:18             ` Daniel Baluta
2016-11-07 16:46           ` Slawomir Stepien
2016-10-23 22:39   ` [PATCH v3 2/8] iio: inkern: add helpers to query available values from channels Peter Rosin
2016-10-30 13:21     ` Jonathan Cameron [this message]
2016-10-30 15:23       ` Peter Meerwald-Stadler
     [not found]         ` <alpine.DEB.2.02.1610301611070.32031-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>
2016-10-30 21:12           ` Peter Rosin
2016-10-23 22:39   ` [PATCH v3 3/8] iio: mcp4531: provide range of available raw values Peter Rosin
     [not found]     ` <1477262381-7800-4-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-10-30 13:26       ` Jonathan Cameron
2016-10-23 22:39   ` [PATCH v3 4/8] dt-bindings: add axentia to vendor-prefixes Peter Rosin
2016-10-30 20:41     ` Rob Herring
2016-10-23 22:39   ` [PATCH v3 6/8] iio: dpot-dac: DAC driver based on a digital potentiometer Peter Rosin
2016-10-30 13:33     ` Jonathan Cameron
     [not found]       ` <301ab064-cd90-d99d-a05a-8a50ba759c62-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-10-30 14:24         ` Peter Rosin
2016-10-30 15:32       ` Peter Meerwald-Stadler
     [not found]         ` <alpine.DEB.2.02.1610301628400.32031-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>
2016-10-30 18:36           ` Peter Rosin
2016-10-23 22:39   ` [PATCH v3 7/8] dt-bindings: iio: document envelope-detector bindings Peter Rosin
2016-10-30 13:35     ` Jonathan Cameron
     [not found]     ` <1477262381-7800-8-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-10-30 20:41       ` Rob Herring
2016-10-23 22:39   ` [PATCH v3 8/8] iio: envelope-detector: ADC driver based on a DAC and a comparator Peter Rosin
     [not found]     ` <1477262381-7800-9-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
2016-10-30 13:44       ` Jonathan Cameron
     [not found]         ` <61cd873a-b6ff-50d5-1161-e9b1ad90af88-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-10-30 14:26           ` Peter Rosin

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=c7848c84-960b-506f-f2e2-4aadfc5246f9@kernel.org \
    --to=jic23@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peda@axentia.se \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).