linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] iio:dac:ad5686: Style fixes no functional changes
@ 2018-03-30 13:55 Stefan Popa
  2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
  2018-04-10 15:56 ` [PATCH v2 1/6] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
  0 siblings, 2 replies; 15+ messages in thread
From: Stefan Popa @ 2018-03-30 13:55 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23
  Cc: knaack.h, pmeerw, linux-pm, linux-iio, linux-kernel, stefan.popa

This patch fixes some indentation issues and does not modify the
functionality of the driver.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/iio/dac/ad5686.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 20254df..f7f975c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -24,7 +24,7 @@
 #define AD5686_ADDR(x)				((x) << 16)
 #define AD5686_CMD(x)				((x) << 20)
 
-#define AD5686_ADDR_DAC(chan)		(0x1 << (chan))
+#define AD5686_ADDR_DAC(chan)			(0x1 << (chan))
 #define AD5686_ADDR_ALL_DAC			0xF
 
 #define AD5686_CMD_NOOP				0x0
@@ -137,7 +137,7 @@ static const char * const ad5686_powerdown_modes[] = {
 };
 
 static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
-	const struct iio_chan_spec *chan)
+				     const struct iio_chan_spec *chan)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
@@ -145,7 +145,8 @@ static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
 }
 
 static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev,
-	const struct iio_chan_spec *chan, unsigned int mode)
+				     const struct iio_chan_spec *chan,
+				     unsigned int mode)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
@@ -163,17 +164,19 @@ static const struct iio_enum ad5686_powerdown_mode_enum = {
 };
 
 static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
-	uintptr_t private, const struct iio_chan_spec *chan, char *buf)
+		uintptr_t private, const struct iio_chan_spec *chan, char *buf)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
 	return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
-			(0x3 << (chan->channel * 2))));
+				       (0x3 << (chan->channel * 2))));
 }
 
 static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
-	 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
-	 size_t len)
+					  uintptr_t private,
+					  const struct iio_chan_spec *chan,
+					  const char *buf,
+					  size_t len)
 {
 	bool readin;
 	int ret;
@@ -221,10 +224,10 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
 }
 
 static int ad5686_write_raw(struct iio_dev *indio_dev,
-			       struct iio_chan_spec const *chan,
-			       int val,
-			       int val2,
-			       long mask)
+			    struct iio_chan_spec const *chan,
+			    int val,
+			    int val2,
+			    long mask)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 	int ret;
-- 
2.7.4

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

* [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support
  2018-03-30 13:55 [PATCH 1/3] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
@ 2018-03-30 13:55 ` Stefan Popa
  2018-04-06 15:19   ` Jonathan Cameron
                     ` (3 more replies)
  2018-04-10 15:56 ` [PATCH v2 1/6] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
  1 sibling, 4 replies; 15+ messages in thread
From: Stefan Popa @ 2018-03-30 13:55 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23
  Cc: knaack.h, pmeerw, linux-pm, linux-iio, linux-kernel, stefan.popa

The AD5684R/AD5685R/AD5686R are a family of 4 channel DACs with 12-bit,
14-bit and 16-bit precision respectively. The devices come either with a
built-in reference or no built-in reference.

The AD5672R/AD5676/AD5676R are similar, except that they have 8 channels
instead of 4.

Datasheets:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5672R_5676R.pdf
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686R_5685R_5684R.pdf

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/iio/dac/ad5686.c | 97 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 74 insertions(+), 23 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index f7f975c..5fb0179 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -19,8 +19,6 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
-#define AD5686_DAC_CHANNELS			4
-
 #define AD5686_ADDR(x)				((x) << 16)
 #define AD5686_CMD(x)				((x) << 20)
 
@@ -46,12 +44,14 @@
 /**
  * struct ad5686_chip_info - chip specific information
  * @int_vref_mv:	AD5620/40/60: the internal reference voltage
+ * @num_channels:	number of channels
  * @channel:		channel specification
 */
 
 struct ad5686_chip_info {
 	u16				int_vref_mv;
-	struct iio_chan_spec		channel[AD5686_DAC_CHANNELS];
+	unsigned int			num_channels;
+	struct iio_chan_spec		*channels;
 };
 
 /**
@@ -88,9 +88,14 @@ struct ad5686_state {
  */
 
 enum ad5686_supported_device_ids {
+	ID_AD5672R,
+	ID_AD5676,
+	ID_AD5676R,
 	ID_AD5684,
-	ID_AD5685,
+	ID_AD5684R,
+	ID_AD5685R,
 	ID_AD5686,
+	ID_AD5686R
 };
 static int ad5686_spi_write(struct ad5686_state *st,
 			     u8 cmd, u8 addr, u16 val, u8 shift)
@@ -269,14 +274,14 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 	{ },
 };
 
-#define AD5868_CHANNEL(chan, bits, _shift) {			\
+#define AD5868_CHANNEL(chan, addr, bits, _shift) {		\
 		.type = IIO_VOLTAGE,				\
 		.indexed = 1,					\
 		.output = 1,					\
 		.channel = chan,				\
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
-		.address = AD5686_ADDR_DAC(chan),		\
+		.address = addr,				\
 		.scan_type = {					\
 			.sign = 'u',				\
 			.realbits = (bits),			\
@@ -286,31 +291,72 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 		.ext_info = ad5686_ext_info,			\
 }
 
+#define DECLARE_AD5686_CHANNELS(name, bits, _shift)		\
+static struct iio_chan_spec name[] = {				\
+		AD5868_CHANNEL(0, 1, bits, _shift),		\
+		AD5868_CHANNEL(1, 2, bits, _shift),		\
+		AD5868_CHANNEL(2, 4, bits, _shift),		\
+		AD5868_CHANNEL(3, 8, bits, _shift),		\
+}
+
+#define DECLARE_AD5676_CHANNELS(name, bits, _shift)		\
+static struct iio_chan_spec name[] = {				\
+		AD5868_CHANNEL(0, 0, bits, _shift),		\
+		AD5868_CHANNEL(1, 1, bits, _shift),		\
+		AD5868_CHANNEL(2, 2, bits, _shift),		\
+		AD5868_CHANNEL(3, 3, bits, _shift),		\
+		AD5868_CHANNEL(4, 4, bits, _shift),		\
+		AD5868_CHANNEL(5, 5, bits, _shift),		\
+		AD5868_CHANNEL(6, 6, bits, _shift),		\
+		AD5868_CHANNEL(7, 7, bits, _shift),		\
+}
+
+DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
+DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
+DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
+DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
+DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
+
 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
+	[ID_AD5672R] = {
+		.channels = ad5672_channels,
+		.int_vref_mv = 2500,
+		.num_channels = 8,
+	},
+	[ID_AD5676] = {
+		.channels = ad5676_channels,
+		.num_channels = 8,
+	},
+	[ID_AD5676R] = {
+		.channels = ad5676_channels,
+		.int_vref_mv = 2500,
+		.num_channels = 8,
+	},
 	[ID_AD5684] = {
-		.channel[0] = AD5868_CHANNEL(0, 12, 4),
-		.channel[1] = AD5868_CHANNEL(1, 12, 4),
-		.channel[2] = AD5868_CHANNEL(2, 12, 4),
-		.channel[3] = AD5868_CHANNEL(3, 12, 4),
+		.channels = ad5684_channels,
+		.num_channels = 4,
+	},
+	[ID_AD5684R] = {
+		.channels = ad5684_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
-	[ID_AD5685] = {
-		.channel[0] = AD5868_CHANNEL(0, 14, 2),
-		.channel[1] = AD5868_CHANNEL(1, 14, 2),
-		.channel[2] = AD5868_CHANNEL(2, 14, 2),
-		.channel[3] = AD5868_CHANNEL(3, 14, 2),
+	[ID_AD5685R] = {
+		.channels = ad5685r_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 	[ID_AD5686] = {
-		.channel[0] = AD5868_CHANNEL(0, 16, 0),
-		.channel[1] = AD5868_CHANNEL(1, 16, 0),
-		.channel[2] = AD5868_CHANNEL(2, 16, 0),
-		.channel[3] = AD5868_CHANNEL(3, 16, 0),
+		.channels = ad5686_channels,
+		.num_channels = 4,
+	},
+	[ID_AD5686R] = {
+		.channels = ad5686_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 };
 
-
 static int ad5686_probe(struct spi_device *spi)
 {
 	struct ad5686_state *st;
@@ -354,8 +400,8 @@ static int ad5686_probe(struct spi_device *spi)
 	indio_dev->name = spi_get_device_id(spi)->name;
 	indio_dev->info = &ad5686_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
-	indio_dev->channels = st->chip_info->channel;
-	indio_dev->num_channels = AD5686_DAC_CHANNELS;
+	indio_dev->channels = st->chip_info->channels;
+	indio_dev->num_channels = st->chip_info->num_channels;
 
 	ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
 				!!voltage_uv, 0);
@@ -387,9 +433,14 @@ static int ad5686_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id ad5686_id[] = {
+	{"ad5672r", ID_AD5672R},
+	{"ad5676", ID_AD5676},
+	{"ad5676r", ID_AD5676R},
 	{"ad5684", ID_AD5684},
-	{"ad5685", ID_AD5685},
+	{"ad5684r", ID_AD5684R},
+	{"ad5685r", ID_AD5685R},
 	{"ad5686", ID_AD5686},
+	{"ad5686r", ID_AD5686R},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, ad5686_id);
-- 
2.7.4

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

* Re: [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support
  2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
@ 2018-04-06 15:19   ` Jonathan Cameron
  2018-04-10 15:57   ` [PATCH v2 2/6] iio:dac:ad5686: Add support for various number of channels Stefan Popa
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2018-04-06 15:19 UTC (permalink / raw)
  To: Stefan Popa
  Cc: lars, Michael.Hennerich, jic23, knaack.h, pmeerw, linux-pm,
	linux-iio, linux-kernel

On Fri, 30 Mar 2018 16:55:18 +0300
Stefan Popa <stefan.popa@analog.com> wrote:

> The AD5684R/AD5685R/AD5686R are a family of 4 channel DACs with 12-bit,
> 14-bit and 16-bit precision respectively. The devices come either with a
> built-in reference or no built-in reference.
> 
> The AD5672R/AD5676/AD5676R are similar, except that they have 8 channels
> instead of 4.
> 
> Datasheets:
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD5672R_5676R.pdf
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686R_5685R_5684R.pdf
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
For ease of review, I would prefer to see this split into 2 patches.
First refactor to add num channels and the new macro forms for existing parts.
Then add the new parts.


Jonathan

> ---
>  drivers/iio/dac/ad5686.c | 97 ++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 74 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index f7f975c..5fb0179 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -19,8 +19,6 @@
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  
> -#define AD5686_DAC_CHANNELS			4
> -
>  #define AD5686_ADDR(x)				((x) << 16)
>  #define AD5686_CMD(x)				((x) << 20)
>  
> @@ -46,12 +44,14 @@
>  /**
>   * struct ad5686_chip_info - chip specific information
>   * @int_vref_mv:	AD5620/40/60: the internal reference voltage
> + * @num_channels:	number of channels
>   * @channel:		channel specification
>  */
>  
>  struct ad5686_chip_info {
>  	u16				int_vref_mv;
> -	struct iio_chan_spec		channel[AD5686_DAC_CHANNELS];
> +	unsigned int			num_channels;
> +	struct iio_chan_spec		*channels;
>  };
>  
>  /**
> @@ -88,9 +88,14 @@ struct ad5686_state {
>   */
>  
>  enum ad5686_supported_device_ids {
> +	ID_AD5672R,
> +	ID_AD5676,
> +	ID_AD5676R,
>  	ID_AD5684,
> -	ID_AD5685,
> +	ID_AD5684R,
> +	ID_AD5685R,
>  	ID_AD5686,
> +	ID_AD5686R
>  };
>  static int ad5686_spi_write(struct ad5686_state *st,
>  			     u8 cmd, u8 addr, u16 val, u8 shift)
> @@ -269,14 +274,14 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
>  	{ },
>  };
>  
> -#define AD5868_CHANNEL(chan, bits, _shift) {			\
> +#define AD5868_CHANNEL(chan, addr, bits, _shift) {		\
>  		.type = IIO_VOLTAGE,				\
>  		.indexed = 1,					\
>  		.output = 1,					\
>  		.channel = chan,				\
>  		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
>  		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
> -		.address = AD5686_ADDR_DAC(chan),		\
> +		.address = addr,				\
>  		.scan_type = {					\
>  			.sign = 'u',				\
>  			.realbits = (bits),			\
> @@ -286,31 +291,72 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
>  		.ext_info = ad5686_ext_info,			\
>  }
>  
> +#define DECLARE_AD5686_CHANNELS(name, bits, _shift)		\
> +static struct iio_chan_spec name[] = {				\
> +		AD5868_CHANNEL(0, 1, bits, _shift),		\
> +		AD5868_CHANNEL(1, 2, bits, _shift),		\
> +		AD5868_CHANNEL(2, 4, bits, _shift),		\
> +		AD5868_CHANNEL(3, 8, bits, _shift),		\
> +}
> +
> +#define DECLARE_AD5676_CHANNELS(name, bits, _shift)		\
> +static struct iio_chan_spec name[] = {				\
> +		AD5868_CHANNEL(0, 0, bits, _shift),		\
> +		AD5868_CHANNEL(1, 1, bits, _shift),		\
> +		AD5868_CHANNEL(2, 2, bits, _shift),		\
> +		AD5868_CHANNEL(3, 3, bits, _shift),		\
> +		AD5868_CHANNEL(4, 4, bits, _shift),		\
> +		AD5868_CHANNEL(5, 5, bits, _shift),		\
> +		AD5868_CHANNEL(6, 6, bits, _shift),		\
> +		AD5868_CHANNEL(7, 7, bits, _shift),		\
> +}
> +
> +DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
> +DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
> +DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
> +DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
> +DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
> +
>  static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
> +	[ID_AD5672R] = {
> +		.channels = ad5672_channels,
> +		.int_vref_mv = 2500,
> +		.num_channels = 8,
> +	},
> +	[ID_AD5676] = {
> +		.channels = ad5676_channels,
> +		.num_channels = 8,
> +	},
> +	[ID_AD5676R] = {
> +		.channels = ad5676_channels,
> +		.int_vref_mv = 2500,
> +		.num_channels = 8,
> +	},
>  	[ID_AD5684] = {
> -		.channel[0] = AD5868_CHANNEL(0, 12, 4),
> -		.channel[1] = AD5868_CHANNEL(1, 12, 4),
> -		.channel[2] = AD5868_CHANNEL(2, 12, 4),
> -		.channel[3] = AD5868_CHANNEL(3, 12, 4),
> +		.channels = ad5684_channels,
> +		.num_channels = 4,
> +	},
> +	[ID_AD5684R] = {
> +		.channels = ad5684_channels,
>  		.int_vref_mv = 2500,
> +		.num_channels = 4,
>  	},
> -	[ID_AD5685] = {
> -		.channel[0] = AD5868_CHANNEL(0, 14, 2),
> -		.channel[1] = AD5868_CHANNEL(1, 14, 2),
> -		.channel[2] = AD5868_CHANNEL(2, 14, 2),
> -		.channel[3] = AD5868_CHANNEL(3, 14, 2),
> +	[ID_AD5685R] = {
> +		.channels = ad5685r_channels,
>  		.int_vref_mv = 2500,
> +		.num_channels = 4,
>  	},
>  	[ID_AD5686] = {
> -		.channel[0] = AD5868_CHANNEL(0, 16, 0),
> -		.channel[1] = AD5868_CHANNEL(1, 16, 0),
> -		.channel[2] = AD5868_CHANNEL(2, 16, 0),
> -		.channel[3] = AD5868_CHANNEL(3, 16, 0),
> +		.channels = ad5686_channels,
> +		.num_channels = 4,
> +	},
> +	[ID_AD5686R] = {
> +		.channels = ad5686_channels,
>  		.int_vref_mv = 2500,
> +		.num_channels = 4,
>  	},
>  };
>  
> -
>  static int ad5686_probe(struct spi_device *spi)
>  {
>  	struct ad5686_state *st;
> @@ -354,8 +400,8 @@ static int ad5686_probe(struct spi_device *spi)
>  	indio_dev->name = spi_get_device_id(spi)->name;
>  	indio_dev->info = &ad5686_info;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
> -	indio_dev->channels = st->chip_info->channel;
> -	indio_dev->num_channels = AD5686_DAC_CHANNELS;
> +	indio_dev->channels = st->chip_info->channels;
> +	indio_dev->num_channels = st->chip_info->num_channels;
>  
>  	ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
>  				!!voltage_uv, 0);
> @@ -387,9 +433,14 @@ static int ad5686_remove(struct spi_device *spi)
>  }
>  
>  static const struct spi_device_id ad5686_id[] = {
> +	{"ad5672r", ID_AD5672R},
> +	{"ad5676", ID_AD5676},
> +	{"ad5676r", ID_AD5676R},
>  	{"ad5684", ID_AD5684},
> -	{"ad5685", ID_AD5685},
> +	{"ad5684r", ID_AD5684R},
> +	{"ad5685r", ID_AD5685R},
>  	{"ad5686", ID_AD5686},
> +	{"ad5686r", ID_AD5686R},
>  	{}
>  };
>  MODULE_DEVICE_TABLE(spi, ad5686_id);

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

* [PATCH v2 1/6] iio:dac:ad5686: Style fixes no functional changes
  2018-03-30 13:55 [PATCH 1/3] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
  2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
@ 2018-04-10 15:56 ` Stefan Popa
  2018-04-11 11:51   ` [PATCH v3 1/7] " Stefan Popa
  1 sibling, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-10 15:56 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

This patch fixes some indentation issues and does not modify the
functionality of the driver.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/iio/dac/ad5686.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 20254df..f7f975c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -24,7 +24,7 @@
 #define AD5686_ADDR(x)				((x) << 16)
 #define AD5686_CMD(x)				((x) << 20)
 
-#define AD5686_ADDR_DAC(chan)		(0x1 << (chan))
+#define AD5686_ADDR_DAC(chan)			(0x1 << (chan))
 #define AD5686_ADDR_ALL_DAC			0xF
 
 #define AD5686_CMD_NOOP				0x0
@@ -137,7 +137,7 @@ static const char * const ad5686_powerdown_modes[] = {
 };
 
 static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
-	const struct iio_chan_spec *chan)
+				     const struct iio_chan_spec *chan)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
@@ -145,7 +145,8 @@ static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
 }
 
 static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev,
-	const struct iio_chan_spec *chan, unsigned int mode)
+				     const struct iio_chan_spec *chan,
+				     unsigned int mode)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
@@ -163,17 +164,19 @@ static const struct iio_enum ad5686_powerdown_mode_enum = {
 };
 
 static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
-	uintptr_t private, const struct iio_chan_spec *chan, char *buf)
+		uintptr_t private, const struct iio_chan_spec *chan, char *buf)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
 	return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
-			(0x3 << (chan->channel * 2))));
+				       (0x3 << (chan->channel * 2))));
 }
 
 static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
-	 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
-	 size_t len)
+					  uintptr_t private,
+					  const struct iio_chan_spec *chan,
+					  const char *buf,
+					  size_t len)
 {
 	bool readin;
 	int ret;
@@ -221,10 +224,10 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
 }
 
 static int ad5686_write_raw(struct iio_dev *indio_dev,
-			       struct iio_chan_spec const *chan,
-			       int val,
-			       int val2,
-			       long mask)
+			    struct iio_chan_spec const *chan,
+			    int val,
+			    int val2,
+			    long mask)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 	int ret;
-- 
2.7.4

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

* [PATCH v2 2/6] iio:dac:ad5686: Add support for various number of channels
  2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
  2018-04-06 15:19   ` Jonathan Cameron
