Re: [PATCH 1/2] iio: adc: Add ad7124 support

2018-10-21 Thread Jonathan Cameron
On Thu, 18 Oct 2018 14:04:53 +0300
Stefan Popa  wrote:

> The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
> with 24-bit precision and reference.
> 
> Three power modes are available which in turn affect the output data rate:
>  * Full power: 9.38 SPS to 19,200 SPS
>  * Mid power: 2.34 SPS to 4800 SPS
>  * Low power: 1.17 SPS to 2400 SPS
> 
> The ad7124-4 can be configured to have four differential inputs, while
> ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> configuration. Each configuration consists of gain, reference source,
> output data rate and bipolar/unipolar configuration.
> 
> Datasheets:
> Link: 
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
> Link: 
> http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf
> 
> Signed-off-by: Stefan Popa 

Hi Stefan,

Just a couple of small things from me. See inline.

Thanks,

Jonathan
> ---
>  MAINTAINERS  |   7 +
>  drivers/iio/adc/Kconfig  |  11 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ad7124.c | 655 
> +++
>  4 files changed, 674 insertions(+)
>  create mode 100644 drivers/iio/adc/ad7124.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index f642044..3a1bfcb 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -839,6 +839,13 @@ S:   Supported
>  F:   drivers/iio/dac/ad5758.c
>  F:   Documentation/devicetree/bindings/iio/dac/ad5758.txt
>  
> +ANALOG DEVICES INC AD7124 DRIVER
> +M:   Stefan Popa 
> +L:   linux-...@vger.kernel.org
> +W:   http://ez.analog.com/community/linux-device-drivers
> +S:   Supported
> +F:   drivers/iio/adc/ad7124.c
> +
>  ANALOG DEVICES INC AD9389B DRIVER
>  M:   Hans Verkuil 
>  L:   linux-me...@vger.kernel.org
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index a52fea8..148a10f 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
>   select IIO_BUFFER
>   select IIO_TRIGGERED_BUFFER
>  
> +config AD7124
> + tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
> + depends on SPI_MASTER
> + select AD_SIGMA_DELTA
> + help
> +   Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
> +   SPI analog to digital converters (ADC).
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called ad7124.
> +
>  config AD7266
>   tristate "Analog Devices AD7265/AD7266 ADC driver"
>   depends on SPI_MASTER
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index a6e6a0b..76168b2 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -5,6 +5,7 @@
>  
>  # When adding new entries keep the list in alphabetical order
>  obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
> +obj-$(CONFIG_AD7124) += ad7124.o
>  obj-$(CONFIG_AD7266) += ad7266.o
>  obj-$(CONFIG_AD7291) += ad7291.o
>  obj-$(CONFIG_AD7298) += ad7298.o
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> new file mode 100644
> index 000..c6d9798
> --- /dev/null
> +++ b/drivers/iio/adc/ad7124.c
> @@ -0,0 +1,655 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * AD7124 SPI ADC driver
> + *
> + * Copyright 2018 Analog Devices Inc.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +/* AD7124 registers */
> +#define AD7124_COMMS 0x00
> +#define AD7124_STATUS0x00
> +#define AD7124_ADC_CONTROL   0x01
> +#define AD7124_DATA  0x02
> +#define AD7124_IO_CONTROL_1  0x03
> +#define AD7124_IO_CONTROL_2  0x04
> +#define AD7124_ID0x05
> +#define AD7124_ERROR 0x06
> +#define AD7124_ERROR_EN  0x07
> +#define AD7124_MCLK_COUNT0x08
> +#define AD7124_CHANNEL(x)(0x09 + (x))
> +#define AD7124_CONFIG(x) (0x19 + (x))
> +#define AD7124_FILTER(x) (0x21 + (x))
> +#define AD7124_OFFSET(x) (0x29 + (x))
> +#define AD7124_GAIN(x)   (0x31 + (x))
> +
> +/* AD7124_STATUS */
> +#define AD7124_STATUS_POR_FLAG_MSK   BIT(4)
> +
> +/* AD7124_ADC_CONTROL */
> +#define AD7124_ADC_CTRL_PWR_MSK  GENMASK(7, 6)
> +#define AD7124_ADC_CTRL_PWR(x)   
> FIELD_PREP(AD7124_ADC_CTRL_PWR_MSK, x)
> +#define AD7124_ADC_CTRL_MODE_MSK GENMASK(5, 2)
> +#define AD7124_ADC_CTRL_MODE(x)  FIELD_PREP(AD7124_ADC_CTRL_MODE_MSK, x)
> +
> +/* AD7124_CHANNEL_X */
> +#define AD7124_CHANNEL_EN_MSKBIT(15)
> +#define AD7124_CHANNEL_EN(x) FIELD_PREP(AD7124_CHANNEL_EN_MSK, x)
> +#define AD7124_CHANNEL_SETUP_MSK GENMASK(14, 12)
> +#define AD7124_CHANNEL_SETUP(x)  FIELD_PREP(AD7124_CHANNEL_SETUP_MSK, x)
> +#define AD7124_CHANNEL_AINP_MSK  GENMASK(9, 5)
> +

