linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: adc: ad7887: Cleanup channel assignment
@ 2019-11-25 13:21 Beniamin Bia
  2019-12-01 11:43 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Beniamin Bia @ 2019-11-25 13:21 UTC (permalink / raw)
  To: jic23
  Cc: lars, Michael.Hennerich, pmeerw, linux-iio, linux-kernel,
	biabeniamin, knaack.h, Beniamin Bia

The channels specification assignment in chip info was simplified.
This patch makes supporting other devices by this driver easier.

Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
---
Changes in v2:
-separate iio_chan_spec for dual mode

 drivers/iio/adc/ad7887.c | 82 +++++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 39 deletions(-)

diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index 6223043e432b..c6a3428e950a 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -43,11 +43,17 @@ enum ad7887_channels {
 /**
  * struct ad7887_chip_info - chip specifc information
  * @int_vref_mv:	the internal reference voltage
- * @channel:		channel specification
+ * @channels:		channels specification
+ * @num_channels:	number of channels
+ * @dual_channels:	channels specification in dual mode
+ * @num_dual_channels:	number of channels in dual mode
  */
 struct ad7887_chip_info {
 	u16				int_vref_mv;
-	struct iio_chan_spec		channel[3];
+	const struct iio_chan_spec	*channels;
+	unsigned int			num_channels;
+	const struct iio_chan_spec	*dual_channels;
+	unsigned int			num_dual_channels;
 };
 
 struct ad7887_state {
@@ -183,45 +189,43 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
+#define AD7887_CHANNEL(x) { \
+	.type = IIO_VOLTAGE, \
+	.indexed = 1, \
+	.channel = (x), \
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+	.address = (x), \
+	.scan_index = (x), \
+	.scan_type = { \
+		.sign = 'u', \
+		.realbits = 12, \
+		.storagebits = 16, \
+		.shift = 0, \
+		.endianness = IIO_BE, \
+	}, \
+}
+
+static const struct iio_chan_spec ad7887_channels[] = {
+	AD7887_CHANNEL(0),
+	IIO_CHAN_SOFT_TIMESTAMP(1),
+};
+
+static const struct iio_chan_spec ad7887_dual_channels[] = {
+	AD7887_CHANNEL(0),
+	AD7887_CHANNEL(1),
+	IIO_CHAN_SOFT_TIMESTAMP(2),
+};
 
 static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
 	/*
 	 * More devices added in future
 	 */
 	[ID_AD7887] = {
-		.channel[0] = {
-			.type = IIO_VOLTAGE,
-			.indexed = 1,
-			.channel = 1,
-			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-			.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
-			.address = 1,
-			.scan_index = 1,
-			.scan_type = {
-				.sign = 'u',
-				.realbits = 12,
-				.storagebits = 16,
-				.shift = 0,
-				.endianness = IIO_BE,
-			},
-		},
-		.channel[1] = {
-			.type = IIO_VOLTAGE,
-			.indexed = 1,
-			.channel = 0,
-			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-			.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
-			.address = 0,
-			.scan_index = 0,
-			.scan_type = {
-				.sign = 'u',
-				.realbits = 12,
-				.storagebits = 16,
-				.shift = 0,
-				.endianness = IIO_BE,
-			},
-		},
-		.channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
+		.channels = ad7887_channels,
+		.num_channels = ARRAY_SIZE(ad7887_channels),
+		.dual_channels = ad7887_dual_channels,
+		.num_dual_channels = ARRAY_SIZE(ad7887_dual_channels),
 		.int_vref_mv = 2500,
 	},
 };
@@ -306,11 +310,11 @@ static int ad7887_probe(struct spi_device *spi)
 		spi_message_init(&st->msg[AD7887_CH1]);
 		spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]);
 
-		indio_dev->channels = st->chip_info->channel;
-		indio_dev->num_channels = 3;
+		indio_dev->channels = st->chip_info->dual_channels;
+		indio_dev->num_channels = st->chip_info->num_dual_channels;
 	} else {
-		indio_dev->channels = &st->chip_info->channel[1];
-		indio_dev->num_channels = 2;
+		indio_dev->channels = st->chip_info->channels;
+		indio_dev->num_channels = st->chip_info->num_channels;
 	}
 
 	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iio: adc: ad7887: Cleanup channel assignment
  2019-11-25 13:21 [PATCH v2] iio: adc: ad7887: Cleanup channel assignment Beniamin Bia
@ 2019-12-01 11:43 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-12-01 11:43 UTC (permalink / raw)
  To: Beniamin Bia
  Cc: lars, Michael.Hennerich, pmeerw, linux-iio, linux-kernel,
	biabeniamin, knaack.h