@ 2018-04-10 15:57   ` Stefan Popa
  2018-04-11 11:52     ` [PATCH v3 3/7] " Stefan Popa
  2018-04-10 15:57   ` [PATCH v2 3/6] iio:dac:ad5686: Add support for AD5685R Stefan Popa
  2018-04-10 15:57   ` [PATCH v2 4/6] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support Stefan Popa
  3 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-10 15:57 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

This patch adds a new num_channels attribute as part of the
ad5686_chip_info struct which replaces the AD5686_DAC_CHANNELS define. This
is a necessary step, since this driver should support similar devices which
differ only in the number of channels.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes in v2:
	- Refactored the patch to add num_channels and the new macro forms
	  for the existing parts.

 drivers/iio/dac/ad5686.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index f7f975c..4d1ae3d 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -19,8 +19,6 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
-#define AD5686_DAC_CHANNELS			4
-
 #define AD5686_ADDR(x)				((x) << 16)
 #define AD5686_CMD(x)				((x) << 20)
 
@@ -46,12 +44,14 @@
 /**
  * struct ad5686_chip_info - chip specific information
  * @int_vref_mv:	AD5620/40/60: the internal reference voltage
+ * @num_channels:	number of channels
  * @channel:		channel specification
 */
 
 struct ad5686_chip_info {
 	u16				int_vref_mv;
-	struct iio_chan_spec		channel[AD5686_DAC_CHANNELS];
+	unsigned int			num_channels;
+	struct iio_chan_spec		*channels;
 };
 
 /**
@@ -269,14 +269,14 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 	{ },
 };
 
-#define AD5868_CHANNEL(chan, bits, _shift) {			\
+#define AD5868_CHANNEL(chan, addr, bits, _shift) {		\
 		.type = IIO_VOLTAGE,				\
 		.indexed = 1,					\
 		.output = 1,					\
 		.channel = chan,				\
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
-		.address = AD5686_ADDR_DAC(chan),		\
+		.address = addr,				\
 		.scan_type = {					\
 			.sign = 'u',				\
 			.realbits = (bits),			\
@@ -286,31 +286,36 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 		.ext_info = ad5686_ext_info,			\
 }
 
+#define DECLARE_AD5686_CHANNELS(name, bits, _shift)		\
+static struct iio_chan_spec name[] = {				\
+		AD5868_CHANNEL(0, 1, bits, _shift),		\
+		AD5868_CHANNEL(1, 2, bits, _shift),		\
+		AD5868_CHANNEL(2, 4, bits, _shift),		\
+		AD5868_CHANNEL(3, 8, bits, _shift),		\
+}
+
+DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
+DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
+DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
+
 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 	[ID_AD5684] = {
-		.channel[0] = AD5868_CHANNEL(0, 12, 4),
-		.channel[1] = AD5868_CHANNEL(1, 12, 4),
-		.channel[2] = AD5868_CHANNEL(2, 12, 4),
-		.channel[3] = AD5868_CHANNEL(3, 12, 4),
+		.channels = ad5684_channels,
+		.num_channels = 4,
 		.int_vref_mv = 2500,
 	},
 	[ID_AD5685] = {
-		.channel[0] = AD5868_CHANNEL(0, 14, 2),
-		.channel[1] = AD5868_CHANNEL(1, 14, 2),
-		.channel[2] = AD5868_CHANNEL(2, 14, 2),
-		.channel[3] = AD5868_CHANNEL(3, 14, 2),
+		.channels = ad5685r_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 	[ID_AD5686] = {
-		.channel[0] = AD5868_CHANNEL(0, 16, 0),
-		.channel[1] = AD5868_CHANNEL(1, 16, 0),
-		.channel[2] = AD5868_CHANNEL(2, 16, 0),
-		.channel[3] = AD5868_CHANNEL(3, 16, 0),
+		.channels = ad5686_channels,
+		.num_channels = 4,
 		.int_vref_mv = 2500,
 	},
 };
 
-
 static int ad5686_probe(struct spi_device *spi)
 {
 	struct ad5686_state *st;
@@ -354,8 +359,8 @@ static int ad5686_probe(struct spi_device *spi)
 	indio_dev->name = spi_get_device_id(spi)->name;
 	indio_dev->info = &ad5686_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
-	indio_dev->channels = st->chip_info->channel;
-	indio_dev->num_channels = AD5686_DAC_CHANNELS;
+	indio_dev->channels = st->chip_info->channels;
+	indio_dev->num_channels = st->chip_info->num_channels;
 
 	ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
 				!!voltage_uv, 0);
-- 
2.7.4

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

* [PATCH v2 3/6] iio:dac:ad5686: Add support for AD5685R
  2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
  2018-04-06 15:19   ` Jonathan Cameron
  2018-04-10 15:57   ` [PATCH v2 2/6] iio:dac:ad5686: Add support for various number of channels Stefan Popa
@ 2018-04-10 15:57   ` Stefan Popa
  2018-04-11 11:52     ` [PATCH v3 4/7] " Stefan Popa
  2018-04-10 15:57   ` [PATCH v2 4/6] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support Stefan Popa
  3 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-10 15:57 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

This driver acctually supports the AD5685R device and NOT the AD5685, which
does not exist.

More information can be found in the datasheet:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686_5684.pdf

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes in v2:
	- Refactored the patch to add support for new parts

 drivers/iio/dac/ad5686.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 4d1ae3d..7353c03 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -89,7 +89,7 @@ struct ad5686_state {
 
 enum ad5686_supported_device_ids {
 	ID_AD5684,
-	ID_AD5685,
+	ID_AD5685R,
 	ID_AD5686,
 };
 static int ad5686_spi_write(struct ad5686_state *st,
@@ -304,7 +304,7 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 		.num_channels = 4,
 		.int_vref_mv = 2500,
 	},
-	[ID_AD5685] = {
+	[ID_AD5685R] = {
 		.channels = ad5685r_channels,
 		.int_vref_mv = 2500,
 		.num_channels = 4,
@@ -393,7 +393,7 @@ static int ad5686_remove(struct spi_device *spi)
 
 static const struct spi_device_id ad5686_id[] = {
 	{"ad5684", ID_AD5684},
-	{"ad5685", ID_AD5685},
+	{"ad5685r", ID_AD5685R},
 	{"ad5686", ID_AD5686},
 	{}
 };
-- 
2.7.4

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

* [PATCH v2 4/6] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support
  2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
                     ` (2 preceding siblings ...)
  2018-04-10 15:57   ` [PATCH v2 3/6] iio:dac:ad5686: Add support for AD5685R Stefan Popa
@ 2018-04-10 15:57   ` Stefan Popa
  2018-04-11 11:53     ` [PATCH v3 5/7] " Stefan Popa
  3 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-10 15:57 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

The AD5684R/AD5686R are a family of 4 channel DACs with 12-bit, 14-bit and
16-bit precision respectively. The devices come either with a built-in
reference or no built-in reference.

The AD5672R/AD5676/AD5676R are similar, except that they have 8 channels
instead of 4.

Datasheets:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5672R_5676R.pdf
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686R_5685R_5684R.pdf

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes in v2:
	- Refactored the patch to add support for new parts
 drivers/iio/dac/ad5686.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 7353c03..5fb0179 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -88,9 +88,14 @@ struct ad5686_state {
  */
 
 enum ad5686_supported_device_ids {
+	ID_AD5672R,
+	ID_AD5676,
+	ID_AD5676R,
 	ID_AD5684,
+	ID_AD5684R,
 	ID_AD5685R,
 	ID_AD5686,
+	ID_AD5686R
 };
 static int ad5686_spi_write(struct ad5686_state *st,
 			     u8 cmd, u8 addr, u16 val, u8 shift)