Re: [PATCH 1/2] iio: adc: Add ad7124 support

2018-10-18 Thread kbuild test robot
Hi Stefan,

I love your patch! Yet something to improve:

[auto build test ERROR on iio/togreg]
[also build test ERROR on v4.19-rc8 next-20181018]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Stefan-Popa/iio-adc-Add-ad7124-support/20181019-051737
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

All error/warnings (new ones prefixed by >>):

>> drivers/iio//adc/ad7124.c:215:3: error: 'const struct ad_sigma_delta_info' 
>> has no member named 'data_reg'
 .data_reg = AD7124_DATA,
  ^~~~
>> drivers/iio//adc/ad7124.c:25:23: warning: excess elements in struct 
>> initializer
#define AD7124_DATA   0x02
  ^
>> drivers/iio//adc/ad7124.c:215:14: note: in expansion of macro 'AD7124_DATA'
 .data_reg = AD7124_DATA,
 ^~~
   drivers/iio//adc/ad7124.c:25:23: note: (near initialization for 
'ad7124_sigma_delta_info')
#define AD7124_DATA   0x02
  ^
>> drivers/iio//adc/ad7124.c:215:14: note: in expansion of macro 'AD7124_DATA'
 .data_reg = AD7124_DATA,
 ^~~

vim +215 drivers/iio//adc/ad7124.c

20  
21  /* AD7124 registers */
22  #define AD7124_COMMS0x00
23  #define AD7124_STATUS   0x00
24  #define AD7124_ADC_CONTROL  0x01
  > 25  #define AD7124_DATA 0x02
26  #define AD7124_IO_CONTROL_1 0x03
27  #define AD7124_IO_CONTROL_2 0x04
28  #define AD7124_ID   0x05
29  #define AD7124_ERROR0x06
30  #define AD7124_ERROR_EN 0x07
31  #define AD7124_MCLK_COUNT   0x08
32  #define AD7124_CHANNEL(x)   (0x09 + (x))
33  #define AD7124_CONFIG(x)(0x19 + (x))
34  #define AD7124_FILTER(x)(0x21 + (x))
35  #define AD7124_OFFSET(x)(0x29 + (x))
36  #define AD7124_GAIN(x)  (0x31 + (x))
37  
38  /* AD7124_STATUS */
39  #define AD7124_STATUS_POR_FLAG_MSK  BIT(4)
40  
41  /* AD7124_ADC_CONTROL */
42  #define AD7124_ADC_CTRL_PWR_MSK GENMASK(7, 6)
43  #define AD7124_ADC_CTRL_PWR(x)  
FIELD_PREP(AD7124_ADC_CTRL_PWR_MSK, x)
44  #define AD7124_ADC_CTRL_MODE_MSKGENMASK(5, 2)
45  #define AD7124_ADC_CTRL_MODE(x) FIELD_PREP(AD7124_ADC_CTRL_MODE_MSK, x)
46  
47  /* AD7124_CHANNEL_X */
48  #define AD7124_CHANNEL_EN_MSK   BIT(15)
49  #define AD7124_CHANNEL_EN(x)
FIELD_PREP(AD7124_CHANNEL_EN_MSK, x)
50  #define AD7124_CHANNEL_SETUP_MSKGENMASK(14, 12)
51  #define AD7124_CHANNEL_SETUP(x) FIELD_PREP(AD7124_CHANNEL_SETUP_MSK, x)
52  #define AD7124_CHANNEL_AINP_MSK GENMASK(9, 5)
53  #define AD7124_CHANNEL_AINP(x)  
FIELD_PREP(AD7124_CHANNEL_AINP_MSK, x)
54  #define AD7124_CHANNEL_AINM_MSK GENMASK(4, 0)
55  #define AD7124_CHANNEL_AINM(x)  
FIELD_PREP(AD7124_CHANNEL_AINM_MSK, x)
56  
57  /* AD7124_CONFIG_X */
58  #define AD7124_CONFIG_BIPOLAR_MSK   BIT(11)
59  #define AD7124_CONFIG_BIPOLAR(x)
FIELD_PREP(AD7124_CONFIG_BIPOLAR_MSK, x)
60  #define AD7124_CONFIG_REF_SEL_MSK   GENMASK(4, 3)
61  #define AD7124_CONFIG_REF_SEL(x)
FIELD_PREP(AD7124_CONFIG_REF_SEL_MSK, x)
62  #define AD7124_CONFIG_PGA_MSK   GENMASK(2, 0)
63  #define AD7124_CONFIG_PGA(x)
FIELD_PREP(AD7124_CONFIG_PGA_MSK, x)
64  
65  /* AD7124_FILTER_X */
66  #define AD7124_FILTER_FS_MSKGENMASK(10, 0)
67  #define AD7124_FILTER_FS(x) 
FIELD_PREP(AD7124_FILTER_FS_MSK, x)
68  
69  enum ad7124_ids {
70  ID_AD7124_4,
71  ID_AD7124_8,
72  };
73  
74  enum ad7124_ref_sel {
75  AD7124_REFIN1,
76  AD7124_REFIN2,
77  AD7124_INT_REF,
78  AD7124_AVDD_REF,
79  };
80  
81  enum ad7124_power_mode {
82  AD7124_LOW_POWER,
83  AD7124_MID_POWER,
84  AD7124_FULL_POWER,
85  };
86  
87  static const unsigned int ad7124_gain[8] = {
88  1, 2, 4, 8, 16, 32, 64, 128
89  };
90  
91  static const int ad7124_master_clk_freq_hz[3] = {
92  [AD7124_LOW_POWER] = 76800,
93  [AD7124_MID_POWER] = 153600,
94  [AD7124_FULL_POWER] = 614400,
95  };
96  
97  static const char * const ad7124_ref_nam

