All of lore.kernel.org
 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>,
	Daniel Baluta <daniel.baluta@intel.com>,
	Slawomir Stepien <sst@poczta.fm>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 3/8] iio: mcp4531: provide range of available raw values
Date: Sat, 12 Nov 2016 17:22:37 +0000	[thread overview]
Message-ID: <a8dcd0d9-76a6-d7df-e27d-4a70f78ab1e5@kernel.org> (raw)
In-Reply-To: <1478606339-31253-4-git-send-email-peda@axentia.se>

On 08/11/16 11:58, Peter Rosin wrote:
> Example:
> 
> $ cat '/sys/bus/iio/devices/iio:device0/out_resistance_raw_available'
> [0 1 256]
> 
> Meaning: min 0, step 1 and max 256.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>
Applied.
> ---
>  .../testing/sysfs-bus-iio-potentiometer-mcp4531    |   8 ++
>  MAINTAINERS                                        |   1 +
>  drivers/iio/potentiometer/mcp4531.c                | 104 ++++++++++++---------
>  3 files changed, 71 insertions(+), 42 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531 b/Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
> new file mode 100644
> index 000000000000..2a91fbe394fc
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
> @@ -0,0 +1,8 @@
> +What:		/sys/bus/iio/devices/iio:deviceX/out_resistance_raw_available
> +Date:		October 2016
> +KernelVersion:	4.9
> +Contact:	Peter Rosin <peda@axentia.se>
> +Description:
> +		The range of available values represented as the minimum value,
> +		the step and the maximum value, all enclosed in square brackets.
> +		Example: [0 1 256]
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 411e3b87b8c2..2409e1d79cb6 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -7707,6 +7707,7 @@ MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER
>  M:	Peter Rosin <peda@axentia.se>
>  L:	linux-iio@vger.kernel.org
>  S:	Maintained
> +F:	Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
>  F:	drivers/iio/potentiometer/mcp4531.c
>  
>  MEASUREMENT COMPUTING CIO-DAC IIO DRIVER
> diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
> index 13b6ae2fcf7b..0d1bcf89ae17 100644
> --- a/drivers/iio/potentiometer/mcp4531.c
> +++ b/drivers/iio/potentiometer/mcp4531.c
> @@ -38,7 +38,7 @@
>  
>  struct mcp4531_cfg {
>  	int wipers;
> -	int max_pos;
> +	int avail[3];
>  	int kohms;
>  };
>  
> @@ -78,38 +78,38 @@ enum mcp4531_type {
>  };
>  
>  static const struct mcp4531_cfg mcp4531_cfg[] = {
> -	[MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
> -	[MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
> -	[MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
> -	[MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
> -	[MCP454x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
> -	[MCP454x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
> -	[MCP454x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
> -	[MCP454x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
> -	[MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
> -	[MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
> -	[MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
> -	[MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
> -	[MCP456x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
> -	[MCP456x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
> -	[MCP456x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
> -	[MCP456x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
> -	[MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
> -	[MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
> -	[MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
> -	[MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
> -	[MCP464x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
> -	[MCP464x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
> -	[MCP464x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
> -	[MCP464x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
> -	[MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
> -	[MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
> -	[MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
> -	[MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
> -	[MCP466x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
> -	[MCP466x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
> -	[MCP466x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
> -	[MCP466x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
> +	[MCP453x_502] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP453x_103] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP453x_503] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP453x_104] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP454x_502] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP454x_103] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP454x_503] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP454x_104] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP455x_502] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP455x_103] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP455x_503] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP455x_104] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 100, },
> +	[MCP456x_502] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP456x_103] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP456x_503] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP456x_104] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 100, },
> +	[MCP463x_502] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP463x_103] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP463x_503] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP463x_104] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP464x_502] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP464x_103] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP464x_503] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP464x_104] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP465x_502] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP465x_103] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP465x_503] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP465x_104] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 100, },
> +	[MCP466x_502] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP466x_103] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP466x_503] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP466x_104] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 100, },
>  };
>  
>  #define MCP4531_WRITE (0 << 2)
> @@ -124,13 +124,14 @@ struct mcp4531_data {
>  	const struct mcp4531_cfg *cfg;
>  };
>  
> -#define MCP4531_CHANNEL(ch) {					\
> -	.type = IIO_RESISTANCE,					\
> -	.indexed = 1,						\
> -	.output = 1,						\
> -	.channel = (ch),					\
> -	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
> -	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
> +#define MCP4531_CHANNEL(ch) {						\
> +	.type = IIO_RESISTANCE,						\
> +	.indexed = 1,							\
> +	.output = 1,							\
> +	.channel = (ch),						\
> +	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
> +	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
> +	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW),	\
>  }
>  
>  static const struct iio_chan_spec mcp4531_channels[] = {
> @@ -156,13 +157,31 @@ static int mcp4531_read_raw(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 1000 * data->cfg->kohms;
> -		*val2 = data->cfg->max_pos;
> +		*val2 = data->cfg->avail[2];
>  		return IIO_VAL_FRACTIONAL;
>  	}
>  
>  	return -EINVAL;
>  }
>  
> +static int mcp4531_read_avail(struct iio_dev *indio_dev,
> +			      struct iio_chan_spec const *chan,
> +			      const int **vals, int *type, int *length,
> +			      long mask)
> +{
> +	struct mcp4531_data *data = iio_priv(indio_dev);
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		*length = ARRAY_SIZE(data->cfg->avail);
> +		*vals = data->cfg->avail;
> +		*type = IIO_VAL_INT;
> +		return IIO_AVAIL_RANGE;
> +	}
> +
> +	return -EINVAL;
> +}
> +
>  static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  			     struct iio_chan_spec const *chan,
>  			     int val, int val2, long mask)
> @@ -172,7 +191,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		if (val > data->cfg->max_pos || val < 0)
> +		if (val > data->cfg->avail[2] || val < 0)
>  			return -EINVAL;
>  		break;
>  	default:
> @@ -186,6 +205,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  
>  static const struct iio_info mcp4531_info = {
>  	.read_raw = mcp4531_read_raw,
> +	.read_avail = mcp4531_read_avail,
>  	.write_raw = mcp4531_write_raw,
>  	.driver_module = THIS_MODULE,
>  };
> 


WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
	Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Peter Meerwald-Stadler
	<pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Daniel Baluta
	<daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Slawomir Stepien <sst-IjDXvh/HVVUAvxtiuMwx3w@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v4 3/8] iio: mcp4531: provide range of available raw values
Date: Sat, 12 Nov 2016 17:22:37 +0000	[thread overview]
Message-ID: <a8dcd0d9-76a6-d7df-e27d-4a70f78ab1e5@kernel.org> (raw)
In-Reply-To: <1478606339-31253-4-git-send-email-peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>

On 08/11/16 11:58, Peter Rosin wrote:
> Example:
> 
> $ cat '/sys/bus/iio/devices/iio:device0/out_resistance_raw_available'
> [0 1 256]
> 
> Meaning: min 0, step 1 and max 256.
> 
> Signed-off-by: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
Applied.
> ---
>  .../testing/sysfs-bus-iio-potentiometer-mcp4531    |   8 ++
>  MAINTAINERS                                        |   1 +
>  drivers/iio/potentiometer/mcp4531.c                | 104 ++++++++++++---------
>  3 files changed, 71 insertions(+), 42 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531 b/Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
> new file mode 100644
> index 000000000000..2a91fbe394fc
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
> @@ -0,0 +1,8 @@
> +What:		/sys/bus/iio/devices/iio:deviceX/out_resistance_raw_available
> +Date:		October 2016
> +KernelVersion:	4.9
> +Contact:	Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
> +Description:
> +		The range of available values represented as the minimum value,
> +		the step and the maximum value, all enclosed in square brackets.
> +		Example: [0 1 256]
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 411e3b87b8c2..2409e1d79cb6 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -7707,6 +7707,7 @@ MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER
>  M:	Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
>  L:	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>  S:	Maintained
> +F:	Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531
>  F:	drivers/iio/potentiometer/mcp4531.c
>  
>  MEASUREMENT COMPUTING CIO-DAC IIO DRIVER
> diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
> index 13b6ae2fcf7b..0d1bcf89ae17 100644
> --- a/drivers/iio/potentiometer/mcp4531.c
> +++ b/drivers/iio/potentiometer/mcp4531.c
> @@ -38,7 +38,7 @@
>  
>  struct mcp4531_cfg {
>  	int wipers;
> -	int max_pos;
> +	int avail[3];
>  	int kohms;
>  };
>  
> @@ -78,38 +78,38 @@ enum mcp4531_type {
>  };
>  
>  static const struct mcp4531_cfg mcp4531_cfg[] = {
> -	[MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
> -	[MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
> -	[MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
> -	[MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
> -	[MCP454x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
> -	[MCP454x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
> -	[MCP454x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
> -	[MCP454x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
> -	[MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
> -	[MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
> -	[MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
> -	[MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
> -	[MCP456x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
> -	[MCP456x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
> -	[MCP456x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
> -	[MCP456x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
> -	[MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
> -	[MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
> -	[MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
> -	[MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
> -	[MCP464x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
> -	[MCP464x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
> -	[MCP464x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
> -	[MCP464x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
> -	[MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
> -	[MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
> -	[MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
> -	[MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
> -	[MCP466x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
> -	[MCP466x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
> -	[MCP466x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
> -	[MCP466x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
> +	[MCP453x_502] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP453x_103] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP453x_503] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP453x_104] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP454x_502] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP454x_103] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP454x_503] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP454x_104] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP455x_502] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP455x_103] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP455x_503] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP455x_104] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 100, },
> +	[MCP456x_502] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP456x_103] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP456x_503] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP456x_104] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 100, },
> +	[MCP463x_502] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP463x_103] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP463x_503] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP463x_104] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP464x_502] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =   5, },
> +	[MCP464x_103] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  10, },
> +	[MCP464x_503] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms =  50, },
> +	[MCP464x_104] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 100, },
> +	[MCP465x_502] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP465x_103] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP465x_503] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP465x_104] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 100, },
> +	[MCP466x_502] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =   5, },
> +	[MCP466x_103] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  10, },
> +	[MCP466x_503] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms =  50, },
> +	[MCP466x_104] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 100, },
>  };
>  
>  #define MCP4531_WRITE (0 << 2)
> @@ -124,13 +124,14 @@ struct mcp4531_data {
>  	const struct mcp4531_cfg *cfg;
>  };
>  
> -#define MCP4531_CHANNEL(ch) {					\
> -	.type = IIO_RESISTANCE,					\
> -	.indexed = 1,						\
> -	.output = 1,						\
> -	.channel = (ch),					\
> -	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
> -	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
> +#define MCP4531_CHANNEL(ch) {						\
> +	.type = IIO_RESISTANCE,						\
> +	.indexed = 1,							\
> +	.output = 1,							\
> +	.channel = (ch),						\
> +	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
> +	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
> +	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW),	\
>  }
>  
>  static const struct iio_chan_spec mcp4531_channels[] = {
> @@ -156,13 +157,31 @@ static int mcp4531_read_raw(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 1000 * data->cfg->kohms;
> -		*val2 = data->cfg->max_pos;
> +		*val2 = data->cfg->avail[2];
>  		return IIO_VAL_FRACTIONAL;
>  	}
>  
>  	return -EINVAL;
>  }
>  
> +static int mcp4531_read_avail(struct iio_dev *indio_dev,
> +			      struct iio_chan_spec const *chan,
> +			      const int **vals, int *type, int *length,
> +			      long mask)
> +{
> +	struct mcp4531_data *data = iio_priv(indio_dev);
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		*length = ARRAY_SIZE(data->cfg->avail);
> +		*vals = data->cfg->avail;
> +		*type = IIO_VAL_INT;
> +		return IIO_AVAIL_RANGE;
> +	}
> +
> +	return -EINVAL;
> +}
> +
>  static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  			     struct iio_chan_spec const *chan,
>  			     int val, int val2, long mask)
> @@ -172,7 +191,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		if (val > data->cfg->max_pos || val < 0)
> +		if (val > data->cfg->avail[2] || val < 0)
>  			return -EINVAL;
>  		break;
>  	default:
> @@ -186,6 +205,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  
>  static const struct iio_info mcp4531_info = {
>  	.read_raw = mcp4531_read_raw,
> +	.read_avail = mcp4531_read_avail,
>  	.write_raw = mcp4531_write_raw,
>  	.driver_module = THIS_MODULE,
>  };
> 

  reply	other threads:[~2016-11-12 17:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-08 11:58 [PATCH v4 0/8] IIO wrapper drivers, dpot-dac and envelope-detector Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-08 11:58 ` [PATCH v4 1/8] iio:core: add a callback to allow drivers to provide _available attributes Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-12 17:17   ` Jonathan Cameron
2016-11-12 17:17     ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 2/8] iio: inkern: add helpers to query available values from channels Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-12 17:17   ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 3/8] iio: mcp4531: provide range of available raw values Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-12 17:22   ` Jonathan Cameron [this message]
2016-11-12 17:22     ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 4/8] dt-bindings: add axentia to vendor-prefixes Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-12 17:23   ` Jonathan Cameron
2016-11-12 17:23     ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 5/8] dt-bindings: iio: document dpot-dac bindings Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-08 11:58 ` [PATCH v4 6/8] iio: dpot-dac: DAC driver based on a digital potentiometer Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-12 17:24   ` Jonathan Cameron
2016-11-12 17:24     ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 7/8] dt-bindings: iio: document envelope-detector bindings Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-12 17:25   ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 8/8] iio: envelope-detector: ADC driver based on a DAC and a comparator Peter Rosin
2016-11-08 11:58   ` Peter Rosin
2016-11-08 15:59   ` Thomas Gleixner
2016-11-08 15:59     ` Thomas Gleixner
2016-11-08 17:03     ` Peter Rosin
2016-11-08 17:03       ` Peter Rosin
2016-11-08 18:38       ` Thomas Gleixner
2016-11-08 20:44         ` Peter Rosin
2016-11-08 20:44           ` Peter Rosin
2016-11-08 21:47           ` Thomas Gleixner
2016-11-08 21:47             ` Thomas Gleixner
2016-11-09 15:01             ` Peter Rosin
2016-11-09 15:01               ` Peter Rosin
2016-11-09 15:06               ` Thomas Gleixner
2016-11-11 11:37                 ` Peter Rosin
2016-11-11 11:37                   ` Peter Rosin
2016-11-12 17:29                   ` Jonathan Cameron
2016-11-12 17:29                     ` Jonathan Cameron
2016-11-12 17:27       ` Jonathan Cameron
2016-11-12 17:27         ` Jonathan Cameron
2016-11-12 17:15 ` [PATCH v4 0/8] IIO wrapper drivers, dpot-dac and envelope-detector Jonathan Cameron
2016-11-12 17:15   ` Jonathan Cameron
2016-11-15 14:03   ` Peter Rosin
2016-11-15 14:03     ` 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=a8dcd0d9-76a6-d7df-e27d-4a70f78ab1e5@kernel.org \
    --to=jic23@kernel.org \
    --cc=daniel.baluta@intel.com \
    --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 \
    --cc=sst@poczta.fm \
    --cc=tglx@linutronix.de \
    /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.