@@ -294,15 +299,47 @@ static struct iio_chan_spec name[] = {				\
 		AD5868_CHANNEL(3, 8, bits, _shift),		\
 }
 
+#define DECLARE_AD5676_CHANNELS(name, bits, _shift)		\
+static struct iio_chan_spec name[] = {				\
+		AD5868_CHANNEL(0, 0, bits, _shift),		\
+		AD5868_CHANNEL(1, 1, bits, _shift),		\
+		AD5868_CHANNEL(2, 2, bits, _shift),		\
+		AD5868_CHANNEL(3, 3, bits, _shift),		\
+		AD5868_CHANNEL(4, 4, bits, _shift),		\
+		AD5868_CHANNEL(5, 5, bits, _shift),		\
+		AD5868_CHANNEL(6, 6, bits, _shift),		\
+		AD5868_CHANNEL(7, 7, bits, _shift),		\
+}
+
+DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
+DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
 DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
 DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
 DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
 
 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
+	[ID_AD5672R] = {
+		.channels = ad5672_channels,
+		.int_vref_mv = 2500,
+		.num_channels = 8,
+	},
+	[ID_AD5676] = {
+		.channels = ad5676_channels,
+		.num_channels = 8,
+	},
+	[ID_AD5676R] = {
+		.channels = ad5676_channels,
+		.int_vref_mv = 2500,
+		.num_channels = 8,
+	},
 	[ID_AD5684] = {
 		.channels = ad5684_channels,
 		.num_channels = 4,
+	},
+	[ID_AD5684R] = {
+		.channels = ad5684_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 	[ID_AD5685R] = {
 		.channels = ad5685r_channels,
@@ -312,7 +349,11 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 	[ID_AD5686] = {
 		.channels = ad5686_channels,
 		.num_channels = 4,
+	},
+	[ID_AD5686R] = {
+		.channels = ad5686_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 };
 
@@ -392,9 +433,14 @@ static int ad5686_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id ad5686_id[] = {
+	{"ad5672r", ID_AD5672R},
+	{"ad5676", ID_AD5676},
+	{"ad5676r", ID_AD5676R},
 	{"ad5684", ID_AD5684},
+	{"ad5684r", ID_AD5684R},
 	{"ad5685r", ID_AD5685R},
 	{"ad5686", ID_AD5686},
+	{"ad5686r", ID_AD5686R},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, ad5686_id);
-- 
2.7.4

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

* [PATCH v3 1/7] iio:dac:ad5686: Style fixes no functional changes
  2018-04-10 15:56 ` [PATCH v2 1/6] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
@ 2018-04-11 11:51   ` Stefan Popa
  2018-04-15 18:11     ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-11 11:51 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

This patch fixes some indentation issues and does not modify the
functionality of the driver.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes v2:
	- Nothing changed, just follow the patch set version.
Changes v3:
        - Nothing changed, just follow the patch set version.

 drivers/iio/dac/ad5686.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 20254df..f7f975c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -24,7 +24,7 @@
 #define AD5686_ADDR(x)				((x) << 16)
 #define AD5686_CMD(x)				((x) << 20)
 
-#define AD5686_ADDR_DAC(chan)		(0x1 << (chan))
+#define AD5686_ADDR_DAC(chan)			(0x1 << (chan))
 #define AD5686_ADDR_ALL_DAC			0xF
 
 #define AD5686_CMD_NOOP				0x0
@@ -137,7 +137,7 @@ static const char * const ad5686_powerdown_modes[] = {
 };
 
 static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
-	const struct iio_chan_spec *chan)
+				     const struct iio_chan_spec *chan)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
@@ -145,7 +145,8 @@ static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
 }
 
 static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev,