[PATCH 1/2] iio: adc: Add ad7124 support

2018-10-18 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 655 +++
 4 files changed, 674 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..c6d9798
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,655 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x)  (0x09 + (x))
+#define AD7124_CONFIG(x)   (0x19 + (x))
+#define AD7124_FILTER(x)   (0x21 + (x))
+#define AD7124_OFFSET(x)   (0x29 + (x))
+#define AD7124_GAIN(x) (0x31 + (x))
+
+/* AD7124_STATUS */
+#define AD7124_STATUS_POR_FLAG_MSK BIT(4)
+
+/* AD7124_ADC_CONTROL */
+#define AD7124_ADC_CTRL_PWR_MSKGENMASK(7, 6)
+#define AD7124_ADC_CTRL_PWR(x) FIELD_PREP(AD7124_ADC_CTRL_PWR_MSK, x)
+#define AD7124_ADC_CTRL_MODE_MSK   GENMASK(5, 2)
+#define AD7124_ADC_CTRL_MODE(x)FIELD_PREP(AD7124_ADC_CTRL_MODE_MSK, x)
+
+/* AD7124_CHANNEL_X */
+#define AD7124_CHANNEL_EN_MSK  BIT(15)
+#define AD7124_CHANNEL_EN(x)   FIELD_PREP(AD7124_CHANNEL_EN_MSK, x)
+#define AD7124_CHANNEL_SETUP_MSK   GENMASK(14, 12)
+#define AD7124_CHANNEL_SETUP(x)FIELD_PREP(AD7124_CHANNEL_SETUP_MSK, x)
+#define AD7124_CHANNEL_AINP_MSKGENMASK(9, 5)
+#define AD7124_CHANNEL_AINP(x) FIELD_PREP(AD7124_CHANNEL_AINP_MSK, x)
+#define AD7124_CHANNEL_AINM_MSKGENMASK(4, 0)
+#define AD7124_CHANNEL_AINM(x) FIELD_PREP(AD7124_CHANNEL_AINM_MSK, x)
+
+/* AD7124_CONFIG_X */
+#define AD7124_CONFIG_BIPOLAR_MSK  BIT(11)
+#define AD7124_CONFIG_BIPOLAR(x)   FIELD_PREP(AD7124_CONFIG_BIPOLAR_MSK, x)
+#de