On Mon, 25 Nov 2019 15:21:37 +0200
Beniamin Bia <beniamin.bia@analog.com> wrote:

> The channels specification assignment in chip info was simplified.
> This patch makes supporting other devices by this driver easier.
> 
> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changes in v2:
> -separate iio_chan_spec for dual mode
> 
>  drivers/iio/adc/ad7887.c | 82 +++++++++++++++++++++-------------------
>  1 file changed, 43 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
> index 6223043e432b..c6a3428e950a 100644
> --- a/drivers/iio/adc/ad7887.c
> +++ b/drivers/iio/adc/ad7887.c
> @@ -43,11 +43,17 @@ enum ad7887_channels {
>  /**
>   * struct ad7887_chip_info - chip specifc information
>   * @int_vref_mv:	the internal reference voltage
> - * @channel:		channel specification
> + * @channels:		channels specification
> + * @num_channels:	number of channels
> + * @dual_channels:	channels specification in dual mode
> + * @num_dual_channels:	number of channels in dual mode
>   */
>  struct ad7887_chip_info {
>  	u16				int_vref_mv;
> -	struct iio_chan_spec		channel[3];
> +	const struct iio_chan_spec	*channels;
> +	unsigned int			num_channels;
> +	const struct iio_chan_spec	*dual_channels;
> +	unsigned int			num_dual_channels;
>  };
>  
>  struct ad7887_state {
> @@ -183,45 +189,43 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
>  	return -EINVAL;
>  }
>  
> +#define AD7887_CHANNEL(x) { \
> +	.type = IIO_VOLTAGE, \
> +	.indexed = 1, \
> +	.channel = (x), \
> +	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> +	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
> +	.address = (x), \
> +	.scan_index = (x), \
> +	.scan_type = { \
> +		.sign = 'u', \
> +		.realbits = 12, \
> +		.storagebits = 16, \
> +		.shift = 0, \
> +		.endianness = IIO_BE, \
> +	}, \
> +}
> +
> +static const struct iio_chan_spec ad7887_channels[] = {
> +	AD7887_CHANNEL(0),
> +	IIO_CHAN_SOFT_TIMESTAMP(1),
> +};
> +
> +static const struct iio_chan_spec ad7887_dual_channels[] = {
> +	AD7887_CHANNEL(0),
> +	AD7887_CHANNEL(1),
> +	IIO_CHAN_SOFT_TIMESTAMP(2),
> +};
>  
>  static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
>  	/*
>  	 * More devices added in future
>  	 */
>  	[ID_AD7887] = {
> -		.channel[0] = {
> -			.type = IIO_VOLTAGE,
> -			.indexed = 1,
> -			.channel = 1,
> -			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> -			.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> -			.address = 1,
> -			.scan_index = 1,
> -			.scan_type = {
> -				.sign = 'u',
> -				.realbits = 12,
> -				.storagebits = 16,
> -				.shift = 0,
> -				.endianness = IIO_BE,
> -			},
> -		},
> -		.channel[1] = {
> -			.type = IIO_VOLTAGE,
> -			.indexed = 1,
> -			.channel = 0,
> -			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> -			.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> -			.address = 0,
> -			.scan_index = 0,
> -			.scan_type = {
> -				.sign = 'u',
> -				.realbits = 12,
> -				.storagebits = 16,
> -				.shift = 0,
> -				.endianness = IIO_BE,
> -			},
> -		},
> -		.channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
> +		.channels = ad7887_channels,
> +		.num_channels = ARRAY_SIZE(ad7887_channels),
> +		.dual_channels = ad7887_dual_channels,
> +		.num_dual_channels = ARRAY_SIZE(ad7887_dual_channels),
>  		.int_vref_mv = 2500,
>  	},
>  };
> @@ -306,11 +310,11 @@ static int ad7887_probe(struct spi_device *spi)
>  		spi_message_init(&st->msg[AD7887_CH1]);
>  		spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]);
>  
> -		indio_dev->channels = st->chip_info->channel;
> -		indio_dev->num_channels = 3;
> +		indio_dev->channels = st->chip_info->dual_channels;
> +		indio_dev->num_channels = st->chip_info->num_dual_channels;
>  	} else {
> -		indio_dev->channels = &st->chip_info->channel[1];
> -		indio_dev->num_channels = 2;
> +		indio_dev->channels = st->chip_info->channels;
> +		indio_dev->num_channels = st->chip_info->num_channels;
>  	}
>  
>  	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-01 11:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25 13:21 [PATCH v2] iio: adc: ad7887: Cleanup channel assignment Beniamin Bia
2019-12-01 11:43 ` Jonathan Cameron

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).