-	const struct iio_chan_spec *chan, unsigned int mode)
+				     const struct iio_chan_spec *chan,
+				     unsigned int mode)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
@@ -163,17 +164,19 @@ static const struct iio_enum ad5686_powerdown_mode_enum = {
 };
 
 static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
-	uintptr_t private, const struct iio_chan_spec *chan, char *buf)
+		uintptr_t private, const struct iio_chan_spec *chan, char *buf)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 
 	return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
-			(0x3 << (chan->channel * 2))));
+				       (0x3 << (chan->channel * 2))));
 }
 
 static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
-	 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
-	 size_t len)
+					  uintptr_t private,
+					  const struct iio_chan_spec *chan,
+					  const char *buf,
+					  size_t len)
 {
 	bool readin;
 	int ret;
@@ -221,10 +224,10 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
 }
 
 static int ad5686_write_raw(struct iio_dev *indio_dev,
-			       struct iio_chan_spec const *chan,
-			       int val,
-			       int val2,
-			       long mask)
+			    struct iio_chan_spec const *chan,
+			    int val,
+			    int val2,
+			    long mask)
 {
 	struct ad5686_state *st = iio_priv(indio_dev);
 	int ret;
-- 
2.7.4

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

* [PATCH v3 3/7] iio:dac:ad5686: Add support for various number of channels
  2018-04-10 15:57   ` [PATCH v2 2/6] iio:dac:ad5686: Add support for various number of channels Stefan Popa
@ 2018-04-11 11:52     ` Stefan Popa
  2018-04-15 18:16       ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-11 11:52 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

This patch adds a new num_channels attribute as part of the
ad5686_chip_info struct which replaces the AD5686_DAC_CHANNELS define. This
is a necessary step, since this driver should support similar devices which
differ only in the number of channels.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes in v2:
	- Refactored the patch to add num_channels and the new macro forms
	  for the existing parts.
Changes in v3:
	- Nothing changed, just follow the patch set version.

 drivers/iio/dac/ad5686.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index e328513..87d6e6e 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -18,8 +18,6 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
-#define AD5686_DAC_CHANNELS			4
-
 #define AD5686_ADDR(x)				((x) << 16)
 #define AD5686_CMD(x)				((x) << 20)
 
@@ -45,12 +43,14 @@
 /**
  * struct ad5686_chip_info - chip specific information
  * @int_vref_mv:	AD5620/40/60: the internal reference voltage
+ * @num_channels:	number of channels
  * @channel:		channel specification
 */
 
 struct ad5686_chip_info {
 	u16				int_vref_mv;
-	struct iio_chan_spec		channel[AD5686_DAC_CHANNELS];
+	unsigned int			num_channels;
+	struct iio_chan_spec		*channels;
 };
 
 /**
@@ -268,14 +268,14 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 	{ },
 };
 
-#define AD5868_CHANNEL(chan, bits, _shift) {			\
+#define AD5868_CHANNEL(chan, addr, bits, _shift) {		\
 		.type = IIO_VOLTAGE,				\
 		.indexed = 1,					\
 		.output = 1,					\
 		.channel = chan,				\
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
-		.address = AD5686_ADDR_DAC(chan),		\
+		.address = addr,				\
 		.scan_type = {					\
 			.sign = 'u',				\
 			.realbits = (bits),			\
@@ -285,31 +285,36 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
 		.ext_info = ad5686_ext_info,			\
 }
 
+#define DECLARE_AD5686_CHANNELS(name, bits, _shift)		\
+static struct iio_chan_spec name[] = {				\
+		AD5868_CHANNEL(0, 1, bits, _shift),		\
+		AD5868_CHANNEL(1, 2, bits, _shift),		\
+		AD5868_CHANNEL(2, 4, bits, _shift),		\
+		AD5868_CHANNEL(3, 8, bits, _shift),		\
+}
+
+DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
+DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
+DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
+
 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 	[ID_AD5684] = {
-		.channel[0] = AD5868_CHANNEL(0, 12, 4),
-		.channel[1] = AD5868_CHANNEL(1, 12, 4),
-		.channel[2] = AD5868_CHANNEL(2, 12, 4),
-		.channel[3] = AD5868_CHANNEL(3, 12, 4),
+		.channels = ad5684_channels,
+		.num_channels = 4,
 		.int_vref_mv = 2500,
 	},
 	[ID_AD5685] = {
-		.channel[0] = AD5868_CHANNEL(0, 14, 2),
-		.channel[1] = AD5868_CHANNEL(1, 14, 2),
-		.channel[2] = AD5868_CHANNEL(2, 14, 2),
-		.channel[3] = AD5868_CHANNEL(3, 14, 2),
+		.channels = ad5685r_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 	[ID_AD5686] = {
-		.channel[0] = AD5868_CHANNEL(0, 16, 0),
-		.channel[1] = AD5868_CHANNEL(1, 16, 0),
-		.channel[2] = AD5868_CHANNEL(2, 16, 0),
-		.channel[3] = AD5868_CHANNEL(3, 16, 0),
+		.channels = ad5686_channels,
+		.num_channels = 4,
 		.int_vref_mv = 2500,
 	},
 };
 
-
 static int ad5686_probe(struct spi_device *spi)
 {
 	struct ad5686_state *st;
@@ -353,8 +358,8 @@ static int ad5686_probe(struct spi_device *spi)
 	indio_dev->name = spi_get_device_id(spi)->name;
 	indio_dev->info = &ad5686_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
-	indio_dev->channels = st->chip_info->channel;
-	indio_dev->num_channels = AD5686_DAC_CHANNELS;
+	indio_dev->channels = st->chip_info->channels;
+	indio_dev->num_channels = st->chip_info->num_channels;
 
 	ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
 				!!voltage_uv, 0);
-- 
2.7.4

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

* [PATCH v3 4/7] iio:dac:ad5686: Add support for AD5685R
  2018-04-10 15:57   ` [PATCH v2 3/6] iio:dac:ad5686: Add support for AD5685R Stefan Popa
@ 2018-04-11 11:52     ` Stefan Popa
  2018-04-15 18:20       ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-11 11:52 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

This driver acctually supports the AD5685R device and NOT the AD5685, which
does not exist.

More information can be found in the datasheet:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686_5684.pdf

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes in v2:
	- Refactored the patch to add support for new parts
Changes in v3:
	- Nothing changed, just to follow the patch set version.

 drivers/iio/dac/ad5686.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 87d6e6e..a753ffd 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -88,7 +88,7 @@ struct ad5686_state {
 
 enum ad5686_supported_device_ids {
 	ID_AD5684,
-	ID_AD5685,
+	ID_AD5685R,
 	ID_AD5686,
 };
 static int ad5686_spi_write(struct ad5686_state *st,
@@ -303,7 +303,7 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 		.num_channels = 4,
 		.int_vref_mv = 2500,
 	},
-	[ID_AD5685] = {
+	[ID_AD5685R] = {
 		.channels = ad5685r_channels,
 		.int_vref_mv = 2500,
 		.num_channels = 4,
@@ -392,7 +392,7 @@ static int ad5686_remove(struct spi_device *spi)
 
 static const struct spi_device_id ad5686_id[] = {
 	{"ad5684", ID_AD5684},
-	{"ad5685", ID_AD5685},
+	{"ad5685r", ID_AD5685R},
 	{"ad5686", ID_AD5686},
 	{}
 };
-- 
2.7.4

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

* [PATCH v3 5/7] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support
  2018-04-10 15:57   ` [PATCH v2 4/6] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support Stefan Popa
@ 2018-04-11 11:53     ` Stefan Popa
  2018-04-15 18:23       ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Popa @ 2018-04-11 11:53 UTC (permalink / raw)
  To: jic23, Michael.Hennerich, lars
  Cc: knaack.h, pmeerw, linux-iio, linux-kernel, stefan.popa

The AD5684R/AD5686R are a family of 4 channel DACs with 12-bit, 14-bit and
16-bit precision respectively. The devices come either with a built-in
reference or no built-in reference.

The AD5672R/AD5676/AD5676R are similar, except that they have 8 channels
instead of 4.

Datasheets:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5672R_5676R.pdf
http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686R_5685R_5684R.pdf

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
Changes in v2:
	- Refactored the patch to add support for new parts
Changes in v3:
	- Nothing changed, just to follow the patch set version

 drivers/iio/dac/ad5686.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index a753ffd..54f67d5 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -87,9 +87,14 @@ struct ad5686_state {
  */
 
 enum ad5686_supported_device_ids {
+	ID_AD5672R,
+	ID_AD5676,
+	ID_AD5676R,
 	ID_AD5684,
+	ID_AD5684R,
 	ID_AD5685R,
 	ID_AD5686,
+	ID_AD5686R
 };
 static int ad5686_spi_write(struct ad5686_state *st,
 			     u8 cmd, u8 addr, u16 val, u8 shift)
@@ -293,15 +298,47 @@ static struct iio_chan_spec name[] = {				\
 		AD5868_CHANNEL(3, 8, bits, _shift),		\
 }
 
+#define DECLARE_AD5676_CHANNELS(name, bits, _shift)		\
+static struct iio_chan_spec name[] = {				\
+		AD5868_CHANNEL(0, 0, bits, _shift),		\
+		AD5868_CHANNEL(1, 1, bits, _shift),		\
+		AD5868_CHANNEL(2, 2, bits, _shift),		\
+		AD5868_CHANNEL(3, 3, bits, _shift),		\
+		AD5868_CHANNEL(4, 4, bits, _shift),		\
+		AD5868_CHANNEL(5, 5, bits, _shift),		\
+		AD5868_CHANNEL(6, 6, bits, _shift),		\
+		AD5868_CHANNEL(7, 7, bits, _shift),		\
+}
+
+DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
+DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
 DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
 DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
 DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
 
 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
+	[ID_AD5672R] = {
+		.channels = ad5672_channels,
+		.int_vref_mv = 2500,
+		.num_channels = 8,
+	},
+	[ID_AD5676] = {
+		.channels = ad5676_channels,
+		.num_channels = 8,
+	},
+	[ID_AD5676R] = {
+		.channels = ad5676_channels,
+		.int_vref_mv = 2500,
+		.num_channels = 8,
+	},
 	[ID_AD5684] = {
 		.channels = ad5684_channels,
 		.num_channels = 4,
+	},
+	[ID_AD5684R] = {
+		.channels = ad5684_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 	[ID_AD5685R] = {
 		.channels = ad5685r_channels,
@@ -311,7 +348,11 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
 	[ID_AD5686] = {
 		.channels = ad5686_channels,
 		.num_channels = 4,
+	},
+	[ID_AD5686R] = {
+		.channels = ad5686_channels,
 		.int_vref_mv = 2500,
+		.num_channels = 4,
 	},
 };
 
@@ -391,9 +432,14 @@ static int ad5686_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id ad5686_id[] = {
+	{"ad5672r", ID_AD5672R},
+	{"ad5676", ID_AD5676},
+	{"ad5676r", ID_AD5676R},
 	{"ad5684", ID_AD5684},
+	{"ad5684r", ID_AD5684R},
 	{"ad5685r", ID_AD5685R},
 	{"ad5686", ID_AD5686},
+	{"ad5686r", ID_AD5686R},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, ad5686_id);
-- 
2.7.4

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

* Re: [PATCH v3 1/7] iio:dac:ad5686: Style fixes no functional changes
  2018-04-11 11:51   ` [PATCH v3 1/7] " Stefan Popa
@ 2018-04-15 18:11     ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2018-04-15 18:11 UTC (permalink / raw)
  To: Stefan Popa
  Cc: Michael.Hennerich, lars, knaack.h, pmeerw, linux-iio, linux-kernel

On Wed, 11 Apr 2018 14:51:51 +0300
Stefan Popa <stefan.popa@analog.com> wrote:

> This patch fixes some indentation issues and does not modify the
> functionality of the driver.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
I'll try unwinding it this time, but please make absolutely
sure you don't reply to an existing series with a new series.
The patches are displayed in my email account, weirdly nested
and interleaved out of order.

Much nicer to have a new separate series!

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it,

Thanks,

Jonathan

> ---
> Changes v2:
> 	- Nothing changed, just follow the patch set version.
> Changes v3:
>         - Nothing changed, just follow the patch set version.
> 
>  drivers/iio/dac/ad5686.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 20254df..f7f975c 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -24,7 +24,7 @@
>  #define AD5686_ADDR(x)				((x) << 16)
>  #define AD5686_CMD(x)				((x) << 20)
>  
> -#define AD5686_ADDR_DAC(chan)		(0x1 << (chan))
> +#define AD5686_ADDR_DAC(chan)			(0x1 << (chan))
>  #define AD5686_ADDR_ALL_DAC			0xF
>  
>  #define AD5686_CMD_NOOP				0x0
> @@ -137,7 +137,7 @@ static const char * const ad5686_powerdown_modes[] = {
>  };
>  
>  static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
> -	const struct iio_chan_spec *chan)
> +				     const struct iio_chan_spec *chan)
>  {
>  	struct ad5686_state *st = iio_priv(indio_dev);
>  
> @@ -145,7 +145,8 @@ static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
>  }
>  
>  static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev,
> -	const struct iio_chan_spec *chan, unsigned int mode)
> +				     const struct iio_chan_spec *chan,
> +				     unsigned int mode)
>  {
>  	struct ad5686_state *st = iio_priv(indio_dev);
>  
> @@ -163,17 +164,19 @@ static const struct iio_enum ad5686_powerdown_mode_enum = {
>  };
>  
>  static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev,
> -	uintptr_t private, const struct iio_chan_spec *chan, char *buf)
> +		uintptr_t private, const struct iio_chan_spec *chan, char *buf)
>  {
>  	struct ad5686_state *st = iio_priv(indio_dev);
>  
>  	return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
> -			(0x3 << (chan->channel * 2))));
> +				       (0x3 << (chan->channel * 2))));
>  }
>  
>  static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev,
> -	 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
> -	 size_t len)
> +					  uintptr_t private,
> +					  const struct iio_chan_spec *chan,
> +					  const char *buf,
> +					  size_t len)
>  {
>  	bool readin;
>  	int ret;
> @@ -221,10 +224,10 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
>  }
>  
>  static int ad5686_write_raw(struct iio_dev *indio_dev,
> -			       struct iio_chan_spec const *chan,
> -			       int val,
> -			       int val2,
> -			       long mask)
> +			    struct iio_chan_spec const *chan,
> +			    int val,
> +			    int val2,
> +			    long mask)
>  {
>  	struct ad5686_state *st = iio_priv(indio_dev);
>  	int ret;

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

* Re: [PATCH v3 3/7] iio:dac:ad5686: Add support for various number of channels
  2018-04-11 11:52     ` [PATCH v3 3/7] " Stefan Popa
@ 2018-04-15 18:16       ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2018-04-15 18:16 UTC (permalink / raw)
  To: Stefan Popa
  Cc: Michael.Hennerich, lars, knaack.h, pmeerw, linux-iio, linux-kernel

On Wed, 11 Apr 2018 14:52:31 +0300
Stefan Popa <stefan.popa@analog.com> wrote:

> This patch adds a new num_channels attribute as part of the
> ad5686_chip_info struct which replaces the AD5686_DAC_CHANNELS define. This
> is a necessary step, since this driver should support similar devices which
> differ only in the number of channels.
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan

> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> ---
> Changes in v2:
> 	- Refactored the patch to add num_channels and the new macro forms
> 	  for the existing parts.
> Changes in v3:
> 	- Nothing changed, just follow the patch set version.
> 
>  drivers/iio/dac/ad5686.c | 45 +++++++++++++++++++++++++--------------------
>  1 file changed, 25 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index e328513..87d6e6e 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -18,8 +18,6 @@
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  
> -#define AD5686_DAC_CHANNELS			4
> -
>  #define AD5686_ADDR(x)				((x) << 16)
>  #define AD5686_CMD(x)				((x) << 20)
>  
> @@ -45,12 +43,14 @@
>  /**
>   * struct ad5686_chip_info - chip specific information
>   * @int_vref_mv:	AD5620/40/60: the internal reference voltage
> + * @num_channels:	number of channels
>   * @channel:		channel specification
>  */
>  
>  struct ad5686_chip_info {
>  	u16				int_vref_mv;
> -	struct iio_chan_spec		channel[AD5686_DAC_CHANNELS];
> +	unsigned int			num_channels;
> +	struct iio_chan_spec		*channels;
>  };
>  
>  /**
> @@ -268,14 +268,14 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
>  	{ },
>  };
>  
> -#define AD5868_CHANNEL(chan, bits, _shift) {			\
> +#define AD5868_CHANNEL(chan, addr, bits, _shift) {		\
>  		.type = IIO_VOLTAGE,				\
>  		.indexed = 1,					\
>  		.output = 1,					\
>  		.channel = chan,				\
>  		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
>  		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
> -		.address = AD5686_ADDR_DAC(chan),		\
> +		.address = addr,				\
>  		.scan_type = {					\
>  			.sign = 'u',				\
>  			.realbits = (bits),			\
> @@ -285,31 +285,36 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
>  		.ext_info = ad5686_ext_info,			\
>  }
>  
> +#define DECLARE_AD5686_CHANNELS(name, bits, _shift)		\
> +static struct iio_chan_spec name[] = {				\
> +		AD5868_CHANNEL(0, 1, bits, _shift),		\
> +		AD5868_CHANNEL(1, 2, bits, _shift),		\
> +		AD5868_CHANNEL(2, 4, bits, _shift),		\
> +		AD5868_CHANNEL(3, 8, bits, _shift),		\
> +}
> +
> +DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
> +DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
> +DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
> +
>  static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
>  	[ID_AD5684] = {
> -		.channel[0] = AD5868_CHANNEL(0, 12, 4),
> -		.channel[1] = AD5868_CHANNEL(1, 12, 4),
> -		.channel[2] = AD5868_CHANNEL(2, 12, 4),
> -		.channel[3] = AD5868_CHANNEL(3, 12, 4),
> +		.channels = ad5684_channels,
> +		.num_channels = 4,
>  		.int_vref_mv = 2500,
>  	},
>  	[ID_AD5685] = {
> -		.channel[0] = AD5868_CHANNEL(0, 14, 2),
> -		.channel[1] = AD5868_CHANNEL(1, 14, 2),
> -		.channel[2] = AD5868_CHANNEL(2, 14, 2),
> -		.channel[3] = AD5868_CHANNEL(3, 14, 2),
> +		.channels = ad5685r_channels,
>  		.int_vref_mv = 2500,
> +		.num_channels = 4,
>  	},
>  	[ID_AD5686] = {
> -		.channel[0] = AD5868_CHANNEL(0, 16, 0),
> -		.channel[1] = AD5868_CHANNEL(1, 16, 0),
> -		.channel[2] = AD5868_CHANNEL(2, 16, 0),
> -		.channel[3] = AD5868_CHANNEL(3, 16, 0),
> +		.channels = ad5686_channels,
> +		.num_channels = 4,
>  		.int_vref_mv = 2500,
>  	},
>  };
>  
> -
>  static int ad5686_probe(struct spi_device *spi)
>  {
>  	struct ad5686_state *st;
> @@ -353,8 +358,8 @@ static int ad5686_probe(struct spi_device *spi)
>  	indio_dev->name = spi_get_device_id(spi)->name;
>  	indio_dev->info = &ad5686_info;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
> -	indio_dev->channels = st->chip_info->channel;
> -	indio_dev->num_channels = AD5686_DAC_CHANNELS;
> +	indio_dev->channels = st->chip_info->channels;
> +	indio_dev->num_channels = st->chip_info->num_channels;
>  
>  	ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
>  				!!voltage_uv, 0);

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

* Re: [PATCH v3 4/7] iio:dac:ad5686: Add support for AD5685R
  2018-04-11 11:52     ` [PATCH v3 4/7] " Stefan Popa
@ 2018-04-15 18:20       ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2018-04-15 18:20 UTC (permalink / raw)
  To: Stefan Popa
  Cc: Michael.Hennerich, lars, knaack.h, pmeerw, linux-iio, linux-kernel

On Wed, 11 Apr 2018 14:52:48 +0300
Stefan Popa <stefan.popa@analog.com> wrote:

> This driver acctually supports the AD5685R device and NOT the AD5685, which
> does not exist.
> 
> More information can be found in the datasheet:
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686_5684.pdf
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Hmm. Problem here is if there are devicetrees out there using the wrong name.
We can't be sure there aren't. So right option is to keep both in the id table.

I've modified the patch to include the wrong name with a note saying it
doesn't actually exist.

Hope that is fine with you

Thanks,

Jonathan

> ---
> Changes in v2:
> 	- Refactored the patch to add support for new parts
> Changes in v3:
> 	- Nothing changed, just to follow the patch set version.
> 
>  drivers/iio/dac/ad5686.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 87d6e6e..a753ffd 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -88,7 +88,7 @@ struct ad5686_state {
>  
>  enum ad5686_supported_device_ids {
>  	ID_AD5684,
> -	ID_AD5685,
> +	ID_AD5685R,
>  	ID_AD5686,
>  };
>  static int ad5686_spi_write(struct ad5686_state *st,
> @@ -303,7 +303,7 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
>  		.num_channels = 4,
>  		.int_vref_mv = 2500,
>  	},
> -	[ID_AD5685] = {
> +	[ID_AD5685R] = {
>  		.channels = ad5685r_channels,
>  		.int_vref_mv = 2500,
>  		.num_channels = 4,
> @@ -392,7 +392,7 @@ static int ad5686_remove(struct spi_device *spi)
>  
>  static const struct spi_device_id ad5686_id[] = {
>  	{"ad5684", ID_AD5684},
> -	{"ad5685", ID_AD5685},
> +	{"ad5685r", ID_AD5685R},
>  	{"ad5686", ID_AD5686},
>  	{}
>  };

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

* Re: [PATCH v3 5/7] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support
  2018-04-11 11:53     ` [PATCH v3 5/7] " Stefan Popa
@ 2018-04-15 18:23       ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2018-04-15 18:23 UTC (permalink / raw)
  To: Stefan Popa
  Cc: Michael.Hennerich, lars, knaack.h, pmeerw, linux-iio, linux-kernel

On Wed, 11 Apr 2018 14:53:01 +0300
Stefan Popa <stefan.popa@analog.com> wrote:

> The AD5684R/AD5686R are a family of 4 channel DACs with 12-bit, 14-bit and
> 16-bit precision respectively. The devices come either with a built-in
> reference or no built-in reference.
> 
> The AD5672R/AD5676/AD5676R are similar, except that they have 8 channels
> instead of 4.
> 
> Datasheets:
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD5672R_5676R.pdf
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD5686R_5685R_5684R.pdf
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Applied.  My tweak to the previous patch made this fiddly, so please
check I didn't mess it up.

Thanks,

Jonathan

> ---
> Changes in v2:
> 	- Refactored the patch to add support for new parts
> Changes in v3:
> 	- Nothing changed, just to follow the patch set version
> 
>  drivers/iio/dac/ad5686.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index a753ffd..54f67d5 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -87,9 +87,14 @@ struct ad5686_state {
>   */
>  
>  enum ad5686_supported_device_ids {
> +	ID_AD5672R,
> +	ID_AD5676,
> +	ID_AD5676R,
>  	ID_AD5684,
> +	ID_AD5684R,
>  	ID_AD5685R,
>  	ID_AD5686,
> +	ID_AD5686R
>  };
>  static int ad5686_spi_write(struct ad5686_state *st,
>  			     u8 cmd, u8 addr, u16 val, u8 shift)
> @@ -293,15 +298,47 @@ static struct iio_chan_spec name[] = {				\
>  		AD5868_CHANNEL(3, 8, bits, _shift),		\
>  }
>  
> +#define DECLARE_AD5676_CHANNELS(name, bits, _shift)		\
> +static struct iio_chan_spec name[] = {				\
> +		AD5868_CHANNEL(0, 0, bits, _shift),		\
> +		AD5868_CHANNEL(1, 1, bits, _shift),		\
> +		AD5868_CHANNEL(2, 2, bits, _shift),		\
> +		AD5868_CHANNEL(3, 3, bits, _shift),		\
> +		AD5868_CHANNEL(4, 4, bits, _shift),		\
> +		AD5868_CHANNEL(5, 5, bits, _shift),		\
> +		AD5868_CHANNEL(6, 6, bits, _shift),		\
> +		AD5868_CHANNEL(7, 7, bits, _shift),		\
> +}
> +
> +DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4);
> +DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0);
>  DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4);
>  DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2);
>  DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0);
>  
>  static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
> +	[ID_AD5672R] = {
> +		.channels = ad5672_channels,
> +		.int_vref_mv = 2500,
> +		.num_channels = 8,
> +	},
> +	[ID_AD5676] = {
> +		.channels = ad5676_channels,
> +		.num_channels = 8,
> +	},
> +	[ID_AD5676R] = {
> +		.channels = ad5676_channels,
> +		.int_vref_mv = 2500,
> +		.num_channels = 8,
> +	},
>  	[ID_AD5684] = {
>  		.channels = ad5684_channels,
>  		.num_channels = 4,
> +	},
> +	[ID_AD5684R] = {
> +		.channels = ad5684_channels,
>  		.int_vref_mv = 2500,
> +		.num_channels = 4,
>  	},
>  	[ID_AD5685R] = {
>  		.channels = ad5685r_channels,
> @@ -311,7 +348,11 @@ static const struct ad5686_chip_info ad5686_chip_info_tbl[] = {
>  	[ID_AD5686] = {
>  		.channels = ad5686_channels,
>  		.num_channels = 4,
> +	},
> +	[ID_AD5686R] = {
> +		.channels = ad5686_channels,
>  		.int_vref_mv = 2500,
> +		.num_channels = 4,
>  	},
>  };
>  
> @@ -391,9 +432,14 @@ static int ad5686_remove(struct spi_device *spi)
>  }
>  
>  static const struct spi_device_id ad5686_id[] = {
> +	{"ad5672r", ID_AD5672R},
> +	{"ad5676", ID_AD5676},
> +	{"ad5676r", ID_AD5676R},
>  	{"ad5684", ID_AD5684},
> +	{"ad5684r", ID_AD5684R},
>  	{"ad5685r", ID_AD5685R},
>  	{"ad5686", ID_AD5686},
> +	{"ad5686r", ID_AD5686R},
>  	{}
>  };
>  MODULE_DEVICE_TABLE(spi, ad5686_id);

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

end of thread, other threads:[~2018-04-15 18:23 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-30 13:55 [PATCH 1/3] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
2018-03-30 13:55 ` [PATCH 2/3] iio:dac:ad5686: Add AD5672R/AD5676/AD5676R/AD5684R/AD5685R/AD5686R support Stefan Popa
2018-04-06 15:19   ` Jonathan Cameron
2018-04-10 15:57   ` [PATCH v2 2/6] iio:dac:ad5686: Add support for various number of channels Stefan Popa
2018-04-11 11:52     ` [PATCH v3 3/7] " Stefan Popa
2018-04-15 18:16       ` Jonathan Cameron
2018-04-10 15:57   ` [PATCH v2 3/6] iio:dac:ad5686: Add support for AD5685R Stefan Popa
2018-04-11 11:52     ` [PATCH v3 4/7] " Stefan Popa
2018-04-15 18:20       ` Jonathan Cameron
2018-04-10 15:57   ` [PATCH v2 4/6] iio:dac:ad5686: Add AD5672R/76/76R/84R/86R support Stefan Popa
2018-04-11 11:53     ` [PATCH v3 5/7] " Stefan Popa
2018-04-15 18:23       ` Jonathan Cameron
2018-04-10 15:56 ` [PATCH v2 1/6] iio:dac:ad5686: Style fixes no functional changes Stefan Popa
2018-04-11 11:51   ` [PATCH v3 1/7] " Stefan Popa
2018-04-15 18:11     ` 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).